1 23 24 29 30 package com.sun.enterprise.deployment.node.ejb; 31 32 import java.util.Map ; 33 import java.util.HashMap ; 34 import org.w3c.dom.Node ; 35 36 import com.sun.enterprise.deployment.node.XMLElement; 37 import com.sun.enterprise.deployment.node.XMLNode; 38 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode; 39 import com.sun.enterprise.deployment.node.LocalizedInfoNode; 40 import com.sun.enterprise.deployment.node.ConfigurableNode; 41 import com.sun.enterprise.deployment.node.DescriptorFactory; 42 43 import com.sun.enterprise.deployment.Descriptor; 44 import com.sun.enterprise.deployment.RelationRoleDescriptor; 45 import com.sun.enterprise.deployment.EjbBundleDescriptor; 46 import com.sun.enterprise.deployment.EjbCMPEntityDescriptor; 47 import com.sun.enterprise.deployment.RelationshipDescriptor; 48 import com.sun.enterprise.deployment.xml.EjbTagNames; 49 50 56 public class EjbRelationshipRoleNode extends DeploymentDescriptorNode { 57 58 RelationRoleDescriptor descriptor; 59 60 public EjbRelationshipRoleNode() { 61 super(); 62 registerElementHandler(new XMLElement(EjbTagNames.DESCRIPTION), LocalizedInfoNode.class); 63 } 64 65 68 public XMLNode getHandlerFor(XMLElement element) { 69 if (EjbTagNames.RELATIONSHIP_ROLE_SOURCE.equals(element.getQName())) { 70 Map dispatchTable = new HashMap (); 71 dispatchTable.put(EjbTagNames.DESCRIPTION, "setRoleSourceDescription"); 72 ConfigurableNode newNode = new ConfigurableNode(getDescriptor(), dispatchTable, element); 73 return newNode; 74 } if (EjbTagNames.CMR_FIELD.equals(element.getQName())) { 75 Map dispatchTable = new HashMap (); 76 dispatchTable.put(EjbTagNames.DESCRIPTION, "setCMRFieldDescription"); 77 ConfigurableNode newNode = new ConfigurableNode(getDescriptor(), dispatchTable, element); 78 return newNode; 79 } else { 80 return super.getHandlerFor(element); 81 } 82 } 83 84 88 public boolean handlesElement(XMLElement element) { 89 if (EjbTagNames.RELATIONSHIP_ROLE_SOURCE.equals(element.getQName())) { 90 return true; 91 } 92 if (EjbTagNames.CMR_FIELD.equals(element.getQName())) { 93 return true; 94 } 95 return super.handlesElement(element); 96 } 97 98 101 public Object getDescriptor() { 102 if (descriptor==null) { 103 descriptor = (RelationRoleDescriptor) DescriptorFactory.getDescriptor(getXMLPath()); 104 } 105 return descriptor; 106 } 107 108 114 protected Map getDispatchTable() { 115 Map table = super.getDispatchTable(); 117 table.put(EjbTagNames.EJB_RELATIONSHIP_ROLE_NAME, "setName"); 118 table.put(EjbTagNames.CMR_FIELD_NAME, "setCMRField"); 119 table.put(EjbTagNames.CMR_FIELD_TYPE, "setCMRFieldType"); 120 return table; 121 } 122 123 129 public boolean endElement(XMLElement element) { 130 if (EjbTagNames.CASCADE_DELETE.equals(element.getQName())) { 131 descriptor.setCascadeDelete(true); 132 } 133 return super.endElement(element); 134 } 135 136 142 public void setElementValue(XMLElement element, String value) { 143 if (EjbTagNames.MULTIPLICITY.equals(element.getQName())) { 144 if ( value.equals("Many") ) 145 descriptor.setIsMany(true); 146 else if ( value.equals("One") ) 147 descriptor.setIsMany(false); 148 else if ( value.equals("many") ) descriptor.setIsMany(true); 150 else if ( value.equals("one") ) descriptor.setIsMany(false); 152 else 153 throw new IllegalArgumentException ("Error in value of multiplicity element in EJB deployment descriptor XML: the value must be One or Many"); 154 } else if (EjbTagNames.EJB_NAME.equals(element.getQName())) { 155 EjbBundleDescriptor bundleDesc = getEjbBundleDescriptor(); 157 EjbCMPEntityDescriptor desc = (EjbCMPEntityDescriptor)bundleDesc.getEjbByName(value); 158 if (desc!=null){ 159 descriptor.setPersistenceDescriptor(desc.getPersistenceDescriptor()); 160 } else { 161 throw new IllegalArgumentException ("Cannot find ejb " + value + " in bundle for relationship " + descriptor.getName()); 162 } 163 } else super.setElementValue(element, value); 164 } 165 166 private EjbBundleDescriptor getEjbBundleDescriptor() { 167 XMLNode parent = getParentNode(); 168 Object parentDesc = parent.getDescriptor(); 169 while (parent!=null && !(parentDesc instanceof EjbBundleDescriptor)) { 170 parent = parent.getParentNode(); 171 if (parent !=null) 172 parentDesc = parent.getDescriptor(); 173 } 174 if (parent!=null) { 175 return (EjbBundleDescriptor) parentDesc; 176 } else { 177 throw new IllegalArgumentException ("Cannot find bundle descriptor"); 178 } 179 } 180 181 189 public Node writeDescriptor(Node parent, String nodeName, RelationRoleDescriptor descriptor) { 190 Node roleNode = super.writeDescriptor(parent, nodeName, descriptor); 191 LocalizedInfoNode localizedNode = new LocalizedInfoNode(); 192 localizedNode.writeLocalizedMap(roleNode, EjbTagNames.DESCRIPTION, descriptor.getLocalizedDescriptions()); 193 if (descriptor.getRelationRoleName() != null) { 194 appendTextChild(roleNode, EjbTagNames.EJB_RELATIONSHIP_ROLE_NAME, 195 descriptor.getRelationRoleName()); 196 } 197 198 if (descriptor.getIsMany()) { 200 appendTextChild(roleNode, EjbTagNames.MULTIPLICITY, "Many"); 201 } else { 202 appendTextChild(roleNode, EjbTagNames.MULTIPLICITY, "One"); 203 } 204 205 if (descriptor.getCascadeDelete()) { 207 appendChild(roleNode, EjbTagNames.CASCADE_DELETE); 208 } 209 210 Node roleSourceNode = appendChild(roleNode, EjbTagNames.RELATIONSHIP_ROLE_SOURCE); 211 appendTextChild(roleSourceNode, EjbTagNames.DESCRIPTION, descriptor.getRoleSourceDescription()); 212 appendTextChild(roleSourceNode, EjbTagNames.EJB_NAME, descriptor.getOwner().getName()); 213 214 if (descriptor.getCMRField() != null ) { 216 Node cmrFieldNode = appendChild(roleNode, EjbTagNames.CMR_FIELD); 217 218 appendTextChild(cmrFieldNode, EjbTagNames.DESCRIPTION, 220 descriptor.getCMRFieldDescription()); 221 appendTextChild(cmrFieldNode, EjbTagNames.CMR_FIELD_NAME, 223 descriptor.getCMRField()); 224 appendTextChild(cmrFieldNode, EjbTagNames.CMR_FIELD_TYPE, 226 descriptor.getCMRFieldType()); 227 } 228 return roleNode; 229 } 230 } 231 | Popular Tags |