1 23 24 package com.sun.enterprise.deployment.node.ejb; 25 26 import java.util.Map ; 27 import org.w3c.dom.Node ; 28 import org.xml.sax.Attributes ; 29 30 import com.sun.enterprise.deployment.Role; 31 32 import com.sun.enterprise.deployment.node.XMLElement; 33 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode; 34 import com.sun.enterprise.deployment.node.MethodNode; 35 import com.sun.enterprise.deployment.node.DescriptorFactory; 36 37 import com.sun.enterprise.deployment.MethodPermissionDescriptor; 38 import com.sun.enterprise.deployment.MethodDescriptor; 39 import com.sun.enterprise.deployment.MethodPermission; 40 import com.sun.enterprise.deployment.EjbDescriptor; 41 import com.sun.enterprise.deployment.Descriptor; 42 import com.sun.enterprise.deployment.xml.EjbTagNames; 43 44 51 public class MethodPermissionNode extends DeploymentDescriptorNode { 52 53 private MethodPermissionDescriptor descriptor; 54 55 56 public MethodPermissionNode() { 57 super(); 58 registerElementHandler(new XMLElement(EjbTagNames.METHOD), 59 MethodNode.class, "addMethod"); 60 } 61 62 65 public Object getDescriptor() { 66 67 if (descriptor==null) { 68 descriptor = (MethodPermissionDescriptor) DescriptorFactory.getDescriptor(getXMLPath()); 69 } 70 return descriptor; 71 } 72 73 76 public void startElement(XMLElement element, Attributes attributes) { 77 78 if (EjbTagNames.UNCHECKED.equals(element.getQName())) { 79 descriptor.addMethodPermission(MethodPermission.getUncheckedMethodPermission()); 80 } else 81 super.startElement(element, attributes); 82 } 83 84 90 public void setElementValue(XMLElement element, String value) { 91 if (EjbTagNames.ROLE_NAME.equals(element.getQName())) { 92 Role role = new Role(value); 93 descriptor.addMethodPermission(new MethodPermission(role)); 94 } else { 95 super.setElementValue(element, value); 96 } 97 } 98 99 100 108 public Node writeDescriptor(Node parent, String nodeName, MethodPermissionDescriptor descriptor, 109 EjbDescriptor ejb) { 110 111 Node subNode = super.writeDescriptor(parent, nodeName, descriptor); 112 return writeDescriptorInNode(subNode, descriptor, ejb); 113 } 114 115 116 123 public Node writeDescriptorInNode(Node subNode, MethodPermissionDescriptor descriptor, 124 EjbDescriptor ejb) { 125 126 writeLocalizedDescriptions(subNode, descriptor); 127 128 MethodPermission[] mps = descriptor.getMethodPermissions(); 129 if (mps.length==0) 130 return null; 131 132 if (!mps[0].isExcluded()) { 133 if (mps[0].isUnchecked()) { 134 appendChild(subNode, EjbTagNames.UNCHECKED); 135 } else { 136 for (int i=0;i<mps.length;i++) { 137 appendTextChild(subNode, EjbTagNames.ROLE_NAME, mps[i].getRole().getName()); 138 } 139 } 140 } 141 142 MethodDescriptor[] methods = descriptor.getMethods(); 143 MethodNode mn = new MethodNode(); 144 for (int i=0;i<methods.length;i++) { 145 String ejbName = ejb.getName(); 146 mn.writeDescriptor(subNode, EjbTagNames.METHOD, methods[i], ejbName); 147 } 148 return subNode; 149 } 150 } 151 | Popular Tags |