1 23 package com.sun.enterprise.deployment.node.runtime.connector; 24 25 import java.util.Map ; 26 import org.w3c.dom.Node ; 27 import org.w3c.dom.Element ; 28 29 import com.sun.enterprise.deployment.node.XMLElement; 30 import com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode; 31 import com.sun.enterprise.deployment.runtime.connector.MapElement; 32 import com.sun.enterprise.deployment.runtime.connector.Principal; 33 import com.sun.enterprise.deployment.xml.RuntimeTagNames; 34 35 41 public class MapElementNode extends RuntimeDescriptorNode { 42 43 public MapElementNode() { 44 registerElementHandler(new XMLElement(RuntimeTagNames.PRINCIPAL), 45 PrincipalNode.class); 46 registerElementHandler(new XMLElement(RuntimeTagNames.BACKEND_PRINCIPAL), 47 PrincipalNode.class); 48 } 49 50 51 57 public void addDescriptor(Object newDescriptor) { 58 MapElement descriptor = (MapElement) getDescriptor(); 59 if (descriptor==null) { 60 throw new RuntimeException ("Cannot set info on null descriptor"); 61 } 62 if (newDescriptor instanceof Principal) { 63 Principal principal = (Principal) newDescriptor; 64 if (principal.getValue(Principal.CREDENTIAL)==null) { 65 descriptor.addPrincipal(principal); 66 } else { 67 descriptor.setBackendPrincipal(true); 68 descriptor.setAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.USER_NAME, principal.getValue(Principal.USER_NAME)); 69 descriptor.setAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.PASSWORD, principal.getValue(Principal.PASSWORD)); 70 descriptor.setAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.CREDENTIAL, principal.getValue(Principal.CREDENTIAL)); 71 72 } 73 } 74 } 75 76 84 public Node writeDescriptor(Node parent, String nodeName, MapElement descriptor) { 85 Node mapElementNode = super.writeDescriptor(parent, nodeName, descriptor); 86 PrincipalNode pn = new PrincipalNode(); 87 Principal[] principals = descriptor.getPrincipal(); 88 for (int i=0;i<principals.length;i++) { 89 pn.writeDescriptor(mapElementNode, RuntimeTagNames.PRINCIPAL, principals[i]); 90 } 91 if (descriptor.isBackendPrincipal()) { 93 Element backend = (Element ) appendChild(mapElementNode, RuntimeTagNames.BACKEND_PRINCIPAL); 94 setAttribute(backend, RuntimeTagNames.USER_NAME, 95 (String ) descriptor.getAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.USER_NAME)); 96 setAttribute(backend, RuntimeTagNames.PASSWORD, 97 (String ) descriptor.getAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.PASSWORD)); 98 setAttribute(backend, RuntimeTagNames.CREDENTIAL, 99 (String ) descriptor.getAttributeValue(MapElement.BACKEND_PRINCIPAL, Principal.CREDENTIAL)); 100 } 101 102 return mapElementNode; 103 } 104 } 105 | Popular Tags |