1 17 package org.apache.geronimo.connector.deployment; 18 19 import java.beans.Introspector ; 20 import java.beans.PropertyEditor ; 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.lang.reflect.Method ; 24 import java.net.URI ; 25 import java.net.URL ; 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Date ; 29 import java.util.Enumeration ; 30 import java.util.HashMap ; 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.LinkedHashMap ; 34 import java.util.Map ; 35 import java.util.Set ; 36 import java.util.jar.JarFile ; 37 import java.util.zip.ZipEntry ; 38 39 import javax.naming.Reference ; 40 import javax.xml.namespace.QName ; 41 42 import org.apache.commons.logging.Log; 43 import org.apache.commons.logging.LogFactory; 44 import org.apache.geronimo.common.DeploymentException; 45 import org.apache.geronimo.common.UnresolvedReferenceException; 46 import org.apache.geronimo.common.propertyeditor.PropertyEditors; 47 import org.apache.geronimo.connector.ActivationSpecWrapperGBean; 48 import org.apache.geronimo.connector.AdminObjectWrapper; 49 import org.apache.geronimo.connector.AdminObjectWrapperGBean; 50 import org.apache.geronimo.connector.JCAResourceImplGBean; 51 import org.apache.geronimo.connector.ResourceAdapterImplGBean; 52 import org.apache.geronimo.connector.ResourceAdapterModuleImplGBean; 53 import org.apache.geronimo.connector.ResourceAdapterWrapperGBean; 54 import org.apache.geronimo.connector.outbound.JCAConnectionFactoryImplGBean; 55 import org.apache.geronimo.connector.outbound.ManagedConnectionFactoryWrapper; 56 import org.apache.geronimo.connector.outbound.ManagedConnectionFactoryWrapperGBean; 57 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.LocalTransactions; 58 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool; 59 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoTransactions; 60 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PartitionedPool; 61 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport; 62 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool; 63 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionLog; 64 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport; 65 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions; 66 import org.apache.geronimo.deployment.ModuleIDBuilder; 67 import org.apache.geronimo.deployment.NamespaceDrivenBuilder; 68 import org.apache.geronimo.deployment.NamespaceDrivenBuilderCollection; 69 import org.apache.geronimo.deployment.service.EnvironmentBuilder; 70 import org.apache.geronimo.deployment.service.GBeanBuilder; 71 import org.apache.geronimo.deployment.util.DeploymentUtil; 72 import org.apache.geronimo.deployment.xbeans.EnvironmentType; 73 import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil; 74 import org.apache.geronimo.gbean.AbstractName; 75 import org.apache.geronimo.gbean.AbstractNameQuery; 76 import org.apache.geronimo.gbean.DynamicGAttributeInfo; 77 import org.apache.geronimo.gbean.GAttributeInfo; 78 import org.apache.geronimo.gbean.GBeanData; 79 import org.apache.geronimo.gbean.GBeanInfo; 80 import org.apache.geronimo.gbean.GBeanInfoBuilder; 81 import org.apache.geronimo.gbean.InvalidConfigurationException; 82 import org.apache.geronimo.j2ee.deployment.ActivationSpecInfoLocator; 83 import org.apache.geronimo.j2ee.deployment.ConnectorModule; 84 import org.apache.geronimo.j2ee.deployment.EARContext; 85 import org.apache.geronimo.j2ee.deployment.Module; 86 import org.apache.geronimo.j2ee.deployment.ModuleBuilder; 87 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 88 import org.apache.geronimo.kernel.GBeanAlreadyExistsException; 89 import org.apache.geronimo.kernel.GBeanNotFoundException; 90 import org.apache.geronimo.kernel.Naming; 91 import org.apache.geronimo.kernel.config.Configuration; 92 import org.apache.geronimo.kernel.config.ConfigurationStore; 93 import org.apache.geronimo.kernel.repository.Environment; 94 import org.apache.geronimo.management.JCAConnectionFactory; 95 import org.apache.geronimo.management.geronimo.JCAAdminObject; 96 import org.apache.geronimo.management.geronimo.JCAResourceAdapter; 97 import org.apache.geronimo.management.geronimo.ResourceAdapterModule; 98 import org.apache.geronimo.naming.deployment.ENCConfigBuilder; 99 import org.apache.geronimo.naming.reference.ResourceReference; 100 import org.apache.geronimo.schema.SchemaConversionUtils; 101 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType; 102 import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType; 103 import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType; 104 import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType; 105 import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType; 106 import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType; 107 import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument; 108 import org.apache.geronimo.xbeans.geronimo.GerConnectorType; 109 import org.apache.geronimo.xbeans.geronimo.GerPartitionedpoolType; 110 import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType; 111 import org.apache.geronimo.xbeans.geronimo.GerSinglepoolType; 112 import org.apache.geronimo.xbeans.j2ee.ActivationspecType; 113 import org.apache.geronimo.xbeans.j2ee.AdminobjectType; 114 import org.apache.geronimo.xbeans.j2ee.ConfigPropertyType; 115 import org.apache.geronimo.xbeans.j2ee.ConnectionDefinitionType; 116 import org.apache.geronimo.xbeans.j2ee.ConnectorDocument; 117 import org.apache.geronimo.xbeans.j2ee.ConnectorType; 118 import org.apache.geronimo.xbeans.j2ee.MessagelistenerType; 119 import org.apache.geronimo.xbeans.j2ee.ResourceadapterType; 120 import org.apache.xmlbeans.XmlCursor; 121 import org.apache.xmlbeans.XmlDocumentProperties; 122 import org.apache.xmlbeans.XmlException; 123 import org.apache.xmlbeans.XmlObject; 124 125 128 public class ConnectorModuleBuilder implements ModuleBuilder, ActivationSpecInfoLocator { 129 private final static Log log = LogFactory.getLog(ConnectorModuleBuilder.class); 130 131 private static QName CONNECTOR_QNAME = GerConnectorDocument.type.getDocumentElementName(); 132 static final String GERCONNECTOR_NAMESPACE = CONNECTOR_QNAME.getNamespaceURI(); 133 134 private final int defaultMaxSize; 135 private final int defaultMinSize; 136 private final int defaultBlockingTimeoutMilliseconds; 137 private final int defaultIdleTimeoutMinutes; 138 private final boolean defaultXATransactionCaching; 139 private final boolean defaultXAThreadCaching; 140 private final Environment defaultEnvironment; 141 private final NamespaceDrivenBuilderCollection serviceBuilders; 142 private static final QName RESOURCE_ADAPTER_VERSION = new QName (SchemaConversionUtils.J2EE_NAMESPACE, "resourceadapter-version"); 143 144 public ConnectorModuleBuilder(Environment defaultEnvironment, 145 int defaultMaxSize, 146 int defaultMinSize, 147 int defaultBlockingTimeoutMilliseconds, 148 int defaultIdleTimeoutMinutes, 149 boolean defaultXATransactionCaching, 150 boolean defaultXAThreadCaching, 151 Collection serviceBuilders) { 152 this.defaultEnvironment = defaultEnvironment; 153 154 this.defaultMaxSize = defaultMaxSize; 155 this.defaultMinSize = defaultMinSize; 156 this.defaultBlockingTimeoutMilliseconds = defaultBlockingTimeoutMilliseconds; 157 this.defaultIdleTimeoutMinutes = defaultIdleTimeoutMinutes; 158 this.defaultXATransactionCaching = defaultXATransactionCaching; 159 this.defaultXAThreadCaching = defaultXAThreadCaching; 160 this.serviceBuilders = new NamespaceDrivenBuilderCollection(serviceBuilders, GBeanBuilder.SERVICE_QNAME); 161 } 162 163 public Module createModule(File plan, JarFile moduleFile, Naming naming, ModuleIDBuilder idBuilder) throws DeploymentException { 164 return createModule(plan, moduleFile, "rar", null, null, null, naming, idBuilder); 165 } 166 167 public Module createModule(Object plan, JarFile moduleFile, String targetPath, URL specDDUrl, Environment environment, Object moduleContextInfo, AbstractName earName, Naming naming, ModuleIDBuilder idBuilder) throws DeploymentException { 168 return createModule(plan, moduleFile, targetPath, specDDUrl, environment, earName, naming, idBuilder); 169 } 170 171 private Module createModule(Object plan, JarFile moduleFile, String targetPath, URL specDDUrl, Environment earEnvironment, AbstractName earName, Naming naming, ModuleIDBuilder idBuilder) throws DeploymentException { 172 assert moduleFile != null: "moduleFile is null"; 173 assert targetPath != null: "targetPath is null"; 174 assert !targetPath.endsWith("/"): "targetPath must not end with a '/'"; 175 176 String specDD; 177 XmlObject connector; 178 try { 179 if (specDDUrl == null) { 180 specDDUrl = DeploymentUtil.createJarURL(moduleFile, "META-INF/ra.xml"); 181 } 182 183 specDD = DeploymentUtil.readAll(specDDUrl); 186 } catch (Exception e) { 187 return null; 189 } 190 try { 192 XmlObject xmlObject = XmlBeansUtil.parse(specDD); 194 ConnectorDocument connectorDoc = convertToConnectorSchema(xmlObject); 195 connector = connectorDoc.getConnector(); 196 } catch (XmlException e) { 197 throw new DeploymentException("Could not parse ra.xml descriptor", e); 198 } 199 GerConnectorType gerConnector = null; 200 try { 201 try { 203 if (plan instanceof XmlObject) { 204 gerConnector = (GerConnectorType) SchemaConversionUtils.getNestedObjectAsType((XmlObject) plan, 205 CONNECTOR_QNAME, 206 GerConnectorType.type); 207 } else { 208 GerConnectorDocument gerConnectorDoc; 209 ArrayList errors = new ArrayList (); 210 if (plan != null) { 211 gerConnectorDoc = GerConnectorDocument.Factory.parse((File ) plan, XmlBeansUtil.createXmlOptions(errors)); 212 } else { 213 URL path = DeploymentUtil.createJarURL(moduleFile, "META-INF/geronimo-ra.xml"); 214 gerConnectorDoc = GerConnectorDocument.Factory.parse(path, XmlBeansUtil.createXmlOptions(errors)); 215 } 216 if (errors.size() > 0) { 217 throw new DeploymentException("Could not parse connector doc: " + errors); 218 } 219 if (gerConnectorDoc != null) { 220 gerConnector = gerConnectorDoc.getConnector(); 221 } 222 } 223 } catch (IOException e) { 224 } 226 227 if (gerConnector == null) { 229 throw new DeploymentException("A connector module must be deployed using a Geronimo deployment plan" + 230 " (either META-INF/geronimo-ra.xml in the RAR file or a standalone deployment plan passed to the deployer)."); 231 } 232 ConnectorPlanRectifier.rectifyPlan(gerConnector); 233 XmlCursor cursor = gerConnector.newCursor(); 234 try { 235 SchemaConversionUtils.convertToGeronimoSubSchemas(cursor); 236 } finally { 237 cursor.dispose(); 238 } 239 240 XmlBeansUtil.validateDD(gerConnector); 241 } catch (XmlException e) { 242 throw new DeploymentException(e); 243 } 244 245 EnvironmentType environmentType = gerConnector.getEnvironment(); 246 Environment environment = EnvironmentBuilder.buildEnvironment(environmentType, defaultEnvironment); 247 if (earEnvironment != null) { 248 EnvironmentBuilder.mergeEnvironments(earEnvironment, environment); 249 environment = earEnvironment; 250 if (!environment.getConfigId().isResolved()) { 251 throw new IllegalStateException ("Connector module ID should be fully resolved (not " + environment.getConfigId() + ")"); 252 } 253 } else { 254 idBuilder.resolve(environment, new File (moduleFile.getName()).getName(), "rar"); 255 } 256 257 AbstractName moduleName; 258 if (earName == null) { 259 earName = naming.createRootName(environment.getConfigId(), NameFactory.NULL, NameFactory.J2EE_APPLICATION); 260 moduleName = naming.createChildName(earName, environment.getConfigId().toString(), NameFactory.RESOURCE_ADAPTER_MODULE); 261 } else { 262 moduleName = naming.createChildName(earName, targetPath, NameFactory.RESOURCE_ADAPTER_MODULE); 263 } 264 265 boolean standAlone = earEnvironment == null; 266 return new ConnectorModule(standAlone, moduleName, environment, moduleFile, targetPath, connector, gerConnector, specDD); 267 } 268 269 static ConnectorDocument convertToConnectorSchema(XmlObject xmlObject) throws XmlException { 270 if (ConnectorDocument.type.equals(xmlObject.schemaType())) { 271 XmlBeansUtil.validateDD(xmlObject); 272 return (ConnectorDocument) xmlObject; 273 } 274 XmlCursor cursor = xmlObject.newCursor(); 275 XmlDocumentProperties xmlDocumentProperties = cursor.documentProperties(); 276 String publicId = xmlDocumentProperties.getDoctypePublicId(); 277 try { 278 if ("-//Sun Microsystems, Inc.//DTD Connector 1.0//EN".equals(publicId)) { 279 XmlCursor moveable = xmlObject.newCursor(); 280 try { 281 String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"; 282 String version = "1.5"; 283 SchemaConversionUtils.convertToSchema(cursor, SchemaConversionUtils.J2EE_NAMESPACE, schemaLocationURL, version); 284 cursor.toStartDoc(); 285 cursor.toChild(SchemaConversionUtils.J2EE_NAMESPACE, "connector"); 286 cursor.toFirstChild(); 287 SchemaConversionUtils.convertToDescriptionGroup(SchemaConversionUtils.J2EE_NAMESPACE, cursor, moveable); 288 cursor.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "spec-version"); 289 cursor.removeXml(); 290 cursor.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "version"); 291 cursor.setName(RESOURCE_ADAPTER_VERSION); 292 cursor.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "resourceadapter"); 293 moveable.toCursor(cursor); 294 cursor.toFirstChild(); 295 cursor.beginElement("outbound-resourceadapter", SchemaConversionUtils.J2EE_NAMESPACE); 296 cursor.beginElement("connection-definition", SchemaConversionUtils.J2EE_NAMESPACE); 297 moveable.toChild(SchemaConversionUtils.J2EE_NAMESPACE, "managedconnectionfactory-class"); 298 moveable.push(); 299 moveable.moveXml(cursor); 301 while (moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "config-property")) { 302 moveable.moveXml(cursor); 303 } 304 moveable.pop(); 305 moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "connectionfactory-interface"); 306 moveable.moveXml(cursor); 307 moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "connectionfactory-impl-class"); 308 moveable.moveXml(cursor); 309 moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "connection-interface"); 310 moveable.moveXml(cursor); 311 moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "connection-impl-class"); 312 moveable.moveXml(cursor); 313 cursor.toNextToken(); 315 moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "transaction-support"); 316 moveable.moveXml(cursor); 317 while (moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "authentication-mechanism")) { 318 moveable.moveXml(cursor); 319 } 320 moveable.toNextSibling(SchemaConversionUtils.J2EE_NAMESPACE, "reauthentication-support"); 321 moveable.moveXml(cursor); 322 } finally { 323 moveable.dispose(); 324 } 325 326 } 327 } finally { 328 cursor.dispose(); 329 } 330 XmlObject result = xmlObject.changeType(ConnectorDocument.type); 331 if (result != null) { 332 XmlBeansUtil.validateDD(result); 333 return (ConnectorDocument) result; 334 } 335 XmlBeansUtil.validateDD(xmlObject); 336 return (ConnectorDocument) xmlObject; 337 338 } 339 340 public void installModule(JarFile earFile, EARContext earContext, Module module, Collection configurationStores, ConfigurationStore targetConfigurationStore, Collection repository) throws DeploymentException { 341 try { 342 JarFile moduleFile = module.getModuleFile(); 343 344 earContext.addManifestClassPath(moduleFile, URI.create(module.getTargetPath())); 351 352 URI targetURI = URI.create(module.getTargetPath() + "/"); 353 Enumeration entries = moduleFile.entries(); 354 while (entries.hasMoreElements()) { 355 ZipEntry entry = (ZipEntry ) entries.nextElement(); 356 URI target = targetURI.resolve(entry.getName()); 357 if (entry.getName().endsWith(".jar")) { 358 earContext.addInclude(target, moduleFile, entry); 359 } else { 360 earContext.addFile(target, moduleFile, entry); 361 } 362 } 363 364 } catch (IOException e) { 365 throw new DeploymentException("Problem deploying connector", e); 366 } 367 } 368 369 public void initContext(EARContext earContext, Module module, ClassLoader cl) throws DeploymentException { 370 ConnectorModule resourceModule = (ConnectorModule) module; 371 372 final ConnectorType connector = (ConnectorType) module.getSpecDD(); 373 374 385 AbstractName resourceAdapterModuleName = resourceModule.getModuleName(); 386 387 AbstractName resourceAdapterjsr77Name = earContext.getNaming().createChildName(resourceAdapterModuleName, module.getName(), NameFactory.RESOURCE_ADAPTER); 388 AbstractName jcaResourcejsr77Name = earContext.getNaming().createChildName(resourceAdapterjsr77Name, module.getName(), NameFactory.JCA_RESOURCE); 389 390 GBeanData resourceAdapterModuleData = new GBeanData(resourceAdapterModuleName, ResourceAdapterModuleImplGBean.GBEAN_INFO); 392 if (earContext.getServerName() != null) { 394 resourceAdapterModuleData.setReferencePattern(NameFactory.J2EE_SERVER, earContext.getServerName()); 396 if (!earContext.getModuleName().equals(resourceAdapterModuleName)) { 398 resourceAdapterModuleData.setReferencePattern(NameFactory.J2EE_APPLICATION, earContext.getModuleName()); 399 } 400 } 401 resourceAdapterModuleData.setReferencePattern("ResourceAdapter", resourceAdapterjsr77Name); 402 403 resourceAdapterModuleData.setAttribute("deploymentDescriptor", module.getOriginalSpecDD()); 404 resourceAdapterModuleData.setAttribute("displayName", connector.getDisplayNameArray().length == 0 ? null : connector.getDisplayNameArray(0).getStringValue()); 405 resourceAdapterModuleData.setAttribute("description", connector.getDescriptionArray().length == 0 ? null : connector.getDescriptionArray(0).getStringValue()); 406 resourceAdapterModuleData.setAttribute("vendorName", connector.getVendorName().getStringValue()); 407 resourceAdapterModuleData.setAttribute("EISType", connector.getEisType().getStringValue()); 408 resourceAdapterModuleData.setAttribute("resourceAdapterVersion", connector.getResourceadapterVersion().getStringValue()); 409 410 ResourceadapterType resourceadapter = connector.getResourceadapter(); 411 if (resourceadapter.isSetResourceadapterClass()) { 413 GBeanInfoBuilder resourceAdapterInfoBuilder = new GBeanInfoBuilder(ResourceAdapterWrapperGBean.class, ResourceAdapterWrapperGBean.GBEAN_INFO); 414 GBeanData resourceAdapterGBeanData = setUpDynamicGBean(resourceAdapterInfoBuilder, resourceadapter.getConfigPropertyArray(), cl); 415 416 resourceAdapterGBeanData.setAttribute("resourceAdapterClass", resourceadapter.getResourceadapterClass().getStringValue().trim()); 417 resourceAdapterModuleData.setAttribute("resourceAdapterGBeanData", resourceAdapterGBeanData); 418 } 419 420 if (resourceadapter.isSetInboundResourceadapter() && resourceadapter.getInboundResourceadapter().isSetMessageadapter()) 421 { 422 Map activationSpecInfoMap = getActivationSpecInfoMap(resourceadapter.getInboundResourceadapter().getMessageadapter().getMessagelistenerArray(), cl); 423 resourceAdapterModuleData.setAttribute("activationSpecInfoMap", activationSpecInfoMap); 424 } 425 Map adminObjectInfoMap = getAdminObjectInfoMap(resourceadapter.getAdminobjectArray(), cl); 426 resourceAdapterModuleData.setAttribute("adminObjectInfoMap", adminObjectInfoMap); 427 if (resourceadapter.isSetOutboundResourceadapter()) { 428 Map managedConnectionFactoryInfoMap = getManagedConnectionFactoryInfoMap(resourceadapter.getOutboundResourceadapter().getConnectionDefinitionArray(), cl); 429 resourceAdapterModuleData.setAttribute("managedConnectionFactoryInfoMap", managedConnectionFactoryInfoMap); 430 } 431 432 try { 433 earContext.addGBean(resourceAdapterModuleData); 434 } catch (GBeanAlreadyExistsException e) { 435 throw new DeploymentException("Could not add resource adapter module gbean to context", e); 436 } 437 438 GBeanData resourceAdapterData = new GBeanData(resourceAdapterjsr77Name, ResourceAdapterImplGBean.GBEAN_INFO); 440 resourceAdapterData.setReferencePattern("JCAResource", jcaResourcejsr77Name); 441 try { 442 earContext.addGBean(resourceAdapterData); 443 } catch (GBeanAlreadyExistsException e) { 444 throw new DeploymentException("Could not add resource adapter gbean to context", e); 445 } 446 447 GBeanData jcaResourceData = new GBeanData(jcaResourcejsr77Name, JCAResourceImplGBean.GBEAN_INFO); 448 Map thisModule = new LinkedHashMap (2); 449 thisModule .put(NameFactory.J2EE_APPLICATION, resourceAdapterModuleName.getNameProperty(NameFactory.J2EE_APPLICATION)); 450 thisModule .put(NameFactory.RESOURCE_ADAPTER_MODULE, resourceAdapterModuleName.getNameProperty(NameFactory.J2EE_NAME)); 451 jcaResourceData.setReferencePattern("ConnectionFactories", new AbstractNameQuery(resourceAdapterModuleName.getArtifact(), thisModule, JCAConnectionFactory.class.getName())); 452 jcaResourceData.setReferencePattern("ResourceAdapters", new AbstractNameQuery(resourceAdapterModuleName.getArtifact(), thisModule, JCAResourceAdapter.class.getName())); 453 jcaResourceData.setReferencePattern("AdminObjects", new AbstractNameQuery(resourceAdapterModuleName.getArtifact(), thisModule, JCAAdminObject.class.getName())); 454 455 try { 456 earContext.addGBean(jcaResourceData); 457 } catch (GBeanAlreadyExistsException e) { 458 throw new DeploymentException("Could not add jca resource gbean to context", e); 459 } 460 461 GerConnectorType geronimoConnector = (GerConnectorType) module.getVendorDD(); 462 463 serviceBuilders.build(geronimoConnector, earContext, earContext); 464 465 addConnectorGBeans(earContext, jcaResourcejsr77Name, resourceAdapterModuleData, connector, geronimoConnector, cl); 466 467 } 468 469 public void addGBeans(EARContext earContext, Module module, ClassLoader cl, Collection repository) throws DeploymentException { 470 } 472 473 public String getSchemaNamespace() { 474 return GERCONNECTOR_NAMESPACE; 475 } 476 477 private void addConnectorGBeans(EARContext earContext, AbstractName jcaResourceName, GBeanData resourceAdapterModuleData, ConnectorType connector, GerConnectorType geronimoConnector, ClassLoader cl) throws DeploymentException { 478 ResourceadapterType resourceadapter = connector.getResourceadapter(); 479 480 GerResourceadapterType[] geronimoResourceAdapters = geronimoConnector.getResourceadapterArray(); 481 for (int k = 0; k < geronimoResourceAdapters.length; k++) { 482 GerResourceadapterType geronimoResourceAdapter = geronimoResourceAdapters[k]; 483 484 AbstractName resourceAdapterAbstractName = null; 486 if (resourceadapter.isSetResourceadapterClass()) { 487 GBeanData resourceAdapterGBeanData = locateResourceAdapterGBeanData(resourceAdapterModuleData); 488 GBeanData resourceAdapterInstanceGBeanData = new GBeanData(resourceAdapterGBeanData); 489 490 setDynamicGBeanDataAttributes(resourceAdapterInstanceGBeanData, geronimoResourceAdapter.getResourceadapterInstance().getConfigPropertySettingArray(), cl); 491 492 AbstractNameQuery workManagerName = ENCConfigBuilder.getGBeanQuery(NameFactory.JCA_WORK_MANAGER, geronimoResourceAdapter.getResourceadapterInstance().getWorkmanager()); 494 resourceAdapterInstanceGBeanData.setReferencePattern("WorkManager", workManagerName); 495 496 resourceAdapterInstanceGBeanData.setReferencePattern("XATerminator", earContext.getTransactionManagerName()); 498 499 String resourceAdapterName = geronimoResourceAdapter.getResourceadapterInstance().getResourceadapterName(); 500 resourceAdapterAbstractName = earContext.getNaming().createChildName(jcaResourceName, resourceAdapterName, NameFactory.JCA_RESOURCE_ADAPTER); 501 resourceAdapterInstanceGBeanData.setAbstractName(resourceAdapterAbstractName); 502 try { 503 earContext.addGBean(resourceAdapterInstanceGBeanData); 504 } catch (GBeanAlreadyExistsException e) { 505 throw new DeploymentException("Could not add resource adapter instance gbean to context", e); 506 } 507 } 508 509 511 if (geronimoResourceAdapter.isSetOutboundResourceadapter()) { 513 if (!resourceadapter.isSetOutboundResourceadapter()) { 514 throw new DeploymentException("Geronimo plan configures an outbound resource adapter but ra.xml does not describe any"); 515 } 516 String transactionSupport = resourceadapter.getOutboundResourceadapter().getTransactionSupport().getStringValue().trim(); 517 for (int i = 0; i < geronimoResourceAdapter.getOutboundResourceadapter().getConnectionDefinitionArray().length; i++) 518 { 519 GerConnectionDefinitionType geronimoConnectionDefinition = geronimoResourceAdapter.getOutboundResourceadapter().getConnectionDefinitionArray(i); 520 assert geronimoConnectionDefinition != null: "Null GeronimoConnectionDefinition"; 521 522 String connectionFactoryInterfaceName = geronimoConnectionDefinition.getConnectionfactoryInterface().trim(); 523 GBeanData connectionFactoryGBeanData = locateConnectionFactoryInfo(resourceAdapterModuleData, connectionFactoryInterfaceName); 524 525 if (connectionFactoryGBeanData == null) { 526 throw new DeploymentException("No connection definition for ConnectionFactory class: " + connectionFactoryInterfaceName); 527 } 528 529 for (int j = 0; j < geronimoConnectionDefinition.getConnectiondefinitionInstanceArray().length; j++) 530 { 531 GerConnectiondefinitionInstanceType connectionfactoryInstance = geronimoConnectionDefinition.getConnectiondefinitionInstanceArray()[j]; 532 533 addOutboundGBeans(earContext, jcaResourceName, resourceAdapterAbstractName, connectionFactoryGBeanData, connectionfactoryInstance, transactionSupport, cl); 534 } 535 } 536 } 537 } 538 540 for (int i = 0; i < geronimoConnector.getAdminobjectArray().length; i++) { 542 GerAdminobjectType gerAdminObject = geronimoConnector.getAdminobjectArray()[i]; 543 544 String adminObjectInterface = gerAdminObject.getAdminobjectInterface().trim(); 545 GBeanData adminObjectGBeanData = locateAdminObjectInfo(resourceAdapterModuleData, adminObjectInterface); 546 547 if (adminObjectGBeanData == null) { 548 throw new DeploymentException("No admin object declared for interface: " + adminObjectInterface); 549 } 550 551 for (int j = 0; j < gerAdminObject.getAdminobjectInstanceArray().length; j++) { 552 GBeanData adminObjectInstanceGBeanData = new GBeanData(adminObjectGBeanData); 553 GerAdminobjectInstanceType gerAdminObjectInstance = gerAdminObject.getAdminobjectInstanceArray()[j]; 554 setDynamicGBeanDataAttributes(adminObjectInstanceGBeanData, gerAdminObjectInstance.getConfigPropertySettingArray(), cl); 555 AbstractName adminObjectAbstractName = earContext.getNaming().createChildName(jcaResourceName, gerAdminObjectInstance.getMessageDestinationName().trim(), NameFactory.JCA_ADMIN_OBJECT); 557 adminObjectInstanceGBeanData.setAbstractName(adminObjectAbstractName); 558 try { 559 earContext.addGBean(adminObjectInstanceGBeanData); 560 } catch (GBeanAlreadyExistsException e) { 561 throw new DeploymentException("Could not add admin object gbean to context", e); 562 } 563 } 564 } 565 } 566 567 private Map getActivationSpecInfoMap(MessagelistenerType[] messagelistenerArray, ClassLoader cl) throws DeploymentException { 568 Map activationSpecInfos = new HashMap (); 569 for (int i = 0; i < messagelistenerArray.length; i++) { 570 MessagelistenerType messagelistenerType = messagelistenerArray[i]; 571 String messageListenerInterface = messagelistenerType.getMessagelistenerType().getStringValue().trim(); 572 ActivationspecType activationspec = messagelistenerType.getActivationspec(); 573 String activationSpecClassName = activationspec.getActivationspecClass().getStringValue().trim(); 574 GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(ActivationSpecWrapperGBean.class, ActivationSpecWrapperGBean.GBEAN_INFO); 575 576 Map getters = new HashMap (); 578 Set setters = new HashSet (); 579 Method [] methods; 580 try { 581 Class activationSpecClass = cl.loadClass(activationSpecClassName); 582 methods = activationSpecClass.getMethods(); 583 } catch (ClassNotFoundException e) { 584 throw new DeploymentException("Can not load activation spec class", e); 585 } 586 for (int j = 0; j < methods.length; j++) { 587 Method method = methods[j]; 588 String methodName = method.getName(); 589 if ((methodName.startsWith("get") || methodName.startsWith("is")) && method.getParameterTypes().length == 0) 590 { 591 String attributeName = (methodName.startsWith("get")) ? methodName.substring(3) : methodName.substring(2); 592 getters.put(Introspector.decapitalize(attributeName), method.getReturnType().getName()); 593 } else if (methodName.startsWith("set") && method.getParameterTypes().length == 1) { 594 setters.add(Introspector.decapitalize(methodName.substring(3))); 595 } 596 } 597 getters.keySet().retainAll(setters); 598 getters.remove("resourceAdapter"); 599 600 for (Iterator iterator = getters.entrySet().iterator(); iterator.hasNext();) { 601 Map.Entry entry = (Map.Entry ) iterator.next(); 602 infoBuilder.addAttribute(new DynamicGAttributeInfo((String ) entry.getKey(), (String ) entry.getValue(), true, true, true, true)); 603 } 604 605 GBeanInfo gbeanInfo = infoBuilder.getBeanInfo(); 606 try { 607 cl.loadClass(activationSpecClassName); 609 } catch (ClassNotFoundException e) { 610 throw new DeploymentException("Could not load ActivationSpec class", e); 611 } 612 GBeanData activationSpecInfo = new GBeanData(gbeanInfo); 613 activationSpecInfo.setAttribute("activationSpecClass", activationSpecClassName); 614 activationSpecInfos.put(messageListenerInterface, activationSpecInfo); 615 } 616 return activationSpecInfos; 617 } 618 619 private Map getManagedConnectionFactoryInfoMap(ConnectionDefinitionType[] connectionDefinitionArray, ClassLoader cl) throws DeploymentException { 620 Map managedConnectionFactoryInfos = new HashMap (); 621 for (int i = 0; i < connectionDefinitionArray.length; i++) { 622 ConnectionDefinitionType connectionDefinition = connectionDefinitionArray[i]; 623 624 GBeanInfoBuilder managedConnectionFactoryInfoBuilder = new GBeanInfoBuilder(ManagedConnectionFactoryWrapper.class, ManagedConnectionFactoryWrapperGBean.GBEAN_INFO); 625 GBeanData managedConnectionFactoryGBeanData = setUpDynamicGBean(managedConnectionFactoryInfoBuilder, connectionDefinition.getConfigPropertyArray(), cl); 626 627 String connectionfactoryInterface = connectionDefinition.getConnectionfactoryInterface().getStringValue().trim(); 629 managedConnectionFactoryGBeanData.setAttribute("managedConnectionFactoryClass", connectionDefinition.getManagedconnectionfactoryClass().getStringValue().trim()); 630 managedConnectionFactoryGBeanData.setAttribute("connectionFactoryInterface", connectionfactoryInterface); 631 managedConnectionFactoryGBeanData.setAttribute("connectionFactoryImplClass", connectionDefinition.getConnectionfactoryImplClass().getStringValue().trim()); 632 managedConnectionFactoryGBeanData.setAttribute("connectionInterface", connectionDefinition.getConnectionInterface().getStringValue().trim()); 633 managedConnectionFactoryGBeanData.setAttribute("connectionImplClass", connectionDefinition.getConnectionImplClass().getStringValue().trim()); 634 managedConnectionFactoryInfos.put(connectionfactoryInterface, managedConnectionFactoryGBeanData); 635 } 636 return managedConnectionFactoryInfos; 637 } 638 639 private Map getAdminObjectInfoMap(AdminobjectType[] adminobjectArray, ClassLoader cl) throws DeploymentException { 640 Map adminObjectInfos = new HashMap (); 641 for (int i = 0; i < adminobjectArray.length; i++) { 642 AdminobjectType adminObject = adminobjectArray[i]; 643 644 GBeanInfoBuilder adminObjectInfoBuilder = new GBeanInfoBuilder(AdminObjectWrapper.class, AdminObjectWrapperGBean.GBEAN_INFO); 645 GBeanData adminObjectGBeanData = setUpDynamicGBean(adminObjectInfoBuilder, adminObject.getConfigPropertyArray(), cl); 646 647 String adminObjectInterface = adminObject.getAdminobjectInterface().getStringValue().trim(); 649 adminObjectGBeanData.setAttribute("adminObjectInterface", adminObjectInterface); 650 adminObjectGBeanData.setAttribute("adminObjectClass", adminObject.getAdminobjectClass().getStringValue().trim()); 651 adminObjectInfos.put(adminObjectInterface, adminObjectGBeanData); 652 } 653 return adminObjectInfos; 654 } 655 656 657 private GBeanData setUpDynamicGBean(GBeanInfoBuilder infoBuilder, ConfigPropertyType[] configProperties, ClassLoader cl) throws DeploymentException { 658 for (int i = 0; i < configProperties.length; i++) { 659 infoBuilder.addAttribute(new DynamicGAttributeInfo(configProperties[i].getConfigPropertyName().getStringValue().trim(), configProperties[i].getConfigPropertyType().getStringValue().trim(), true, true, true, true)); 660 } 661 662 GBeanInfo gbeanInfo = infoBuilder.getBeanInfo(); 663 GBeanData gbeanData = new GBeanData(gbeanInfo); 664 for (int i = 0; i < configProperties.length; i++) { 665 if (configProperties[i].isSetConfigPropertyValue()) { 666 gbeanData.setAttribute(configProperties[i].getConfigPropertyName().getStringValue(), 667 getValue(configProperties[i].getConfigPropertyType().getStringValue(), 668 configProperties[i].getConfigPropertyValue().getStringValue(), 669 cl)); 670 } 671 } 672 return gbeanData; 673 } 674 675 private void setDynamicGBeanDataAttributes(GBeanData gbeanData, GerConfigPropertySettingType[] configProperties, ClassLoader cl) throws DeploymentException { 676 677 try { 678 for (int i = 0; i < configProperties.length; i++) { 679 String name = configProperties[i].getName(); 680 GAttributeInfo attributeInfo = gbeanData.getGBeanInfo().getAttribute(name); 681 if (attributeInfo == null) { 682 throw new DeploymentException("The plan is trying to set attribute: " + name + " which does not exist. Known attributs are: " + gbeanData.getGBeanInfo().getAttributes()); 683 } 684 String type = attributeInfo.getType(); 685 gbeanData.setAttribute(name, 686 getValue(type, configProperties[i].getStringValue().trim(), cl)); 687 } 688 } catch (DeploymentException e) { 689 throw e; 690 } catch (Exception e) { 691 throw new DeploymentException(e); 692 } 693 } 694 695 private Object getValue(String type, String value, ClassLoader cl) throws DeploymentException { 696 if (value == null) { 697 return null; 698 } 699 700 Class clazz; 701 try { 702 clazz = cl.loadClass(type); 703 } catch (ClassNotFoundException e) { 704 throw new DeploymentException("Could not load attribute class: type: " + type, e); 705 } 706 707 if (value.equals("")) { 709 if (Number .class.isAssignableFrom(clazz) || Date .class.isAssignableFrom(clazz)) { 710 return null; 711 } 712 } 713 714 PropertyEditor editor = PropertyEditors.getEditor(clazz); 715 editor.setAsText(value); 716 return editor.getValue(); 717 } 718 719 private AbstractName configureConnectionManager(EARContext earContext, AbstractName jcaResourceName, String ddTransactionSupport, GerConnectiondefinitionInstanceType connectionfactoryInstance, ClassLoader cl) throws DeploymentException { 720 729 AbstractName connectionManagerAbstractName = earContext.getNaming().createChildName(jcaResourceName, connectionfactoryInstance.getName().trim(), NameFactory.JCA_CONNECTION_MANAGER); 731 732 GBeanInfo gbeanInfo; 734 try { 735 gbeanInfo = GBeanInfo.getGBeanInfo("org.apache.geronimo.connector.outbound.GenericConnectionManagerGBean", cl); 736 } catch (InvalidConfigurationException e) { 737 throw new DeploymentException("Unable to create GMBean", e); 738 } 739 GBeanData connectionManagerGBean = new GBeanData(connectionManagerAbstractName, gbeanInfo); 740 741 GerConnectionmanagerType connectionManager = connectionfactoryInstance.getConnectionmanager(); 743 TransactionSupport transactionSupport; 744 if (connectionManager.isSetNoTransaction()) { 745 transactionSupport = NoTransactions.INSTANCE; 746 } else if (connectionManager.isSetLocalTransaction()) { 747 if ("NoTransaction".equals(ddTransactionSupport)) { 748 throw new DeploymentException("You are requesting local transaction support for a connector that does not support transactions: named: " + connectionfactoryInstance.getName().trim()); 749 } 750 transactionSupport = LocalTransactions.INSTANCE; 751 } else if (connectionManager.isSetTransactionLog()) { 752 if ("NoTransaction".equals(ddTransactionSupport)) { 753 throw new DeploymentException("You are requesting local transaction support for a connector that does not support transactions: named: " + connectionfactoryInstance.getName().trim()); 754 } 755 transactionSupport = TransactionLog.INSTANCE; 756 } else if (connectionManager.isSetXaTransaction()) { 757 if ("NoTransaction".equals(ddTransactionSupport)) { 758 throw new DeploymentException("You are requesting xa transaction support for a connector that does not support transactions: named: " + connectionfactoryInstance.getName().trim()); 759 } 760 if ("LocalTransaction".equals(ddTransactionSupport)) { 761 throw new DeploymentException("You are requesting xa transaction support for a connector that supports only local transactions: named: " + connectionfactoryInstance.getName().trim()); 762 } 763 transactionSupport = new XATransactions(connectionManager.getXaTransaction().isSetTransactionCaching(), 764 connectionManager.getXaTransaction().isSetThreadCaching()); 765 } else if ("NoTransaction".equals(ddTransactionSupport)) { 766 transactionSupport = NoTransactions.INSTANCE; 767 } else if ("LocalTransaction".equals(ddTransactionSupport)) { 768 transactionSupport = LocalTransactions.INSTANCE; 769 } else if ("XATransaction".equals(ddTransactionSupport)) { 770 transactionSupport = new XATransactions(defaultXATransactionCaching, defaultXAThreadCaching); 771 } else { 772 throw new DeploymentException("Unexpected transaction support element in connector named: " + connectionfactoryInstance.getName().trim()); 774 } 775 PoolingSupport pooling; 776 if (connectionManager.getSinglePool() != null) { 777 GerSinglepoolType pool = connectionManager.getSinglePool(); 778 779 pooling = new SinglePool(pool.isSetMaxSize() ? pool.getMaxSize() : defaultMaxSize, 780 pool.isSetMinSize() ? pool.getMinSize() : defaultMinSize, 781 pool.isSetBlockingTimeoutMilliseconds() ? pool.getBlockingTimeoutMilliseconds() : defaultBlockingTimeoutMilliseconds, 782 pool.isSetIdleTimeoutMinutes() ? pool.getIdleTimeoutMinutes() : defaultIdleTimeoutMinutes, 783 pool.getMatchOne() != null, 784 pool.getMatchAll() != null, 785 pool.getSelectOneAssumeMatch() != null); 786 } else if (connectionManager.getPartitionedPool() != null) { 787 GerPartitionedpoolType pool = connectionManager.getPartitionedPool(); 788 pooling = new PartitionedPool(pool.isSetMaxSize() ? pool.getMaxSize() : defaultMaxSize, 789 pool.isSetMinSize() ? pool.getMinSize() : defaultMinSize, 790 pool.isSetBlockingTimeoutMilliseconds() ? pool.getBlockingTimeoutMilliseconds() : defaultBlockingTimeoutMilliseconds, 791 pool.isSetIdleTimeoutMinutes() ? pool.getIdleTimeoutMinutes() : defaultIdleTimeoutMinutes, 792 pool.getMatchOne() != null, 793 pool.getMatchAll() != null, 794 pool.getSelectOneAssumeMatch() != null, 795 pool.isSetPartitionByConnectionrequestinfo(), 796 pool.isSetPartitionBySubject()); 797 } else if (connectionManager.getNoPool() != null) { 798 pooling = new NoPool(); 799 } else { 800 throw new DeploymentException("Unexpected pooling support element in connector named " + connectionfactoryInstance.getName().trim()); 801 } 802 try { 803 connectionManagerGBean.setAttribute("transactionSupport", transactionSupport); 804 connectionManagerGBean.setAttribute("pooling", pooling); 805 connectionManagerGBean.setReferencePattern("ConnectionTracker", earContext.getConnectionTrackerName()); 806 connectionManagerGBean.setAttribute("containerManagedSecurity", Boolean.valueOf(connectionManager.isSetContainerManagedSecurity())); 807 connectionManagerGBean.setReferencePattern("TransactionManager", earContext.getTransactionManagerName()); 808 } catch (Exception e) { 809 throw new DeploymentException("Problem setting up ConnectionManager named " + connectionfactoryInstance.getName().trim(), e); 810 } 811 812 try { 813 earContext.addGBean(connectionManagerGBean); 814 } catch (GBeanAlreadyExistsException e) { 815 throw new DeploymentException("Could not add connection manager gbean to context: name: " + connectionfactoryInstance.getName().trim(), e); 816 } 817 return connectionManagerAbstractName; 818 } 819 820 private void addOutboundGBeans(EARContext earContext, AbstractName jcaResourceName, AbstractName resourceAdapterAbstractName, GBeanData managedConnectionFactoryPrototypeGBeanData, GerConnectiondefinitionInstanceType connectiondefinitionInstance, String transactionSupport, ClassLoader cl) throws DeploymentException { 821 GBeanData managedConnectionFactoryInstanceGBeanData = new GBeanData(managedConnectionFactoryPrototypeGBeanData); 822 AbstractName connectionFactoryAbstractName = earContext.getNaming().createChildName(jcaResourceName, connectiondefinitionInstance.getName().trim(), NameFactory.JCA_CONNECTION_FACTORY); 823 AbstractName managedConnectionFactoryAbstractName = earContext.getNaming().createChildName(connectionFactoryAbstractName, connectiondefinitionInstance.getName().trim(), NameFactory.JCA_MANAGED_CONNECTION_FACTORY); 824 AbstractName connectionManagerAbstractName = configureConnectionManager(earContext, managedConnectionFactoryAbstractName, transactionSupport, connectiondefinitionInstance, cl); 826 827 setDynamicGBeanDataAttributes(managedConnectionFactoryInstanceGBeanData, connectiondefinitionInstance.getConfigPropertySettingArray(), cl); 829 830 833 Object driver = managedConnectionFactoryInstanceGBeanData.getAttribute("Driver"); 834 if (driver != null && driver instanceof String ) { 835 try { 836 cl.loadClass((String )driver); 837 } catch (ClassNotFoundException e1) { 838 log.warn("Problem loading driver class '"+driver+"', possibly due to a missing dependency on the driver jar!!", e1); 839 } 840 } 841 842 try { 843 if (resourceAdapterAbstractName != null) { 844 managedConnectionFactoryInstanceGBeanData.setReferencePattern("ResourceAdapterWrapper", resourceAdapterAbstractName); 845 } 846 managedConnectionFactoryInstanceGBeanData.setReferencePattern("ConnectionManagerContainer", connectionManagerAbstractName); 847 String [] implementedInterfaces = connectiondefinitionInstance.getImplementedInterfaceArray(); 849 if (implementedInterfaces != null) { 850 for (int i = 0; i < implementedInterfaces.length; i++) { 851 implementedInterfaces[i] = implementedInterfaces[i].trim(); 852 } 853 } else { 854 implementedInterfaces = new String [0]; 855 } 856 managedConnectionFactoryInstanceGBeanData.setAttribute("implementedInterfaces", implementedInterfaces); 857 858 } catch (Exception e) { 859 throw new DeploymentException(e); 860 } 861 862 managedConnectionFactoryInstanceGBeanData.setAbstractName(managedConnectionFactoryAbstractName); 863 try { 864 earContext.addGBean(managedConnectionFactoryInstanceGBeanData); 865 } catch (GBeanAlreadyExistsException e) { 866 throw new DeploymentException("Could not add managed connection factory gbean to context", e); 867 } 868 869 GBeanData connectionFactoryGBeanData = new GBeanData(connectionFactoryAbstractName, JCAConnectionFactoryImplGBean.GBEAN_INFO); 871 connectionFactoryGBeanData.setReferencePattern("JCAManagedConnectionFactory", managedConnectionFactoryAbstractName); 872 873 try { 874 earContext.addGBean(connectionFactoryGBeanData); 875 } catch (GBeanAlreadyExistsException e) { 876 throw new DeploymentException("Could not add connection factory gbean to context", e); 877 } 878 } 879 880 public Reference createResourceRef(AbstractNameQuery containerId, Class iface, Configuration configuration) throws DeploymentException { 882 try { 883 configuration.findGBean(containerId); 884 } catch (GBeanNotFoundException e) { 885 throw new UnresolvedReferenceException("Resource", false, containerId.toString(), configuration.getId().toString()); 886 } 887 return new ResourceReference(configuration.getId(), containerId, iface); 888 } 889 890 public Reference createAdminObjectRef(AbstractNameQuery containerId, Class iface, Configuration configuration) throws DeploymentException { 891 try { 892 configuration.findGBean(containerId); 893 } catch (GBeanNotFoundException e) { 894 throw new DeploymentException("Can not resolve admin object ref " + containerId + " in configuration " + configuration.getId()); 895 } 896 return new ResourceReference(configuration.getId(), containerId, iface); 897 } 898 899 public GBeanData locateActivationSpecInfo(AbstractNameQuery resourceAdapterInstanceQuery, String messageListenerInterface, Configuration configuration) throws DeploymentException { 900 AbstractName instanceName; 902 try { 903 instanceName = configuration.findGBean(resourceAdapterInstanceQuery); 904 } catch (GBeanNotFoundException e) { 905 throw new DeploymentException("No resource adapter instance gbean found matching " + resourceAdapterInstanceQuery + " from configuration " + configuration.getId()); 906 } 907 String moduleName = (String ) instanceName.getName().get(NameFactory.RESOURCE_ADAPTER_MODULE); 908 Map moduleNameMap = new HashMap (instanceName.getName()); 909 moduleNameMap.remove(NameFactory.JCA_RESOURCE); 910 moduleNameMap.remove(NameFactory.RESOURCE_ADAPTER); 911 moduleNameMap.remove(NameFactory.RESOURCE_ADAPTER_MODULE); 912 moduleNameMap.put(NameFactory.J2EE_TYPE, NameFactory.RESOURCE_ADAPTER_MODULE); 913 moduleNameMap.put(NameFactory.J2EE_NAME, moduleName); 914 AbstractNameQuery nameQuery = new AbstractNameQuery(instanceName.getArtifact(), moduleNameMap, ResourceAdapterModule.class.getName()); 915 GBeanData resourceModuleData; 917 try { 918 resourceModuleData = configuration.findGBeanData(nameQuery); 919 } catch (GBeanNotFoundException e) { 920 throw new DeploymentException("No resource module gbean found matching " + nameQuery + " from configuration " + configuration.getId()); 921 } 922 Map activationSpecInfos = (Map ) resourceModuleData.getAttribute("activationSpecInfoMap"); 923 if (activationSpecInfos == null) { 924 throw new DeploymentException("No activation spec info map found in resource adapter module: " + resourceModuleData.getAbstractName()); 925 } 926 return (GBeanData) activationSpecInfos.get(messageListenerInterface); 927 } 928 929 private GBeanData locateResourceAdapterGBeanData(GBeanData resourceAdapterModuleData) throws DeploymentException { 930 GBeanData data = (GBeanData) resourceAdapterModuleData.getAttribute("resourceAdapterGBeanData"); 931 if (data == null) { 932 throw new DeploymentException("No resource adapter info found for resource adapter module: " + resourceAdapterModuleData.getAbstractName()); 933 } 934 return data; 935 } 936 937 private GBeanData locateAdminObjectInfo(GBeanData resourceAdapterModuleData, String adminObjectInterfaceName) throws DeploymentException { 938 Map adminObjectInfos = (Map ) resourceAdapterModuleData.getAttribute("adminObjectInfoMap"); 939 if (adminObjectInfos == null) { 940 throw new DeploymentException("No admin object infos found for resource adapter module: " + resourceAdapterModuleData.getAbstractName()); 941 } 942 return (GBeanData) adminObjectInfos.get(adminObjectInterfaceName); 943 } 944 945 private GBeanData locateConnectionFactoryInfo(GBeanData resourceAdapterModuleData, String connectionFactoryInterfaceName) throws DeploymentException { 946 Map managedConnectionFactoryInfos = (Map ) resourceAdapterModuleData.getAttribute("managedConnectionFactoryInfoMap"); 947 if (managedConnectionFactoryInfos == null) { 948 throw new DeploymentException("No managed connection factory infos found for resource adapter module: " + resourceAdapterModuleData.getAbstractName()); 949 } 950 return (GBeanData) managedConnectionFactoryInfos.get(connectionFactoryInterfaceName); 951 } 952 953 public static final GBeanInfo GBEAN_INFO; 954 955 static { 956 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(ConnectorModuleBuilder.class, NameFactory.MODULE_BUILDER); 957 958 infoBuilder.addAttribute("defaultEnvironment", Environment.class, true, true); 959 infoBuilder.addAttribute("defaultMaxSize", int.class, true, true); 960 infoBuilder.addAttribute("defaultMinSize", int.class, true, true); 961 infoBuilder.addAttribute("defaultBlockingTimeoutMilliseconds", int.class, true, true); 962 infoBuilder.addAttribute("defaultIdleTimeoutMinutes", int.class, true, true); 963 infoBuilder.addAttribute("defaultXATransactionCaching", boolean.class, true, true); 964 infoBuilder.addAttribute("defaultXAThreadCaching", boolean.class, true, true); 965 966 infoBuilder.addReference("ServiceBuilders", NamespaceDrivenBuilder.class, NameFactory.MODULE_BUILDER); 967 968 infoBuilder.addInterface(ModuleBuilder.class); 969 infoBuilder.addInterface(ActivationSpecInfoLocator.class); 970 971 infoBuilder.setConstructor(new String []{"defaultEnvironment", 972 "defaultMaxSize", 973 "defaultMinSize", 974 "defaultBlockingTimeoutMilliseconds", 975 "defaultIdleTimeoutMinutes", 976 "defaultXATransactionCaching", 977 "defaultXAThreadCaching", 978 "ServiceBuilders"}); 979 GBEAN_INFO = infoBuilder.getBeanInfo(); 980 } 981 982 public static GBeanInfo getGBeanInfo() { 983 return GBEAN_INFO; 984 } 985 986 } 987 | Popular Tags |