KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.modules.j2ee.ejbjar.EarAccessor;
22 import org.netbeans.modules.j2ee.spi.ejbjar.EarImplementation;
23 import org.netbeans.modules.j2ee.spi.ejbjar.EarProvider;
24 import org.netbeans.modules.j2ee.spi.ejbjar.EarProvider;
25 import org.netbeans.modules.web.api.webmodule.WebModule;
26 import org.openide.filesystems.FileObject;
27 import org.openide.util.Lookup;
28
29 /**
30  * Ear should be used to access properties of an ear module.
31  * <p>
32  * A client may obtain a Ear instance using
33  * <code>Ear.getEar(fileObject)</code> static method, for any
34  * FileObject in the ear module directory structure.
35  * </p>
36  * <div class="nonnormative">
37  * Note that the particular directory structure for ear module is not guaranteed
38  * by this API.
39  * </div>
40  *
41  * @author Pavel Buzek
42  */

43 public final class Ear {
44     
45     private final EarImplementation impl;
46     private static final Lookup.Result<EarProvider> implementations =
47         Lookup.getDefault().lookup(new Lookup.Template<EarProvider>(EarProvider.class));
48     
49     static {
50         EarAccessor.DEFAULT = new EarAccessor() {
51             public Ear createEar(EarImplementation spiEar) {
52                 return new Ear(spiEar);
53             }
54
55             public EarImplementation getEarImplementation(Ear wm) {
56                 return wm == null ? null : wm.impl;
57             }
58         };
59     }
60     
61     private Ear (EarImplementation impl) {
62         if (impl == null)
63             throw new IllegalArgumentException JavaDoc ();
64         this.impl = impl;
65     }
66     
67     /**
68      * Find the Ear for given file or <code>null</code> if the file does not
69      * belong to any Enterprise Application.
70      */

71     public static Ear getEar (FileObject f) {
72         if (f == null) {
73             throw new NullPointerException JavaDoc("Passed null to Ear.getEar(FileObject)"); // NOI18N
74
}
75         for (EarProvider earProvider : implementations.allInstances()) {
76             Ear wm = earProvider.findEar(f);
77             if (wm != null) {
78                 return wm;
79             }
80         }
81         return null;
82     }
83
84     
85     /** J2EE platform version - one of the constants
86      * defined in {@link org.netbeans.modules.j2ee.api.common.EjbProjectConstants}.
87      * @return J2EE platform version
88      */

89     public String JavaDoc getJ2eePlatformVersion () {
90         return impl.getJ2eePlatformVersion();
91     }
92     
93     /** Deployment descriptor (ejb-jar.xml file) of the ejb module.
94      */

95     public FileObject getDeploymentDescriptor () {
96         return impl.getDeploymentDescriptor();
97     }
98     
99     /** Add j2ee webmodule into application.
100      * @param module the module to be added
101      */

102     public void addWebModule (WebModule module) {
103         impl.addWebModule (module);
104     }
105     
106     /** Add j2ee Ejb module into application.
107      * @param module the module to be added
108      */

109     public void addEjbJarModule (EjbJar module) {
110         impl.addEjbJarModule (module);
111     }
112     
113     /** Add j2ee application client module into application.
114      * @param module the module to be added
115      */

116     public void addCarModule(Car module) {
117         impl.addCarModule(module);
118     }
119     
120 }
121
Popular Tags