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.ConstraintField; 33 import com.sun.enterprise.deployment.xml.RuntimeTagNames; 34 import com.sun.enterprise.deployment.node.XMLElement; 35 36 41 public class ConstraintFieldNode extends WebRuntimeNode { 42 43 49 protected Map getDispatchTable() { 50 Map dispatchTable = super.getDispatchTable(); 51 dispatchTable.put(RuntimeTagNames.VALUE, "addValue"); 53 dispatchTable.put(RuntimeTagNames.CONSTRAINT_FIELD_VALUE, "addValue"); 54 return dispatchTable; 55 } 56 57 public void startElement(XMLElement element, Attributes attributes) { 58 if (element.getQName().equals(RuntimeTagNames.CONSTRAINT_FIELD)) { 59 ConstraintField descriptor = 60 (ConstraintField) getRuntimeDescriptor(); 61 for (int i=0; i<attributes.getLength();i++) { 62 if (RuntimeTagNames.NAME.equals(attributes.getQName(i))) { 63 descriptor.setAttributeValue(ConstraintField.NAME, 64 attributes.getValue(i)); 65 } else 66 if (RuntimeTagNames.SCOPE.equals(attributes.getQName(i))) { 67 descriptor.setAttributeValue(ConstraintField.SCOPE, 68 attributes.getValue(i)); 69 } else 70 if (RuntimeTagNames.CACHE_ON_MATCH.equals( 71 attributes.getQName(i))) { 72 descriptor.setAttributeValue( 73 ConstraintField.CACHE_ON_MATCH, 74 attributes.getValue(i)); 75 } else 76 if (RuntimeTagNames.CACHE_ON_MATCH_FAILURE.equals( 77 attributes.getQName(i))) { 78 descriptor.setAttributeValue( 79 ConstraintField.CACHE_ON_MATCH_FAILURE, 80 attributes.getValue(i)); 81 } 82 } 83 } else if (element.getQName().equals(RuntimeTagNames.VALUE) || 87 element.getQName().equals(RuntimeTagNames.CONSTRAINT_FIELD_VALUE)) { 88 ConstraintField descriptor = 89 (ConstraintField) getRuntimeDescriptor(); 90 int index = descriptor.sizeValue(); 91 for (int i=0; i<attributes.getLength();i++) { 92 if (RuntimeTagNames.MATCH_EXPR.equals( 93 attributes.getQName(i))) { 94 descriptor.setAttributeValue(ConstraintField.VALUE, 95 index, ConstraintField.MATCH_EXPR, 96 attributes.getValue(i)); 97 } else 98 if (RuntimeTagNames.CACHE_ON_MATCH.equals( 99 attributes.getQName(i))) { 100 descriptor.setAttributeValue(ConstraintField.VALUE, 101 index, ConstraintField.CACHE_ON_MATCH, 102 attributes.getValue(i)); 103 } else 104 if (RuntimeTagNames.CACHE_ON_MATCH_FAILURE.equals( 105 attributes.getQName(i))) { 106 descriptor.setAttributeValue(ConstraintField.VALUE, 107 index, ConstraintField.CACHE_ON_MATCH_FAILURE, 108 attributes.getValue(i)); 109 } 110 } 111 } else super.startElement(element, attributes); 112 } 113 114 122 public void writeDescriptor(Node parent, String nodeName, ConstraintField[] descriptors) { 123 for (int i=0;i<descriptors.length;i++) { 124 writeDescriptor(parent, nodeName, descriptors[i]); 125 } 126 } 127 128 136 public Node writeDescriptor(Node parent, String nodeName, ConstraintField descriptor) { 137 138 Element constraintField = (Element ) super.writeDescriptor(parent, nodeName, descriptor); 139 140 String [] values = descriptor.getValue(); 142 for (int i=0;i<values.length;i++) { 143 Element value = (Element ) appendTextChild(constraintField, RuntimeTagNames.CONSTRAINT_FIELD_VALUE, values[i]); 144 setAttribute(value, RuntimeTagNames.MATCH_EXPR, (String ) descriptor.getAttributeValue(ConstraintField.VALUE, i, ConstraintField.MATCH_EXPR)); 145 setAttribute(value, RuntimeTagNames.CACHE_ON_MATCH, (String ) descriptor.getAttributeValue(ConstraintField.VALUE, i, ConstraintField.CACHE_ON_MATCH)); 146 setAttribute(value, RuntimeTagNames.CACHE_ON_MATCH_FAILURE, (String ) descriptor.getAttributeValue(ConstraintField.VALUE, i, ConstraintField.CACHE_ON_MATCH_FAILURE)); 147 148 } 149 setAttribute(constraintField, RuntimeTagNames.NAME, (String ) descriptor.getAttributeValue(ConstraintField.NAME)); 151 setAttribute(constraintField, RuntimeTagNames.SCOPE, (String ) descriptor.getAttributeValue(ConstraintField.SCOPE)); 152 setAttribute(constraintField, RuntimeTagNames.CACHE_ON_MATCH, (String ) descriptor.getAttributeValue(ConstraintField.CACHE_ON_MATCH)); 153 setAttribute(constraintField, RuntimeTagNames.CACHE_ON_MATCH_FAILURE, (String ) descriptor.getAttributeValue(ConstraintField.CACHE_ON_MATCH_FAILURE)); 154 155 return constraintField; 156 } 157 } 158 | Popular Tags |