1 17 18 package org.apache.geronimo.connector.deployment.dconfigbean; 19 20 import java.util.HashMap ; 21 import java.util.Map ; 22 import javax.enterprise.deploy.model.DDBean ; 23 import javax.enterprise.deploy.spi.DConfigBean ; 24 import javax.enterprise.deploy.spi.exceptions.ConfigurationException ; 25 26 import org.apache.geronimo.deployment.plugin.DConfigBeanSupport; 27 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType; 28 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType; 29 import org.apache.geronimo.xbeans.geronimo.GerOutboundResourceadapterType; 30 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterInstanceType; 31 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType; 32 import org.apache.xmlbeans.SchemaTypeLoader; 33 34 40 public class ResourceAdapterDConfigBean extends DConfigBeanSupport { 41 42 private final static String [][] RESOURCE_ADAPTER_XPATHS = { 43 {"config-property"}, 44 {"outbound-resourceadapter", "connection-definition"}, 45 {"adminobject"}}; 46 private Map configPropertiesMap = new HashMap (); 47 private Map connectionDefinitionsMap = new HashMap (); 48 private Map adminObjectsMap = new HashMap (); 49 50 public ResourceAdapterDConfigBean(DDBean ddBean, final GerResourceadapterType resourceadapter) { 51 super(ddBean, resourceadapter); 52 if (getResourceadapterInstance() == null) { 53 resourceadapter.addNewResourceadapterInstance(); 54 } 55 ConfigPropertiesHelper.initializeConfigSettings(ddBean, new ConfigPropertiesHelper.ConfigPropertiesSource() { 56 public GerConfigPropertySettingType[] getConfigPropertySettingArray() { 57 return getResourceadapterInstance().getConfigPropertySettingArray(); 58 } 59 60 public GerConfigPropertySettingType addNewConfigPropertySetting() { 61 return getResourceadapterInstance().addNewConfigPropertySetting(); 62 } 63 64 public void removeConfigPropertySetting(int j) { 65 } 66 67 public ConfigPropertySettings[] getConfigPropertySettings() { 68 return new ConfigPropertySettings[0]; 69 } 70 71 public void setConfigPropertySettings(ConfigPropertySettings[] configs) { 72 } 73 74 }, configPropertiesMap, "config-property", "config-property-name"); 75 GerOutboundResourceadapterType outboundResourceadapter = resourceadapter.getOutboundResourceadapter(); 77 if (outboundResourceadapter == null) { 78 outboundResourceadapter = resourceadapter.addNewOutboundResourceadapter(); 79 } 80 DDBean [] connectionDefinitionDDBeans = ddBean.getChildBean(getXpaths()[1]); 81 GerConnectionDefinitionType[] connectionDefinitions = outboundResourceadapter.getConnectionDefinitionArray(); 82 83 if (connectionDefinitions.length == 0) { 84 for (int i = 0; i < connectionDefinitionDDBeans.length; i++) { 86 DDBean connectionDefinitionDdBean = connectionDefinitionDDBeans[i]; 87 GerConnectionDefinitionType connectionDefinition = outboundResourceadapter.addNewConnectionDefinition(); 88 String connectionfactoryInterface = connectionDefinitionDdBean.getText("connectionfactory-interface")[0]; 89 ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean = new ConnectionDefinitionDConfigBean(connectionDefinitionDdBean, connectionDefinition); 90 connectionDefinitionsMap.put(connectionfactoryInterface, connectionDefinitionDConfigBean); 91 } 92 } else { 93 assert connectionDefinitionDDBeans.length == connectionDefinitions.length; 95 for (int i = 0; i < connectionDefinitionDDBeans.length; i++) { 96 DDBean connectionDefinitionDdBean = connectionDefinitionDDBeans[i]; 97 GerConnectionDefinitionType connectionDefinition = connectionDefinitions[i]; 98 String connectionfactoryInterface = connectionDefinitionDdBean.getText("connectionfactory-interface")[0]; 99 assert connectionfactoryInterface.equals(connectionDefinition.getConnectionfactoryInterface()); 100 ConnectionDefinitionDConfigBean connectionDefinitionDConfigBean = new ConnectionDefinitionDConfigBean(connectionDefinitionDdBean, connectionDefinition); 101 connectionDefinitionsMap.put(connectionfactoryInterface, connectionDefinitionDConfigBean); 102 } 103 } 104 105 135 } 136 137 GerResourceadapterType getResourceadapter() { 138 return (GerResourceadapterType) getXmlObject(); 139 } 140 141 private GerResourceadapterInstanceType getResourceadapterInstance() { 142 return getResourceadapter().getResourceadapterInstance(); 143 } 144 145 public String getResourceAdapterName() { 146 return getResourceadapterInstance().getResourceadapterName(); 147 } 148 149 public void setResourceAdapterName(String resourceAdapterName) { 150 getResourceadapterInstance().setResourceadapterName(resourceAdapterName); 151 } 152 153 public String getWorkManager() { 154 if(getResourceadapterInstance() == null || getResourceadapterInstance().getWorkmanager() == null) { 155 return null; 156 } 157 return getResourceadapterInstance().getWorkmanager().getGbeanLink(); 158 } 159 160 public void setWorkManager(String workManager) { 161 if(getResourceadapterInstance() == null) { 162 getResourceadapter().addNewResourceadapterInstance(); 163 } 164 if(getResourceadapterInstance().getWorkmanager() == null) { 165 getResourceadapterInstance().addNewWorkmanager(); 166 } 167 getResourceadapterInstance().getWorkmanager().setGbeanLink(workManager); 168 } 169 170 public DConfigBean getDConfigBean(DDBean bean) throws ConfigurationException { 171 String xpath = bean.getXpath(); 172 String [] xpaths = getXpaths(); 173 if (xpath.equals(xpaths[0])) { 174 String configPropertyName = bean.getText("config-property-name")[0]; 176 ConfigPropertySettingDConfigBean configPropertySetting = (ConfigPropertySettingDConfigBean) configPropertiesMap.get(configPropertyName); 177 assert configPropertySetting != null; 178 return configPropertySetting; 179 } 180 if (xpath.equals(xpaths[1])) { 181 String connectionFactoryInterface = bean.getText("connectionfactory-interface")[0]; 183 ConnectionDefinitionDConfigBean connectionDefinition = (ConnectionDefinitionDConfigBean) connectionDefinitionsMap.get(connectionFactoryInterface); 184 assert connectionDefinition != null; 185 return connectionDefinition; 186 } 187 if (xpath.equals(xpaths[2])) { 188 String adminObjectInterface = bean.getText("adminobject-interface")[0]; 190 String adminObjectClass = bean.getText("adminobject-class")[0]; 191 AdminObjectDConfigBean adminObject = (AdminObjectDConfigBean) adminObjectsMap.get(new Key(adminObjectInterface, adminObjectClass)); 192 assert adminObject != null; 193 return adminObject; 194 } 195 return null; 196 } 197 198 199 public String [] getXpaths() { 200 return getXPathsForJ2ee_1_4(RESOURCE_ADAPTER_XPATHS); 201 } 202 203 protected SchemaTypeLoader getSchemaTypeLoader() { 204 return ResourceAdapterDConfigRoot.SCHEMA_TYPE_LOADER; 205 } 206 207 208 private final static class Key { 210 private final Object part1; 211 private final Object part2; 212 213 public Key(Object part1, Object part2) { 214 this.part1 = part1; 215 this.part2 = part2; 216 } 217 218 public int hashCode() { 219 return part1.hashCode() ^ part2.hashCode(); 220 } 221 222 public boolean equals(Object obj) { 223 if (obj instanceof Key) { 224 Key other = (Key) obj; 225 return this.part1.equals(other.part1) && this.part2.equals(other.part2); 226 } else { 227 return false; 228 } 229 } 230 } 231 } 232 | Popular Tags |