001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.j2ee.api.ejbjar;
042:
043: import org.netbeans.api.project.Project;
044: import org.netbeans.modules.j2ee.ejbjar.CarAccessor;
045: import org.netbeans.modules.j2ee.spi.ejbjar.CarImplementation;
046: import org.netbeans.modules.j2ee.spi.ejbjar.CarProvider;
047: import org.netbeans.modules.j2ee.spi.ejbjar.CarsInProject;
048: import org.openide.filesystems.FileObject;
049: import org.openide.util.Lookup;
050:
051: /**
052: * Car should be used to access properties of an Enterprise application client module.
053: * <p>
054: * A client may obtain a Car instance using
055: * <code>Car.getCar(fileObject)</code> static method, for any
056: * FileObject in the application client module directory structure.
057: * </p>
058: * <div class="nonnormative">
059: * Note that the particular directory structure for application client module
060: * is not guaranteed by this API.
061: * </div>
062: *
063: *
064: * @author Pavel Buzek
065: * @author Lukas Jungmann
066: */
067: public final class Car {
068: private CarImplementation impl;
069: private static final Lookup.Result<CarProvider> implementations = Lookup
070: .getDefault()
071: .lookup(new Lookup.Template<CarProvider>(CarProvider.class));
072:
073: static {
074: CarAccessor.DEFAULT = new CarAccessor() {
075: public Car createCar(CarImplementation spiEjbJar) {
076: return new Car(spiEjbJar);
077: }
078:
079: public CarImplementation getCarImplementation(Car wm) {
080: return wm == null ? null : wm.impl;
081: }
082: };
083: }
084:
085: private Car(CarImplementation impl) {
086: if (impl == null)
087: throw new IllegalArgumentException();
088: this .impl = impl;
089: }
090:
091: /**
092: * Find the Car for given file or null if the file does not belong
093: * to any application client module.
094: */
095: public static Car getCar(FileObject f) {
096: if (f == null) {
097: throw new NullPointerException(
098: "Passed null to Car.getCar(FileObject)"); // NOI18N
099: }
100: for (CarProvider impl : implementations.allInstances()) {
101: Car wm = impl.findCar(f);
102: if (wm != null) {
103: return wm;
104: }
105: }
106: return null;
107: }
108:
109: /** Find Car(s) for all application clients within a given project.
110: * @return an array of Car instance (empty array if no instance are found).
111: */
112: public static Car[] getCars(Project project) {
113: CarsInProject providers = project.getLookup().lookup(
114: CarsInProject.class);
115: if (providers != null) {
116: Car jars[] = providers.getCars();
117: if (jars != null) {
118: return jars;
119: }
120: }
121: return new Car[] {};
122: }
123:
124: /** J2EE platform version - one of the constants
125: * defined in {@link org.netbeans.modules.j2ee.api.common.J2eeProjectConstants}.
126: * @return J2EE platform version
127: */
128: public String getJ2eePlatformVersion() {
129: return impl.getJ2eePlatformVersion();
130: }
131:
132: /** Deployment descriptor (application-client.xml file) of the application client module.
133: */
134: public FileObject getDeploymentDescriptor() {
135: return impl.getDeploymentDescriptor();
136: }
137:
138: /** Source roots associated with the Car module.
139: * <div class="nonnormative">
140: * Note that not all the java source roots in the project (e.g. in a freeform project)
141: * belong to the Car module.
142: * </div>
143: */
144: public FileObject[] getJavaSources() {
145: return impl.getJavaSources();
146: }
147:
148: /** Meta-inf
149: */
150: public FileObject getMetaInf() {
151: return impl.getMetaInf();
152: }
153: }
|