1 23 24 package com.sun.enterprise.deployment.node.runtime.web; 25 26 import java.util.Map ; 27 import org.xml.sax.Attributes ; 28 import org.w3c.dom.Node ; 29 import org.w3c.dom.Element ; 30 31 import com.sun.enterprise.deployment.runtime.RuntimeDescriptor; 32 import com.sun.enterprise.deployment.runtime.web.CacheMapping; 33 import com.sun.enterprise.deployment.runtime.web.ConstraintField; 34 import com.sun.enterprise.deployment.xml.RuntimeTagNames; 35 import com.sun.enterprise.deployment.node.XMLElement; 36 37 42 public class CacheMappingNode extends WebRuntimeNode { 43 44 public CacheMappingNode() { 45 46 registerElementHandler(new XMLElement(RuntimeTagNames.CONSTRAINT_FIELD), 47 ConstraintFieldNode.class, "addNewConstraintField"); 48 } 49 50 56 protected Map getDispatchTable() { 57 Map dispatchTable = super.getDispatchTable(); 58 dispatchTable.put(RuntimeTagNames.SERVLET_NAME, "setServletName"); 59 dispatchTable.put(RuntimeTagNames.URL_PATTERN, "setUrlPattern"); 60 dispatchTable.put(RuntimeTagNames.CACHE_HELPER_REF, "setCacheHelperRef"); 61 dispatchTable.put(RuntimeTagNames.TIMEOUT, "setTimeout"); 62 dispatchTable.put(RuntimeTagNames.HTTP_METHOD, "addNewHttpMethod"); 63 dispatchTable.put(RuntimeTagNames.DISPATCHER, "addNewDispatcher"); 64 return dispatchTable; 65 } 66 67 public void startElement(XMLElement element, Attributes attributes) { 68 CacheMapping descriptor = (CacheMapping) getRuntimeDescriptor(); 69 if (descriptor==null) { 70 throw new RuntimeException ("Trying to set values on a null descriptor"); 71 } 72 if (element.getQName().equals(RuntimeTagNames.TIMEOUT)) { 73 for (int i=0; i<attributes.getLength();i++) { 74 if (RuntimeTagNames.NAME.equals(attributes.getQName(i))) { 75 descriptor.setAttributeValue(CacheMapping.TIMEOUT, CacheMapping.NAME, attributes.getValue(i)); 76 } else 77 if (RuntimeTagNames.SCOPE.equals(attributes.getQName(i))) { 78 int index=0; 79 while (descriptor.getAttributeValue(CacheMapping.TIMEOUT, index, CacheMapping.NAME)!=null) { 80 index++; 81 } 82 descriptor.setAttributeValue(CacheMapping.TIMEOUT, index-1, CacheMapping.SCOPE, attributes.getValue(i)); 83 } 84 } 85 } else 86 if (element.getQName().equals(RuntimeTagNames.REFRESH_FIELD)) { 87 descriptor.setRefreshField(true); 88 for (int i=0; i<attributes.getLength();i++) { 89 if (RuntimeTagNames.NAME.equals(attributes.getQName(i))) { 90 descriptor.setAttributeValue(CacheMapping.REFRESH_FIELD, 0, CacheMapping.NAME, attributes.getValue(i)); 91 } else 92 if (RuntimeTagNames.SCOPE.equals(attributes.getQName(i))) { 93 descriptor.setAttributeValue(CacheMapping.REFRESH_FIELD, 0, CacheMapping.SCOPE, attributes.getValue(i)); 94 } 95 } 96 } else 97 if (element.getQName().equals(RuntimeTagNames.KEY_FIELD)) { 98 descriptor.addKeyField(true); 99 for (int i=0; i<attributes.getLength();i++) { 100 if (RuntimeTagNames.NAME.equals(attributes.getQName(i))) { 101 descriptor.setAttributeValue(CacheMapping.KEY_FIELD, CacheMapping.NAME, attributes.getValue(i)); 102 } else 103 if (RuntimeTagNames.SCOPE.equals(attributes.getQName(i))) { 104 int index = descriptor.sizeKeyField(); 105 descriptor.setAttributeValue(CacheMapping.KEY_FIELD, index-1, CacheMapping.SCOPE, attributes.getValue(i)); 106 } 107 } 108 } else super.startElement(element, attributes); 109 } 110 111 119 public Node writeDescriptor(Node parent, String nodeName, CacheMapping descriptor) { 120 Node cacheMapping = super.writeDescriptor(parent, nodeName, descriptor); 121 if (descriptor.getServletName()!=null) { 122 appendTextChild(cacheMapping, RuntimeTagNames.SERVLET_NAME, descriptor.getServletName()); 123 } else { 124 appendTextChild(cacheMapping, RuntimeTagNames.URL_PATTERN, descriptor.getUrlPattern()); 125 } 126 127 appendTextChild(cacheMapping, RuntimeTagNames.CACHE_HELPER_REF, 129 (String ) descriptor.getValue(CacheMapping.CACHE_HELPER_REF)); 130 131 String [] dispatchers = descriptor.getDispatcher(); 133 if (dispatchers!=null) { 134 for (int i=0;i<dispatchers.length;i++) { 135 appendTextChild(cacheMapping, RuntimeTagNames.DISPATCHER, dispatchers[i]); 136 } 137 } 138 139 Element timeout = (Element ) forceAppendTextChild(cacheMapping, RuntimeTagNames.TIMEOUT, 141 (String ) descriptor.getValue(CacheMapping.TIMEOUT)); 142 String name = descriptor.getAttributeValue(CacheMapping.TIMEOUT, CacheMapping.NAME); 144 if (name!=null) { 145 setAttribute(timeout, RuntimeTagNames.NAME, name); 146 } 147 String scope = descriptor.getAttributeValue(CacheMapping.TIMEOUT, CacheMapping.SCOPE); 148 if (scope!=null) { 149 setAttribute(timeout, RuntimeTagNames.SCOPE, scope); 150 } 151 152 if (descriptor.isRefreshField()) { 154 Element refreshField = (Element ) appendChild(cacheMapping, RuntimeTagNames.REFRESH_FIELD); 155 setAttribute(refreshField, RuntimeTagNames.NAME, 156 (String ) descriptor.getAttributeValue(CacheMapping.REFRESH_FIELD, CacheMapping.NAME)); 157 setAttribute(refreshField, RuntimeTagNames.SCOPE, 158 (String ) descriptor.getAttributeValue(CacheMapping.REFRESH_FIELD, CacheMapping.SCOPE)); 159 } 160 161 String [] httpMethods = descriptor.getHttpMethod(); 163 if (httpMethods!=null) { 164 for (int i=0;i<httpMethods.length;i++) { 165 appendTextChild(cacheMapping, RuntimeTagNames.HTTP_METHOD, httpMethods[i]); 166 } 167 } 168 169 if (descriptor.sizeKeyField()>0) { 171 for (int i=0;i<descriptor.sizeKeyField();i++) { 172 173 if (descriptor.isKeyField(i)) { 174 Element keyField = (Element ) appendChild(cacheMapping, RuntimeTagNames.KEY_FIELD); 175 setAttribute(keyField, RuntimeTagNames.NAME, 176 (String ) descriptor.getAttributeValue(CacheMapping.KEY_FIELD, i, CacheMapping.NAME)); 177 setAttribute(keyField, RuntimeTagNames.SCOPE, 178 (String ) descriptor.getAttributeValue(CacheMapping.KEY_FIELD, i, CacheMapping.SCOPE)); 179 } 180 } 181 } 182 183 if (descriptor.sizeConstraintField()>0) { 185 ConstraintField[] constraintFields = descriptor.getConstraintField(); 186 ConstraintFieldNode cfn = new ConstraintFieldNode(); 187 cfn.writeDescriptor(cacheMapping, RuntimeTagNames.CONSTRAINT_FIELD, constraintFields); 188 } 189 190 return cacheMapping; 191 } 192 } 193 | Popular Tags |