1 17 package org.apache.geronimo.connector.deployment.jsr88; 18 19 import java.util.Set ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 22 import javax.enterprise.deploy.model.DDBean ; 23 import org.apache.geronimo.deployment.plugin.XmlBeanSupport; 24 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType; 25 import org.apache.geronimo.xbeans.geronimo.GerOutboundResourceadapterType; 26 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType; 27 import org.apache.xmlbeans.SchemaTypeLoader; 28 29 36 public class ResourceAdapter extends XmlBeanSupport { 37 private DDBean resourceAdapter; 38 private ConnectionDefinition[] instances = new ConnectionDefinition[0]; 39 private ResourceAdapterInstance resourceAdapterInstance; 40 41 public ResourceAdapter() { 42 super(null); 43 } 44 45 public ResourceAdapter(DDBean resourceAdapter, GerResourceadapterType ra) { 46 super(null); 47 configure(resourceAdapter, ra); 48 } 49 50 protected GerResourceadapterType getResourceAdapter() { 51 return (GerResourceadapterType)getXmlObject(); 52 } 53 54 void configure(DDBean resourceAdapter, GerResourceadapterType ra) { 55 this.resourceAdapter = resourceAdapter; 56 setXmlObject(ra); 57 if(ra.isSetResourceadapterInstance()) { 58 resourceAdapterInstance = new ResourceAdapterInstance(resourceAdapter, ra.getResourceadapterInstance()); 59 } else { 60 resourceAdapterInstance = null; 61 } 62 if(ra.isSetOutboundResourceadapter()) { 63 DDBean [] test = resourceAdapter.getChildBean("outbound-resourceadapter"); 64 if(test != null && test.length > 0) { 65 GerOutboundResourceadapterType outbound = ra.getOutboundResourceadapter(); 66 GerConnectionDefinitionType[] defs = outbound.getConnectionDefinitionArray(); 67 if(defs != null) { 68 instances = new ConnectionDefinition[defs.length]; 69 for (int i = 0; i < defs.length; i++) { 70 GerConnectionDefinitionType def = defs[i]; 71 instances[i] = new ConnectionDefinition(resourceAdapter, def); 72 } 73 } 74 } else { 75 } 77 } 78 } 79 80 82 public ConnectionDefinition[] getConnectionDefinition() { 83 return instances; 84 } 85 86 public ConnectionDefinition getConnectionDefinition(int index) { 87 return instances[index]; 88 } 89 90 public void setConnectionDefinition(ConnectionDefinition[] definitions) { 91 ConnectionDefinition[] old = getConnectionDefinition(); 92 93 if(definitions != null && definitions.length > 0) { 94 if(!getResourceAdapter().isSetOutboundResourceadapter()) { 95 getResourceAdapter().addNewOutboundResourceadapter(); 96 } 97 } else { 98 if(getResourceAdapter().isSetOutboundResourceadapter()) { 99 getResourceAdapter().unsetOutboundResourceadapter(); 100 } 101 } 102 Set before = new HashSet (); 103 for (int i = 0; i < old.length; i++) { 104 before.add(old[i]); 105 } 106 instances = definitions; 107 for (int i = 0; i < definitions.length; i++) { 109 ConnectionDefinition definition = definitions[i]; 110 if(definition.getConnectionDefinition() == null) { 111 definition.configure(resourceAdapter, getResourceAdapter().getOutboundResourceadapter().addNewConnectionDefinition()); 112 } else { 113 before.remove(definition); 114 } 115 } 116 for (Iterator it = before.iterator(); it.hasNext();) { 118 ConnectionDefinition definition = (ConnectionDefinition) it.next(); 119 GerConnectionDefinitionType all[] = getResourceAdapter().isSetOutboundResourceadapter() ? getResourceAdapter().getOutboundResourceadapter().getConnectionDefinitionArray() : new GerConnectionDefinitionType[0]; 120 for (int i = 0; i < all.length; i++) { 121 if(all[i] == definition) { 122 getResourceAdapter().getOutboundResourceadapter().removeConnectionDefinition(i); 123 break; 124 } 125 } 126 } 127 pcs.firePropertyChange("connectionDefinition", old, instances); 128 } 129 130 public void setConnectionDefinition(int index, ConnectionDefinition definition) { 131 ConnectionDefinition[] old = instances; 132 instances[index] = definition; 133 if(definition.getConnectionDefinition() == null) { 134 definition.configure(resourceAdapter, getResourceAdapter().getOutboundResourceadapter().addNewConnectionDefinition()); 135 } 136 pcs.firePropertyChange("connectionDefinition", old, instances); 137 } 138 139 public ResourceAdapterInstance getResourceAdapterInstance() { 140 return resourceAdapterInstance; 141 } 142 143 public void setResourceAdapterInstance(ResourceAdapterInstance resourceAdapterInstance) { 144 ResourceAdapterInstance old = this.resourceAdapterInstance; 145 this.resourceAdapterInstance = resourceAdapterInstance; 146 if(resourceAdapterInstance.getResourceAdapterInstance() == null) { 147 if(getResourceAdapter().isSetResourceadapterInstance()) { 148 resourceAdapterInstance.configure(resourceAdapter, getResourceAdapter().getResourceadapterInstance()); 149 } else { 150 resourceAdapterInstance.configure(resourceAdapter, getResourceAdapter().addNewResourceadapterInstance()); 151 } 152 } 153 pcs.firePropertyChange("resourceAdapterInstance", old, instances); 154 } 155 156 158 protected SchemaTypeLoader getSchemaTypeLoader() { 159 return Connector15DCBRoot.SCHEMA_TYPE_LOADER; 160 } 161 } 162 | Popular Tags |