KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import javax.enterprise.deploy.model.DDBean JavaDoc;
29 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
30 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
31 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
32 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
33 import org.netbeans.modules.j2ee.sun.dd.api.client.JavaWebStartAccess;
34
35 import org.xml.sax.SAXException JavaDoc;
36
37 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
38 import org.netbeans.modules.j2ee.sun.dd.api.DDException;
39 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider;
40 import org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException;
41 import org.netbeans.modules.j2ee.sun.dd.api.client.SunApplicationClient;
42 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestination;
43
44 import org.netbeans.modules.schema2beans.BaseBean;
45
46
47 /** Property structure of AppClientRoot from DTD (sections that are handled
48  * by child DConfigBeans have been removed.):
49  *
50  * sun-application-client : SunApplicationClient
51  * javaWebStartAccess <java-web-start-access> : JavaWebStartAccess[0,1]
52  * contextRoot <context-root> : String[0,1]
53  * eligible <eligible> : String[0,1]
54  * vendor <vendor> : String[0,1]
55  * messageDestination <message-destination> : MessageDestination[0,n]
56  * messageDestinationName <message-destination-name> : String
57  * jndiName <jndi-name> : String
58  *
59  * @author Peter Williams
60  */

61 public class AppClientRoot extends BaseRoot {
62
63     /** Holds list of MessageDestination properties. */
64     private List JavaDoc messageDestinations;
65     
66     /** Holds value of property contextRoot. */
67     private String JavaDoc contextRoot;
68
69     /** Holds value of property eligible. */
70     private Boolean JavaDoc eligible;
71
72     /** Holds value of property vendor. */
73     private String JavaDoc vendor;
74     
75     /** Creates a new instance of AppClientRoot */
76     public AppClientRoot() {
77         setDescriptorElement(bundle.getString("BDN_AppClientRoot")); // NOI18N
78
}
79
80     protected void init(DDBeanRoot JavaDoc dDBean, SunONEDeploymentConfiguration parent, DDBean JavaDoc ddbExtra) throws ConfigurationException JavaDoc {
81         super.init(dDBean, parent, ddbExtra);
82         loadFromPlanFile(parent);
83     }
84
85     /** Getter for helpId property
86      * @return Help context ID for this DConfigBean
87      */

88     public String JavaDoc getHelpId() {
89         return "AS_CFG_AppClient";
90     }
91
92     /** Get the appclient version of this module.
93      *
94      * @return AppClientVersion enum for the version of this module.
95      */

96      public J2EEBaseVersion getJ2EEModuleVersion() {
97         DDBeanRoot JavaDoc ddbRoot = (DDBeanRoot JavaDoc) getDDBean();
98
99         // From JSR-88 1.1
100
String JavaDoc versionString = ddbRoot.getDDBeanRootVersion();
101         if(versionString == null) {
102             // If the above doesn't get us what we want.
103
versionString = ddbRoot.getModuleDTDVersion();
104         }
105
106         J2EEBaseVersion appClientVersion = AppClientVersion.getAppClientVersion(versionString);
107         if(appClientVersion == null) {
108             // Default to AppClient 1.4 if we can't find out what version this is.
109
appClientVersion = AppClientVersion.APP_CLIENT_1_4;
110         }
111
112         return appClientVersion;
113     }
114
115     /** Generate a DOCTYPE string for the specified version (which may be different
116      * than the current version of the tree
117      */

118     public String JavaDoc generateDocType(ASDDVersion version) {
119         return generateDocType("sun-application-client", version.getSunAppClientPublicId(), version.getSunAppClientSystemId()); // NOI18N
120
}
121      
122     /* ------------------------------------------------------------------------
123      * Property getters & setters
124      */

125     /** Getter for property contextRoot.
126      * @return Value of property contextRoot.
127      */

128     public String JavaDoc getContextRoot() {
129         return contextRoot;
130     }
131
132     /**
133      * Setter for property newContextRoot.
134      *
135      * @param newContextRoot New value of property contextRoot.
136      */

137     public void setContextRoot(String JavaDoc newContextRoot) throws java.beans.PropertyVetoException JavaDoc {
138         newContextRoot = Utils.encodeUrlField(newContextRoot);
139         String JavaDoc oldContextRoot = contextRoot;
140         getVCS().fireVetoableChange("contextRoot", oldContextRoot, newContextRoot); // NOI18N
141
contextRoot = newContextRoot;
142         getPCS().firePropertyChange("contextRoot", oldContextRoot, contextRoot); // NOI18N
143
}
144
145     /** Getter for property eligible.
146      * @return Value of property eligible.
147      */

148     public boolean isEligible() {
149         return eligible != null ? eligible.booleanValue() : false;
150     }
151
152     /**
153      * Setter for property newEligible.
154      *
155      * @param newEligible New value of property eligible.
156      */

157     public void setEligible(boolean newEligible) throws java.beans.PropertyVetoException JavaDoc {
158         Boolean JavaDoc oldEligible = eligible;
159         Boolean JavaDoc newEligibleAsBoolean = newEligible ? Boolean.TRUE : Boolean.FALSE;
160         getVCS().fireVetoableChange("eligible", oldEligible, newEligibleAsBoolean);
161         eligible = newEligibleAsBoolean;
162         getPCS().firePropertyChange("eligible", oldEligible, eligible);
163         
164     }
165
166     /** Getter for property vendor.
167      * @return Value of property vendor.
168      */

169     public String JavaDoc getVendor() {
170         return vendor;
171     }
172
173     /**
174      * Setter for property newVendor.
175      *
176      * @param newVendor New value of property vendor.
177      */

178     public void setVendor(String JavaDoc newVendor) throws java.beans.PropertyVetoException JavaDoc {
179         String JavaDoc oldVendor = vendor;
180         getVCS().fireVetoableChange("vendor", oldVendor, newVendor); // NOI18N
181
vendor = newVendor;
182         getPCS().firePropertyChange("vendor", oldVendor, vendor); // NOI18N
183
}
184
185     /** Getter for property messageDestinations.
186      * @return Value of property messageDestinations.
187      *
188      */

189     public List JavaDoc getMessageDestinations() {
190         return messageDestinations;
191     }
192
193     public MessageDestination getMessageDestination(int index) {
194         return (MessageDestination) messageDestinations.get(index);
195     }
196
197     /** Setter for property messageDestinations.
198      * @param messageDestinations New value of property messageDestinations.
199      *
200      * @throws PropertyVetoException
201      *
202      */

203     public void setMessageDestinations(List JavaDoc newMessageDestinations) throws java.beans.PropertyVetoException JavaDoc {
204         List JavaDoc oldMessageDestinations = messageDestinations;
205         getVCS().fireVetoableChange("messageDestinations", oldMessageDestinations, newMessageDestinations); // NOI18N
206
messageDestinations = newMessageDestinations;
207         getPCS().firePropertyChange("messageDestinations", oldMessageDestinations, messageDestinations); // NOI18N
208
}
209     
210     public void addMessageDestination(MessageDestination newMessageDestination) throws java.beans.PropertyVetoException JavaDoc {
211         getVCS().fireVetoableChange("messageDestination", null, newMessageDestination); // NOI18N
212
if(messageDestinations == null) {
213             messageDestinations = new ArrayList JavaDoc();
214         }
215         messageDestinations.add(newMessageDestination);
216         getPCS().firePropertyChange("messageDestination", null, newMessageDestination ); // NOI18N
217
}
218
219     public void removeMessageDestination(MessageDestination oldMessageDestination) throws java.beans.PropertyVetoException JavaDoc {
220         getVCS().fireVetoableChange("messageDestination", oldMessageDestination, null); // NOI18N
221
messageDestinations.remove(oldMessageDestination);
222         getPCS().firePropertyChange("messageDestination", oldMessageDestination, null ); // NOI18N
223
}
224
225     /* ------------------------------------------------------------------------
226      * Persistence support. Loads DConfigBeans from previously saved Deployment
227      * plan file.
228      */

229     Collection JavaDoc getSnippets() {
230         Collection JavaDoc snippets = new ArrayList JavaDoc();
231         Snippet snipOne = new DefaultSnippet() {
232
233             public CommonDDBean getDDSnippet() {
234                 SunApplicationClient sac = getConfig().getStorageFactory().createSunApplicationClient();
235                 String JavaDoc version = sac.getVersion().toString();
236
237                 try {
238                     JavaWebStartAccess jwsa = sac.newJavaWebStartAccess();
239                     if(jwsa != null) {
240                         boolean hasContent = false;
241                         if(Utils.notEmpty(contextRoot)) {
242                             jwsa.setContextRoot(contextRoot);
243                             hasContent = true;
244                         }
245
246                         if(eligible != null) {
247                             jwsa.setEligible(Boolean.toString(isEligible()));
248                             hasContent = true;
249                         }
250
251                         if(Utils.notEmpty(vendor)) {
252                             jwsa.setVendor(vendor);
253                             hasContent = true;
254                         }
255
256                         if(hasContent) {
257                             sac.setJavaWebStartAccess(jwsa);
258                         }
259                     }
260                 } catch(VersionNotSupportedException ex) {
261                 }
262                 
263                 MessageDestination [] msgDests = (MessageDestination [])
264                         Utils.listToArray(getMessageDestinations(), MessageDestination.class, version);
265                 if(msgDests != null) {
266                         sac.setMessageDestination(msgDests);
267                 }
268
269                 /* IZ 84549, etc - add remaining saved named beans here. All entries that are represented
270                  * by real DConfigBeans should have been removed by now. */

271                 restoreAllNamedBeans(sac, version);
272
273                 return sac;
274             }
275         };
276
277         snippets.add(snipOne);
278         return snippets;
279     }
280
281     public class AppClientRootParser implements ConfigParser {
282         public Object JavaDoc parse(java.io.InputStream JavaDoc stream) throws IOException JavaDoc, SAXException JavaDoc, DDException {
283             DDProvider provider = DDProvider.getDefault();
284             SunApplicationClient result = null;
285             
286             if(stream != null) {
287                 // Exceptions (due to bad graph or other problem) are handled by caller.
288
result = provider.getAppClientDDRoot(new org.xml.sax.InputSource JavaDoc(stream));
289             } else {
290                 // If we have a null stream, return a blank graph.
291
result = (SunApplicationClient) provider.newGraph(SunApplicationClient.class,
292                         getConfig().getAppServerVersion().getAppClientVersionAsString());
293             }
294
295             // First set our version to match that of this deployment descriptor.
296
getConfig().internalSetAppServerVersion(ASDDVersion.getASDDVersionFromAppClientVersion(result.getVersion()));
297             
298             return result;
299         }
300     }
301
302     public class AppClientRootFinder implements ConfigFinder {
303         public Object JavaDoc find(Object JavaDoc obj) {
304             SunApplicationClient result = null;
305             if(obj instanceof SunApplicationClient) {
306                 result = (SunApplicationClient) obj;
307             }
308             return result;
309         }
310     }
311
312     protected ConfigParser getParser() {
313         return new AppClientRootParser();
314     }
315
316     boolean loadFromPlanFile(SunONEDeploymentConfiguration config) {
317         String JavaDoc uriText = getUriText();
318         SunApplicationClient beanGraph = (SunApplicationClient) config.getBeans(uriText, constructFileName(),
319             getParser(), new AppClientRootFinder());
320
321         clearProperties();
322
323         if(null != beanGraph) {
324             try {
325                 JavaWebStartAccess jwsa = beanGraph.getJavaWebStartAccess();
326                 if(jwsa != null) {
327                     contextRoot = jwsa.getContextRoot();
328                     vendor = jwsa.getVendor();
329                     
330                     String JavaDoc eligibleAsString = jwsa.getEligible();
331                     if(eligibleAsString != null) {
332                         eligible = Utils.booleanValueOf(eligibleAsString) ? Boolean.TRUE : Boolean.FALSE;
333                     }
334                 }
335             } catch (VersionNotSupportedException ex) {
336             }
337             
338             messageDestinations = Utils.arrayToList(beanGraph.getMessageDestination());
339             
340             // IZ 84549, etc - cache the data for all named beans.
341
saveAllNamedBeans(beanGraph);
342         } else {
343             setDefaultProperties();
344         }
345
346         return (beanGraph != null);
347     }
348
349     protected void clearProperties() {
350         contextRoot = null;
351         eligible = null;
352         vendor = null;
353         messageDestinations = null;
354     }
355
356     protected void setDefaultProperties() {
357     }
358
359     private static Collection JavaDoc appClientBeanSpecs = new ArrayList JavaDoc();
360     
361     static {
362         appClientBeanSpecs.addAll(getCommonNamedBeanSpecs());
363 // sunWebAppBeanSpecs.add(new NamedBean(SunWebApp.MESSAGE_DESTINATION,
364
// org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestination.MESSAGE_DESTINATION_NAME));
365
}
366     
367     protected Collection JavaDoc getNamedBeanSpecs() {
368         return appClientBeanSpecs;
369     }
370     
371     /* ------------------------------------------------------------------------
372      * XPath to Factory mapping support
373      */

374     private HashMap JavaDoc appClientRootMap;
375
376     /** Retrieve the XPathToFactory map for this DConfigBean. For AppRoot,
377      * this maps application xpaths to factories for other contained root
378      * objects plus a SecurityRoleModel factory
379      * @return
380      */

381     protected Map JavaDoc getXPathToFactoryMap() {
382         if(appClientRootMap == null) {
383             appClientRootMap = new HashMap JavaDoc(17);
384
385             appClientRootMap.put("ejb-ref", new DCBGenericFactory(EjbRef.class)); // NOI18N
386
appClientRootMap.put("resource-ref", new DCBGenericFactory(ResourceRef.class)); // NOI18N
387
appClientRootMap.put("resource-env-ref", new DCBGenericFactory(ResourceEnvRef.class)); // NOI18N
388

389             J2EEBaseVersion moduleVersion = getJ2EEModuleVersion();
390             if(moduleVersion.compareTo(AppClientVersion.APP_CLIENT_1_4) >= 0) {
391 // appClientRootMap.put("message-destination", new DCBGenericFactory(MessageDestination.class)); // NOI18N
392
appClientRootMap.put("service-ref", new DCBGenericFactory(ServiceRef.class)); // NOI18N
393

394                 if(moduleVersion.compareTo(AppClientVersion.APP_CLIENT_5_0) >= 0) {
395                     appClientRootMap.put("message-destination-ref", new DCBGenericFactory(MessageDestinationRef.class));// NOI18N
396
}
397             }
398         }
399
400         return appClientRootMap;
401     }
402 }
403
Popular Tags