1 23 24 package com.sun.enterprise.deployment.node.runtime.web; 25 26 import java.util.Map ; 27 import org.w3c.dom.Node ; 28 import org.w3c.dom.Element ; 29 30 import com.sun.enterprise.deployment.runtime.RuntimeDescriptor; 31 import com.sun.enterprise.deployment.runtime.web.Cache; 32 import com.sun.enterprise.deployment.runtime.web.CacheHelper; 33 import com.sun.enterprise.deployment.runtime.web.DefaultHelper; 34 import com.sun.enterprise.deployment.runtime.web.CacheMapping; 35 import com.sun.enterprise.deployment.xml.RuntimeTagNames; 36 import com.sun.enterprise.deployment.node.XMLElement; 37 38 43 public class CacheNode extends WebRuntimeNode { 44 45 public CacheNode() { 46 47 registerElementHandler(new XMLElement(RuntimeTagNames.CACHE_HELPER), 48 CacheHelperNode.class, "addNewCacheHelper"); 49 registerElementHandler(new XMLElement(RuntimeTagNames.DEFAULT_HELPER), 50 WebPropertyNode.class, "setDefaultHelper"); 51 registerElementHandler(new XMLElement(RuntimeTagNames.PROPERTY), 52 WebPropertyNode.class, "addWebProperty"); 53 registerElementHandler(new XMLElement(RuntimeTagNames.CACHE_MAPPING), 54 CacheMappingNode.class, "addNewCacheMapping"); 55 } 56 64 protected boolean setAttributeValue(XMLElement elementName, XMLElement attributeName, String value) { 65 RuntimeDescriptor descriptor = (RuntimeDescriptor) getRuntimeDescriptor(); 66 if (descriptor==null) { 67 throw new RuntimeException ("Trying to set values on a null descriptor"); 68 } 69 if (attributeName.getQName().equals(RuntimeTagNames.MAX_ENTRIES)) { 70 descriptor.setAttributeValue(Cache.MAX_ENTRIES, value); 71 return true; 72 } else 73 if (attributeName.getQName().equals(RuntimeTagNames.TIMEOUT_IN_SECONDS)) { 74 descriptor.setAttributeValue(Cache.TIMEOUT_IN_SECONDS, value); 75 return true; 76 } else 77 if (attributeName.getQName().equals(RuntimeTagNames.ENABLED)) { 78 descriptor.setAttributeValue(Cache.ENABLED, value); 79 return true; 80 } else 81 return false; 82 } 83 84 92 public Node writeDescriptor(Node parent, String nodeName, Cache descriptor) { 93 94 Element cache = (Element ) super.writeDescriptor(parent, nodeName, descriptor); 95 96 CacheHelper[] cacheHelpers = descriptor.getCacheHelper(); 98 if (cacheHelpers!=null && cacheHelpers.length>0) { 99 CacheHelperNode chn = new CacheHelperNode(); 100 for (int i=0;i<cacheHelpers.length;i++) { 101 chn.writeDescriptor(cache, RuntimeTagNames.CACHE_HELPER, cacheHelpers [i]); 102 } 103 } 104 105 WebPropertyNode wpn = new WebPropertyNode(); 106 107 DefaultHelper dh = descriptor.getDefaultHelper(); 109 if (dh!=null && dh.getWebProperty()!=null) { 110 Node dhn = appendChild(cache, RuntimeTagNames.DEFAULT_HELPER); 111 wpn.writeDescriptor(dhn, RuntimeTagNames.PROPERTY, dh.getWebProperty()); 112 } 113 114 wpn.writeDescriptor(cache, RuntimeTagNames.PROPERTY, descriptor.getWebProperty()); 116 117 CacheMapping[] mappings = descriptor.getCacheMapping(); 119 if (mappings!=null && mappings.length>0) { 120 CacheMappingNode cmn = new CacheMappingNode(); 121 for (int i=0;i<mappings.length;i++) { 122 cmn.writeDescriptor(cache, RuntimeTagNames.CACHE_MAPPING, mappings[i]); 123 } 124 } 125 126 setAttribute(cache, RuntimeTagNames.MAX_ENTRIES, (String ) descriptor.getAttributeValue(Cache.MAX_ENTRIES)); 128 setAttribute(cache, RuntimeTagNames.TIMEOUT_IN_SECONDS, (String ) descriptor.getAttributeValue(Cache.TIMEOUT_IN_SECONDS)); 129 setAttribute(cache, RuntimeTagNames.ENABLED, (String ) descriptor.getAttributeValue(Cache.ENABLED)); 130 131 return cache; 132 } 133 } 134 | Popular Tags |