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 java.util.Map ; 23 import java.util.HashMap ; 24 import javax.enterprise.deploy.model.DDBean ; 25 import org.apache.geronimo.deployment.plugin.XmlBeanSupport; 26 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType; 27 import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType; 28 import org.apache.xmlbeans.SchemaTypeLoader; 29 30 40 public class ConnectionDefinition extends XmlBeanSupport { 41 private DDBean resourceAdapter; 42 private ConnectionDefinitionInstance[] instances = new ConnectionDefinitionInstance[0]; 43 44 public ConnectionDefinition() { 45 super(null); 46 } 47 48 public ConnectionDefinition(DDBean resourceAdapter, GerConnectionDefinitionType definition) { 49 super(null); 50 configure(resourceAdapter, definition); 51 } 52 53 protected GerConnectionDefinitionType getConnectionDefinition() { 54 return (GerConnectionDefinitionType) getXmlObject(); 55 } 56 57 void configure(DDBean resourceAdapter, GerConnectionDefinitionType definition) { 58 this.resourceAdapter = resourceAdapter; 59 setXmlObject(definition); 60 instances = new ConnectionDefinitionInstance[definition.getConnectiondefinitionInstanceArray().length]; 62 DDBean [] beans = resourceAdapter.getChildBean("outbound-resourceadapter/connection-definition"); 63 DDBean match = null; 64 for (int i = 0; i < beans.length; i++) { 65 DDBean bean = beans[i]; 66 if(bean.getText("connectionfactory-interface")[0].equals(definition.getConnectionfactoryInterface())) { 67 match = bean; 68 break; 69 } 70 } 71 for (int i = 0; i < instances.length; i++) { 72 GerConnectiondefinitionInstanceType gerInstance = definition.getConnectiondefinitionInstanceArray()[i]; 73 instances[i] = new ConnectionDefinitionInstance(match, gerInstance); 74 } 75 } 76 77 79 public String getConnectionFactoryInterface() { 81 return getConnectionDefinition().getConnectionfactoryInterface(); 82 } 83 84 public void setConnectionFactoryInterface(String iface) { 85 String old = getConnectionFactoryInterface(); 86 getConnectionDefinition().setConnectionfactoryInterface(iface); 87 DDBean match = getConnectionDefinitionDDBean(); 88 for (int i = 0; i < instances.length; i++) { 89 ConnectionDefinitionInstance instance = instances[i]; 90 if(instance.getDDBean() != match) { 91 instance.configure(match, instance.getConnectionInstance()); 92 } 93 } 94 pcs.firePropertyChange("connectionFactoryInterface", old, iface); 95 } 96 97 public ConnectionDefinitionInstance[] getConnectionInstances() { 98 return instances; 99 } 100 101 public void setConnectionInstance(ConnectionDefinitionInstance[] instances) { 102 ConnectionDefinitionInstance[] old = this.instances; 103 Set before = new HashSet (); 104 for (int i = 0; i < old.length; i++) { 105 before.add(old[i]); 106 } 107 this.instances = instances; 108 for (int i = 0; i < instances.length; i++) { 110 ConnectionDefinitionInstance instance = instances[i]; 111 if(instance.getConnectionInstance() == null) { 112 instance.configure(getConnectionDefinitionDDBean(), getConnectionDefinition().addNewConnectiondefinitionInstance()); 113 } else { 114 before.remove(instance); 115 } 116 } 117 for (Iterator it = before.iterator(); it.hasNext();) { 119 ConnectionDefinitionInstance instance = (ConnectionDefinitionInstance) it.next(); 120 GerConnectiondefinitionInstanceType all[] = getConnectionDefinition().getConnectiondefinitionInstanceArray(); 121 for (int i = 0; i < all.length; i++) { 122 if(all[i] == instance) { 123 getConnectionDefinition().removeConnectiondefinitionInstance(i); 124 break; 125 } 126 } 127 } 128 pcs.firePropertyChange("connectionInstance", old, instances); 129 130 } 131 132 133 135 138 private DDBean getConnectionDefinitionDDBean() { 139 String iface = getConnectionFactoryInterface(); 140 if(iface == null || iface.equals("")) { 141 return null; 142 } 143 DDBean list[] = resourceAdapter.getChildBean("outbound-resourceadapter/connection-definition"); 144 for (int i = 0; i < list.length; i++) { 145 DDBean bean = list[i]; 146 String [] test = bean.getText("connectionfactory-interface"); 147 if(test.length > 0) { 148 String myface = test[0]; 149 if(myface.equals(iface)) { 150 return bean; 151 } 152 } 153 } 154 return null; 155 } 156 157 protected SchemaTypeLoader getSchemaTypeLoader() { 158 return Connector15DCBRoot.SCHEMA_TYPE_LOADER; 159 } 160 } 161 | Popular Tags |