KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > RootDeploymentDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment;
24
25 import java.util.*;
26 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
27 import java.util.logging.*;
28 import com.sun.enterprise.deployment.util.DOLUtils;
29
30 /**
31  * This descriptor contains all common information amongst root element
32  * of the J2EE Deployment Descriptors (application, ejb-jar, web-app,
33  * connector...).
34  *
35  * @author Jerome Dochez
36  */

37 public abstract class RootDeploymentDescriptor extends Descriptor {
38     
39     /**
40      * each module is uniquely identified with a moduleID
41      */

42     protected String JavaDoc moduleID;
43     
44     /**
45      * version of the specification loaded by this descriptor
46      */

47     private String JavaDoc specVersion;
48     
49     /**
50      * class loader associated to this module to load classes
51      * contained in the archive file
52      */

53     protected ClassLoader JavaDoc classLoader = null;
54
55     /**
56      * key is the URI representing PURoot.
57      */

58     protected Map<String JavaDoc, PersistenceUnitsDescriptor> persistenceUnitsDescriptors
59             = new HashMap<String JavaDoc, PersistenceUnitsDescriptor>();
60
61     /**
62      * Construct a new RootDeploymentDescriptor
63      */

64     public RootDeploymentDescriptor() {
65         super();
66     }
67     
68     /**
69      * Construct a new RootDeploymentDescriptor with a name and description
70      */

71     public RootDeploymentDescriptor(String JavaDoc name, String JavaDoc description) {
72         super(name, description);
73     }
74     
75     /**
76      * each module is uniquely identified with a moduleID
77      * @param moduleID for this module
78      */

79     public void setModuleID(String JavaDoc moduleID) {
80         this.moduleID = moduleID;
81     }
82     
83     /**
84      * @return the module ID for this module descriptor
85      */

86     public abstract String JavaDoc getModuleID();
87
88     /**
89      * @return the default version of the deployment descriptor
90      * loaded by this descriptor
91      */

92     public abstract String JavaDoc getDefaultSpecVersion();
93
94         
95     /**
96      * @return the specification version of the deployment descriptor
97      * loaded by this descriptor
98      */

99     public String JavaDoc getSpecVersion() {
100         if (specVersion == null) {
101             specVersion = getDefaultSpecVersion();
102         }
103         try {
104             Double.parseDouble(specVersion);
105         } catch (NumberFormatException JavaDoc nfe) {
106             DOLUtils.getDefaultLogger().log(Level.WARNING, "invalidSpecVersion",
107                 new Object JavaDoc[] {specVersion, getDefaultSpecVersion()});
108             specVersion = getDefaultSpecVersion();
109         }
110
111         return specVersion;
112     }
113     
114     /**
115      * Sets the specification version of the deployment descriptor
116      * @param specVersion version number
117      */

118     public void setSpecVersion(String JavaDoc specVersion) {
119         this.specVersion = specVersion;
120     }
121     
122     /**
123      * @return the module type for this bundle descriptor
124      */

125     public abstract ModuleType JavaDoc getModuleType();
126
127     /**
128      * Sets the class loader for this application
129      */

130     public void setClassLoader(ClassLoader JavaDoc classLoader) {
131         this.classLoader = classLoader;
132     }
133     
134     /**
135      * @return the class loader associated with this module
136      */

137     public abstract ClassLoader JavaDoc getClassLoader();
138
139     /**
140      * sets the display name for this bundle
141      */

142     public void setDisplayName(String JavaDoc name) {
143         super.setName(name);
144     }
145     
146     /**
147      * @return the display name
148      */

149     public String JavaDoc getDisplayName() {
150         return super.getName();
151     }
152     
153     /**
154      * as of J2EE1.4, get/setName are deprecated,
155      * people should use the set/getDisplayName or
156      * the set/getModuleID.
157      */

158     public void setName(String JavaDoc name) {
159         setModuleID(name);
160     }
161     
162     /**
163      * as of J2EE1.4, get/setName are deprecated,
164      * people should use the set/getDisplayName or
165      * the set/getModuleID.
166      * note : backward compatibility
167      */

168     public String JavaDoc getName() {
169         if (getModuleID()!=null) {
170             return getModuleID();
171         } else {
172             return getDisplayName();
173         }
174     }
175         
176     public void setSchemaLocation(String JavaDoc schemaLocation) {
177         addExtraAttribute("schema-location", schemaLocation);
178     }
179     
180     public String JavaDoc getSchemaLocation() {
181         return (String JavaDoc) getExtraAttribute("schema-location");
182     }
183     
184     /**
185      * @return true if this module is an application object
186      */

187     public abstract boolean isApplication();
188     
189     /**
190      * print a meaningful string for this object
191      */

192     public void print(StringBuffer JavaDoc toStringBuffer) {
193         super.print(toStringBuffer);
194         toStringBuffer.append("\n Module Type = ").append(getModuleType());
195         toStringBuffer.append("\n Module spec version = ").append(getSpecVersion());
196         if (moduleID!=null)
197             toStringBuffer.append("\n Module ID = ").append(moduleID);
198         if (getSchemaLocation()!=null)
199             toStringBuffer.append("\n Client SchemaLocation = ").append(getSchemaLocation());
200     }
201
202     /**
203      * This method returns PersistenceUnitDescriptor objects in the
204      * scope of this RootDeploymentDescriptor.
205      * @return it returns an unmodifiable collection.
206      * returns an empty collection if there is no PersistenceUnitDescriptor.
207      */

208     public Collection<PersistenceUnitsDescriptor> getPersistenceUnitsDescriptors() {
209         return Collections.unmodifiableCollection(persistenceUnitsDescriptors.values());
210     }
211
212     /**
213      * This method returns PersistenceUnitDescriptor object with matching
214      * PURoot in the scope of this RootDeploymentDescriptor.
215      * @param puRoot used for lookup
216      * @return return the PersisteneUnitsDescriptor for the given PURoot.
217      * It returns null if not found.
218      */

219     public PersistenceUnitsDescriptor getPersistenceUnitsDescriptor(
220             String JavaDoc puRoot) {
221         return persistenceUnitsDescriptors.get(puRoot);
222     }
223
224     /**
225      * Add deplyoment information about all the persistence units
226      * defined in a persistence.xml to this RootDeploymentDescriptor.
227      * All the persistence units defined inside the same persistence.xml
228      * will be added with same PURoot. This method also sets the parent
229      * reference in PersistenceUnitsDescriptor.
230      * @param puRoot root of the persistence unit (its a relative path)
231      * @param persistenceUnitsDescriptor is the descriptor object
232      * representing the persistence unit.
233      */

234     public void addPersistenceUnitsDescriptor(String JavaDoc puRoot, PersistenceUnitsDescriptor persistenceUnitsDescriptor) {
235         // We don't expect the parent to be already set
236
// because that indicates transfer of ownership.
237
assert(persistenceUnitsDescriptor.getParent() == null);
238         persistenceUnitsDescriptor.setParent(this);
239         persistenceUnitsDescriptor.setPuRoot(puRoot);
240         persistenceUnitsDescriptors.put(puRoot, persistenceUnitsDescriptor);
241     }
242
243 }
244
245
Popular Tags