1 23 24 package com.sun.enterprise.deployment.node; 25 26 import java.util.Map ; 27 import org.w3c.dom.Node ; 28 29 import com.sun.enterprise.deployment.InjectionTarget; 30 import com.sun.enterprise.deployment.xml.TagNames; 31 import com.sun.enterprise.deployment.Descriptor; 32 import com.sun.enterprise.deployment.EnvironmentProperty; 33 34 40 public class EnvEntryNode extends DeploymentDescriptorNode { 41 42 private boolean setValueCalled = false; 43 44 public EnvEntryNode() { 45 super(); 46 registerElementHandler(new XMLElement(TagNames.INJECTION_TARGET), 47 InjectionTargetNode.class, "addInjectionTarget"); 48 } 49 50 56 protected Map getDispatchTable() { 57 Map table = super.getDispatchTable(); 58 table.put(TagNames.ENVIRONMENT_PROPERTY_NAME, "setName"); 59 table.put(TagNames.ENVIRONMENT_PROPERTY_VALUE, "setValue"); 60 table.put(TagNames.ENVIRONMENT_PROPERTY_TYPE, "setType"); 61 table.put(TagNames.MAPPED_NAME, "setMappedName"); 62 return table; 63 } 64 65 public boolean endElement(XMLElement element) { 66 67 if (TagNames.ENVIRONMENT_PROPERTY_NAME.equals(element.getQName())) { 68 setValueCalled = false; 71 } else if( TagNames.ENVIRONMENT_PROPERTY_VALUE.equals 72 (element.getQName()) ) { 73 setValueCalled = true; 74 } 75 76 return super.endElement(element); 77 } 78 79 public void addDescriptor(Object newDescriptor) { 80 if( setValueCalled ) { 81 super.addDescriptor(newDescriptor); 82 } else { 83 } 86 } 87 88 96 public Node writeDescriptor(Node parent, String nodeName, Descriptor descriptor) { 97 if (!(descriptor instanceof EnvironmentProperty)) { 98 throw new IllegalArgumentException (getClass() + " cannot handles descriptors of type " + descriptor.getClass()); 99 } 100 EnvironmentProperty envProp = (EnvironmentProperty) descriptor; 101 Node envEntryNode = super.writeDescriptor(parent, nodeName, descriptor); 102 103 writeLocalizedDescriptions(envEntryNode, envProp); 104 appendTextChild(envEntryNode, TagNames.ENVIRONMENT_PROPERTY_NAME, envProp.getName()); 105 appendTextChild(envEntryNode, TagNames.ENVIRONMENT_PROPERTY_TYPE, envProp.getType()); 106 appendTextChild(envEntryNode, TagNames.ENVIRONMENT_PROPERTY_VALUE, envProp.getValue()); 107 appendTextChild(envEntryNode, TagNames.MAPPED_NAME, envProp.getMappedName()); 108 if( envProp.isInjectable() ) { 109 InjectionTargetNode ijNode = new InjectionTargetNode(); 110 for (InjectionTarget target : envProp.getInjectionTargets()) { 111 ijNode.writeDescriptor(envEntryNode, TagNames.INJECTION_TARGET, target); 112 } 113 } 114 115 return envEntryNode; 116 } 117 } 118 | Popular Tags |