KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28
29 import java.beans.PropertyChangeSupport JavaDoc;
30 import java.beans.PropertyChangeListener JavaDoc;
31 import java.beans.VetoableChangeSupport JavaDoc;
32 import java.beans.VetoableChangeListener JavaDoc;
33
34 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
35 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
36 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
37 import javax.enterprise.deploy.model.DDBean JavaDoc;
38
39 import org.netbeans.modules.j2ee.sun.share.Constants;
40
41 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
42 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
43 import org.netbeans.modules.j2ee.sun.dd.api.web.Cache;
44 import org.netbeans.modules.j2ee.sun.dd.api.web.CacheHelper;
45 import org.netbeans.modules.j2ee.sun.dd.api.web.CacheMapping;
46 import org.netbeans.modules.j2ee.sun.dd.api.web.DefaultHelper;
47 import org.netbeans.modules.j2ee.sun.dd.api.web.WebProperty;
48
49
50 /** Property structure of cache from DTD
51  *
52  * cache : Cache?
53  * [attr: max-entries CDATA 4096]
54  * [attr: timeout-in-seconds CDATA 30]
55  * [attr: enabled CDATA false] // default is true for 8.1 onward
56  * property : WebProperty[0,n]
57  * [attr: name CDATA #REQUIRED ]
58  * [attr: value CDATA #REQUIRED ]
59  * description : String?
60  * default-helper : DefaultHelper?
61  * property : WebProperty[0,n]
62  * [attr: name CDATA #REQUIRED ]
63  * [attr: value CDATA #REQUIRED ]
64  * description : String?
65  * cache-helper : CacheHelper[0,n]
66  * [attr: name CDATA #REQUIRED ]
67  * [attr: class-name CDATA #REQUIRED ]
68  * property : WebProperty[0,n]
69  * [attr: name CDATA #REQUIRED ]
70  * [attr: value CDATA #REQUIRED ]
71  * description : String?
72  * cache-mapping : CacheMapping[0,n]
73  * | servlet-name : String
74  * | url-pattern : String
75  * | cache-helper-ref : String
76  * | dispatcher <dispatcher> : String[0,n] // 8.1 onward
77  * | timeout : String?
78  * | [attr: name CDATA #REQUIRED ]
79  * | [attr: scope CDATA request.attribute]
80  * | refresh-field : Boolean?
81  * | [attr: name CDATA #REQUIRED ]
82  * | [attr: scope CDATA request.parameter]
83  * | EMPTY : String
84  * | http-method : String[0,n]
85  * | key-field : Boolean[0,n]
86  * | [attr: name CDATA #REQUIRED ]
87  * | [attr: scope CDATA request.parameter]
88  * | EMPTY : String
89  * | constraint-field : ConstraintField[0,n]
90  * | [attr: name CDATA #REQUIRED ]
91  * | [attr: scope CDATA request.parameter]
92  * | [attr: cache-on-match CDATA true]
93  * | [attr: cache-on-match-failure CDATA false]
94  * | constraint-field-value : String[0,n]
95  * | [attr: match-expr CDATA equals]
96  * | [attr: cache-on-match CDATA true]
97  * | [attr: cache-on-match-failure CDATA false]
98  *
99  * This object is a "wanna be" DConfigBean. JSR-88 prevents us from having a real
100  * DConfigBean for the cache block because there is no J2EE deployment descriptor
101  * field to bind it to. I am working with the server team to come up with an
102  * extension that would allow this, but in the meantime, Cache needed it's own
103  * JavaBean oriented object. The implementation is very similar to a regular
104  * DConfigBean but has been wired into the structure differently.
105  *
106  * @author Peter Williams
107  * @version %I%, %G%
108  */

109 public class WebAppCache {
110     
111     /** Resource bundle
112      */

113     private static final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
114         "org.netbeans.modules.j2ee.sun.share.configbean.Bundle"); // NOI18N
115

116     private static final String JavaDoc SunWebFileName = "sun-web.xml"; // NOI18N
117

118     /** takes place of Base.parent, which we don't have */
119     private WebAppRoot webAppRoot;
120     
121     /** Holds value of property cacheMaxEntries. */
122     private String JavaDoc cacheMaxEntries;
123     
124     /** Holds value of property timeoutInSeconds. */
125     private String JavaDoc timeoutInSeconds;
126     
127     /** Holds value of property cacheEnabled. */
128     private String JavaDoc cacheEnabled;
129     
130     /** Holds List of WebProperty's. */
131     private List JavaDoc properties;
132     
133     /** Holds value of property defaultHelper. */
134     private DefaultHelper defaultHelper;
135     
136     /** Holds List of CacheHelpers. */
137     private List JavaDoc cacheHelpers;
138     
139     /** Holds List of CacheMappings. */
140     private List JavaDoc cacheMappings;
141     
142     /** Creates a new instance of WebAppCache */
143     public WebAppCache() {
144     }
145     
146     /** Override init to load from persistent storage if necessary
147      * @param dDBean DDBean matching this bean
148      * @param parent Parent DConfigBean in the tree
149      */

150 /*
151     protected void init(DDBean dDBean, Base parent) throws ConfigurationException {
152         super.init(dDBean, parent);
153         loadFromPlanFile(getConfig());
154     }
155  */

156     protected void init(WebAppRoot parent) {
157         webAppRoot = parent;
158         
159 // loadFromPlanFile(config); // !PW handled by WebAppRoot
160
}
161     
162     public Base getParent() {
163         return webAppRoot;
164     }
165     
166     /** -----------------------------------------------------------------------
167      * Validation support
168      */

169     /** isValid represents the valid state of the bean:
170      * null: unknown
171      * TRUE: bean is valid
172      * FALSE: bean has at least one invalid field.
173      */

174     private Boolean JavaDoc isValid = null;
175     
176     protected List JavaDoc validationFieldList = new ArrayList JavaDoc();
177     
178     public static final String JavaDoc FIELD_CACHE_MAX_ENTRIES=":max-entries";
179     public static final String JavaDoc FIELD_CACHE_TIMEOUT=":timeout";
180     
181     protected void updateValidationFieldList() {
182         validationFieldList.add(FIELD_CACHE_MAX_ENTRIES);
183         validationFieldList.add(FIELD_CACHE_TIMEOUT);
184     }
185     
186     public void validationStateChanged(Boolean JavaDoc newState) {
187         isValid = newState;
188     }
189     
190     /** Returns previous result of validateFields() or invokes method if status is
191      * out of date.
192      *
193      * @return true if valid, false otherwise.
194      */

195     public boolean isValid() {
196         if(isValid == null) {
197             boolean tempValid = validateFields(true);
198             isValid = Boolean.valueOf(tempValid);
199         }
200         
201         return isValid.booleanValue();
202     }
203     
204     /** Validate the fields managed by this bean. Used by the customizers
205      * (and possibly incremental deployment.)
206      *
207      * @return true or false as to whether bean is valid or not.
208      */

209     public boolean validateFields(boolean shortCircuit) {
210         ErrorMessageDB messageDB = webAppRoot.getMessageDB();
211         boolean result = true;
212         
213         messageDB.clearErrors();
214         for(Iterator JavaDoc iter = validationFieldList.iterator(); iter.hasNext() && (result || !shortCircuit); ) {
215             boolean fieldResult = validateField((String JavaDoc) iter.next());
216             result = result && fieldResult;
217         }
218         
219         return result;
220     }
221
222     /** Validate a single field managed by this bean. Used by the customizers
223      * (and possibly incremental deployment.)
224      *
225      * @param field Field spec (xpath to this field in DTD, should be defined
226      * constant in bean class.)
227      * @return true or false as to whether field is valid or not.
228      */

229     public boolean validateField(String JavaDoc fieldId) {
230         ValidationError error = null;
231         
232         if(fieldId.equals(FIELD_CACHE_MAX_ENTRIES)) {
233             String JavaDoc absoluteFieldXpath = getAbsoluteXpath(fieldId);
234             
235             if(Utils.notEmpty(cacheMaxEntries)) {
236                 try {
237                     int value = Integer.parseInt(cacheMaxEntries);
238                     if(value < 0) {
239                         Object JavaDoc [] args = new Object JavaDoc[2];
240                         args[0] = cacheMaxEntries;
241                         args[1] = "0"; // NOI18N
242
String JavaDoc message = MessageFormat.format(bundle.getString("ERR_NumberTooLow"), args); // NOI18N
243
error = ValidationError.getValidationError(ValidationError.PARTITION_CACHE_GENERAL, absoluteFieldXpath, message);
244                     }
245                 } catch(NumberFormatException JavaDoc ex) {
246                     Object JavaDoc [] args = new Object JavaDoc[1];
247                     args[0] = cacheMaxEntries; // NOI18N
248
String JavaDoc message = MessageFormat.format(bundle.getString("ERR_NumberInvalid"), args); // NOI18N
249
error = ValidationError.getValidationError(ValidationError.PARTITION_CACHE_GENERAL, absoluteFieldXpath, message);
250                 }
251             }
252             
253             if(error == null) {
254                 error = ValidationError.getValidationErrorMask(ValidationError.PARTITION_CACHE_GENERAL, absoluteFieldXpath);
255             }
256         } else if(fieldId.equals(FIELD_CACHE_TIMEOUT)) {
257             String JavaDoc absoluteFieldXpath = getAbsoluteXpath(fieldId);
258             
259             if(Utils.notEmpty(timeoutInSeconds)) {
260                 try {
261                     int value = Integer.parseInt(timeoutInSeconds);
262                     if(value < -1) {
263                         Object JavaDoc [] args = new Object JavaDoc[2];
264                         args[0] = timeoutInSeconds;
265                         args[1] = "-1"; // NOI18N
266
String JavaDoc message = MessageFormat.format(bundle.getString("ERR_NumberTooLow"), args); // NOI18N
267
error = ValidationError.getValidationError(ValidationError.PARTITION_CACHE_GENERAL, absoluteFieldXpath, message);
268                     }
269                 } catch(NumberFormatException JavaDoc ex) {
270                     Object JavaDoc [] args = new Object JavaDoc[1];
271                     args[0] = timeoutInSeconds; // NOI18N
272
String JavaDoc message = MessageFormat.format(bundle.getString("ERR_NumberInvalid"), args); // NOI18N
273
error = ValidationError.getValidationError(ValidationError.PARTITION_CACHE_GENERAL, absoluteFieldXpath, message);
274                 }
275             }
276             
277             if(error == null) {
278                 error = ValidationError.getValidationErrorMask(ValidationError.PARTITION_CACHE_GENERAL, absoluteFieldXpath);
279             }
280         }
281         
282         if(error != null) {
283             webAppRoot.getMessageDB().updateError(error);
284         }
285         
286         // return true if there was no error added
287
return (error == null || !Utils.notEmpty(error.getMessage()));
288     }
289     
290     protected String JavaDoc getAbsoluteXpath(String JavaDoc field) {
291         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(field.length() + 20);
292         buf.append("/sun-web-app/cache/"); // NOI18N
293
buf.append(field);
294         return buf.toString();
295     }
296     
297     /** -----------------------------------------------------------------------
298      */

299     
300     /** Getter for property cacheMaxEntries.
301      * @return Value of property cacheMaxEntries.
302      *
303      */

304     public String JavaDoc getCacheMaxEntries() {
305         return this.cacheMaxEntries;
306     }
307     
308     /** Setter for property cacheMaxEntries.
309      * @param newCacheMaxEntries New value of property cacheMaxEntries.
310      *
311      * @throws PropertyVetoException
312      *
313      */

314     public void setCacheMaxEntries(String JavaDoc newCacheMaxEntries) throws java.beans.PropertyVetoException JavaDoc {
315         if(newCacheMaxEntries == null || newCacheMaxEntries.length() == 0) { // if empty, set to null
316
newCacheMaxEntries = null;
317         }
318         
319         String JavaDoc oldCacheMaxEntries = cacheMaxEntries;
320         getVCS().fireVetoableChange("cacheMaxEntries", oldCacheMaxEntries, newCacheMaxEntries); // NOI18N
321
cacheMaxEntries = newCacheMaxEntries;
322         getPCS().firePropertyChange("cacheMaxEntries", oldCacheMaxEntries, cacheMaxEntries); // NOI18N
323
}
324
325     /** Getter for property timeoutInSeconds.
326      * @return Value of property timeoutInSeconds.
327      *
328      */

329     public String JavaDoc getTimeoutInSeconds() {
330         return timeoutInSeconds;
331     }
332     
333     /** Setter for property timeoutInSeconds.
334      * @param newTimeoutInSeconds New value of property timeoutInSeconds.
335      *
336      * @throws PropertyVetoException
337      *
338      */

339     public void setTimeoutInSeconds(String JavaDoc newTimeoutInSeconds) throws java.beans.PropertyVetoException JavaDoc {
340         if(newTimeoutInSeconds == null || newTimeoutInSeconds.length() == 0) { // if empty, set to null
341
newTimeoutInSeconds = null;
342         }
343         
344         String JavaDoc oldTimeoutInSeconds = timeoutInSeconds;
345         getVCS().fireVetoableChange("timeoutInSeconds", oldTimeoutInSeconds, newTimeoutInSeconds); // NOI18N
346
timeoutInSeconds = newTimeoutInSeconds;
347         getPCS().firePropertyChange("timeoutInSeconds", oldTimeoutInSeconds, timeoutInSeconds); // NOI18N
348
}
349
350     /** Getter for property cacheEnabled.
351      * @return Value of property cacheEnabled.
352      *
353      */

354     public String JavaDoc getCacheEnabled() {
355         return cacheEnabled;
356     }
357     
358     /** Setter for property cacheEnabled.
359      * @param newCacheEnabled New value of property cacheEnabled.
360      *
361      * @throws PropertyVetoException
362      *
363      */

364     public void setCacheEnabled(String JavaDoc newCacheEnabled) throws java.beans.PropertyVetoException JavaDoc {
365         String JavaDoc oldClassLoader = cacheEnabled;
366         getVCS().fireVetoableChange("cacheEnabled", new Boolean JavaDoc(oldClassLoader), new Boolean JavaDoc(newCacheEnabled)); // NOI18N
367
cacheEnabled = newCacheEnabled;
368         getPCS().firePropertyChange("cacheEnabled", new Boolean JavaDoc(oldClassLoader), new Boolean JavaDoc(cacheEnabled)); // NOI18N
369
}
370     
371     /** Getter for property Property.
372      * @return Value of property pPoperty.
373      *
374      */

375     public List JavaDoc getProperties() {
376         return properties;
377     }
378     
379     public WebProperty getProperty(int index) {
380         return (WebProperty) properties.get(index);
381     }
382     
383     /** Setter for property Property.
384      * @param property New value of property Property.
385      *
386      * @throws PropertyVetoException
387      *
388      */

389     public void setProperties(List JavaDoc newProperties) throws java.beans.PropertyVetoException JavaDoc {
390         List JavaDoc oldProperties = properties;
391         getVCS().fireVetoableChange("properties", oldProperties, newProperties); // NOI18N
392
properties = newProperties;
393         getPCS().firePropertyChange("properties", oldProperties, properties); // NOI18N
394
}
395     
396     public void addProperty(WebProperty newProperty) throws java.beans.PropertyVetoException JavaDoc {
397         getVCS().fireVetoableChange("property", null, newProperty); // NOI18N
398
if(properties == null) {
399             properties = new ArrayList JavaDoc();
400         }
401         properties.add(newProperty);
402         getPCS().firePropertyChange("property", null, newProperty ); // NOI18N
403
}
404     
405     public void removeProperty(WebProperty oldProperty) throws java.beans.PropertyVetoException JavaDoc {
406         getVCS().fireVetoableChange("property", oldProperty, null); // NOI18N
407
properties.remove(oldProperty);
408         getPCS().firePropertyChange("property", oldProperty, null ); // NOI18N
409
}
410     
411     /** Getter for property defaultHelper.
412      * @return Value of property defaultHelper.
413      */

414     public DefaultHelper getDefaultHelper() {
415         return this.defaultHelper;
416     }
417     
418     /** Setter for property defaultHelper.
419      * @param newDefaultHelper New value of property defaultHelper.
420      *
421      * @throws PropertyVetoException
422      */

423     public void setDefaultHelper(DefaultHelper newDefaultHelper) throws java.beans.PropertyVetoException JavaDoc {
424         if(newDefaultHelper == null) {
425             newDefaultHelper = webAppRoot.getConfig().getStorageFactory().createDefaultHelper();
426         }
427         
428         DefaultHelper oldDefaultHelper = this.defaultHelper;
429         getVCS().fireVetoableChange("defaultHelper", oldDefaultHelper, newDefaultHelper); // NOI18N
430
this.defaultHelper = newDefaultHelper;
431         getPCS().firePropertyChange("defaultHelper", oldDefaultHelper, defaultHelper); // NOI18N
432
}
433     
434     /** Getter for property cacheHelpers.
435      * @return Value of property cacheHelpers.
436      *
437      */

438     public List JavaDoc getCacheHelpers() {
439         return cacheHelpers;
440     }
441     
442     public CacheHelper getCacheHelper(int index) {
443         return (CacheHelper) cacheHelpers.get(index);
444     }
445     
446     /** Setter for property cacheHelpers.
447      * @param newCacheHelpers New value of property cacheHelpers.
448      *
449      * @throws PropertyVetoException
450      *
451      */

452     public void setCacheHelpers(List JavaDoc newCacheHelpers) throws java.beans.PropertyVetoException JavaDoc {
453         List JavaDoc oldCacheHelpers = cacheHelpers;
454         getVCS().fireVetoableChange("cacheHelpers", oldCacheHelpers, newCacheHelpers); // NOI18N
455
cacheHelpers = newCacheHelpers;
456         getPCS().firePropertyChange("cacheHelpers", oldCacheHelpers, cacheHelpers); // NOI18N
457
}
458     
459     public void addProperty(CacheHelper newCacheHelper) throws java.beans.PropertyVetoException JavaDoc {
460         getVCS().fireVetoableChange("cacheHelper", null, newCacheHelper); // NOI18N
461
if(cacheHelpers == null) {
462             cacheHelpers = new ArrayList JavaDoc();
463         }
464         cacheHelpers.add(newCacheHelper);
465         getPCS().firePropertyChange("cacheHelper", null, newCacheHelper); // NOI18N
466
}
467     
468     public void removeProperty(CacheHelper oldCacheHelper) throws java.beans.PropertyVetoException JavaDoc {
469         getVCS().fireVetoableChange("cacheHelper", oldCacheHelper, null); // NOI18N
470
cacheHelpers.remove(oldCacheHelper);
471         getPCS().firePropertyChange("cacheHelper", oldCacheHelper, null ); // NOI18N
472
}
473
474     /** Getter for property cacheMappings.
475      * @return Value of property cacheMappings.
476      *
477      */

478     public List JavaDoc getCacheMappings() {
479         return cacheMappings;
480     }
481     
482     public CacheMapping getCacheMapping(int index) {
483         return (CacheMapping) cacheMappings.get(index);
484     }
485     
486     /** Setter for property cacheMappings.
487      * @param newCacheMappings New value of property cacheMappings.
488      *
489      * @throws PropertyVetoException
490      *
491      */

492     public void setCacheMappings(List JavaDoc newCacheMappings) throws java.beans.PropertyVetoException JavaDoc {
493         List JavaDoc oldCacheMappings = cacheMappings;
494         getVCS().fireVetoableChange("cacheMappings", oldCacheMappings, newCacheMappings); // NOI18N
495
cacheMappings = newCacheMappings;
496         getPCS().firePropertyChange("cacheMappings", oldCacheMappings, cacheMappings); // NOI18N
497
}
498     
499     public void addCacheMapping(CacheMapping newCacheMapping) throws java.beans.PropertyVetoException JavaDoc {
500         getVCS().fireVetoableChange("cacheMapping", null, newCacheMapping); // NOI18N
501
if(cacheMappings == null) {
502             cacheMappings = new ArrayList JavaDoc();
503         }
504         cacheMappings.add(newCacheMapping);
505         getPCS().firePropertyChange("cacheMapping", null, newCacheMapping); // NOI18N
506
}
507     
508     public void removeCacheMapping(CacheMapping oldCacheMapping) throws java.beans.PropertyVetoException JavaDoc {
509         getVCS().fireVetoableChange("cacheMapping", oldCacheMapping, null); // NOI18N
510
cacheMappings.remove(oldCacheMapping);
511         getPCS().firePropertyChange("cacheMapping", oldCacheMapping, null ); // NOI18N
512
}
513
514     
515     /* ------------------------------------------------------------------------
516      * Persistence support. Loads DConfigBeans from previously saved Deployment
517      * plan file.
518      */

519     Collection JavaDoc getSnippets() {
520         Collection JavaDoc snippets = new ArrayList JavaDoc();
521         Snippet snipOne = new Snippet() {
522             
523             public org.netbeans.modules.schema2beans.BaseBean getCmpDDSnippet() {
524                 return null;
525             }
526
527             public CommonDDBean getDDSnippet() {
528                 Cache cache = webAppRoot.getConfig().getStorageFactory().createCache_NoDefaults();
529                 String JavaDoc version = webAppRoot.getAppServerVersion().getWebAppVersionAsString();
530                 
531                 // simple properties
532
if(cacheMaxEntries != null) {
533                     cache.setMaxEntries(cacheMaxEntries);
534                 }
535                 
536                 if(timeoutInSeconds != null) {
537                     cache.setTimeoutInSeconds(timeoutInSeconds);
538                 }
539                 
540                 if(cacheEnabled != null) {
541                     cache.setEnabled(cacheEnabled);
542                 }
543                 
544                 // cache helpers
545
CacheHelper [] helpers = (CacheHelper [])
546                     Utils.listToArray(getCacheHelpers(), CacheHelper.class, version);
547                 if(helpers != null) {
548                     cache.setCacheHelper(helpers);
549                 }
550                 
551                 // default helper
552
DefaultHelper dh = getDefaultHelper();
553                 if(dh.sizeWebProperty() > 0) {
554                     cache.setDefaultHelper((DefaultHelper) dh.cloneVersion(version));
555                 }
556                 
557                 // properties
558
WebProperty [] webProps = (WebProperty [])
559                     Utils.listToArray(getProperties(), WebProperty.class, version);
560                 if(webProps != null) {
561                     cache.setWebProperty(webProps);
562                 }
563                 
564                 // cache mappings
565
CacheMapping [] mappings = (CacheMapping [])
566                     Utils.listToArray(getCacheMappings(), CacheMapping.class, version);
567                 if(mappings != null) {
568                     cache.setCacheMapping(mappings);
569                 }
570                 
571                 return cache;
572             }
573
574             public boolean hasDDSnippet() {
575                 if(getCacheMaxEntries() != null) {
576                     return true;
577                 }
578                 
579                 if(getTimeoutInSeconds() != null) {
580                     return true;
581                 }
582                 
583                 if(getCacheEnabled() != null) {
584                     return true;
585                 }
586                 
587                 List JavaDoc cacheHelpers = getCacheHelpers();
588                 if(cacheHelpers != null && cacheHelpers.size() > 0) {
589                     return true;
590                 }
591                 
592                 DefaultHelper dh = getDefaultHelper();
593                 if(dh.sizeWebProperty() > 0) {
594                     return true;
595                 }
596                 
597                 List JavaDoc properties = getProperties();
598                 if(properties != null && properties.size() > 0) {
599                     return true;
600                 }
601                 
602                 List JavaDoc cacheMappings = getCacheMappings();
603                 if(cacheMappings != null && cacheMappings.size() > 0) {
604                     return true;
605                 }
606                 
607                 return false;
608             }
609             
610             public String JavaDoc getPropertyName() {
611                 return SunWebApp.CACHE;
612             }
613
614 /** ---------------------------------------------------------------------------
615  * The following methods would have been inherited from DefaultSnippet if we
616  * could derive from that class. (Another artifact of not being a real DConfigBean
617  */

618             public String JavaDoc getFileName() {
619                 return SunWebFileName; // NOI18N
620
}
621             
622             public CommonDDBean mergeIntoRootDD(CommonDDBean ddRoot) {
623                 Cache cache = (Cache) getDDSnippet();
624                 
625                 if(ddRoot instanceof SunWebApp) {
626                     SunWebApp swa = (SunWebApp) ddRoot;
627                     swa.setCache(cache);
628                 }
629                 
630                 return cache;
631             }
632
633             public CommonDDBean mergeIntoRovingDD(CommonDDBean ddParent) {
634                 // !PW I don't think this can ever be called, but if so, it should
635
// be called with ddParent being an instance of SunWebApp and so
636
// mergeIntoRootDD() performs the correct action.
637
//
638
return mergeIntoRootDD(ddParent);
639             }
640 /** ------------------------------------------------------------------------- */
641         };
642         
643         snippets.add(snipOne);
644         return snippets;
645     }
646         
647     private class CacheFinder implements ConfigFinder {
648         public Object JavaDoc find(Object JavaDoc obj) {
649             Cache result = null;
650             
651             if(obj instanceof SunWebApp) {
652                 SunWebApp swa = (SunWebApp) obj;
653                 result = swa.getCache();
654             }
655             
656             return result;
657         }
658     }
659     
660     boolean loadFromPlanFile(SunONEDeploymentConfiguration config) {
661         String JavaDoc uriText = webAppRoot.getUriText();
662         
663         Cache beanGraph = (Cache) config.getBeans(
664             uriText, SunWebFileName, webAppRoot.getParser(), new CacheFinder());
665         
666         clearProperties();
667         
668         if(null != beanGraph) {
669             cacheMaxEntries = beanGraph.getMaxEntries();
670             timeoutInSeconds = beanGraph.getTimeoutInSeconds();
671             cacheEnabled = beanGraph.getEnabled();
672
673             cacheHelpers = Utils.arrayToList(beanGraph.getCacheHelper());
674
675             DefaultHelper dh = beanGraph.getDefaultHelper();
676             if(dh != null && dh.sizeWebProperty() > 0) {
677                 defaultHelper = (DefaultHelper) dh.clone();
678             }
679             
680             properties = Utils.arrayToList(beanGraph.getWebProperty());
681             cacheMappings = Utils.arrayToList(beanGraph.getCacheMapping());
682         } else {
683             setDefaultProperties();
684         }
685         
686         return (beanGraph != null);
687     }
688     
689     protected void clearProperties() {
690         cacheMaxEntries = null;
691         timeoutInSeconds = null;
692         cacheEnabled = null;
693         cacheHelpers = null;
694         defaultHelper = webAppRoot.getConfig().getStorageFactory().createDefaultHelper();
695         properties = null;
696         cacheMappings = null;
697     }
698     
699     protected void setDefaultProperties() {
700         // no defaults
701
}
702     
703     /** -----------------------------------------------------------------------
704      * JavaBean support that would have been inherited from Base if this was a
705      * true DConfigBean.
706      *
707      * !PW I amended this code to forward property notifications
708      * to the webAppRoot parent DConfigBean.
709      */

710     /**
711      * @return PropertyChangeSupport object used by this bean.
712      */

713     protected java.beans.PropertyChangeSupport JavaDoc getPCS() {
714         return webAppRoot.getPCS();
715     }
716
717     /**
718      * @return VetoableChangeSupport object used by this bean.
719      */

720     protected java.beans.VetoableChangeSupport JavaDoc getVCS() {
721         return webAppRoot.getVCS();
722     }
723 }
724
Popular Tags