KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.netbeans.modules.j2ee.sun.share.configbean;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import java.text.MessageFormat JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import javax.enterprise.deploy.model.DDBean JavaDoc;
32 import javax.enterprise.deploy.model.DDBeanRoot JavaDoc;
33 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
34 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
35
36 import org.xml.sax.SAXException JavaDoc;
37
38 import org.openide.ErrorManager;
39
40 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
41 import org.netbeans.modules.j2ee.sun.dd.api.DDException;
42 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider;
43 import org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException;
44 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
45 import org.netbeans.modules.j2ee.sun.dd.api.web.MyClassLoader;
46 import org.netbeans.modules.j2ee.sun.dd.api.web.JspConfig;
47 import org.netbeans.modules.j2ee.sun.dd.api.web.LocaleCharsetInfo;
48 import org.netbeans.modules.j2ee.sun.dd.api.web.WebProperty;
49 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestination;
50
51 import org.netbeans.modules.j2ee.sun.share.configbean.Base.DefaultSnippet;
52
53
54 /** Property structure of WebAppRoot from DTD (sections that are handled
55  * by child DConfigBeans have been removed.):
56  *
57  * sun-web-app : SunWebApp
58  * [attr: error-url CDATA ]
59  * [attr: httpservlet-security-provider CDATA #IMPLIED ]
60  * contextRoot <context-root> : String[0,1]
61  * idempotentUrlPattern <idempotent-url-pattern> : boolean[0,n]
62  * [attr: url-pattern CDATA #REQUIRED ]
63  * [attr: num-of-retries CDATA -1]
64  * EMPTY : String
65  * classLoader <class-loader> : ClassLoader[0,1]
66  * [attr: extra-class-path CDATA #IMPLIED ]
67  * [attr: delegate ENUM ( yes no on off 1 0 true false ) true]
68  * [attr: dynamic-reload-interval CDATA #IMPLIED ]
69  * webProperty <property> : WebProperty[0,n]
70  * [attr: name CDATA #REQUIRED ]
71  * [attr: value CDATA #REQUIRED ]
72  * description <description> : String[0,1]
73  * jspConfig <jsp-config> : JspConfig[0,1]
74  * property <property> : WebProperty[0,n]
75  * [attr: name CDATA #REQUIRED ]
76  * [attr: value CDATA #REQUIRED ]
77  * description <description> : String[0,1]
78  * localeCharsetInfo <locale-charset-info> : LocaleCharsetInfo[0,1]
79  * [attr: default-locale CDATA #IMPLIED ]
80  * localeCharsetMap <locale-charset-map> : LocaleCharsetMap[1,n]
81  * [attr: locale CDATA #REQUIRED ]
82  * [attr: agent CDATA #IMPLIED ]
83  * [attr: charset CDATA #REQUIRED ]
84  * description <description> : String[0,1]
85  * parameterEncoding <parameter-encoding> : boolean[0,1]
86  * [attr: form-hint-field CDATA #IMPLIED ]
87  * [attr: default-charset CDATA #IMPLIED ]
88  * EMPTY : String
89  * parameterEncoding <parameter-encoding> : boolean[0,1]
90  * [attr: form-hint-field CDATA #IMPLIED ]
91  * [attr: default-charset CDATA #IMPLIED ]
92  * EMPTY : String
93  * property <property> : WebProperty[0,n]
94  * [attr: name CDATA #REQUIRED ]
95  * [attr: value CDATA #REQUIRED ]
96  * description <description> : String[0,1]
97  * message-destination : MessageDestination[0,n]
98  * message-destination-name : String
99  * jndi-name : String
100  *
101  *
102  * @author Peter Williams
103  * @version %I%, %G%
104  */

105 public class WebAppRoot extends BaseRoot implements javax.enterprise.deploy.spi.DConfigBean JavaDoc {
106
107     /** This property change event is to notify interested systems, particularly
108      * the associated customizer, that list of servlets in web.xml has changed.
109      */

110     public static final String JavaDoc SERVLET_LIST_CHANGED = "ServletListChanged"; //NOI18N
111

112     private static final String JavaDoc JSPCONFIG_CLASSDEBUGINFO="classdebuginfo"; //NOI18N
113
private static final String JavaDoc JSPCONFIG_MAPPEDFILE="mappedfile"; //NOI18N
114

115     public WebAppRoot() {
116         setDescriptorElement(bundle.getString("BDN_WebAppRoot")); // NOI18N
117
}
118     
119     protected void init(DDBeanRoot JavaDoc dDBean, SunONEDeploymentConfiguration parent, DDBean JavaDoc ddbExtra) throws ConfigurationException JavaDoc {
120         super.init(dDBean, parent, ddbExtra);
121         
122         sessionConfigBean = new SessionConfigSubBean();
123         sessionConfigBean.init(this);
124         
125         cacheBean = new WebAppCache();
126         cacheBean.init(this);
127         
128         loadFromPlanFile(parent);
129     }
130     
131     /** -----------------------------------------------------------------------
132      * Validation implementation
133      */

134     
135     // relative xpaths (double as field id's)
136
// public static final String FIELD_CONTEXT_ROOT="context-root";
137
public static final String JavaDoc FIELD_FORM_HINT="locale-charset-info/parameter-encoding/form-hint-field";
138
139     protected void updateValidationFieldList() {
140         super.updateValidationFieldList();
141 // validationFieldList.add(FIELD_CONTEXT_ROOT);
142
validationFieldList.add(FIELD_FORM_HINT);
143     }
144     
145     public boolean validateField(String JavaDoc fieldId) {
146         ValidationError error = null;
147         
148         // !PW use visitor pattern to get rid of switch/if statement for validation
149
// field -- data member mapping.
150
//
151
/* According to DTD, context root can be empty.
152         if(fieldId.equals(FIELD_CONTEXT_ROOT)) {
153             // validation version will be:
154             // expand relative field id to full xpath id based on current context
155             // lookup validator for this field in field validator DB
156             // execute validator
157             // add any validation errors to database
158             //
159             String absoluteFieldXpath = getAbsoluteXpath(fieldId);
160             
161             if(!Utils.notEmpty(contextRoot)) {
162                 error = ValidationError.getValidationError(ValidationError.PARTITION_WEB_GENERAL, absoluteFieldXpath, "Context root cannot be empty.");
163             } else {
164                 error = ValidationError.getValidationErrorMask(ValidationError.PARTITION_WEB_GENERAL, absoluteFieldXpath);
165             }
166         } else
167 */

168         if(fieldId.equals(FIELD_FORM_HINT)) {
169             String JavaDoc absoluteFieldXpath = getAbsoluteXpath(fieldId);
170             
171             if(localeInfo != null) {
172                 String JavaDoc formHint = localeInfo.getParameterEncodingFormHintField();
173                 if(Utils.notEmpty(formHint)) {
174                     if(!Utils.isJavaIdentifier(formHint)) {
175                         Object JavaDoc [] args = new Object JavaDoc[1];
176                         args[0] = "form-hint-field"; // NOI18N
177
String JavaDoc message = MessageFormat.format(bundle.getString("ERR_NotValidIdentifier"), args); // NOI18N
178
error = ValidationError.getValidationError(ValidationError.PARTITION_WEB_LOCALE, absoluteFieldXpath, message);
179                     }
180                 }
181             }
182             
183             if(error == null) {
184                 error = ValidationError.getValidationErrorMask(ValidationError.PARTITION_WEB_LOCALE, absoluteFieldXpath);
185             }
186         }
187         
188         if(error != null) {
189             getMessageDB().updateError(error);
190         }
191         
192         // return true if there was no error added
193
return (error == null || !Utils.notEmpty(error.getMessage()));
194     }
195     
196     /** Getter for helpId property
197      * @return Help context ID for this DConfigBean
198      */

199     public String JavaDoc getHelpId() {
200         return "AS_CFG_WebAppGeneral";
201     }
202     
203     public DConfigBean JavaDoc getDConfigBean(DDBeanRoot JavaDoc dDBeanRoot) {
204         BaseRoot rootDCBean = null;
205         
206         J2EEBaseVersion moduleVersion = getJ2EEModuleVersion();
207         if(moduleVersion.compareTo(ServletVersion.SERVLET_2_4) >= 0) {
208             rootDCBean = createWebServicesRoot(dDBeanRoot);
209         }
210         
211         return rootDCBean;
212     }
213     
214     /** Get the servlet version of this module.
215      *
216      * @return ServletVersion enum for the version of this module.
217      */

218     public J2EEBaseVersion getJ2EEModuleVersion() {
219         DDBeanRoot JavaDoc ddbRoot = (DDBeanRoot JavaDoc) getDDBean();
220         
221         // From JSR-88 1.1
222
String JavaDoc versionString = ddbRoot.getDDBeanRootVersion();
223         if(versionString == null) {
224             // If the above doesn't get us what we want.
225
versionString = ddbRoot.getModuleDTDVersion();
226         }
227         
228         J2EEBaseVersion servletVersion = ServletVersion.getServletVersion(versionString);
229         if(servletVersion == null) {
230             // Default to Servlet 2.4 if we can't find out what version this is.
231
servletVersion = ServletVersion.SERVLET_2_4;
232         }
233         
234         return servletVersion;
235     }
236     
237     /** Generate a DOCTYPE string for the specified version (which may be different
238      * than the current version of the tree
239      */

240     public String JavaDoc generateDocType(ASDDVersion version) {
241         return generateDocType("sun-web-app", version.getSunWebAppPublicId(), version.getSunWebAppSystemId()); // NOI18N
242
}
243      
244     /** !PW FIXME Workaround for broken XpathEvent.BEAN_ADDED not being sent.
245      * Override this method (see WebAppRoot) to be notified if a child bean
246      * is created. See IZ 41214
247      */

248     protected void beanAdded(String JavaDoc xpath) {
249         super.beanAdded(xpath);
250         
251         if("/web-app/servlet".equals(xpath)) { // NOI18N
252
getPCS().firePropertyChange(SERVLET_LIST_CHANGED, false, true);
253         }
254     }
255     
256     /** !PW FIXME Workaround for broken XpathEvent.BEAN_REMOVED not being sent.
257      * Override this method (see WebAppRoot) to be notified if a child bean
258      * is destroyed. See IZ 41214
259      */

260     protected void beanRemoved(String JavaDoc xpath) {
261         super.beanRemoved(xpath);
262         
263         if("/web-app/servlet".equals(xpath)) { // NOI18N
264
getPCS().firePropertyChange(SERVLET_LIST_CHANGED, false, true);
265         }
266     }
267
268     /** Retrieves a list of the servlet child DConfigBeans contained in this
269      * web application.
270      */

271     public List JavaDoc getServlets() {
272         List JavaDoc servlets = new ArrayList JavaDoc();
273         for(Iterator JavaDoc iter = getChildren().iterator(); iter.hasNext(); ) {
274             Object JavaDoc child = iter.next();
275             if(child instanceof ServletRef) {
276                 servlets.add(child);
277             }
278         }
279         return servlets;
280     }
281     
282     /* ------------------------------------------------------------------------
283      * Persistence support. Loads DConfigBeans from previously saved Deployment
284      * plan file.
285      */

286     Collection JavaDoc getSnippets() {
287         Collection JavaDoc snippets = new ArrayList JavaDoc();
288         Snippet snipOne = new DefaultSnippet() {
289             public CommonDDBean getDDSnippet() {
290                 SunWebApp swa = getConfig().getStorageFactory().createSunWebApp();
291                 String JavaDoc version = swa.getVersion().toString();
292                 
293                 if(contextRoot != null) {
294                     swa.setContextRoot(contextRoot);
295                 }
296                 
297                 if(errorUrl != null) {
298                     try {
299                         swa.setErrorUrl(errorUrl);
300                     } catch(VersionNotSupportedException ex) {
301                     }
302                 }
303
304                 if(httpservletSecurityProvider != null) {
305                     try {
306                         swa.setHttpservletSecurityProvider(httpservletSecurityProvider);
307                     } catch(VersionNotSupportedException ex) {
308                     }
309                 }
310                 
311                 if(classLoader != null) {
312                     if(classLoader.toString().equals("true")){ //NOI18N
313
try {
314                             MyClassLoader webClassLoader = swa.newMyClassLoader();
315
316                             if(delegate != null) {
317                                 webClassLoader.setDelegate(Boolean.toString(isDelegate()));
318                             } else {
319                                 webClassLoader.setDelegate(Boolean.TRUE.toString());
320                             }
321
322                             if(Utils.notEmpty(getExtraClassPath())) {
323                                 webClassLoader.setExtraClassPath(getExtraClassPath());
324                             }
325                             
326                             if(Utils.notEmpty(getDynamicReloadInterval())) {
327                                 webClassLoader.setDynamicReloadInterval(getDynamicReloadInterval());
328                             }
329                             
330                             WebProperty [] classLoaderProps = (WebProperty [])
331                                 Utils.listToArray(getClassLoaderProperties(), WebProperty.class, version);
332                             if(classLoaderProps != null) {
333                                 webClassLoader.setWebProperty(classLoaderProps);
334                             }
335
336                             swa.setMyClassLoader(webClassLoader);
337                         } catch(VersionNotSupportedException ex) {
338                             // Should not happen, but we have to catch it for now.
339
}
340                     }
341                 }
342                                 
343                 try {
344                     if(Utils.notEmpty(defaultCharset) || Utils.notEmpty(formHintField)) {
345                         swa.setParameterEncoding(true);
346                         swa.setParameterEncodingDefaultCharset(defaultCharset);
347                         swa.setParameterEncodingFormHintField(formHintField);
348                     }
349
350                     int numPatterns = idempotentUrlPattern.sizeIdempotentUrlPattern();
351                     if(numPatterns > 0) {
352                         swa.setIdempotentUrlPattern(new boolean[numPatterns]);
353                         for(int i = 0; i < numPatterns; i++) {
354                             swa.setIdempotentUrlPatternUrlPattern(i, idempotentUrlPattern.getIdempotentUrlPatternUrlPattern(i));
355                             swa.setIdempotentUrlPatternNumOfRetries(i, idempotentUrlPattern.getIdempotentUrlPatternNumOfRetries(i));
356                         }
357                     }
358                 } catch(VersionNotSupportedException ex) {
359                     //Should never happen
360
}
361
362                 JspConfig jc = getJspConfig();
363                 if(jc.sizeWebProperty() > 0) {
364                     swa.setJspConfig((JspConfig) jc.cloneVersion(version));
365                 }
366
367                 WebProperty [] webProps = (WebProperty [])
368                     Utils.listToArray(getProperties(), WebProperty.class, version);
369                 if(webProps != null) {
370                     swa.setWebProperty(webProps);
371                 }
372                 
373                 MessageDestination [] msgDests = (MessageDestination [])
374                     Utils.listToArray(getMessageDestinations(), MessageDestination.class, version);
375                 if(msgDests != null) {
376                     swa.setMessageDestination(msgDests);
377                 }
378                 
379                 if(localeInfo.sizeLocaleCharsetMap() > 0 ||
380                     Utils.notEmpty(localeInfo.getDefaultLocale()) ||
381                     Utils.notEmpty(localeInfo.getParameterEncodingDefaultCharset()) ||
382                     Utils.notEmpty(localeInfo.getParameterEncodingFormHintField())
383                     ) {
384                     swa.setLocaleCharsetInfo((LocaleCharsetInfo) localeInfo.cloneVersion(version));
385                 }
386                 
387                 // SessionConfig snippet is retrieved below and added to the snippet list
388
// for WebAppRoot.
389

390                 // Cache snippet is retrieved below and added to the snippet list
391
// for WebAppRoot.
392

393                 /* IZ 84549, etc - add remaining saved named beans here. All entries that are represented
394                  * by real DConfigBeans should have been removed by now. */

395                 restoreAllNamedBeans(swa, version);
396                 
397                 return swa;
398             }
399         };
400         
401         snippets.add(snipOne);
402         snippets.addAll(sessionConfigBean.getSnippets());
403         snippets.addAll(cacheBean.getSnippets());
404         return snippets;
405     }
406    
407     private class WebAppRootParser implements ConfigParser {
408         public Object JavaDoc parse(java.io.InputStream JavaDoc stream) throws IOException JavaDoc, SAXException JavaDoc, DDException {
409             DDProvider provider = DDProvider.getDefault();
410             SunWebApp result = null;
411             
412             if(stream != null) {
413                 // Exceptions (due to bad graph or other problem) are handled by caller.
414
result = provider.getWebDDRoot(new org.xml.sax.InputSource JavaDoc(stream));
415             } else {
416                 // If we have a null stream, return a blank graph.
417
result = (SunWebApp) provider.newGraph(SunWebApp.class,
418                         getConfig().getAppServerVersion().getWebAppVersionAsString());
419             }
420
421             // First set our version to match that of this deployment descriptor.
422
getConfig().internalSetAppServerVersion(ASDDVersion.getASDDVersionFromServletVersion(result.getVersion()));
423             
424             return result;
425         }
426     }
427     
428     private class WebAppRootFinder implements ConfigFinder {
429         public Object JavaDoc find(Object JavaDoc obj) {
430             SunWebApp result = null;
431             
432             if(obj instanceof SunWebApp) {
433                 result = (SunWebApp) obj;
434             }
435             
436             return result;
437         }
438     }
439     
440     protected ConfigParser getParser() {
441         return new WebAppRootParser();
442     }
443
444     boolean loadFromPlanFile(SunONEDeploymentConfiguration config) {
445         String JavaDoc uriText = getUriText();
446         
447         SunWebApp beanGraph = (SunWebApp) config.getBeans(uriText, constructFileName(),
448             getParser(), new WebAppRootFinder());
449         
450         clearProperties();
451         
452         if(null != beanGraph) {
453             contextRoot = beanGraph.getContextRoot();
454             
455             try {
456                 errorUrl = beanGraph.getErrorUrl();
457             } catch(VersionNotSupportedException ex) {
458                 errorUrl = "";
459             }
460             
461             try {
462                 httpservletSecurityProvider = beanGraph.getHttpservletSecurityProvider();
463             } catch(VersionNotSupportedException ex) {
464                 httpservletSecurityProvider = "";
465             }
466             
467             try {
468                 // This block is separate from the rest because classloader exists for both 2.4.0 and 2.4.1
469
MyClassLoader myClassLoader = beanGraph.getMyClassLoader();
470                 if(myClassLoader != null) {
471                     delegate = Utils.booleanValueOf(myClassLoader.getDelegate()) ? Boolean.TRUE : Boolean.FALSE;
472                     extraClassPath = myClassLoader.getExtraClassPath();
473                     dynamicReloadInterval = myClassLoader.getDynamicReloadInterval();
474                     classLoaderProperties = Utils.arrayToList(myClassLoader.getWebProperty());
475                     if((delegate != null) || (extraClassPath != null) || (dynamicReloadInterval != null) ||
476                             (classLoaderProperties != null && classLoaderProperties.size() > 0)) {
477                         classLoader = Boolean.TRUE;
478                     }
479                 }
480             } catch(VersionNotSupportedException ex) {
481                 //Should never happen
482
delegate = Boolean.TRUE;
483                 classLoader = Boolean.TRUE;
484             }
485                         
486             try {
487                 defaultCharset = beanGraph.getParameterEncodingDefaultCharset();
488                 formHintField = beanGraph.getParameterEncodingFormHintField();
489
490                 int numPatterns = beanGraph.sizeIdempotentUrlPattern();
491                 if(numPatterns > 0) {
492                     idempotentUrlPattern.setIdempotentUrlPattern(new boolean[numPatterns]);
493                     for(int i = 0; i < numPatterns; i++) {
494                         idempotentUrlPattern.setIdempotentUrlPatternUrlPattern(i, beanGraph.getIdempotentUrlPatternUrlPattern(i));
495                         idempotentUrlPattern.setIdempotentUrlPatternNumOfRetries(i, beanGraph.getIdempotentUrlPatternNumOfRetries(i));
496                     }
497                 }
498             } catch(VersionNotSupportedException ex) {
499                 //Should never happen
500
}
501
502             JspConfig jc = beanGraph.getJspConfig();
503             if(jc != null && jc.sizeWebProperty() > 0) {
504                 jspConfig = (JspConfig) jc.clone();
505             }
506             
507             properties = Utils.arrayToList(beanGraph.getWebProperty());
508             messageDestinations = Utils.arrayToList(beanGraph.getMessageDestination());
509             
510             // Save any portion of the locale that has been specifie, regardless
511
// of whether it is DTD valid or not (e.g. we could save default locale
512
// without any entries in the locale-charset-mapping table.)
513
//
514
LocaleCharsetInfo info = beanGraph.getLocaleCharsetInfo();
515             if(info != null &&
516                 (info.sizeLocaleCharsetMap() > 0 ||
517                  Utils.notEmpty(info.getDefaultLocale()) ||
518                  Utils.notEmpty(info.getParameterEncodingDefaultCharset()) ||
519                  Utils.notEmpty(info.getParameterEncodingFormHintField())
520                     )) {
521                 localeInfo = (LocaleCharsetInfo) info.clone();
522             }
523             
524             // IZ 84549, etc - cache the data for all named beans.
525
saveAllNamedBeans(beanGraph);
526         } else {
527             setDefaultProperties();
528         }
529
530         // Now load session configuration pseudo DConfigBean
531
sessionConfigBean.loadFromPlanFile(config);
532         
533         // Now load cache pseudo DConfigBean
534
cacheBean.loadFromPlanFile(config);
535         
536         return (beanGraph != null);
537     }
538     
539     protected void clearProperties() {
540         StorageBeanFactory beanFactory = getConfig().getStorageFactory();
541         
542         contextRoot = null;
543         errorUrl = null;
544         httpservletSecurityProvider = null;
545         extraClassPath = null;
546         dynamicReloadInterval = null;
547         classLoaderProperties = null;
548         defaultCharset = null;
549         formHintField = null;
550         idempotentUrlPattern = beanFactory.createSunWebApp();
551         jspConfig = beanFactory.createJspConfig();
552         properties = null;
553         messageDestinations = null;
554         localeInfo = beanFactory.createLocaleCharsetInfo();
555
556         classLoader = Boolean.FALSE;
557         delegate = Boolean.FALSE;
558     }
559     
560     protected void setDefaultProperties() {
561         StorageBeanFactory beanFactory = getConfig().getStorageFactory();
562         
563         // Add two properties to make developing and debugging JSP's easier by
564
// by default for new web applications.]
565
WebProperty classDebugInfoProperty = beanFactory.createWebProperty();
566         classDebugInfoProperty.setName(JSPCONFIG_CLASSDEBUGINFO);
567         classDebugInfoProperty.setValue("true"); // NOI18N
568
classDebugInfoProperty.setDescription(bundle.getString("DESC_ClassDebugInfo")); // NOI18N
569
jspConfig.addWebProperty(classDebugInfoProperty);
570
571         WebProperty mappedFileProperty = beanFactory.createWebProperty();
572         mappedFileProperty.setName(JSPCONFIG_MAPPEDFILE);
573         mappedFileProperty.setValue("true"); // NOI18N
574
mappedFileProperty.setDescription(bundle.getString("DESC_MappedFile")); // NOI18N
575
jspConfig.addWebProperty(mappedFileProperty);
576
577         classLoader = Boolean.TRUE;
578         delegate = Boolean.TRUE;
579
580         // errorUrl is required for SJSAS 8.1
581
errorUrl = "";
582     }
583     
584     private static Collection JavaDoc sunWebAppBeanSpecs = new ArrayList JavaDoc();
585     
586     static {
587         sunWebAppBeanSpecs.addAll(getCommonNamedBeanSpecs());
588 // sunWebAppBeanSpecs.add(new NamedBean(SunWebApp.MESSAGE_DESTINATION,
589
// org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestination.MESSAGE_DESTINATION_NAME));
590
sunWebAppBeanSpecs.add(new NamedBean(SunWebApp.SECURITY_ROLE_MAPPING,
591                 org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping.ROLE_NAME));
592         sunWebAppBeanSpecs.add(new NamedBean(SunWebApp.SERVLET,
593                 org.netbeans.modules.j2ee.sun.dd.api.web.Servlet.SERVLET_NAME));
594     }
595     
596     protected Collection JavaDoc getNamedBeanSpecs() {
597         return sunWebAppBeanSpecs;
598     }
599     
600     /* ------------------------------------------------------------------------
601      * XPath to Factory mapping support
602      */

603     private HashMap JavaDoc webAppRootFactoryMap;
604     
605     /** Retrieve the XPathToFactory map for this DConfigBean. For AppRoot,
606      * this maps application xpaths to factories for other contained root
607      * objects plus a SecurityRoleModel factory
608      * @return
609      */

610     protected java.util.Map JavaDoc getXPathToFactoryMap() {
611         if(webAppRootFactoryMap == null) {
612             webAppRootFactoryMap = new HashMap JavaDoc(17);
613
614             webAppRootFactoryMap.put("ejb-ref", new DCBGenericFactory(EjbRef.class)); // NOI18N
615
webAppRootFactoryMap.put("resource-env-ref", new DCBGenericFactory(ResourceEnvRef.class)); // NOI18N
616
webAppRootFactoryMap.put("resource-ref", new DCBGenericFactory(ResourceRef.class)); // NOI18N
617
webAppRootFactoryMap.put("security-role", new DCBGenericFactory(SecurityRoleMapping.class)); // NOI18N
618
webAppRootFactoryMap.put("servlet", new DCBGenericFactory(ServletRef.class)); // NOI18N
619

620 // Removed as genuine DConfigBean due to issues with NetBeans DDEditor & web.xml
621
// webAppRootFactoryMap.put("session-config", new DCBGenericFactory(SessionConfiguration.class)); // NOI18N
622

623             J2EEBaseVersion moduleVersion = getJ2EEModuleVersion();
624             if(moduleVersion.compareTo(ServletVersion.SERVLET_2_4) >= 0) {
625 // webAppRootFactoryMap.put("message-destination", new DCBGenericFactory(MessageDestination.class)); // NOI18N
626
webAppRootFactoryMap.put("service-ref", new DCBGenericFactory(ServiceRef.class)); // NOI18N
627

628                 if(moduleVersion.compareTo(ServletVersion.SERVLET_2_5) >= 0) {
629                     webAppRootFactoryMap.put("message-destination-ref", new DCBGenericFactory(MessageDestinationRef.class)); // NOI18N
630
}
631             }
632         }
633         
634         return webAppRootFactoryMap;
635     }
636
637     /* ------------------------------------------------------------------------
638      * Property support
639      */

640     
641     /** Holds value of property contextRoot. */
642     private String JavaDoc contextRoot;
643     
644     /** Holds value of property errorUrl. */
645     private String JavaDoc errorUrl;
646     
647     /** Holds value of property httpservletSecurityProvider. */
648     private String JavaDoc httpservletSecurityProvider;
649     
650     /** Holds value of property classLoader. */
651     private Boolean JavaDoc classLoader;
652     
653     /** Holds value of property extraClassPath. */
654     private String JavaDoc extraClassPath;
655     
656     /** Holds value of property delegate. */
657     private Boolean JavaDoc delegate;
658
659     /** Holds value of property dynamicReloadInterval. */
660     private String JavaDoc dynamicReloadInterval;
661     
662     /** Holds list of WebProperty classLoaderProperties. */
663     private List JavaDoc classLoaderProperties;
664     
665     /** Holds value of property parameterEncoding-defaultCharset. */
666     private String JavaDoc defaultCharset;
667         
668     /** Holds value of property parameterEncoding-formHintField. */
669     private String JavaDoc formHintField;
670         
671     /** Holds value of property idempotentUrlPattern */
672     private SunWebApp idempotentUrlPattern;
673         
674     /** Holds value of property jspConfig. */
675     private JspConfig jspConfig;
676     
677     /** Holds list of WebProperty properties. */
678     private List JavaDoc properties;
679     
680     /** Holds list of MessageDestination properties. */
681     private List JavaDoc messageDestinations;
682     
683     /* Holds value of property LocaleCharsetInfo. */
684     private LocaleCharsetInfo localeInfo;
685     
686     /* Holds value of property SessionConfig. */
687     private SessionConfigSubBean sessionConfigBean;
688     
689     /* Holds value of property Cache. */
690     private WebAppCache cacheBean;
691     
692     /** Getter for property contextRoot.
693      * @return Value of property contextRoot.
694      *
695      */

696     public String JavaDoc getContextRoot() {
697         return contextRoot;
698     }
699     
700     /** Setter for property contextRoot.
701      * @param contextRoot New value of property contextRoot.
702      *
703      * @throws PropertyVetoException
704      *
705      */

706     public void setContextRoot(String JavaDoc newContextRoot) throws java.beans.PropertyVetoException JavaDoc {
707         newContextRoot = Utils.encodeUrlField(newContextRoot);
708         String JavaDoc oldContextRoot = contextRoot;
709         getVCS().fireVetoableChange("contextRoot", oldContextRoot, newContextRoot);
710         contextRoot = newContextRoot;
711         getPCS().firePropertyChange("contextRoot", oldContextRoot, contextRoot);
712     }
713     
714     /** Getter for property errorUrl.
715      * @return Value of property errorUrl.
716      *
717      */

718     public String JavaDoc getErrorUrl() {
719         return errorUrl;
720     }
721
722     /** Setter for property errorUrl.
723      * @param newErrorUrl New value of property errorUrl.
724      *
725      * @throws PropertyVetoException
726      *
727      */

728     public void setErrorUrl(String JavaDoc newErrorUrl) throws java.beans.PropertyVetoException JavaDoc {
729         newErrorUrl = Utils.encodeUrlField(newErrorUrl);
730         String JavaDoc oldErrorUrl = errorUrl;
731         getVCS().fireVetoableChange("errorUrl", oldErrorUrl, newErrorUrl);
732         errorUrl = newErrorUrl;
733         getPCS().firePropertyChange("errorUrl", oldErrorUrl, errorUrl);
734     }
735
736     /** Getter for property httpservletSecurityProvider.
737      * @return Value of property httpservletSecurityProvider.
738      *
739      */

740     public String JavaDoc getHttpservletSecurityProvider() {
741         return httpservletSecurityProvider;
742     }
743
744     /** Setter for property httpservletSecurityProvider.
745      * @param newHttpservletSecurityProvider New value of property httpservletSecurityProvider.
746      *
747      * @throws PropertyVetoException
748      *
749      */

750     public void setHttpservletSecurityProvider(String JavaDoc newHttpservletSecurityProvider) throws java.beans.PropertyVetoException JavaDoc {
751         String JavaDoc oldHttpservletSecurityProvider = httpservletSecurityProvider;
752         getVCS().fireVetoableChange("httpservletSecurityProvider", oldHttpservletSecurityProvider, newHttpservletSecurityProvider);
753         httpservletSecurityProvider = newHttpservletSecurityProvider;
754         getPCS().firePropertyChange("httpservletSecurityProvider", oldHttpservletSecurityProvider, httpservletSecurityProvider);
755     }
756     
757     /** Getter for property classLoader.
758      * @return Value of property classLoader.
759      *
760      */

761     public boolean isClassLoader() {
762         return classLoader.booleanValue();
763     }
764     
765     /** Setter for property classLoader.
766      * @param classLoader New value of property classLoader.
767      *
768      * @throws PropertyVetoException
769      *
770      */

771     public void setClassLoader(boolean newClassLoader) throws java.beans.PropertyVetoException JavaDoc {
772         Boolean JavaDoc oldClassLoader = classLoader;
773         Boolean JavaDoc newClassLoaderAsBoolean = newClassLoader ? Boolean.TRUE : Boolean.FALSE;
774         getVCS().fireVetoableChange("classLoader", oldClassLoader, newClassLoaderAsBoolean);
775         classLoader = newClassLoaderAsBoolean;
776         getPCS().firePropertyChange("classLoader", oldClassLoader, classLoader);
777     }
778     
779     /** Getter for property extraClassPath.
780      * @return Value of property extraClassPath.
781      *
782      */

783     public String JavaDoc getExtraClassPath() {
784         return extraClassPath;
785     }
786     
787     /** Setter for property extraClassPath.
788      * @param newExtraClassPath New value of property extraClassPath.
789      *
790      * @throws PropertyVetoException
791      *
792      */

793     public void setExtraClassPath(String JavaDoc newExtraClassPath) throws java.beans.PropertyVetoException JavaDoc {
794         String JavaDoc oldExtraClassPath = extraClassPath;
795         getVCS().fireVetoableChange("extraClassPath", oldExtraClassPath, newExtraClassPath);
796         extraClassPath = newExtraClassPath;
797         getPCS().firePropertyChange("extraClassPath", oldExtraClassPath, extraClassPath);
798     }
799     
800     /** Getter for property delegate.
801      * @return Value of property delegate.
802      *
803      */

804     public boolean isDelegate() {
805         return delegate.booleanValue();
806     }
807     
808     /** Setter for property delegate.
809      * @param newDelegate New value of property delegate.
810      *
811      * @throws PropertyVetoException
812      *
813      */

814     public void setDelegate(boolean newDelegate) throws java.beans.PropertyVetoException JavaDoc {
815         Boolean JavaDoc oldDelegate = delegate;
816         Boolean JavaDoc newDelegateAsBoolean = newDelegate ? Boolean.TRUE : Boolean.FALSE;
817         getVCS().fireVetoableChange("delegate", oldDelegate, newDelegateAsBoolean);
818         delegate = newDelegateAsBoolean;
819         getPCS().firePropertyChange("delegate", oldDelegate, delegate);
820     }
821
822     /** Getter for property dynamicReloadInterval.
823      * @return Value of property dynamicReloadInterval.
824      *
825      */

826     public String JavaDoc getDynamicReloadInterval() {
827         return dynamicReloadInterval;
828     }
829     
830     /** Setter for property dynamicReloadInterval.
831      * @param newDynamicReloadInterval New value of property dynamicReloadInterval.
832      *
833      * @throws PropertyVetoException
834      *
835      */

836     public void setDynamicReloadInterval(String JavaDoc newDynamicReloadInterval) throws java.beans.PropertyVetoException JavaDoc {
837         String JavaDoc oldDynamicReloadInterval = dynamicReloadInterval;
838         getVCS().fireVetoableChange("dynamicReloadInterval", oldDynamicReloadInterval, newDynamicReloadInterval);
839         dynamicReloadInterval = newDynamicReloadInterval;
840         getPCS().firePropertyChange("dynamicReloadInterval", oldDynamicReloadInterval, dynamicReloadInterval);
841     }
842     
843     /** Getter for property classLoaderProperties.
844      * @return Value of property classLoaderProperties.
845      *
846      */

847     public List JavaDoc getClassLoaderProperties() {
848         return classLoaderProperties;
849     }
850     
851     public WebProperty getClassLoaderProperty(int index) {
852         return (WebProperty) classLoaderProperties.get(index);
853     }
854     
855     /** Setter for property classLoaderProperties.
856      * @param newClassLoaderProperty New value of property classLoaderProperties.
857      *
858      * @throws PropertyVetoException
859      *
860      */

861     public void setClassLoaderProperties(List JavaDoc newClassLoaderProperties) throws java.beans.PropertyVetoException JavaDoc {
862         List JavaDoc oldClassLoaderProperties = classLoaderProperties;
863         getVCS().fireVetoableChange("classLoaderProperties", oldClassLoaderProperties, newClassLoaderProperties); // NOI18N
864
classLoaderProperties = newClassLoaderProperties;
865         getPCS().firePropertyChange("classLoaderProperties", oldClassLoaderProperties, classLoaderProperties); // NOI18N
866
}
867     
868     public void addClassLoaderProperty(WebProperty newClassLoaderProperty) throws java.beans.PropertyVetoException JavaDoc {
869         getVCS().fireVetoableChange("classLoaderProperty", null, newClassLoaderProperty); // NOI18N
870
if(classLoaderProperties == null) {
871             classLoaderProperties = new ArrayList JavaDoc();
872         }
873         classLoaderProperties.add(newClassLoaderProperty);
874         getPCS().firePropertyChange("classLoaderProperty", null, newClassLoaderProperty ); // NOI18N
875
}
876     
877     public void removeClassLoaderProperty(WebProperty oldClassLoaderProperty) throws java.beans.PropertyVetoException JavaDoc {
878         getVCS().fireVetoableChange("classLoaderProperty", oldClassLoaderProperty, null); // NOI18N
879
classLoaderProperties.remove(oldClassLoaderProperty);
880         getPCS().firePropertyChange("classLoaderProperty", oldClassLoaderProperty, null ); // NOI18N
881
}
882
883     /** Getter for property parameterEncodingDefaultCharset.
884      * @return Value of property parameterEncodingDefaultCharset.
885      *
886      */

887     public String JavaDoc getDefaultCharset() {
888         return defaultCharset;
889     }
890     
891     /** Setter for property parameterEncodingDefaultCharset.
892      * @param newDefaultCharset New value of property parameterEncodingDefaultCharset.
893      *
894      * @throws PropertyVetoException
895      *
896      */

897     public void setDefaultCharset(String JavaDoc newDefaultCharset) throws java.beans.PropertyVetoException JavaDoc {
898         String JavaDoc oldDefaultCharset = defaultCharset;
899         getVCS().fireVetoableChange("defaultCharset", oldDefaultCharset, newDefaultCharset);
900         defaultCharset = newDefaultCharset;
901         getPCS().firePropertyChange("defaultCharset", oldDefaultCharset, defaultCharset);
902     }
903     
904     /** Getter for property parameterEncodingFormHintField.
905      * @return Value of property parameterEncodingFormHintField.
906      *
907      */

908     public String JavaDoc getFormHintField() {
909         return formHintField;
910     }
911     
912     /** Setter for property parameterEncodingFormHintField.
913      * @param newFormHintField New value of property parameterEncodingFormHintField.
914      *
915      * @throws PropertyVetoException
916      *
917      */

918     public void setFormHintField(String JavaDoc newFormHintField) throws java.beans.PropertyVetoException JavaDoc {
919         String JavaDoc oldFormHintField = formHintField;
920         getVCS().fireVetoableChange("formHintField", oldFormHintField, newFormHintField);
921         formHintField = newFormHintField;
922         getPCS().firePropertyChange("formHintField", oldFormHintField, formHintField);
923     }
924     
925     /** Getter for property idempotentUrlPattern.
926      * @return SunWebApp instance that only holds the list of idempotentUrlPatterns
927      * that have been set.
928      */

929     public SunWebApp getIdempotentUrlPattern() {
930         return idempotentUrlPattern;
931     }
932     
933     /** Setter for property idempotentUrlPattern.
934      * @param iup New value of property idempotentUrlPattern
935      *
936      * @throws PropertyVetoException
937      */

938     public void setIdempotentUrlPattern(SunWebApp newIdempotentUrlPattern) throws java.beans.PropertyVetoException JavaDoc {
939         SunWebApp oldIdempotentUrlPattern = idempotentUrlPattern;
940         getVCS().fireVetoableChange("idempotentUrlPatterns", oldIdempotentUrlPattern, newIdempotentUrlPattern);
941         idempotentUrlPattern = newIdempotentUrlPattern;
942         getPCS().firePropertyChange("idempotentUrlPatterns", oldIdempotentUrlPattern, idempotentUrlPattern);
943     }
944     
945 // !PW May not need these.
946
// public void addIdempotentUrlPattern(String urlPattern, String numRetries) throws java.beans.PropertyVetoException {
947
// getVCS().fireVetoableChange("idempotentUrlPattern", null, urlPattern); // NOI18N
948
// if(idempotentUrlPattern == null) {
949
// DDProvider provider = DDProvider.getDefault();
950
// idempotentUrlPattern = (SunWebApp) provider.newGraph(SunWebApp.class);
951
// }
952
//
953
// try {
954
// int index = idempotentUrlPattern.addIdempotentUrlPattern(true);
955
// idempotentUrlPattern.setIdempotentUrlPatternUrlPattern(index, urlPattern);
956
// idempotentUrlPattern.setIdempotentUrlPatternNumOfRetries(index, numRetries);
957
// } catch (VersionNotSupportedException ex) {
958
// ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
959
// }
960
//
961
// getPCS().firePropertyChange("idempotentUrlPattern", null, urlPattern ); // NOI18N
962
// }
963
//
964
// public void removeIdempotentUrlPattern(String urlPattern) throws java.beans.PropertyVetoException {
965
// getVCS().fireVetoableChange("idempotentUrlPattern", oldProperty, null); // NOI18N
966
// FIXME unfinished.
967
// properties.remove(oldProperty);
968
// getPCS().firePropertyChange("idempotentUrlPattern", oldProperty, null ); // NOI18N
969
// }
970

971     /** Getter for property jspConfig.
972      * @return Value of property jspConfig.
973      *
974      */

975     public JspConfig getJspConfig() {
976         return jspConfig;
977     }
978     
979     /** Setter for property jspConfig.
980      * @param jspConfig New value of property jspConfig.
981      *
982      * @throws PropertyVetoException
983      *
984      */

985     public void setJspConfig(JspConfig newJspConfig) throws java.beans.PropertyVetoException JavaDoc {
986         JspConfig oldJspConfig = jspConfig;
987         getVCS().fireVetoableChange("jspConfig", oldJspConfig, newJspConfig);
988         jspConfig = newJspConfig;
989         getPCS().firePropertyChange("jspConfig", oldJspConfig, jspConfig);
990     }
991     
992     /** Getter for property property.
993      * @return Value of property property.
994      *
995      */

996     public List JavaDoc getProperties() {
997         return properties;
998     }
999     
1000    public WebProperty getProperty(int index) {
1001        return (WebProperty) properties.get(index);
1002    }
1003    
1004    /** Setter for property property.
1005     * @param property New value of property property.
1006     *
1007     * @throws PropertyVetoException
1008     *
1009     */

1010    public void setProperties(List JavaDoc newProperties) throws java.beans.PropertyVetoException JavaDoc {
1011        List JavaDoc oldProperties = properties;
1012        getVCS().fireVetoableChange("properties", oldProperties, newProperties); // NOI18N
1013
properties = newProperties;
1014        getPCS().firePropertyChange("properties", oldProperties, properties); // NOI18N
1015
}
1016    
1017    public void addProperty(WebProperty newProperty) throws java.beans.PropertyVetoException JavaDoc {
1018        getVCS().fireVetoableChange("property", null, newProperty); // NOI18N
1019
if(properties == null) {
1020            properties = new ArrayList JavaDoc();
1021        }
1022        properties.add(newProperty);
1023        getPCS().firePropertyChange("property", null, newProperty ); // NOI18N
1024
}
1025    
1026    public void removeProperty(WebProperty oldProperty) throws java.beans.PropertyVetoException JavaDoc {
1027        getVCS().fireVetoableChange("property", oldProperty, null); // NOI18N
1028
properties.remove(oldProperty);
1029        getPCS().firePropertyChange("property", oldProperty, null ); // NOI18N
1030
}
1031
1032    /** Getter for property messageDestinations.
1033     * @return Value of property messageDestinations.
1034     *
1035     */

1036    public List JavaDoc getMessageDestinations() {
1037        return messageDestinations;
1038    }
1039    
1040    public MessageDestination getMessageDestination(int index) {
1041        return (MessageDestination) messageDestinations.get(index);
1042    }
1043    
1044    /** Setter for property messageDestinations.
1045     * @param messageDestinations New value of property messageDestinations.
1046     *
1047     * @throws PropertyVetoException
1048     *
1049     */

1050    public void setMessageDestinations(List JavaDoc newMessageDestinations) throws java.beans.PropertyVetoException JavaDoc {
1051        List JavaDoc oldMessageDestinations = messageDestinations;
1052        getVCS().fireVetoableChange("messageDestinations", oldMessageDestinations, newMessageDestinations); // NOI18N
1053
messageDestinations = newMessageDestinations;
1054        getPCS().firePropertyChange("messageDestinations", oldMessageDestinations, messageDestinations); // NOI18N
1055
}
1056    
1057    public void addMessageDestination(MessageDestination newMessageDestination) throws java.beans.PropertyVetoException JavaDoc {
1058        getVCS().fireVetoableChange("messageDestination", null, newMessageDestination); // NOI18N
1059
if(messageDestinations == null) {
1060            messageDestinations = new ArrayList JavaDoc();
1061        }
1062        messageDestinations.add(newMessageDestination);
1063        getPCS().firePropertyChange("messageDestination", null, newMessageDestination ); // NOI18N
1064
}
1065    
1066    public void removeMessageDestination(MessageDestination oldMessageDestination) throws java.beans.PropertyVetoException JavaDoc {
1067        getVCS().fireVetoableChange("messageDestination", oldMessageDestination, null); // NOI18N
1068
messageDestinations.remove(oldMessageDestination);
1069        getPCS().firePropertyChange("messageDestination", oldMessageDestination, null ); // NOI18N
1070
}
1071    
1072    /** Getter for property localeInfo.
1073     * @return Value of property localeInfo.
1074     *
1075     */

1076    public LocaleCharsetInfo getLocaleCharsetInfo() {
1077        return localeInfo;
1078    }
1079    
1080    /** Setter for property localeInfo.
1081     * @param localeInfo New value of property localeInfo.
1082     *
1083     * @throws PropertyVetoException
1084     *
1085     */

1086    public void setLocaleCharsetInfo(LocaleCharsetInfo newLocaleInfo) throws java.beans.PropertyVetoException JavaDoc {
1087        LocaleCharsetInfo oldLocaleInfo = localeInfo;
1088        getVCS().fireVetoableChange("localeInfo", oldLocaleInfo, newLocaleInfo);
1089        localeInfo = newLocaleInfo;
1090        getPCS().firePropertyChange("localeInfo", oldLocaleInfo, localeInfo);
1091    }
1092    
1093    /** Retrieve the java bean that handles the web-app session-config settings
1094     * @return Value of sessionConfigBean.
1095     *
1096     */

1097    public SessionConfigSubBean getSessionConfigBean() {
1098        return sessionConfigBean;
1099    }
1100    
1101    /** Retrieve the java bean that handles the web-app cache settings
1102     * @return Value of cacheBean.
1103     *
1104     */

1105    public WebAppCache getCacheBean() {
1106        return cacheBean;
1107    }
1108}
1109
Popular Tags