1 17 18 package org.apache.geronimo.connector.deployment.dconfigbean; 19 20 import javax.enterprise.deploy.model.DDBean ; 21 22 import org.apache.geronimo.deployment.plugin.DConfigBeanSupport; 23 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType; 24 import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType; 25 import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType; 26 import org.apache.xmlbeans.SchemaTypeLoader; 27 28 34 public class ConnectionDefinitionDConfigBean extends DConfigBeanSupport { 35 36 private ConnectionDefinitionInstance[] instances = new ConnectionDefinitionInstance[0]; 37 38 public ConnectionDefinitionDConfigBean(DDBean ddBean, GerConnectionDefinitionType connectionDefinition) { 39 super(ddBean, connectionDefinition); 40 String connectionfactoryInterface = ddBean.getText("connectionfactory-interface")[0]; 41 if (connectionDefinition.getConnectionfactoryInterface() == null) { 42 connectionDefinition.setConnectionfactoryInterface(connectionfactoryInterface); 43 } else { 44 assert connectionfactoryInterface.equals(connectionDefinition.getConnectionfactoryInterface()); 45 } 46 instances = new ConnectionDefinitionInstance[getConnectionDefinition().getConnectiondefinitionInstanceArray().length]; 48 for (int i = 0; i < instances.length; i++) { 49 instances[i] = new ConnectionDefinitionInstance(); 50 instances[i].initialize(getConnectionDefinition().getConnectiondefinitionInstanceArray(i), this); 51 } 52 } 53 54 GerConnectionDefinitionType getConnectionDefinition() { 55 return (GerConnectionDefinitionType) getXmlObject(); 56 } 57 58 public ConnectionDefinitionInstance[] getConnectionDefinitionInstance() { 59 return instances; 60 } 61 62 public void setConnectionDefinitionInstance(ConnectionDefinitionInstance[] instances) { 63 ConnectionDefinitionInstance[] old = getConnectionDefinitionInstance(); 64 this.instances = instances; 65 for (int i = 0; i < instances.length; i++) { ConnectionDefinitionInstance instance = instances[i]; 67 if (!instance.hasParent()) { 68 GerConnectiondefinitionInstanceType xmlObject = getConnectionDefinition().addNewConnectiondefinitionInstance(); 69 xmlObject.setConnectionmanager(GerConnectionmanagerType.Factory.newInstance()); 70 instance.initialize(xmlObject, this); 71 } 72 } 73 for (int i = 0; i < old.length; i++) { ConnectionDefinitionInstance instance = old[i]; 75 boolean found = false; 76 for (int j = 0; j < instances.length; j++) { 77 if (instances[j] == instance) { 78 found = true; 79 break; 80 } 81 } 82 if (!found) { 83 for (int j = 0; j < getConnectionDefinition().getConnectiondefinitionInstanceArray().length; j++) { 85 GerConnectiondefinitionInstanceType test = getConnectionDefinition().getConnectiondefinitionInstanceArray(j); 86 if (test == instance.getConnectiondefinitionInstance()) { 87 getConnectionDefinition().removeConnectiondefinitionInstance(j); 88 break; 89 } 90 } 91 instance.dispose(); 93 } 94 } 95 pcs.firePropertyChange("connectionDefinitionInstance", old, instances); 96 } 97 98 protected SchemaTypeLoader getSchemaTypeLoader() { 99 return ResourceAdapterDConfigRoot.SCHEMA_TYPE_LOADER; 100 } 101 102 } 103 | Popular Tags |