0001: /**
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */package org.apache.geronimo.connector.deployment;
0017:
0018: import java.beans.Introspector;
0019: import java.beans.PropertyEditor;
0020: import java.io.File;
0021: import java.io.IOException;
0022: import java.lang.reflect.Method;
0023: import java.net.URI;
0024: import java.net.URL;
0025: import java.util.ArrayList;
0026: import java.util.Collection;
0027: import java.util.Date;
0028: import java.util.Enumeration;
0029: import java.util.HashMap;
0030: import java.util.HashSet;
0031: import java.util.LinkedHashMap;
0032: import java.util.List;
0033: import java.util.Map;
0034: import java.util.Set;
0035: import java.util.TreeMap;
0036: import java.util.Collections;
0037: import java.util.jar.JarFile;
0038: import java.util.zip.ZipEntry;
0039:
0040: import javax.xml.namespace.QName;
0041:
0042: import org.apache.commons.logging.Log;
0043: import org.apache.commons.logging.LogFactory;
0044: import org.apache.geronimo.common.DeploymentException;
0045: import org.apache.geronimo.common.propertyeditor.PropertyEditors;
0046: import org.apache.geronimo.connector.ActivationSpecWrapperGBean;
0047: import org.apache.geronimo.connector.AdminObjectWrapper;
0048: import org.apache.geronimo.connector.AdminObjectWrapperGBean;
0049: import org.apache.geronimo.connector.JCAResourceImplGBean;
0050: import org.apache.geronimo.connector.ResourceAdapterImplGBean;
0051: import org.apache.geronimo.connector.ResourceAdapterModuleImplGBean;
0052: import org.apache.geronimo.connector.ResourceAdapterWrapperGBean;
0053: import org.apache.geronimo.connector.outbound.JCAConnectionFactoryImplGBean;
0054: import org.apache.geronimo.connector.outbound.ManagedConnectionFactoryWrapper;
0055: import org.apache.geronimo.connector.outbound.ManagedConnectionFactoryWrapperGBean;
0056: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.LocalTransactions;
0057: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool;
0058: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoTransactions;
0059: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PartitionedPool;
0060: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
0061: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool;
0062: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionLog;
0063: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
0064: import org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions;
0065: import org.apache.geronimo.deployment.ModuleIDBuilder;
0066: import org.apache.geronimo.deployment.NamespaceDrivenBuilder;
0067: import org.apache.geronimo.deployment.NamespaceDrivenBuilderCollection;
0068: import org.apache.geronimo.deployment.service.EnvironmentBuilder;
0069: import org.apache.geronimo.deployment.service.GBeanBuilder;
0070: import org.apache.geronimo.deployment.util.DeploymentUtil;
0071: import org.apache.geronimo.deployment.xbeans.EnvironmentType;
0072: import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
0073: import org.apache.geronimo.gbean.AbstractName;
0074: import org.apache.geronimo.gbean.AbstractNameQuery;
0075: import org.apache.geronimo.gbean.DynamicGAttributeInfo;
0076: import org.apache.geronimo.gbean.GAttributeInfo;
0077: import org.apache.geronimo.gbean.GBeanData;
0078: import org.apache.geronimo.gbean.GBeanInfo;
0079: import org.apache.geronimo.gbean.GBeanInfoBuilder;
0080: import org.apache.geronimo.gbean.InvalidConfigurationException;
0081: import org.apache.geronimo.gbean.GBeanLifecycle;
0082: import org.apache.geronimo.j2ee.deployment.ActivationSpecInfoLocator;
0083: import org.apache.geronimo.j2ee.deployment.ConnectorModule;
0084: import org.apache.geronimo.j2ee.deployment.EARContext;
0085: import org.apache.geronimo.j2ee.deployment.Module;
0086: import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
0087: import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedApp;
0088: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
0089: import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
0090: import org.apache.geronimo.kernel.GBeanNotFoundException;
0091: import org.apache.geronimo.kernel.Naming;
0092: import org.apache.geronimo.kernel.config.Configuration;
0093: import org.apache.geronimo.kernel.config.ConfigurationStore;
0094: import org.apache.geronimo.kernel.repository.Environment;
0095: import org.apache.geronimo.management.JCAConnectionFactory;
0096: import org.apache.geronimo.management.geronimo.JCAAdminObject;
0097: import org.apache.geronimo.management.geronimo.JCAResourceAdapter;
0098: import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
0099: import org.apache.geronimo.naming.deployment.ENCConfigBuilder;
0100: import org.apache.geronimo.schema.SchemaConversionUtils;
0101: import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType;
0102: import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType;
0103: import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
0104: import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
0105: import org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
0106: import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
0107: import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
0108: import org.apache.geronimo.xbeans.geronimo.GerConnectorType;
0109: import org.apache.geronimo.xbeans.geronimo.GerPartitionedpoolType;
0110: import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
0111: import org.apache.geronimo.xbeans.geronimo.GerSinglepoolType;
0112: import org.apache.geronimo.xbeans.j2ee.ActivationspecType;
0113: import org.apache.geronimo.xbeans.j2ee.AdminobjectType;
0114: import org.apache.geronimo.xbeans.j2ee.ConfigPropertyType;
0115: import org.apache.geronimo.xbeans.j2ee.ConnectionDefinitionType;
0116: import org.apache.geronimo.xbeans.j2ee.ConnectorDocument;
0117: import org.apache.geronimo.xbeans.j2ee.ConnectorType;
0118: import org.apache.geronimo.xbeans.j2ee.MessagelistenerType;
0119: import org.apache.geronimo.xbeans.j2ee.ResourceadapterType;
0120: import org.apache.xmlbeans.XmlCursor;
0121: import org.apache.xmlbeans.XmlDocumentProperties;
0122: import org.apache.xmlbeans.XmlException;
0123: import org.apache.xmlbeans.XmlObject;
0124:
0125: /**
0126: * @version $Rev:385659 $ $Date: 2008-01-17 23:54:14 -0800 (Thu, 17 Jan 2008) $
0127: */
0128: public class ConnectorModuleBuilder implements ModuleBuilder,
0129: ActivationSpecInfoLocator, GBeanLifecycle {
0130: private final static Log log = LogFactory
0131: .getLog(ConnectorModuleBuilder.class);
0132:
0133: private static final QName RESOURCE_ADAPTER_VERSION = new QName(
0134: SchemaConversionUtils.J2EE_NAMESPACE,
0135: "resourceadapter-version");
0136: private static QName CONNECTOR_QNAME = GerConnectorDocument.type
0137: .getDocumentElementName();
0138: static final String GERCONNECTOR_NAMESPACE = CONNECTOR_QNAME
0139: .getNamespaceURI();
0140: private static final Map<String, String> NAMESPACE_UPDATES = new HashMap<String, String>();
0141: static {
0142: NAMESPACE_UPDATES.put(
0143: "http://geronimo.apache.org/xml/ns/j2ee/connector",
0144: "http://geronimo.apache.org/xml/ns/j2ee/connector-1.2");
0145: NAMESPACE_UPDATES.put(
0146: "http://geronimo.apache.org/xml/ns/j2ee/connector-1.1",
0147: "http://geronimo.apache.org/xml/ns/j2ee/connector-1.2");
0148: }
0149:
0150: private final int defaultMaxSize;
0151: private final int defaultMinSize;
0152: private final int defaultBlockingTimeoutMilliseconds;
0153: private final int defaultIdleTimeoutMinutes;
0154: private final boolean defaultXATransactionCaching;
0155: private final boolean defaultXAThreadCaching;
0156: private final Environment defaultEnvironment;
0157: private final NamespaceDrivenBuilderCollection serviceBuilders;
0158:
0159: public ConnectorModuleBuilder(Environment defaultEnvironment,
0160: int defaultMaxSize, int defaultMinSize,
0161: int defaultBlockingTimeoutMilliseconds,
0162: int defaultIdleTimeoutMinutes,
0163: boolean defaultXATransactionCaching,
0164: boolean defaultXAThreadCaching, Collection serviceBuilders) {
0165: this .defaultEnvironment = defaultEnvironment;
0166:
0167: this .defaultMaxSize = defaultMaxSize;
0168: this .defaultMinSize = defaultMinSize;
0169: this .defaultBlockingTimeoutMilliseconds = defaultBlockingTimeoutMilliseconds;
0170: this .defaultIdleTimeoutMinutes = defaultIdleTimeoutMinutes;
0171: this .defaultXATransactionCaching = defaultXATransactionCaching;
0172: this .defaultXAThreadCaching = defaultXAThreadCaching;
0173: this .serviceBuilders = new NamespaceDrivenBuilderCollection(
0174: serviceBuilders, GBeanBuilder.SERVICE_QNAME);
0175: }
0176:
0177: public void doStart() throws Exception {
0178: XmlBeansUtil.registerNamespaceUpdates(NAMESPACE_UPDATES);
0179: }
0180:
0181: public void doStop() {
0182: XmlBeansUtil.unregisterNamespaceUpdates(NAMESPACE_UPDATES);
0183: }
0184:
0185: public void doFail() {
0186: doStop();
0187: }
0188:
0189: public Module createModule(File plan, JarFile moduleFile,
0190: Naming naming, ModuleIDBuilder idBuilder)
0191: throws DeploymentException {
0192: return createModule(plan, moduleFile, "rar", null, null, null,
0193: naming, idBuilder);
0194: }
0195:
0196: public Module createModule(Object plan, JarFile moduleFile,
0197: String targetPath, URL specDDUrl, Environment environment,
0198: Object moduleContextInfo, AbstractName earName,
0199: Naming naming, ModuleIDBuilder idBuilder)
0200: throws DeploymentException {
0201: return createModule(plan, moduleFile, targetPath, specDDUrl,
0202: environment, earName, naming, idBuilder);
0203: }
0204:
0205: private Module createModule(Object plan, JarFile moduleFile,
0206: String targetPath, URL specDDUrl,
0207: Environment earEnvironment, AbstractName earName,
0208: Naming naming, ModuleIDBuilder idBuilder)
0209: throws DeploymentException {
0210: assert moduleFile != null : "moduleFile is null";
0211: assert targetPath != null : "targetPath is null";
0212: assert !targetPath.endsWith("/") : "targetPath must not end with a '/'";
0213:
0214: String specDD;
0215: XmlObject connector;
0216: try {
0217: if (specDDUrl == null) {
0218: specDDUrl = DeploymentUtil.createJarURL(moduleFile,
0219: "META-INF/ra.xml");
0220: }
0221:
0222: // read in the entire specDD as a string, we need this for getDeploymentDescriptor
0223: // on the J2ee management object
0224: specDD = DeploymentUtil.readAll(specDDUrl);
0225: } catch (Exception e) {
0226: //no ra.xml, not for us.
0227: return null;
0228: }
0229: //we found ra.xml, if it won't parse it's an error.
0230: try {
0231: // parse it
0232: XmlObject xmlObject = XmlBeansUtil.parse(specDD);
0233: ConnectorDocument connectorDoc = convertToConnectorSchema(xmlObject);
0234: connector = connectorDoc.getConnector();
0235: } catch (XmlException e) {
0236: throw new DeploymentException(
0237: "Could not parse ra.xml descriptor", e);
0238: }
0239: GerConnectorType gerConnector = null;
0240: try {
0241: // load the geronimo connector plan from either the supplied plan or from the earFile
0242: try {
0243: if (plan instanceof XmlObject) {
0244: gerConnector = (GerConnectorType) SchemaConversionUtils
0245: .getNestedObjectAsType((XmlObject) plan,
0246: CONNECTOR_QNAME,
0247: GerConnectorType.type);
0248: } else {
0249: GerConnectorDocument gerConnectorDoc;
0250: ArrayList errors = new ArrayList();
0251: if (plan != null) {
0252: gerConnectorDoc = GerConnectorDocument.Factory
0253: .parse((File) plan, XmlBeansUtil
0254: .createXmlOptions(errors));
0255: } else {
0256: URL path = DeploymentUtil.createJarURL(
0257: moduleFile, "META-INF/geronimo-ra.xml");
0258: gerConnectorDoc = GerConnectorDocument.Factory
0259: .parse(path, XmlBeansUtil
0260: .createXmlOptions(errors));
0261: }
0262: if (errors.size() > 0) {
0263: throw new DeploymentException(
0264: "Could not parse connector doc: "
0265: + errors);
0266: }
0267: if (gerConnectorDoc != null) {
0268: gerConnector = gerConnectorDoc.getConnector();
0269: }
0270: }
0271: } catch (IOException e) {
0272: //do nothing
0273: }
0274:
0275: // if we got one extract the validate it otherwise create a default one
0276: if (gerConnector == null) {
0277: throw new DeploymentException(
0278: "A connector module must be deployed using a Geronimo deployment plan"
0279: + " (either META-INF/geronimo-ra.xml in the RAR file or a standalone deployment plan passed to the deployer).");
0280: }
0281: ConnectorPlanRectifier.rectifyPlan(gerConnector);
0282: XmlCursor cursor = gerConnector.newCursor();
0283: try {
0284: SchemaConversionUtils
0285: .convertToGeronimoSubSchemas(cursor);
0286: } finally {
0287: cursor.dispose();
0288: }
0289:
0290: XmlBeansUtil.validateDD(gerConnector);
0291: } catch (XmlException e) {
0292: throw new DeploymentException(
0293: "Could not parse module descriptor", e);
0294: }
0295:
0296: EnvironmentType environmentType = gerConnector.getEnvironment();
0297: Environment environment = EnvironmentBuilder.buildEnvironment(
0298: environmentType, defaultEnvironment);
0299: if (earEnvironment != null) {
0300: EnvironmentBuilder.mergeEnvironments(earEnvironment,
0301: environment);
0302: environment = earEnvironment;
0303: if (!environment.getConfigId().isResolved()) {
0304: throw new IllegalStateException(
0305: "Connector module ID should be fully resolved (not "
0306: + environment.getConfigId() + ")");
0307: }
0308: } else {
0309: idBuilder.resolve(environment, new File(moduleFile
0310: .getName()).getName(), "rar");
0311: }
0312:
0313: AbstractName moduleName;
0314: if (earName == null) {
0315: earName = naming.createRootName(environment.getConfigId(),
0316: NameFactory.NULL, NameFactory.J2EE_APPLICATION);
0317: moduleName = naming.createChildName(earName, environment
0318: .getConfigId().toString(),
0319: NameFactory.RESOURCE_ADAPTER_MODULE);
0320: } else {
0321: moduleName = naming.createChildName(earName, targetPath,
0322: NameFactory.RESOURCE_ADAPTER_MODULE);
0323: }
0324:
0325: boolean standAlone = earEnvironment == null;
0326: AnnotatedApp annotatedApp = null;
0327: return new ConnectorModule(standAlone, moduleName, environment,
0328: moduleFile, targetPath, connector, gerConnector,
0329: specDD, annotatedApp);
0330:
0331: }
0332:
0333: static ConnectorDocument convertToConnectorSchema(
0334: XmlObject xmlObject) throws XmlException {
0335: if (ConnectorDocument.type.equals(xmlObject.schemaType())) {
0336: XmlBeansUtil.validateDD(xmlObject);
0337: return (ConnectorDocument) xmlObject;
0338: }
0339: XmlCursor cursor = xmlObject.newCursor();
0340: XmlDocumentProperties xmlDocumentProperties = cursor
0341: .documentProperties();
0342: String publicId = xmlDocumentProperties.getDoctypePublicId();
0343: try {
0344: if ("-//Sun Microsystems, Inc.//DTD Connector 1.0//EN"
0345: .equals(publicId)) {
0346: XmlCursor moveable = xmlObject.newCursor();
0347: try {
0348: String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd";
0349: String version = "1.5";
0350: SchemaConversionUtils.convertToSchema(cursor,
0351: SchemaConversionUtils.J2EE_NAMESPACE,
0352: schemaLocationURL, version);
0353: cursor.toStartDoc();
0354: cursor.toChild(
0355: SchemaConversionUtils.J2EE_NAMESPACE,
0356: "connector");
0357: cursor.toFirstChild();
0358: SchemaConversionUtils.convertToDescriptionGroup(
0359: SchemaConversionUtils.J2EE_NAMESPACE,
0360: cursor, moveable);
0361: cursor.toNextSibling(
0362: SchemaConversionUtils.J2EE_NAMESPACE,
0363: "spec-version");
0364: cursor.removeXml();
0365: cursor.toNextSibling(
0366: SchemaConversionUtils.J2EE_NAMESPACE,
0367: "version");
0368: cursor.setName(RESOURCE_ADAPTER_VERSION);
0369: cursor.toNextSibling(
0370: SchemaConversionUtils.J2EE_NAMESPACE,
0371: "resourceadapter");
0372: moveable.toCursor(cursor);
0373: cursor.toFirstChild();
0374: cursor.beginElement("outbound-resourceadapter",
0375: SchemaConversionUtils.J2EE_NAMESPACE);
0376: cursor.beginElement("connection-definition",
0377: SchemaConversionUtils.J2EE_NAMESPACE);
0378: moveable.toChild(
0379: SchemaConversionUtils.J2EE_NAMESPACE,
0380: "managedconnectionfactory-class");
0381: moveable.push();
0382: //from moveable to cursor
0383: moveable.moveXml(cursor);
0384: while (moveable.toNextSibling(
0385: SchemaConversionUtils.J2EE_NAMESPACE,
0386: "config-property")) {
0387: moveable.moveXml(cursor);
0388: }
0389: moveable.pop();
0390: moveable.toNextSibling(
0391: SchemaConversionUtils.J2EE_NAMESPACE,
0392: "connectionfactory-interface");
0393: moveable.moveXml(cursor);
0394: moveable.toNextSibling(
0395: SchemaConversionUtils.J2EE_NAMESPACE,
0396: "connectionfactory-impl-class");
0397: moveable.moveXml(cursor);
0398: moveable.toNextSibling(
0399: SchemaConversionUtils.J2EE_NAMESPACE,
0400: "connection-interface");
0401: moveable.moveXml(cursor);
0402: moveable.toNextSibling(
0403: SchemaConversionUtils.J2EE_NAMESPACE,
0404: "connection-impl-class");
0405: moveable.moveXml(cursor);
0406: //get out of connection-definition element
0407: cursor.toNextToken();
0408: moveable.toNextSibling(
0409: SchemaConversionUtils.J2EE_NAMESPACE,
0410: "transaction-support");
0411: moveable.moveXml(cursor);
0412: while (moveable.toNextSibling(
0413: SchemaConversionUtils.J2EE_NAMESPACE,
0414: "authentication-mechanism")) {
0415: moveable.moveXml(cursor);
0416: }
0417: moveable.toNextSibling(
0418: SchemaConversionUtils.J2EE_NAMESPACE,
0419: "reauthentication-support");
0420: moveable.moveXml(cursor);
0421: } finally {
0422: moveable.dispose();
0423: }
0424:
0425: }
0426: } finally {
0427: cursor.dispose();
0428: }
0429: XmlObject result = xmlObject.changeType(ConnectorDocument.type);
0430: if (result != null) {
0431: XmlBeansUtil.validateDD(result);
0432: return (ConnectorDocument) result;
0433: }
0434: XmlBeansUtil.validateDD(xmlObject);
0435: return (ConnectorDocument) xmlObject;
0436:
0437: }
0438:
0439: public void installModule(JarFile earFile, EARContext earContext,
0440: Module module, Collection configurationStores,
0441: ConfigurationStore targetConfigurationStore,
0442: Collection repository) throws DeploymentException {
0443: try {
0444: JarFile moduleFile = module.getModuleFile();
0445:
0446: // add the manifest classpath entries declared in the connector to the class loader
0447: // we have to explicitly add these since we are unpacking the connector module
0448: // and the url class loader will not pick up a manifiest from an unpacked dir
0449: // N.B. If we ever introduce a separate configuration/module for a rar inside an ear
0450: // this will need to be modified to use "../" instead of module.getTargetPath().
0451: // See AbstractWebModuleBuilder.
0452: earContext.addManifestClassPath(moduleFile, URI
0453: .create(module.getTargetPath()));
0454:
0455: URI targetURI = URI.create(module.getTargetPath() + "/");
0456: Enumeration entries = moduleFile.entries();
0457: while (entries.hasMoreElements()) {
0458: ZipEntry entry = (ZipEntry) entries.nextElement();
0459: URI target = targetURI.resolve(entry.getName());
0460: if (entry.getName().endsWith(".jar")) {
0461: earContext.addInclude(target, moduleFile, entry);
0462: } else {
0463: earContext.addFile(target, moduleFile, entry);
0464: }
0465: }
0466:
0467: } catch (IOException e) {
0468: throw new DeploymentException(
0469: "Problem deploying connector", e);
0470: }
0471: }
0472:
0473: public void initContext(EARContext earContext, Module module,
0474: ClassLoader cl) throws DeploymentException {
0475: ConnectorModule resourceModule = (ConnectorModule) module;
0476:
0477: final ConnectorType connector = (ConnectorType) module
0478: .getSpecDD();
0479:
0480: /*
0481: The chain of idiotic jsr-77 meaningless objects is:
0482: ResourceAdapterModule (1) >
0483: ResourceAdapter (n, but there can only be 1 resource adapter in a rar, so we use 1) >
0484: JCAResource (1) >
0485: JCAConnectionFactory (n) >
0486: JCAManagedConnectionFactory (1)
0487: We also include:
0488: JCAResourceAdapter (n) (from JCAResource) (actual instance of ResourceAdapter)
0489: TODO include admin objects (n) from JCAResource presumably
0490: */
0491: AbstractName resourceAdapterModuleName = resourceModule
0492: .getModuleName();
0493:
0494: AbstractName resourceAdapterjsr77Name = earContext.getNaming()
0495: .createChildName(resourceAdapterModuleName,
0496: module.getName(), NameFactory.RESOURCE_ADAPTER);
0497: AbstractName jcaResourcejsr77Name = earContext.getNaming()
0498: .createChildName(resourceAdapterjsr77Name,
0499: module.getName(), NameFactory.JCA_RESOURCE);
0500:
0501: //set up the metadata for the ResourceAdapterModule
0502: GBeanData resourceAdapterModuleData = new GBeanData(
0503: resourceAdapterModuleName,
0504: ResourceAdapterModuleImplGBean.GBEAN_INFO);
0505: // initalize the GBean
0506: if (earContext.getServerName() != null) {
0507: //app clients don't have a Server gbean
0508: resourceAdapterModuleData
0509: .setReferencePattern(NameFactory.J2EE_SERVER,
0510: earContext.getServerName());
0511: //app clients don't have an application name either
0512: if (!earContext.getModuleName().equals(
0513: resourceAdapterModuleName)) {
0514: resourceAdapterModuleData.setReferencePattern(
0515: NameFactory.J2EE_APPLICATION, earContext
0516: .getModuleName());
0517: }
0518: }
0519: resourceAdapterModuleData.setReferencePattern(
0520: "ResourceAdapter", resourceAdapterjsr77Name);
0521:
0522: resourceAdapterModuleData.setAttribute("deploymentDescriptor",
0523: module.getOriginalSpecDD());
0524: resourceAdapterModuleData.setAttribute("displayName", connector
0525: .getDisplayNameArray().length == 0 ? null : connector
0526: .getDisplayNameArray(0).getStringValue());
0527: resourceAdapterModuleData.setAttribute("description", connector
0528: .getDescriptionArray().length == 0 ? null : connector
0529: .getDescriptionArray(0).getStringValue());
0530: resourceAdapterModuleData.setAttribute("vendorName", connector
0531: .getVendorName().getStringValue());
0532: resourceAdapterModuleData.setAttribute("EISType", connector
0533: .getEisType().getStringValue());
0534: resourceAdapterModuleData.setAttribute(
0535: "resourceAdapterVersion", connector
0536: .getResourceadapterVersion().getStringValue());
0537:
0538: ResourceadapterType resourceadapter = connector
0539: .getResourceadapter();
0540: // Create the resource adapter gbean
0541: if (resourceadapter.isSetResourceadapterClass()) {
0542: GBeanInfoBuilder resourceAdapterInfoBuilder = new GBeanInfoBuilder(
0543: ResourceAdapterWrapperGBean.class,
0544: ResourceAdapterWrapperGBean.GBEAN_INFO);
0545: String resourceAdapterClassName = resourceadapter
0546: .getResourceadapterClass().getStringValue().trim();
0547: GBeanData resourceAdapterGBeanData = setUpDynamicGBeanWithProperties(
0548: resourceAdapterClassName,
0549: resourceAdapterInfoBuilder, resourceadapter
0550: .getConfigPropertyArray(), cl, Collections
0551: .<String> emptySet());
0552:
0553: resourceAdapterGBeanData.setAttribute(
0554: "resourceAdapterClass", resourceAdapterClassName);
0555:
0556: // Add map from messageListenerInterface to activationSpec class
0557: Map<String, String> messageListenerToActivationSpecMap = new TreeMap<String, String>();
0558: if (resourceadapter.isSetInboundResourceadapter()
0559: && resourceadapter.getInboundResourceadapter()
0560: .isSetMessageadapter()) {
0561: for (MessagelistenerType messagelistenerType : resourceadapter
0562: .getInboundResourceadapter()
0563: .getMessageadapter().getMessagelistenerArray()) {
0564: String messageListenerInterface = messagelistenerType
0565: .getMessagelistenerType().getStringValue()
0566: .trim();
0567: ActivationspecType activationspec = messagelistenerType
0568: .getActivationspec();
0569: String activationSpecClassName = activationspec
0570: .getActivationspecClass().getStringValue()
0571: .trim();
0572: messageListenerToActivationSpecMap.put(
0573: messageListenerInterface,
0574: activationSpecClassName);
0575: resourceAdapterGBeanData.setAttribute(
0576: "messageListenerToActivationSpecMap",
0577: messageListenerToActivationSpecMap);
0578: resourceAdapterGBeanData.setReferencePattern(
0579: "TransactionManager", earContext
0580: .getTransactionManagerName());
0581: }
0582: }
0583:
0584: resourceAdapterModuleData.setAttribute(
0585: "resourceAdapterGBeanData",
0586: resourceAdapterGBeanData);
0587: }
0588:
0589: if (resourceadapter.isSetInboundResourceadapter()
0590: && resourceadapter.getInboundResourceadapter()
0591: .isSetMessageadapter()) {
0592: Map activationSpecInfoMap = getActivationSpecInfoMap(
0593: resourceadapter.getInboundResourceadapter()
0594: .getMessageadapter()
0595: .getMessagelistenerArray(), cl);
0596: resourceAdapterModuleData.setAttribute(
0597: "activationSpecInfoMap", activationSpecInfoMap);
0598: }
0599: Map adminObjectInfoMap = getAdminObjectInfoMap(resourceadapter
0600: .getAdminobjectArray(), cl);
0601: resourceAdapterModuleData.setAttribute("adminObjectInfoMap",
0602: adminObjectInfoMap);
0603: if (resourceadapter.isSetOutboundResourceadapter()) {
0604: Map managedConnectionFactoryInfoMap = getManagedConnectionFactoryInfoMap(
0605: resourceadapter.getOutboundResourceadapter()
0606: .getConnectionDefinitionArray(), cl);
0607: resourceAdapterModuleData.setAttribute(
0608: "managedConnectionFactoryInfoMap",
0609: managedConnectionFactoryInfoMap);
0610: }
0611:
0612: try {
0613: earContext.addGBean(resourceAdapterModuleData);
0614: } catch (GBeanAlreadyExistsException e) {
0615: throw new DeploymentException(
0616: "Could not add resource adapter module gbean to context",
0617: e);
0618: }
0619:
0620: //construct the bogus resource adapter and jca resource placeholders
0621: GBeanData resourceAdapterData = new GBeanData(
0622: resourceAdapterjsr77Name,
0623: ResourceAdapterImplGBean.GBEAN_INFO);
0624: resourceAdapterData.setReferencePattern("JCAResource",
0625: jcaResourcejsr77Name);
0626: try {
0627: earContext.addGBean(resourceAdapterData);
0628: } catch (GBeanAlreadyExistsException e) {
0629: throw new DeploymentException(
0630: "Could not add resource adapter gbean to context",
0631: e);
0632: }
0633:
0634: GBeanData jcaResourceData = new GBeanData(jcaResourcejsr77Name,
0635: JCAResourceImplGBean.GBEAN_INFO);
0636: Map<String, String> this Module = new LinkedHashMap<String, String>(
0637: 2);
0638: this Module.put(NameFactory.J2EE_APPLICATION,
0639: resourceAdapterModuleName
0640: .getNameProperty(NameFactory.J2EE_APPLICATION));
0641: this Module.put(NameFactory.RESOURCE_ADAPTER_MODULE,
0642: resourceAdapterModuleName
0643: .getNameProperty(NameFactory.J2EE_NAME));
0644: jcaResourceData.setReferencePattern("ConnectionFactories",
0645: new AbstractNameQuery(resourceAdapterModuleName
0646: .getArtifact(), this Module,
0647: JCAConnectionFactory.class.getName()));
0648: jcaResourceData.setReferencePattern("ResourceAdapters",
0649: new AbstractNameQuery(resourceAdapterModuleName
0650: .getArtifact(), this Module,
0651: JCAResourceAdapter.class.getName()));
0652: jcaResourceData.setReferencePattern("AdminObjects",
0653: new AbstractNameQuery(resourceAdapterModuleName
0654: .getArtifact(), this Module,
0655: JCAAdminObject.class.getName()));
0656:
0657: try {
0658: earContext.addGBean(jcaResourceData);
0659: } catch (GBeanAlreadyExistsException e) {
0660: throw new DeploymentException(
0661: "Could not add jca resource gbean to context", e);
0662: }
0663:
0664: GerConnectorType geronimoConnector = (GerConnectorType) module
0665: .getVendorDD();
0666:
0667: serviceBuilders
0668: .build(geronimoConnector, earContext, earContext);
0669:
0670: addConnectorGBeans(earContext, jcaResourcejsr77Name,
0671: resourceAdapterModuleData, connector,
0672: geronimoConnector, cl);
0673:
0674: }
0675:
0676: public void addGBeans(EARContext earContext, Module module,
0677: ClassLoader cl, Collection repository)
0678: throws DeploymentException {
0679: //all our gbeans are added in the initContext step
0680: }
0681:
0682: public String getSchemaNamespace() {
0683: return GERCONNECTOR_NAMESPACE;
0684: }
0685:
0686: private void addConnectorGBeans(EARContext earContext,
0687: AbstractName jcaResourceName,
0688: GBeanData resourceAdapterModuleData,
0689: ConnectorType connector,
0690: GerConnectorType geronimoConnector, ClassLoader cl)
0691: throws DeploymentException {
0692: ResourceadapterType resourceadapter = connector
0693: .getResourceadapter();
0694:
0695: GerResourceadapterType[] geronimoResourceAdapters = geronimoConnector
0696: .getResourceadapterArray();
0697: for (GerResourceadapterType geronimoResourceAdapter : geronimoResourceAdapters) {
0698: // Resource Adapter
0699: AbstractName resourceAdapterAbstractName = null;
0700: if (resourceadapter.isSetResourceadapterClass()) {
0701: GBeanData resourceAdapterGBeanData = locateResourceAdapterGBeanData(resourceAdapterModuleData);
0702: GBeanData resourceAdapterInstanceGBeanData = new GBeanData(
0703: resourceAdapterGBeanData);
0704:
0705: setDynamicGBeanDataAttributes(
0706: resourceAdapterInstanceGBeanData,
0707: geronimoResourceAdapter
0708: .getResourceadapterInstance()
0709: .getConfigPropertySettingArray(), cl);
0710:
0711: // set the work manager name
0712: AbstractNameQuery workManagerName = ENCConfigBuilder
0713: .getGBeanQuery(NameFactory.JCA_WORK_MANAGER,
0714: geronimoResourceAdapter
0715: .getResourceadapterInstance()
0716: .getWorkmanager());
0717: resourceAdapterInstanceGBeanData.setReferencePattern(
0718: "WorkManager", workManagerName);
0719:
0720: // set the xa terminator name which is the same as our transaction manager
0721: resourceAdapterInstanceGBeanData.setReferencePattern(
0722: "XATerminator", earContext
0723: .getTransactionManagerName());
0724:
0725: String resourceAdapterName = geronimoResourceAdapter
0726: .getResourceadapterInstance()
0727: .getResourceadapterName();
0728: resourceAdapterAbstractName = earContext.getNaming()
0729: .createChildName(jcaResourceName,
0730: resourceAdapterName,
0731: NameFactory.JCA_RESOURCE_ADAPTER);
0732: resourceAdapterInstanceGBeanData
0733: .setAbstractName(resourceAdapterAbstractName);
0734: try {
0735: earContext
0736: .addGBean(resourceAdapterInstanceGBeanData);
0737: } catch (GBeanAlreadyExistsException e) {
0738: throw new DeploymentException(
0739: "Could not add resource adapter instance gbean to context",
0740: e);
0741: }
0742: }
0743:
0744: // Outbound Managed Connection Factories (think JDBC data source or JMS connection factory)
0745:
0746: // ManagedConnectionFactory setup
0747: if (geronimoResourceAdapter.isSetOutboundResourceadapter()) {
0748: if (!resourceadapter.isSetOutboundResourceadapter()) {
0749: throw new DeploymentException(
0750: "Geronimo plan configures an outbound resource adapter but ra.xml does not describe any");
0751: }
0752: String transactionSupport = resourceadapter
0753: .getOutboundResourceadapter()
0754: .getTransactionSupport().getStringValue()
0755: .trim();
0756: for (int i = 0; i < geronimoResourceAdapter
0757: .getOutboundResourceadapter()
0758: .getConnectionDefinitionArray().length; i++) {
0759: GerConnectionDefinitionType geronimoConnectionDefinition = geronimoResourceAdapter
0760: .getOutboundResourceadapter()
0761: .getConnectionDefinitionArray(i);
0762: assert geronimoConnectionDefinition != null : "Null GeronimoConnectionDefinition";
0763:
0764: String connectionFactoryInterfaceName = geronimoConnectionDefinition
0765: .getConnectionfactoryInterface().trim();
0766: GBeanData connectionFactoryGBeanData = locateConnectionFactoryInfo(
0767: resourceAdapterModuleData,
0768: connectionFactoryInterfaceName);
0769:
0770: if (connectionFactoryGBeanData == null) {
0771: throw new DeploymentException(
0772: "No connection definition for ConnectionFactory class: "
0773: + connectionFactoryInterfaceName);
0774: }
0775:
0776: for (int j = 0; j < geronimoConnectionDefinition
0777: .getConnectiondefinitionInstanceArray().length; j++) {
0778: GerConnectiondefinitionInstanceType connectionfactoryInstance = geronimoConnectionDefinition
0779: .getConnectiondefinitionInstanceArray()[j];
0780:
0781: addOutboundGBeans(earContext, jcaResourceName,
0782: resourceAdapterAbstractName,
0783: connectionFactoryGBeanData,
0784: connectionfactoryInstance,
0785: transactionSupport, cl);
0786: }
0787: }
0788: }
0789: }
0790: // admin objects (think message queues and topics)
0791:
0792: // add configured admin objects
0793: for (int i = 0; i < geronimoConnector.getAdminobjectArray().length; i++) {
0794: GerAdminobjectType gerAdminObject = geronimoConnector
0795: .getAdminobjectArray()[i];
0796:
0797: String adminObjectInterface = gerAdminObject
0798: .getAdminobjectInterface().trim();
0799: GBeanData adminObjectGBeanData = locateAdminObjectInfo(
0800: resourceAdapterModuleData, adminObjectInterface);
0801:
0802: if (adminObjectGBeanData == null) {
0803: throw new DeploymentException(
0804: "No admin object declared for interface: "
0805: + adminObjectInterface);
0806: }
0807:
0808: for (GerAdminobjectInstanceType gerAdminObjectInstance : gerAdminObject
0809: .getAdminobjectInstanceArray()) {
0810: GBeanData adminObjectInstanceGBeanData = new GBeanData(
0811: adminObjectGBeanData);
0812: setDynamicGBeanDataAttributes(
0813: adminObjectInstanceGBeanData,
0814: gerAdminObjectInstance
0815: .getConfigPropertySettingArray(), cl);
0816: // add it
0817: AbstractName adminObjectAbstractName = earContext
0818: .getNaming().createChildName(
0819: jcaResourceName,
0820: gerAdminObjectInstance
0821: .getMessageDestinationName()
0822: .trim(),
0823: NameFactory.JCA_ADMIN_OBJECT);
0824: adminObjectInstanceGBeanData
0825: .setAbstractName(adminObjectAbstractName);
0826: try {
0827: earContext.addGBean(adminObjectInstanceGBeanData);
0828: } catch (GBeanAlreadyExistsException e) {
0829: throw new DeploymentException(
0830: "Could not add admin object gbean to context",
0831: e);
0832: }
0833: }
0834: }
0835: }
0836:
0837: private Map getActivationSpecInfoMap(
0838: MessagelistenerType[] messagelistenerArray, ClassLoader cl)
0839: throws DeploymentException {
0840: Map<String, GBeanData> activationSpecInfos = new HashMap<String, GBeanData>();
0841: for (MessagelistenerType messagelistenerType : messagelistenerArray) {
0842: String messageListenerInterface = messagelistenerType
0843: .getMessagelistenerType().getStringValue().trim();
0844: ActivationspecType activationspec = messagelistenerType
0845: .getActivationspec();
0846: String activationSpecClassName = activationspec
0847: .getActivationspecClass().getStringValue().trim();
0848: GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(
0849: ActivationSpecWrapperGBean.class,
0850: ActivationSpecWrapperGBean.GBEAN_INFO);
0851: Set<String> ignore = Collections
0852: .singleton("resourceAdapter");
0853: setUpDynamicGBean(activationSpecClassName, infoBuilder,
0854: ignore, cl, true);
0855:
0856: GBeanInfo gbeanInfo = infoBuilder.getBeanInfo();
0857:
0858: GBeanData activationSpecInfo = new GBeanData(gbeanInfo);
0859: activationSpecInfo.setAttribute("activationSpecClass",
0860: activationSpecClassName);
0861: activationSpecInfos.put(messageListenerInterface,
0862: activationSpecInfo);
0863: }
0864: return activationSpecInfos;
0865: }
0866:
0867: private void setUpDynamicGBean(String activationSpecClassName,
0868: GBeanInfoBuilder infoBuilder, Set<String> ignore,
0869: ClassLoader cl, boolean decapitalize)
0870: throws DeploymentException {
0871: //add all javabean properties that have both getter and setter. Ignore the "required" flag from the dd.
0872: Map<String, String> getters = new HashMap<String, String>();
0873: Set<String> setters = new HashSet<String>();
0874: Method[] methods;
0875: try {
0876: Class activationSpecClass = cl
0877: .loadClass(activationSpecClassName);
0878: methods = activationSpecClass.getMethods();
0879: } catch (ClassNotFoundException e) {
0880: throw new DeploymentException(
0881: "Can not load activation spec class", e);
0882: }
0883: for (Method method : methods) {
0884: String methodName = method.getName();
0885: if ((methodName.startsWith("get") || methodName
0886: .startsWith("is"))
0887: && method.getParameterTypes().length == 0) {
0888: String attributeName = (methodName.startsWith("get")) ? methodName
0889: .substring(3)
0890: : methodName.substring(2);
0891: getters.put(setCase(attributeName, decapitalize),
0892: method.getReturnType().getName());
0893: } else if (methodName.startsWith("set")
0894: && method.getParameterTypes().length == 1) {
0895: setters.add(setCase(methodName.substring(3),
0896: decapitalize));
0897: }
0898: }
0899: getters.keySet().retainAll(setters);
0900: getters.keySet().removeAll(ignore);
0901:
0902: for (Map.Entry<String, String> entry : getters.entrySet()) {
0903: infoBuilder
0904: .addAttribute(new DynamicGAttributeInfo(entry
0905: .getKey(), entry.getValue(), true, true,
0906: true, true));
0907: }
0908: }
0909:
0910: private String setCase(String attributeName, boolean decapitalize) {
0911: if (decapitalize) {
0912: return Introspector.decapitalize(attributeName);
0913: } else {
0914: return attributeName;
0915: }
0916: }
0917:
0918: private Map getManagedConnectionFactoryInfoMap(
0919: ConnectionDefinitionType[] connectionDefinitionArray,
0920: ClassLoader cl) throws DeploymentException {
0921: Map<String, GBeanData> managedConnectionFactoryInfos = new HashMap<String, GBeanData>();
0922: for (ConnectionDefinitionType connectionDefinition : connectionDefinitionArray) {
0923: GBeanInfoBuilder managedConnectionFactoryInfoBuilder = new GBeanInfoBuilder(
0924: ManagedConnectionFactoryWrapper.class,
0925: ManagedConnectionFactoryWrapperGBean.GBEAN_INFO);
0926: String managedConnectionfactoryClassName = connectionDefinition
0927: .getManagedconnectionfactoryClass()
0928: .getStringValue().trim();
0929: Set<String> ignore = new HashSet<String>();
0930: ignore.add("ResourceAdapter");
0931: ignore.add("LogWriter");
0932: GBeanData managedConnectionFactoryGBeanData = setUpDynamicGBeanWithProperties(
0933: managedConnectionfactoryClassName,
0934: managedConnectionFactoryInfoBuilder,
0935: connectionDefinition.getConfigPropertyArray(), cl,
0936: ignore);
0937:
0938: // set the standard properties
0939: String connectionfactoryInterface = connectionDefinition
0940: .getConnectionfactoryInterface().getStringValue()
0941: .trim();
0942: managedConnectionFactoryGBeanData.setAttribute(
0943: "managedConnectionFactoryClass",
0944: managedConnectionfactoryClassName);
0945: managedConnectionFactoryGBeanData.setAttribute(
0946: "connectionFactoryInterface",
0947: connectionfactoryInterface);
0948: managedConnectionFactoryGBeanData.setAttribute(
0949: "connectionFactoryImplClass", connectionDefinition
0950: .getConnectionfactoryImplClass()
0951: .getStringValue().trim());
0952: managedConnectionFactoryGBeanData.setAttribute(
0953: "connectionInterface", connectionDefinition
0954: .getConnectionInterface().getStringValue()
0955: .trim());
0956: managedConnectionFactoryGBeanData.setAttribute(
0957: "connectionImplClass", connectionDefinition
0958: .getConnectionImplClass().getStringValue()
0959: .trim());
0960: managedConnectionFactoryInfos.put(
0961: connectionfactoryInterface,
0962: managedConnectionFactoryGBeanData);
0963: }
0964: return managedConnectionFactoryInfos;
0965: }
0966:
0967: private Map getAdminObjectInfoMap(
0968: AdminobjectType[] adminobjectArray, ClassLoader cl)
0969: throws DeploymentException {
0970: Map<String, GBeanData> adminObjectInfos = new HashMap<String, GBeanData>();
0971: for (AdminobjectType adminObject : adminobjectArray) {
0972: GBeanInfoBuilder adminObjectInfoBuilder = new GBeanInfoBuilder(
0973: AdminObjectWrapper.class,
0974: AdminObjectWrapperGBean.GBEAN_INFO);
0975: String adminObjectClassName = adminObject
0976: .getAdminobjectClass().getStringValue().trim();
0977: GBeanData adminObjectGBeanData = setUpDynamicGBeanWithProperties(
0978: adminObjectClassName, adminObjectInfoBuilder,
0979: adminObject.getConfigPropertyArray(), cl,
0980: Collections.<String> emptySet());
0981:
0982: // set the standard properties
0983: String adminObjectInterface = adminObject
0984: .getAdminobjectInterface().getStringValue().trim();
0985: adminObjectGBeanData.setAttribute("adminObjectInterface",
0986: adminObjectInterface);
0987: adminObjectGBeanData.setAttribute("adminObjectClass",
0988: adminObjectClassName);
0989: adminObjectInfos.put(adminObjectInterface,
0990: adminObjectGBeanData);
0991: }
0992: return adminObjectInfos;
0993: }
0994:
0995: private GBeanData setUpDynamicGBeanWithProperties(String className,
0996: GBeanInfoBuilder infoBuilder,
0997: ConfigPropertyType[] configProperties, ClassLoader cl,
0998: Set<String> ignore) throws DeploymentException {
0999: setUpDynamicGBean(className, infoBuilder, ignore, cl, false);
1000:
1001: GBeanInfo gbeanInfo = infoBuilder.getBeanInfo();
1002: GBeanData gbeanData = new GBeanData(gbeanInfo);
1003: for (ConfigPropertyType configProperty : configProperties) {
1004: if (configProperty.isSetConfigPropertyValue()) {
1005: gbeanData.setAttribute(configProperty
1006: .getConfigPropertyName().getStringValue(),
1007: getValue(configProperty.getConfigPropertyType()
1008: .getStringValue(), configProperty
1009: .getConfigPropertyValue()
1010: .getStringValue(), cl));
1011: }
1012: }
1013: return gbeanData;
1014: }
1015:
1016: private void setDynamicGBeanDataAttributes(GBeanData gbeanData,
1017: GerConfigPropertySettingType[] configProperties,
1018: ClassLoader cl) throws DeploymentException {
1019: List<String> unknownNames = new ArrayList<String>();
1020: for (GerConfigPropertySettingType configProperty : configProperties) {
1021: String name = configProperty.getName();
1022: GAttributeInfo attributeInfo = gbeanData.getGBeanInfo()
1023: .getAttribute(name);
1024: if (attributeInfo == null) {
1025: unknownNames.add(name);
1026: // throw new DeploymentException("The plan is trying to set attribute: " + name + " which does not exist. Known attributes are: " + gbeanData.getGBeanInfo().getAttributes());
1027: } else {
1028: String type = attributeInfo.getType();
1029: gbeanData.setAttribute(name, getValue(type,
1030: configProperty.getStringValue().trim(), cl));
1031: }
1032: }
1033: if (unknownNames.size() > 0) {
1034: StringBuffer buf = new StringBuffer(
1035: "The plan is trying to set attributes: ").append(
1036: unknownNames).append("\n");
1037: buf.append("Known attributes: \n");
1038: for (GAttributeInfo attributeInfo : gbeanData
1039: .getGBeanInfo().getAttributes()) {
1040: buf.append(attributeInfo).append("\n");
1041: }
1042: throw new DeploymentException(buf.toString());
1043: }
1044: }
1045:
1046: private Object getValue(String type, String value, ClassLoader cl)
1047: throws DeploymentException {
1048: if (value == null) {
1049: return null;
1050: }
1051:
1052: Class clazz;
1053: try {
1054: clazz = cl.loadClass(type);
1055: } catch (ClassNotFoundException e) {
1056: throw new DeploymentException(
1057: "Could not load attribute class: type: " + type, e);
1058: }
1059:
1060: // Handle numeric fields with no value set
1061: if (value.equals("")) {
1062: if (Number.class.isAssignableFrom(clazz)
1063: || Date.class.isAssignableFrom(clazz)) {
1064: return null;
1065: }
1066: }
1067:
1068: PropertyEditor editor = PropertyEditors.getEditor(clazz);
1069: editor.setAsText(value);
1070: return editor.getValue();
1071: }
1072:
1073: private AbstractName configureConnectionManager(
1074: EARContext earContext,
1075: AbstractName jcaResourceName,
1076: String ddTransactionSupport,
1077: GerConnectiondefinitionInstanceType connectionfactoryInstance,
1078: ClassLoader cl) throws DeploymentException {
1079: // if (connectionfactoryInstance.getConnectionmanagerRef() != null) {
1080: //we don't configure anything, just use the supplied gbean
1081: // try {
1082: // return AbstractName.getInstance(connectionfactoryInstance.getConnectionmanagerRef());
1083: // } catch (MalformedAbstractNameException e) {
1084: // throw new DeploymentException("Invalid AbstractName string supplied for ConnectionManager reference", e);
1085: // }
1086: // }
1087:
1088: // create the object name for our connection manager
1089: AbstractName connectionManagerAbstractName = earContext
1090: .getNaming().createChildName(jcaResourceName,
1091: connectionfactoryInstance.getName().trim(),
1092: NameFactory.JCA_CONNECTION_MANAGER);
1093:
1094: // create the data holder for our connection manager
1095: GBeanInfo gbeanInfo;
1096: try {
1097: gbeanInfo = GBeanInfo
1098: .getGBeanInfo(
1099: "org.apache.geronimo.connector.outbound.GenericConnectionManagerGBean",
1100: cl);
1101: } catch (InvalidConfigurationException e) {
1102: throw new DeploymentException("Unable to create GMBean", e);
1103: }
1104: GBeanData connectionManagerGBean = new GBeanData(
1105: connectionManagerAbstractName, gbeanInfo);
1106:
1107: //we configure our connection manager
1108: GerConnectionmanagerType connectionManager = connectionfactoryInstance
1109: .getConnectionmanager();
1110: TransactionSupport transactionSupport;
1111: if (connectionManager.isSetNoTransaction()) {
1112: transactionSupport = NoTransactions.INSTANCE;
1113: } else if (connectionManager.isSetLocalTransaction()) {
1114: if ("NoTransaction".equals(ddTransactionSupport)) {
1115: throw new DeploymentException(
1116: "You are requesting local transaction support for a connector that does not support transactions: named: "
1117: + connectionfactoryInstance.getName()
1118: .trim());
1119: }
1120: transactionSupport = LocalTransactions.INSTANCE;
1121: } else if (connectionManager.isSetTransactionLog()) {
1122: if ("NoTransaction".equals(ddTransactionSupport)) {
1123: throw new DeploymentException(
1124: "You are requesting local transaction support for a connector that does not support transactions: named: "
1125: + connectionfactoryInstance.getName()
1126: .trim());
1127: }
1128: transactionSupport = TransactionLog.INSTANCE;
1129: } else if (connectionManager.isSetXaTransaction()) {
1130: if ("NoTransaction".equals(ddTransactionSupport)) {
1131: throw new DeploymentException(
1132: "You are requesting xa transaction support for a connector that does not support transactions: named: "
1133: + connectionfactoryInstance.getName()
1134: .trim());
1135: }
1136: if ("LocalTransaction".equals(ddTransactionSupport)) {
1137: throw new DeploymentException(
1138: "You are requesting xa transaction support for a connector that supports only local transactions: named: "
1139: + connectionfactoryInstance.getName()
1140: .trim());
1141: }
1142: transactionSupport = new XATransactions(connectionManager
1143: .getXaTransaction().isSetTransactionCaching(),
1144: connectionManager.getXaTransaction()
1145: .isSetThreadCaching());
1146: } else if ("NoTransaction".equals(ddTransactionSupport)) {
1147: transactionSupport = NoTransactions.INSTANCE;
1148: } else if ("LocalTransaction".equals(ddTransactionSupport)) {
1149: transactionSupport = LocalTransactions.INSTANCE;
1150: } else if ("XATransaction".equals(ddTransactionSupport)) {
1151: transactionSupport = new XATransactions(
1152: defaultXATransactionCaching, defaultXAThreadCaching);
1153: } else {
1154: //this should not happen
1155: throw new DeploymentException(
1156: "Unexpected transaction support element in connector named: "
1157: + connectionfactoryInstance.getName()
1158: .trim());
1159: }
1160: PoolingSupport pooling;
1161: if (connectionManager.getSinglePool() != null) {
1162: GerSinglepoolType pool = connectionManager.getSinglePool();
1163:
1164: pooling = new SinglePool(pool.isSetMaxSize() ? pool
1165: .getMaxSize() : defaultMaxSize,
1166: pool.isSetMinSize() ? pool.getMinSize()
1167: : defaultMinSize, pool
1168: .isSetBlockingTimeoutMilliseconds() ? pool
1169: .getBlockingTimeoutMilliseconds()
1170: : defaultBlockingTimeoutMilliseconds, pool
1171: .isSetIdleTimeoutMinutes() ? pool
1172: .getIdleTimeoutMinutes()
1173: : defaultIdleTimeoutMinutes, pool
1174: .getMatchOne() != null,
1175: pool.getMatchAll() != null, pool
1176: .getSelectOneAssumeMatch() != null);
1177: } else if (connectionManager.getPartitionedPool() != null) {
1178: GerPartitionedpoolType pool = connectionManager
1179: .getPartitionedPool();
1180: pooling = new PartitionedPool(pool.isSetMaxSize() ? pool
1181: .getMaxSize() : defaultMaxSize,
1182: pool.isSetMinSize() ? pool.getMinSize()
1183: : defaultMinSize, pool
1184: .isSetBlockingTimeoutMilliseconds() ? pool
1185: .getBlockingTimeoutMilliseconds()
1186: : defaultBlockingTimeoutMilliseconds, pool
1187: .isSetIdleTimeoutMinutes() ? pool
1188: .getIdleTimeoutMinutes()
1189: : defaultIdleTimeoutMinutes, pool
1190: .getMatchOne() != null,
1191: pool.getMatchAll() != null, pool
1192: .getSelectOneAssumeMatch() != null, pool
1193: .isSetPartitionByConnectionrequestinfo(),
1194: pool.isSetPartitionBySubject());
1195: } else if (connectionManager.getNoPool() != null) {
1196: pooling = new NoPool();
1197: } else {
1198: throw new DeploymentException(
1199: "Unexpected pooling support element in connector named "
1200: + connectionfactoryInstance.getName()
1201: .trim());
1202: }
1203: try {
1204: connectionManagerGBean.setAttribute("transactionSupport",
1205: transactionSupport);
1206: connectionManagerGBean.setAttribute("pooling", pooling);
1207: connectionManagerGBean.setReferencePattern(
1208: "ConnectionTracker", earContext
1209: .getConnectionTrackerName());
1210: connectionManagerGBean.setAttribute(
1211: "containerManagedSecurity", connectionManager
1212: .isSetContainerManagedSecurity());
1213: connectionManagerGBean.setReferencePattern(
1214: "TransactionManager", earContext
1215: .getTransactionManagerName());
1216: } catch (Exception e) {
1217: throw new DeploymentException(
1218: "Problem setting up ConnectionManager named "
1219: + connectionfactoryInstance.getName()
1220: .trim(), e);
1221: }
1222:
1223: try {
1224: earContext.addGBean(connectionManagerGBean);
1225: } catch (GBeanAlreadyExistsException e) {
1226: throw new DeploymentException(
1227: "Could not add connection manager gbean to context: name: "
1228: + connectionfactoryInstance.getName()
1229: .trim(), e);
1230: }
1231: return connectionManagerAbstractName;
1232: }
1233:
1234: private void addOutboundGBeans(
1235: EARContext earContext,
1236: AbstractName jcaResourceName,
1237: AbstractName resourceAdapterAbstractName,
1238: GBeanData managedConnectionFactoryPrototypeGBeanData,
1239: GerConnectiondefinitionInstanceType connectiondefinitionInstance,
1240: String transactionSupport, ClassLoader cl)
1241: throws DeploymentException {
1242: GBeanData managedConnectionFactoryInstanceGBeanData = new GBeanData(
1243: managedConnectionFactoryPrototypeGBeanData);
1244: AbstractName connectionFactoryAbstractName = earContext
1245: .getNaming().createChildName(jcaResourceName,
1246: connectiondefinitionInstance.getName().trim(),
1247: NameFactory.JCA_CONNECTION_FACTORY);
1248: AbstractName managedConnectionFactoryAbstractName = earContext
1249: .getNaming().createChildName(
1250: connectionFactoryAbstractName,
1251: connectiondefinitionInstance.getName().trim(),
1252: NameFactory.JCA_MANAGED_CONNECTION_FACTORY);
1253: // ConnectionManager
1254: AbstractName connectionManagerAbstractName = configureConnectionManager(
1255: earContext, managedConnectionFactoryAbstractName,
1256: transactionSupport, connectiondefinitionInstance, cl);
1257:
1258: // ManagedConnectionFactory
1259: setDynamicGBeanDataAttributes(
1260: managedConnectionFactoryInstanceGBeanData,
1261: connectiondefinitionInstance
1262: .getConfigPropertySettingArray(), cl);
1263:
1264: //Check if Driver class is available here. This should be available in cl. If not log a warning as
1265: //the plan gets deployed and while starting GBean an error is thrown
1266:
1267: Object driver = managedConnectionFactoryInstanceGBeanData
1268: .getAttribute("Driver");
1269: if (driver != null && driver instanceof String) {
1270: try {
1271: cl.loadClass((String) driver);
1272: } catch (ClassNotFoundException e1) {
1273: log
1274: .warn(
1275: "Problem loading driver class '"
1276: + driver
1277: + "', possibly due to a missing dependency on the driver jar!!",
1278: e1);
1279: }
1280: }
1281:
1282: try {
1283: if (resourceAdapterAbstractName != null) {
1284: managedConnectionFactoryInstanceGBeanData
1285: .setReferencePattern("ResourceAdapterWrapper",
1286: resourceAdapterAbstractName);
1287: }
1288: managedConnectionFactoryInstanceGBeanData
1289: .setReferencePattern("ConnectionManagerContainer",
1290: connectionManagerAbstractName);
1291: //additional interfaces implemented by connection factory
1292: String[] implementedInterfaces = connectiondefinitionInstance
1293: .getImplementedInterfaceArray();
1294: if (implementedInterfaces != null) {
1295: for (int i = 0; i < implementedInterfaces.length; i++) {
1296: implementedInterfaces[i] = implementedInterfaces[i]
1297: .trim();
1298: }
1299: } else {
1300: implementedInterfaces = new String[0];
1301: }
1302: managedConnectionFactoryInstanceGBeanData.setAttribute(
1303: "implementedInterfaces", implementedInterfaces);
1304:
1305: } catch (Exception e) {
1306: throw new DeploymentException(e);
1307: }
1308:
1309: managedConnectionFactoryInstanceGBeanData
1310: .setAbstractName(managedConnectionFactoryAbstractName);
1311: try {
1312: earContext
1313: .addGBean(managedConnectionFactoryInstanceGBeanData);
1314: } catch (GBeanAlreadyExistsException e) {
1315: throw new DeploymentException(
1316: "Could not add managed connection factory gbean to context",
1317: e);
1318: }
1319:
1320: // ConnectionFactory
1321: GBeanData connectionFactoryGBeanData = new GBeanData(
1322: connectionFactoryAbstractName,
1323: JCAConnectionFactoryImplGBean.GBEAN_INFO);
1324: connectionFactoryGBeanData.setReferencePattern(
1325: "JCAManagedConnectionFactory",
1326: managedConnectionFactoryAbstractName);
1327:
1328: try {
1329: earContext.addGBean(connectionFactoryGBeanData);
1330: } catch (GBeanAlreadyExistsException e) {
1331: throw new DeploymentException(
1332: "Could not add connection factory gbean to context",
1333: e);
1334: }
1335: }
1336:
1337: public GBeanData locateActivationSpecInfo(
1338: AbstractNameQuery resourceAdapterInstanceQuery,
1339: String messageListenerInterface, Configuration configuration)
1340: throws DeploymentException {
1341: //First, locate the module gbean from the JCAResourceAdapter instance
1342: AbstractName instanceName;
1343: try {
1344: instanceName = configuration
1345: .findGBean(resourceAdapterInstanceQuery);
1346: } catch (GBeanNotFoundException e) {
1347: throw new DeploymentException(
1348: "No resource adapter instance gbean found matching "
1349: + resourceAdapterInstanceQuery
1350: + " from configuration "
1351: + configuration.getId(), e);
1352: }
1353: String moduleName = (String) instanceName.getName().get(
1354: NameFactory.RESOURCE_ADAPTER_MODULE);
1355: Map<String, String> moduleNameMap = new HashMap<String, String>(
1356: instanceName.getName());
1357: moduleNameMap.remove(NameFactory.JCA_RESOURCE);
1358: moduleNameMap.remove(NameFactory.RESOURCE_ADAPTER);
1359: moduleNameMap.remove(NameFactory.RESOURCE_ADAPTER_MODULE);
1360: moduleNameMap.put(NameFactory.J2EE_TYPE,
1361: NameFactory.RESOURCE_ADAPTER_MODULE);
1362: moduleNameMap.put(NameFactory.J2EE_NAME, moduleName);
1363: AbstractNameQuery nameQuery = new AbstractNameQuery(
1364: instanceName.getArtifact(), moduleNameMap,
1365: ResourceAdapterModule.class.getName());
1366: //now find the gbeandata and extract the activation spec info.
1367: GBeanData resourceModuleData;
1368: try {
1369: resourceModuleData = configuration.findGBeanData(nameQuery);
1370: } catch (GBeanNotFoundException e) {
1371: throw new DeploymentException(
1372: "No resource module gbean found matching "
1373: + nameQuery + " from configuration "
1374: + configuration.getId(), e);
1375: }
1376: Map activationSpecInfos = (Map) resourceModuleData
1377: .getAttribute("activationSpecInfoMap");
1378: if (activationSpecInfos == null) {
1379: throw new DeploymentException(
1380: "No activation spec info map found in resource adapter module: "
1381: + resourceModuleData.getAbstractName());
1382: }
1383: return (GBeanData) activationSpecInfos
1384: .get(messageListenerInterface);
1385: }
1386:
1387: private GBeanData locateResourceAdapterGBeanData(
1388: GBeanData resourceAdapterModuleData)
1389: throws DeploymentException {
1390: GBeanData data = (GBeanData) resourceAdapterModuleData
1391: .getAttribute("resourceAdapterGBeanData");
1392: if (data == null) {
1393: throw new DeploymentException(
1394: "No resource adapter info found for resource adapter module: "
1395: + resourceAdapterModuleData
1396: .getAbstractName());
1397: }
1398: return data;
1399: }
1400:
1401: private GBeanData locateAdminObjectInfo(
1402: GBeanData resourceAdapterModuleData,
1403: String adminObjectInterfaceName) throws DeploymentException {
1404: Map adminObjectInfos = (Map) resourceAdapterModuleData
1405: .getAttribute("adminObjectInfoMap");
1406: if (adminObjectInfos == null) {
1407: throw new DeploymentException(
1408: "No admin object infos found for resource adapter module: "
1409: + resourceAdapterModuleData
1410: .getAbstractName());
1411: }
1412: return (GBeanData) adminObjectInfos
1413: .get(adminObjectInterfaceName);
1414: }
1415:
1416: private GBeanData locateConnectionFactoryInfo(
1417: GBeanData resourceAdapterModuleData,
1418: String connectionFactoryInterfaceName)
1419: throws DeploymentException {
1420: Map managedConnectionFactoryInfos = (Map) resourceAdapterModuleData
1421: .getAttribute("managedConnectionFactoryInfoMap");
1422: if (managedConnectionFactoryInfos == null) {
1423: throw new DeploymentException(
1424: "No managed connection factory infos found for resource adapter module: "
1425: + resourceAdapterModuleData
1426: .getAbstractName());
1427: }
1428: return (GBeanData) managedConnectionFactoryInfos
1429: .get(connectionFactoryInterfaceName);
1430: }
1431:
1432: public static final GBeanInfo GBEAN_INFO;
1433:
1434: static {
1435: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
1436: ConnectorModuleBuilder.class,
1437: NameFactory.MODULE_BUILDER);
1438:
1439: infoBuilder.addAttribute("defaultEnvironment",
1440: Environment.class, true, true);
1441: infoBuilder.addAttribute("defaultMaxSize", int.class, true,
1442: true);
1443: infoBuilder.addAttribute("defaultMinSize", int.class, true,
1444: true);
1445: infoBuilder.addAttribute("defaultBlockingTimeoutMilliseconds",
1446: int.class, true, true);
1447: infoBuilder.addAttribute("defaultIdleTimeoutMinutes",
1448: int.class, true, true);
1449: infoBuilder.addAttribute("defaultXATransactionCaching",
1450: boolean.class, true, true);
1451: infoBuilder.addAttribute("defaultXAThreadCaching",
1452: boolean.class, true, true);
1453:
1454: infoBuilder.addReference("ServiceBuilders",
1455: NamespaceDrivenBuilder.class,
1456: NameFactory.MODULE_BUILDER);
1457:
1458: infoBuilder.addInterface(ModuleBuilder.class);
1459: infoBuilder.addInterface(ActivationSpecInfoLocator.class);
1460:
1461: infoBuilder.setConstructor(new String[] { "defaultEnvironment",
1462: "defaultMaxSize", "defaultMinSize",
1463: "defaultBlockingTimeoutMilliseconds",
1464: "defaultIdleTimeoutMinutes",
1465: "defaultXATransactionCaching",
1466: "defaultXAThreadCaching", "ServiceBuilders" });
1467: GBEAN_INFO = infoBuilder.getBeanInfo();
1468: }
1469:
1470: public static GBeanInfo getGBeanInfo() {
1471: return GBEAN_INFO;
1472: }
1473:
1474: }
|