KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > api > ejbjar > EjbJar


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.api.ejbjar;
20
21 import java.util.Iterator JavaDoc;
22 import org.netbeans.api.project.Project;
23 import org.netbeans.modules.j2ee.ejbjar.EjbJarAccessor;
24 import org.netbeans.modules.j2ee.metadata.MetadataUnit;
25 import org.netbeans.modules.j2ee.spi.ejbjar.*;
26 import org.netbeans.modules.j2ee.spi.ejbjar.EjbJarProvider;
27 import org.openide.filesystems.FileObject;
28 import org.openide.util.Lookup;
29
30 /**
31  * EjbJar should be used to access properties of an ejb jar module.
32  * <p>
33  * A client may obtain an EjbJar instance using {@link EjbJar#getEjbJar} method
34  * for any FileObject in the ejb jar module directory structure.
35  * </p>
36  * <div class="nonnormative">
37  * Note that the particular directory structure for ejb jar module is not guaranteed
38  * by this API.
39  * </div>
40  *
41  * @author Pavel Buzek
42  */

43 public final class EjbJar {
44     
45     private EjbJarImplementation impl;
46     private static final Lookup.Result<EjbJarProvider> implementations =
47         Lookup.getDefault().lookup(new Lookup.Template<EjbJarProvider>(EjbJarProvider.class));
48     
49     static {
50         EjbJarAccessor.DEFAULT = new EjbJarAccessor() {
51             public EjbJar createEjbJar(EjbJarImplementation spiEjbJar) {
52                 return new EjbJar(spiEjbJar);
53             }
54
55             public EjbJarImplementation getEjbJarImplementation(EjbJar wm) {
56                 return wm == null ? null : wm.impl;
57             }
58         };
59     }
60     
61     private EjbJar (EjbJarImplementation impl) {
62         if (impl == null)
63             throw new IllegalArgumentException JavaDoc ();
64         this.impl = impl;
65     }
66     
67     /** Find the EjbJar for given file or null if the file does not belong
68      * to any web module.
69      */

70     public static EjbJar getEjbJar (FileObject f) {
71         if (f == null) {
72             throw new NullPointerException JavaDoc("Passed null to EjbJar.getEjbJar(FileObject)"); // NOI18N
73
}
74         for (EjbJarProvider impl : implementations.allInstances()) {
75             EjbJar wm = impl.findEjbJar (f);
76             if (wm != null) {
77                 return wm;
78             }
79         }
80         return null;
81     }
82
83     /** Find EjbJar(s) for all ejb modules within a given project.
84      * @return an array of EjbJar instance (empty array if no instance are found).
85      */

86     public static EjbJar [] getEjbJars (Project project) {
87         EjbJarsInProject providers = project.getLookup().lookup(EjbJarsInProject.class);
88         if (providers != null) {
89             EjbJar jars [] = providers.getEjbJars();
90             if (jars != null) {
91                 return jars;
92             }
93         }
94         return new EjbJar[] {};
95     }
96     
97     /** J2EE platform version - one of the constants
98      * defined in {@link org.netbeans.modules.j2ee.api.common.EjbProjectConstants}.
99      * @return J2EE platform version
100      */

101     public String JavaDoc getJ2eePlatformVersion () {
102         return impl.getJ2eePlatformVersion();
103     }
104     
105     /**
106      * Deployment descriptor (ejb-jar.xml file) of an ejb module.
107      *
108      * @return descriptor FileObject or <code>null</code> if not available.
109      */

110     public FileObject getDeploymentDescriptor () {
111         return impl.getDeploymentDescriptor();
112     }
113
114     /** Source roots associated with the EJB module.
115      * <div class="nonnormative">
116      * Note that not all the java source roots in the project (e.g. in a freeform project)
117      * belong to the EJB module.
118      * </div>
119      */

120     public FileObject[] getJavaSources() {
121         return impl.getJavaSources();
122     }
123     
124     /** Meta-inf
125      */

126     public FileObject getMetaInf() {
127         return impl.getMetaInf();
128     }
129
130     /**
131      * Coupling of deployment desrciptor and classpath containing annotated classes
132      * describing metadata of the EJB module
133      *
134      * @return non-null value
135      */

136     public MetadataUnit getMetadataUnit() {
137         return impl.getMetadataUnit();
138     }
139     
140 }
141
Popular Tags