1 23 24 package com.sun.enterprise.deployment.node.runtime; 25 26 import java.util.Map ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.logging.Level ; 30 import org.w3c.dom.Node ; 31 32 import com.sun.enterprise.deployment.types.ResourceReferenceContainer; 33 import com.sun.enterprise.deployment.ResourceReferenceDescriptor; 34 import com.sun.enterprise.deployment.MailConfiguration; 35 import com.sun.enterprise.deployment.node.XMLElement; 36 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode; 37 import com.sun.enterprise.deployment.xml.RuntimeTagNames; 38 import com.sun.enterprise.deployment.ResourcePrincipal; 39 import com.sun.enterprise.deployment.util.DOLUtils; 40 41 47 public class ResourceRefNode extends DeploymentDescriptorNode { 48 49 ResourceReferenceDescriptor descriptor=null; 50 51 52 public ResourceRefNode() { 53 registerElementHandler(new XMLElement(RuntimeTagNames.DEFAULT_RESOURCE_PRINCIPAL), 54 DefaultResourcePrincipalNode.class, "setResourcePrincipal"); 55 } 56 57 60 public Object getDescriptor() { 61 return descriptor; 62 } 63 64 70 protected Map getDispatchTable() { 71 Map table = super.getDispatchTable(); 72 table.put(RuntimeTagNames.JNDI_NAME, "setJndiName"); 73 return table; 74 } 75 76 82 public void setElementValue(XMLElement element, String value) { 83 if (RuntimeTagNames.RESOURCE_REFERENCE_NAME.equals(element.getQName())) { 84 Object parentDesc = getParentNode().getDescriptor(); 85 if (parentDesc instanceof ResourceReferenceContainer) { 86 descriptor = ((ResourceReferenceContainer) parentDesc).getResourceReferenceByName(value); 87 DOLUtils.getDefaultLogger().fine("Applying res-ref " + value + " runtime settings to " + descriptor); 88 } 89 } else super.setElementValue(element, value); 90 } 91 92 98 public void addDescriptor(Object newDescriptor) { 99 if (newDescriptor instanceof ResourcePrincipal) { 100 descriptor.setResourcePrincipal((ResourcePrincipal) newDescriptor); 101 } else if (newDescriptor instanceof MailConfiguration) { 102 descriptor.setMailConfiguration((MailConfiguration) newDescriptor); 103 } else { 104 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.addDescriptorFailure", 105 new Object []{"In " + this + " do not know what to do with " + newDescriptor}); 106 } 107 } 108 109 117 public Node writeDescriptor(Node parent, String nodeName, ResourceReferenceDescriptor rrDescriptor) { 118 Node rrNode = super.writeDescriptor(parent, nodeName, descriptor); 119 appendTextChild(rrNode, RuntimeTagNames.RESOURCE_REFERENCE_NAME, rrDescriptor.getName()); 120 appendTextChild(rrNode, RuntimeTagNames.JNDI_NAME, rrDescriptor.getJndiName()); 121 if (rrDescriptor.getResourcePrincipal() != null) { 122 DefaultResourcePrincipalNode drpNode = new DefaultResourcePrincipalNode(); 123 drpNode.writeDescriptor(rrNode, RuntimeTagNames.DEFAULT_RESOURCE_PRINCIPAL, 124 rrDescriptor.getResourcePrincipal()); 125 } 126 return rrNode; 127 } 128 129 135 public static void writeResourceReferences(Node parent, ResourceReferenceContainer descriptor) { 136 137 Iterator rrs = descriptor.getResourceReferenceDescriptors().iterator(); 139 if (rrs.hasNext()) { 140 141 ResourceRefNode rrNode = new ResourceRefNode(); 142 while (rrs.hasNext()) { 143 rrNode.writeDescriptor(parent, RuntimeTagNames.RESOURCE_REFERENCE, 144 (ResourceReferenceDescriptor) rrs.next()); 145 } 146 } 147 } 148 } 149 | Popular Tags |