1 19 20 package org.netbeans.modules.web.api.webmodule; 21 22 import java.util.Collections ; 23 import java.util.Iterator ; 24 import org.netbeans.api.java.classpath.ClassPath; 25 import org.netbeans.modules.j2ee.metadata.ClassPathSupport; 26 import org.netbeans.modules.j2ee.metadata.MetadataUnit; 27 import org.netbeans.modules.web.webmodule.WebModuleAccessor; 28 import org.netbeans.modules.web.spi.webmodule.*; 29 import org.openide.filesystems.FileObject; 30 import org.openide.util.Lookup; 31 32 55 public final class WebModule implements MetadataUnit { 56 57 public static final String J2EE_13_LEVEL = "1.3"; public static final String J2EE_14_LEVEL = "1.4"; public static final String JAVA_EE_5_LEVEL = "1.5"; 62 private WebModuleImplementation impl; 63 private static final Lookup.Result implementations = 64 Lookup.getDefault().lookup(new Lookup.Template(WebModuleProvider.class)); 65 66 static { 67 WebModuleAccessor.DEFAULT = new WebModuleAccessor() { 68 public WebModule createWebModule(WebModuleImplementation spiWebmodule) { 69 return new WebModule(spiWebmodule); 70 } 71 72 public WebModuleImplementation getWebModuleImplementation(WebModule wm) { 73 return wm == null ? null : wm.impl; 74 } 75 }; 76 } 77 78 private WebModule (WebModuleImplementation impl) { 79 if (impl == null) 80 throw new IllegalArgumentException (); 81 this.impl = impl; 82 } 83 84 87 public static WebModule getWebModule (FileObject f) { 88 if (f == null) { 89 throw new NullPointerException ("Passed null to WebModule.getWebModule(FileObject)"); } 91 Iterator it = implementations.allInstances().iterator(); 92 while (it.hasNext()) { 93 WebModuleProvider impl = (WebModuleProvider)it.next(); 94 WebModule wm = impl.findWebModule (f); 95 if (wm != null) { 96 return wm; 97 } 98 } 99 return null; 100 } 101 102 105 public FileObject getDocumentBase () { 106 return impl.getDocumentBase (); 107 } 108 109 116 public FileObject getWebInf () { 117 return impl.getWebInf (); 118 } 119 120 126 public FileObject getDeploymentDescriptor () { 127 return impl.getDeploymentDescriptor (); 128 } 129 130 132 public String getContextPath () { 133 return impl.getContextPath (); 134 } 135 136 140 public String getJ2eePlatformVersion () { 141 return impl.getJ2eePlatformVersion (); 142 } 143 144 150 public FileObject[] getJavaSources() { 151 return impl.getJavaSources(); 152 } 153 154 156 public boolean equals (Object obj) { 157 if (obj == null) { 158 return false; 159 } 160 if (!WebModule.class.isAssignableFrom(obj.getClass())) 161 return false; 162 WebModule wm = (WebModule) obj; 163 return getDocumentBase().equals(wm.getDocumentBase()) 164 && getJ2eePlatformVersion().equals (wm.getJ2eePlatformVersion()) 165 && getContextPath().equals(wm.getContextPath()); 166 } 167 168 public int hashCode () { 169 return getDocumentBase ().getPath ().length () + getContextPath ().length (); 170 } 171 172 public ClassPath getClassPath() { 173 FileObject[] roots = getJavaSources(); 174 if (roots.length > 0) { 175 FileObject fo = roots[0]; 176 return ClassPathSupport.createWeakProxyClassPath(new ClassPath[] { 177 ClassPath.getClassPath(fo, ClassPath.SOURCE), 178 ClassPath.getClassPath(fo, ClassPath.COMPILE) 179 }); 180 } else { 181 return org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath(Collections.emptyList()); 182 } 183 } 184 } 185 | Popular Tags |