KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > AppRoot


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.sun.share.configbean;
20
21 import java.io.IOException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
30 import javax.enterprise.deploy.model.DDBean JavaDoc;
31 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
32
33 import org.xml.sax.SAXException JavaDoc;
34
35 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
36 import org.netbeans.modules.j2ee.sun.dd.api.DDException;
37 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider;
38 import org.netbeans.modules.j2ee.sun.dd.api.app.SunApplication;
39 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
40
41 import org.netbeans.modules.j2ee.sun.share.configbean.Base.DefaultSnippet;
42
43
44 /** This bean represents the content of the sun-application deployment
45  * descriptor.
46  *
47  * It can be a parent to beans that describe the content of the sun-ejb-jar,
48  * sun-web-app, sun-connector, and sun-application-client deployment
49  * descriptors.
50  *
51  * The bean that represents the content of the sun-web-app has the "alternate"
52  * context-root data that is optional in this descriptor.
53  *
54  * sun-application : SunApplication
55  * web : Web[0,n]
56  * web-uri : String
57  * context-root : String
58  * pass-by-reference : String?
59  * realm : String?
60  *
61  * @author vkraemer
62  */

63 public class AppRoot extends BaseRoot {
64
65     /** Holds value of property passByReference. */
66     private String JavaDoc passByReference;
67     
68     /** Holds value of property realm. */
69     private String JavaDoc realm;
70     
71     /** Holds list of web properties. */
72 // private List webModules;
73

74     /** Creates a new instance of AppRoot
75      * @param dDBean The root of the application.xml file
76      * @param parent The bean's DeploymentConfiguration parent
77      */

78     public AppRoot() {
79         setDescriptorElement(bundle.getString("BDN_AppRoot")); // NOI18N
80
}
81     
82     protected void init(DDBeanRoot JavaDoc dDBean, SunONEDeploymentConfiguration parent, DDBean JavaDoc ddbExtra) throws ConfigurationException JavaDoc {
83         super.init(dDBean, parent, ddbExtra);
84         
85 // initWebModuleList(dDBean.getChildBean("module/web"));
86

87         loadFromPlanFile(parent);
88     }
89     
90 /*
91     private void initWebModuleList(DDBean [] webDDBeans) {
92     if(webDDBeans != null) {
93             webModules = new ArrayList(webDDBeans.length);
94             Web webEntry;
95             
96             for(int i = 0; i < webDDBeans.length; i++) {
97                 webEntry = new Web();
98                 webEntry.setWebUri(webDDBeans[i].getText("web-uri")[0]);
99                 webEntry.setContextRoot(webDDBeans[i].getText("context-root")[0]);
100             }
101         }
102     }
103 */

104     
105     public String JavaDoc getUriText() {
106         // FIXME !PW What can we put here? Name of EAR file?
107
return "EAR"; // NOI18N
108
}
109     
110     /** Get the application root version of this module.
111      *
112      * @return ApplicationVersion enum for the version of this module.
113      */

114      public J2EEBaseVersion getJ2EEModuleVersion() {
115         DDBeanRoot JavaDoc ddbRoot = (DDBeanRoot JavaDoc) getDDBean();
116         
117         // From JSR-88 1.1
118
String JavaDoc versionString = ddbRoot.getDDBeanRootVersion();
119         if(versionString == null) {
120             // If the above doesn't get us what we want.
121
versionString = ddbRoot.getModuleDTDVersion();
122         }
123         
124         J2EEBaseVersion applicationVersion = ApplicationVersion.getApplicationVersion(versionString);
125         if(applicationVersion == null) {
126             // Default to Application 1.4 if we can't find out what version this is.
127
applicationVersion = ApplicationVersion.APPLICATION_1_4;
128         }
129         
130         return applicationVersion;
131     }
132      
133     /** Generate a DOCTYPE string for the specified version (which may be different
134      * than the current version of the tree
135      */

136     public String JavaDoc generateDocType(ASDDVersion version) {
137         return generateDocType("sun-application", version.getSunApplicationPublicId(), version.getSunApplicationSystemId()); // NOI18N
138
}
139      
140     /* ------------------------------------------------------------------------
141      * Property getters/setters.
142      */

143     
144     /** Getter for property passByReference.
145      * @return Value of property passByReference.
146      */

147     public String JavaDoc getPassByReference() {
148         return passByReference;
149     }
150     
151     /** Setter for property passByReference.
152      * @param newPassByReference New value of property passByReference.
153      * @throws PropertyVetoException if the property change is vetoed
154      */

155     public void setPassByReference(String JavaDoc newPassByReference) throws java.beans.PropertyVetoException JavaDoc {
156         String JavaDoc oldPassByReference = passByReference;
157         getVCS().fireVetoableChange("passByReference", oldPassByReference, newPassByReference);
158         passByReference = newPassByReference;
159         getPCS().firePropertyChange("passByReference", oldPassByReference, passByReference);
160     }
161     
162     /** Getter for property realm.
163      * @return Value of property realm.
164      */

165     public String JavaDoc getRealm() {
166         return realm;
167     }
168     
169     /** Setter for property realm.
170      * @param newRealm New value of property realm.
171      * @throws PropertyVetoException if the property change is vetoed
172      */

173     public void setRealm(String JavaDoc newRealm) throws java.beans.PropertyVetoException JavaDoc {
174         String JavaDoc oldRealm = realm;
175         getVCS().fireVetoableChange("realm", oldRealm, newRealm);
176         realm = newRealm;
177         getPCS().firePropertyChange("realm", oldRealm, realm);
178     }
179     
180     /* ------------------------------------------------------------------------
181      * Persistence support. Loads DConfigBeans from previously saved Deployment
182      * plan file.
183      */

184     Collection JavaDoc getSnippets() {
185         Collection JavaDoc snippets = new ArrayList JavaDoc();
186         Snippet snipOne = new DefaultSnippet() {
187             
188             public CommonDDBean getDDSnippet() {
189                 SunApplication sa = getConfig().getStorageFactory().createSunApplication();
190                 String JavaDoc version = sa.getVersion().toString();
191                 
192                 if(passByReference != null && passByReference.length() > 0) {
193                     sa.setPassByReference(passByReference);
194                 }
195                 
196                 if(realm != null && realm.length() > 0) {
197                     sa.setRealm(realm);
198                 }
199                 
200                 /* IZ 78686, etc - add remaining saved named beans here. All entries that are represented
201                  * by real DConfigBeans should have been removed by now. */

202                 restoreAllNamedBeans(sa, version);
203                 
204                 return sa;
205             }
206         };
207         
208         snippets.add(snipOne);
209         return snippets;
210     }
211     
212     public class AppRootParser implements ConfigParser {
213         public Object JavaDoc parse(java.io.InputStream JavaDoc stream) throws IOException JavaDoc, SAXException JavaDoc, DDException {
214             DDProvider provider = DDProvider.getDefault();
215             SunApplication result = null;
216             
217             if(stream != null) {
218                 // Exceptions (due to bad graph or other problem) are handled by caller.
219
result = provider.getAppDDRoot(new org.xml.sax.InputSource JavaDoc(stream));
220             } else {
221                 // If we have a null stream, return a blank graph.
222
result = (SunApplication) provider.newGraph(SunApplication.class,
223                         getConfig().getAppServerVersion().getApplicationVersionAsString());
224             }
225
226             // First set our version to match that of this deployment descriptor.
227
getConfig().internalSetAppServerVersion(ASDDVersion.getASDDVersionFromAppVersion(result.getVersion()));
228             
229             return result;
230         }
231     }
232     
233     public class AppRootFinder implements ConfigFinder {
234         public Object JavaDoc find(Object JavaDoc obj) {
235             Object JavaDoc result = null;
236             if(obj instanceof SunApplication) {
237                 result = (SunApplication) obj;
238             }
239             return result;
240         }
241     }
242     
243     protected ConfigParser getParser() {
244         return new AppRootParser();
245     }
246     
247     boolean loadFromPlanFile(SunONEDeploymentConfiguration config) {
248         String JavaDoc uriText = getUriText();
249         SunApplication beanGraph = (SunApplication) config.getBeans(uriText, constructFileName(),
250             getParser(), new AppRootFinder());
251         
252         clearProperties();
253         
254         if(beanGraph != null) {
255             passByReference = beanGraph.getPassByReference();
256             realm = beanGraph.getRealm();
257             
258             // IZ 78686, etc - cache the data for all named beans.
259
saveAllNamedBeans(beanGraph);
260         } else {
261             setDefaultProperties();
262         }
263         
264         return (beanGraph != null);
265     }
266
267     private static Collection JavaDoc appRootBeanSpecs = new ArrayList JavaDoc();
268     
269     static {
270         appRootBeanSpecs.add(new NamedBean(SunWebApp.SECURITY_ROLE_MAPPING,
271                 org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping.ROLE_NAME));
272     }
273     
274     protected Collection JavaDoc getNamedBeanSpecs() {
275         return appRootBeanSpecs;
276     }
277
278     public String JavaDoc getHelpId() {
279         return "AS_CFG_Application"; //NOI18N
280
}
281
282     
283     protected void clearProperties() {
284         passByReference = null;
285         realm = null;
286     }
287
288     protected void setDefaultProperties() {
289     }
290     
291     /* ------------------------------------------------------------------------
292      * XPath to Factory mapping support
293      */

294     private HashMap JavaDoc appRootFactoryMap;
295     
296     /** Retrieve the XPathToFactory map for this DConfigBean. For AppRoot,
297      * this maps application xpaths to factories for other contained root
298      * objects plus a SecurityRoleModel factory
299      * @return
300      */

301     protected Map JavaDoc getXPathToFactoryMap() {
302         if(appRootFactoryMap == null) {
303             appRootFactoryMap = new HashMap JavaDoc(17);
304             
305             appRootFactoryMap.put("module/ejb", new DCBGenericFactory(EjbJarRef.class)); // NOI18N
306
appRootFactoryMap.put("module/web", new DCBGenericFactory(WebAppRef.class)); // NOI18N
307
// appRootFactoryMap.put("module/connector", new DCBGenericFactory(ConnectorRef.class)); // NOI18N
308
appRootFactoryMap.put("module/java", new DCBGenericFactory(AppClientRef.class)); // NOI18N
309
appRootFactoryMap.put("security-role", new DCBGenericFactory(SecurityRoleMapping.class)); // NOI18N
310
}
311         
312         return appRootFactoryMap;
313     }
314 }
315
Popular Tags