1 23 24 package com.sun.enterprise.deployment.node; 25 26 import java.util.Map ; 27 import javax.persistence.PersistenceContextType; 28 import org.w3c.dom.Node ; 29 30 import com.sun.enterprise.deployment.Descriptor; 31 import com.sun.enterprise.deployment.InjectionTarget; 32 import com.sun.enterprise.deployment.EntityManagerReferenceDescriptor; 33 import com.sun.enterprise.deployment.xml.EjbTagNames; 34 import com.sun.enterprise.deployment.xml.TagNames; 35 36 42 public class EntityManagerReferenceNode extends DeploymentDescriptorNode { 43 private static final String TRANSACTION = "Transaction"; 44 private static final String EXTENDED = "Extended"; 45 46 private String propertyName = null; 48 49 public EntityManagerReferenceNode() { 50 super(); 51 registerElementHandler(new XMLElement(TagNames.INJECTION_TARGET), 52 InjectionTargetNode.class, "addInjectionTarget"); 53 } 54 55 56 64 protected Map getDispatchTable() { 65 Map table = super.getDispatchTable(); 67 table.put(TagNames.PERSISTENCE_CONTEXT_REF_NAME, "setName"); 68 table.put(TagNames.PERSISTENCE_UNIT_NAME, "setUnitName"); 69 return table; 70 } 71 72 78 public void setElementValue(XMLElement element, String value) { 79 if (TagNames.PERSISTENCE_CONTEXT_TYPE.equals(element.getQName())) { 80 EntityManagerReferenceDescriptor entityMgrReferenceDescriptor = 81 (EntityManagerReferenceDescriptor)getDescriptor(); 82 PersistenceContextType contextType = null; 83 if (EXTENDED.equals(value)) { 84 contextType = PersistenceContextType.EXTENDED; 85 } else if (TRANSACTION.equals(value)) { 86 contextType = PersistenceContextType.TRANSACTION; 87 } else { 88 throw new IllegalArgumentException (localStrings.getLocalString( 89 "enterprise.deployment.node.invalidvalue", 90 "Invalid value for a tag under {0} : {1}", 91 new Object [] {TagNames.PERSISTENCE_CONTEXT_TYPE, value})); 92 } 93 94 entityMgrReferenceDescriptor.setPersistenceContextType(contextType); 95 96 } else if (TagNames.NAME_VALUE_PAIR_NAME.equals(element.getQName())) { 97 propertyName = value; 98 } else if (TagNames.NAME_VALUE_PAIR_VALUE.equals(element.getQName())) { 99 EntityManagerReferenceDescriptor entityMgrReferenceDescriptor = 100 (EntityManagerReferenceDescriptor)getDescriptor(); 101 entityMgrReferenceDescriptor.addProperty(propertyName, value); 102 propertyName = null; 103 } else { 104 super.setElementValue(element, value); 105 } 106 } 107 108 116 public Node writeDescriptor(Node parent, String nodeName, EntityManagerReferenceDescriptor descriptor) { 117 Node entityMgrRefNode = appendChild(parent, nodeName); 118 writeLocalizedDescriptions(entityMgrRefNode, descriptor); 119 120 appendTextChild(entityMgrRefNode, TagNames.PERSISTENCE_CONTEXT_REF_NAME, descriptor.getName()); 121 appendTextChild(entityMgrRefNode, TagNames.PERSISTENCE_UNIT_NAME, descriptor.getUnitName()); 122 PersistenceContextType contextType = descriptor.getPersistenceContextType(); 123 String contextTypeString = (contextType != null && 124 PersistenceContextType.EXTENDED.equals(contextType)) ? 125 EXTENDED : TRANSACTION; 126 appendTextChild(entityMgrRefNode, TagNames.PERSISTENCE_CONTEXT_TYPE, 127 contextTypeString); 128 129 for(Map.Entry <String , String > property : 130 descriptor.getProperties().entrySet()) { 131 Node propertyNode = appendChild(entityMgrRefNode, 132 TagNames.PERSISTENCE_PROPERTY); 133 appendTextChild(propertyNode, TagNames.NAME_VALUE_PAIR_NAME, 134 property.getKey()); 135 appendTextChild(propertyNode, TagNames.NAME_VALUE_PAIR_VALUE, 136 property.getValue()); 137 } 138 139 if( descriptor.isInjectable() ) { 140 InjectionTargetNode ijNode = new InjectionTargetNode(); 141 for (InjectionTarget target : descriptor.getInjectionTargets()) { 142 ijNode.writeDescriptor(entityMgrRefNode, TagNames.INJECTION_TARGET, target); 143 } 144 } 145 146 return entityMgrRefNode; 147 } 148 } 149 | Popular Tags |