1 19 package org.netbeans.modules.j2ee.api.ejbjar; 20 21 import java.util.Collections ; 22 import org.netbeans.api.java.classpath.ClassPath; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.modules.j2ee.ejbjar.CarAccessor; 25 import org.netbeans.modules.j2ee.metadata.ClassPathSupport; 26 import org.netbeans.modules.j2ee.metadata.MetadataUnit; 27 import org.netbeans.modules.j2ee.spi.ejbjar.CarImplementation; 28 import org.netbeans.modules.j2ee.spi.ejbjar.CarProvider; 29 import org.netbeans.modules.j2ee.spi.ejbjar.CarsInProject; 30 import org.netbeans.spi.java.classpath.PathResourceImplementation; 31 import org.openide.filesystems.FileObject; 32 import org.openide.util.Lookup; 33 34 50 public final class Car implements MetadataUnit { 51 private CarImplementation impl; 52 private static final Lookup.Result<CarProvider> implementations = 53 Lookup.getDefault().lookup(new Lookup.Template<CarProvider>(CarProvider.class)); 54 55 static { 56 CarAccessor.DEFAULT = new CarAccessor() { 57 public Car createCar(CarImplementation spiEjbJar) { 58 return new Car(spiEjbJar); 59 } 60 61 public CarImplementation getCarImplementation(Car wm) { 62 return wm == null ? null : wm.impl; 63 } 64 }; 65 } 66 67 private Car (CarImplementation impl) { 68 if (impl == null) 69 throw new IllegalArgumentException (); 70 this.impl = impl; 71 } 72 73 77 public static Car getCar (FileObject f) { 78 if (f == null) { 79 throw new NullPointerException ("Passed null to Car.getCar(FileObject)"); } 81 for (CarProvider impl : implementations.allInstances()) { 82 Car wm = impl.findCar (f); 83 if (wm != null) { 84 return wm; 85 } 86 } 87 return null; 88 } 89 90 93 public static Car[] getCars (Project project) { 94 CarsInProject providers = project.getLookup().lookup(CarsInProject.class); 95 if (providers != null) { 96 Car jars [] = providers.getCars(); 97 if (jars != null) { 98 return jars; 99 } 100 } 101 return new Car[] {}; 102 } 103 104 108 public String getJ2eePlatformVersion () { 109 return impl.getJ2eePlatformVersion(); 110 } 111 112 114 public FileObject getDeploymentDescriptor () { 115 return impl.getDeploymentDescriptor(); 116 } 117 118 124 public FileObject[] getJavaSources() { 125 return impl.getJavaSources(); 126 } 127 128 130 public FileObject getMetaInf() { 131 return impl.getMetaInf(); 132 } 133 134 141 public ClassPath getClassPath() { 142 FileObject[] roots = getJavaSources(); 143 if (roots.length > 0) { 144 FileObject fo = roots[0]; 145 return ClassPathSupport.createWeakProxyClassPath(new ClassPath[] { 146 ClassPath.getClassPath(fo, ClassPath.SOURCE), 147 ClassPath.getClassPath(fo, ClassPath.COMPILE) 148 }); 149 } else { 150 return org.netbeans.spi.java.classpath.support.ClassPathSupport.createClassPath(Collections.<PathResourceImplementation>emptyList()); 151 } 152 } 153 } 154 | Popular Tags |