KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > deployment > ConnectorModuleBuilder


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.connector.deployment;
18
19 import java.beans.Introspector JavaDoc;
20 import java.beans.PropertyEditor JavaDoc;
21 import java.io.File JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.lang.reflect.Method JavaDoc;
24 import java.net.URI JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Date JavaDoc;
29 import java.util.Enumeration JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.LinkedHashMap JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Set JavaDoc;
36 import java.util.jar.JarFile JavaDoc;
37 import java.util.zip.ZipEntry JavaDoc;
38
39 import javax.naming.Reference JavaDoc;
40 import javax.xml.namespace.QName JavaDoc;
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 /**
126  * @version $Rev:385659 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
127  */

128 public class ConnectorModuleBuilder implements ModuleBuilder, ActivationSpecInfoLocator {
129     private final static Log log = LogFactory.getLog(ConnectorModuleBuilder.class);
130
131     private static QName JavaDoc CONNECTOR_QNAME = GerConnectorDocument.type.getDocumentElementName();
132     static final String JavaDoc 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 JavaDoc RESOURCE_ADAPTER_VERSION = new QName JavaDoc(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 JavaDoc 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 JavaDoc plan, JarFile JavaDoc 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 JavaDoc plan, JarFile JavaDoc moduleFile, String JavaDoc targetPath, URL JavaDoc specDDUrl, Environment environment, Object JavaDoc 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 JavaDoc plan, JarFile JavaDoc moduleFile, String JavaDoc targetPath, URL JavaDoc 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 JavaDoc specDD;
177         XmlObject connector;
178         try {
179             if (specDDUrl == null) {
180                 specDDUrl = DeploymentUtil.createJarURL(moduleFile, "META-INF/ra.xml");
181             }
182
183             // read in the entire specDD as a string, we need this for getDeploymentDescriptor
184
// on the J2ee management object
185
specDD = DeploymentUtil.readAll(specDDUrl);
186         } catch (Exception JavaDoc e) {
187             //no ra.xml, not for us.
188
return null;
189         }
190         //we found ra.xml, if it won't parse it's an error.
191
try {
192             // parse it
193
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             // load the geronimo connector plan from either the supplied plan or from the earFile
202
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 JavaDoc errors = new ArrayList JavaDoc();
210                     if (plan != null) {
211                         gerConnectorDoc = GerConnectorDocument.Factory.parse((File JavaDoc) plan, XmlBeansUtil.createXmlOptions(errors));
212                     } else {
213                         URL JavaDoc 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 JavaDoc e) {
224                 //do nothing
225
}
226
227             // if we got one extract the validate it otherwise create a default one
228
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 JavaDoc("Connector module ID should be fully resolved (not " + environment.getConfigId() + ")");
252             }
253         } else {
254             idBuilder.resolve(environment, new File JavaDoc(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 JavaDoc 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 JavaDoc schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd";
282                     String JavaDoc 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                     //from moveable to cursor
300
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                     //get out of connection-definition element
314
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 JavaDoc earFile, EARContext earContext, Module module, Collection JavaDoc configurationStores, ConfigurationStore targetConfigurationStore, Collection JavaDoc repository) throws DeploymentException {
341         try {
342             JarFile JavaDoc moduleFile = module.getModuleFile();
343
344             // add the manifest classpath entries declared in the connector to the class loader
345
// we have to explicitly add these since we are unpacking the connector module
346
// and the url class loader will not pick up a manifiest from an unpacked dir
347
// N.B. If we ever introduce a separate configuration/module for a rar inside an ear
348
// this will need to be modified to use "../" instead of module.getTargetPath().
349
// See AbstractWebModuleBuilder.
350
earContext.addManifestClassPath(moduleFile, URI.create(module.getTargetPath()));
351
352             URI JavaDoc targetURI = URI.create(module.getTargetPath() + "/");
353             Enumeration JavaDoc entries = moduleFile.entries();
354             while (entries.hasMoreElements()) {
355                 ZipEntry JavaDoc entry = (ZipEntry JavaDoc) entries.nextElement();
356                 URI JavaDoc 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 JavaDoc e) {
365             throw new DeploymentException("Problem deploying connector", e);
366         }
367     }
368
369     public void initContext(EARContext earContext, Module module, ClassLoader JavaDoc cl) throws DeploymentException {
370         ConnectorModule resourceModule = (ConnectorModule) module;
371
372         final ConnectorType connector = (ConnectorType) module.getSpecDD();
373
374         /*
375         The chain of idiotic jsr-77 meaningless objects is:
376         ResourceAdapterModule (1) >
377         ResourceAdapter (n, but there can only be 1 resource adapter in a rar, so we use 1) >
378         JCAResource (1) >
379         JCAConnectionFactory (n) >
380         JCAManagedConnectionFactory (1)
381         We also include:
382         JCAResourceAdapter (n) (from JCAResource) (actual instance of ResourceAdapter)
383         TODO include admin objects (n) from JCAResource presumably
384         */

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         //set up the metadata for the ResourceAdapterModule
391
GBeanData resourceAdapterModuleData = new GBeanData(resourceAdapterModuleName, ResourceAdapterModuleImplGBean.GBEAN_INFO);
392         // initalize the GBean
393
if (earContext.getServerName() != null) {
394             //app clients don't have a Server gbean
395
resourceAdapterModuleData.setReferencePattern(NameFactory.J2EE_SERVER, earContext.getServerName());
396             //app clients don't have an application name either
397
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         // Create the resource adapter gbean
412
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 JavaDoc activationSpecInfoMap = getActivationSpecInfoMap(resourceadapter.getInboundResourceadapter().getMessageadapter().getMessagelistenerArray(), cl);
423             resourceAdapterModuleData.setAttribute("activationSpecInfoMap", activationSpecInfoMap);
424         }
425         Map JavaDoc adminObjectInfoMap = getAdminObjectInfoMap(resourceadapter.getAdminobjectArray(), cl);
426         resourceAdapterModuleData.setAttribute("adminObjectInfoMap", adminObjectInfoMap);
427         if (resourceadapter.isSetOutboundResourceadapter()) {
428             Map JavaDoc 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         //construct the bogus resource adapter and jca resource placeholders
439
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 JavaDoc thisModule = new LinkedHashMap JavaDoc(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 JavaDoc cl, Collection JavaDoc repository) throws DeploymentException {
470         //all our gbeans are added in the initContext step
471
}
472
473     public String JavaDoc getSchemaNamespace() {
474         return GERCONNECTOR_NAMESPACE;
475     }
476
477     private void addConnectorGBeans(EARContext earContext, AbstractName jcaResourceName, GBeanData resourceAdapterModuleData, ConnectorType connector, GerConnectorType geronimoConnector, ClassLoader JavaDoc 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             // Resource Adapter
485
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                 // set the work manager name
493
AbstractNameQuery workManagerName = ENCConfigBuilder.getGBeanQuery(NameFactory.JCA_WORK_MANAGER, geronimoResourceAdapter.getResourceadapterInstance().getWorkmanager());
494                 resourceAdapterInstanceGBeanData.setReferencePattern("WorkManager", workManagerName);
495
496                 // set the xa terminator name which is the same as our transaction manager
497
resourceAdapterInstanceGBeanData.setReferencePattern("XATerminator", earContext.getTransactionManagerName());
498
499                 String JavaDoc 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             // Outbound Managed Connection Factories (think JDBC data source or JMS connection factory)
510

511             // ManagedConnectionFactory setup
512
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 JavaDoc 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 JavaDoc 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         // admin objects (think message queues and topics)
539

540         // add configured admin objects
541
for (int i = 0; i < geronimoConnector.getAdminobjectArray().length; i++) {
542             GerAdminobjectType gerAdminObject = geronimoConnector.getAdminobjectArray()[i];
543
544             String JavaDoc 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                 // add it
556
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 JavaDoc getActivationSpecInfoMap(MessagelistenerType[] messagelistenerArray, ClassLoader JavaDoc cl) throws DeploymentException {
568         Map JavaDoc activationSpecInfos = new HashMap JavaDoc();
569         for (int i = 0; i < messagelistenerArray.length; i++) {
570             MessagelistenerType messagelistenerType = messagelistenerArray[i];
571             String JavaDoc messageListenerInterface = messagelistenerType.getMessagelistenerType().getStringValue().trim();
572             ActivationspecType activationspec = messagelistenerType.getActivationspec();
573             String JavaDoc activationSpecClassName = activationspec.getActivationspecClass().getStringValue().trim();
574             GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(ActivationSpecWrapperGBean.class, ActivationSpecWrapperGBean.GBEAN_INFO);
575
576             //add all javabean properties that have both getter and setter. Ignore the "required" flag from the dd.
577
Map JavaDoc getters = new HashMap JavaDoc();
578             Set JavaDoc setters = new HashSet JavaDoc();
579             Method JavaDoc[] methods;
580             try {
581                 Class JavaDoc activationSpecClass = cl.loadClass(activationSpecClassName);
582                 methods = activationSpecClass.getMethods();
583             } catch (ClassNotFoundException JavaDoc e) {
584                 throw new DeploymentException("Can not load activation spec class", e);
585             }
586             for (int j = 0; j < methods.length; j++) {
587                 Method JavaDoc method = methods[j];
588                 String JavaDoc methodName = method.getName();
589                 if ((methodName.startsWith("get") || methodName.startsWith("is")) && method.getParameterTypes().length == 0)
590                 {
591                     String JavaDoc 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 JavaDoc iterator = getters.entrySet().iterator(); iterator.hasNext();) {
601                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iterator.next();
602                 infoBuilder.addAttribute(new DynamicGAttributeInfo((String JavaDoc) entry.getKey(), (String JavaDoc) entry.getValue(), true, true, true, true));
603             }
604
605             GBeanInfo gbeanInfo = infoBuilder.getBeanInfo();
606             try {
607                 //make sure the class is available, but we don't use it.
608
cl.loadClass(activationSpecClassName);
609             } catch (ClassNotFoundException JavaDoc 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 JavaDoc getManagedConnectionFactoryInfoMap(ConnectionDefinitionType[] connectionDefinitionArray, ClassLoader JavaDoc cl) throws DeploymentException {
620         Map JavaDoc managedConnectionFactoryInfos = new HashMap JavaDoc();
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             // set the standard properties
628
String JavaDoc 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 JavaDoc getAdminObjectInfoMap(AdminobjectType[] adminobjectArray, ClassLoader JavaDoc cl) throws DeploymentException {
640         Map JavaDoc adminObjectInfos = new HashMap JavaDoc();
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             // set the standard properties
648
String JavaDoc 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 JavaDoc 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 JavaDoc cl) throws DeploymentException {
676
677         try {
678             for (int i = 0; i < configProperties.length; i++) {
679                 String JavaDoc 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 JavaDoc 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 JavaDoc e) {
691             throw new DeploymentException(e);
692         }
693     }
694
695     private Object JavaDoc getValue(String JavaDoc type, String JavaDoc value, ClassLoader JavaDoc cl) throws DeploymentException {
696         if (value == null) {
697             return null;
698         }
699
700         Class JavaDoc clazz;
701         try {
702             clazz = cl.loadClass(type);
703         } catch (ClassNotFoundException JavaDoc e) {
704             throw new DeploymentException("Could not load attribute class: type: " + type, e);
705         }
706
707         // Handle numeric fields with no value set
708
if (value.equals("")) {
709             if (Number JavaDoc.class.isAssignableFrom(clazz) || Date JavaDoc.class.isAssignableFrom(clazz)) {
710                 return null;
711             }
712         }
713
714         PropertyEditor JavaDoc editor = PropertyEditors.getEditor(clazz);
715         editor.setAsText(value);
716         return editor.getValue();
717     }
718
719     private AbstractName configureConnectionManager(EARContext earContext, AbstractName jcaResourceName, String JavaDoc ddTransactionSupport, GerConnectiondefinitionInstanceType connectionfactoryInstance, ClassLoader JavaDoc cl) throws DeploymentException {
720 // if (connectionfactoryInstance.getConnectionmanagerRef() != null) {
721
//we don't configure anything, just use the supplied gbean
722
// try {
723
// return AbstractName.getInstance(connectionfactoryInstance.getConnectionmanagerRef());
724
// } catch (MalformedAbstractNameException e) {
725
// throw new DeploymentException("Invalid AbstractName string supplied for ConnectionManager reference", e);
726
// }
727
// }
728

729         // create the object name for our connection manager
730
AbstractName connectionManagerAbstractName = earContext.getNaming().createChildName(jcaResourceName, connectionfactoryInstance.getName().trim(), NameFactory.JCA_CONNECTION_MANAGER);
731
732         // create the data holder for our connection manager
733
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         //we configure our connection manager
742
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             //this should not happen
773
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 JavaDoc 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 JavaDoc transactionSupport, ClassLoader JavaDoc 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         // ConnectionManager
825
AbstractName connectionManagerAbstractName = configureConnectionManager(earContext, managedConnectionFactoryAbstractName, transactionSupport, connectiondefinitionInstance, cl);
826
827         // ManagedConnectionFactory
828
setDynamicGBeanDataAttributes(managedConnectionFactoryInstanceGBeanData, connectiondefinitionInstance.getConfigPropertySettingArray(), cl);
829
830         //Check if Driver class is available here. This should be available in cl. If not log a warning as
831
//the plan gets deployed and while starting GBean an error is thrown
832

833         Object JavaDoc driver = managedConnectionFactoryInstanceGBeanData.getAttribute("Driver");
834         if (driver != null && driver instanceof String JavaDoc) {
835             try {
836                 cl.loadClass((String JavaDoc)driver);
837             } catch (ClassNotFoundException JavaDoc 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             //additional interfaces implemented by connection factory
848
String JavaDoc[] 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 JavaDoc[0];
855             }
856             managedConnectionFactoryInstanceGBeanData.setAttribute("implementedInterfaces", implementedInterfaces);
857
858         } catch (Exception JavaDoc 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         // ConnectionFactory
870
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     //ResourceRefBuilder implementation
881
public Reference JavaDoc createResourceRef(AbstractNameQuery containerId, Class JavaDoc 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 JavaDoc createAdminObjectRef(AbstractNameQuery containerId, Class JavaDoc 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 JavaDoc messageListenerInterface, Configuration configuration) throws DeploymentException {
900         //First, locate the module gbean from the JCAResourceAdapter instance
901
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 JavaDoc moduleName = (String JavaDoc) instanceName.getName().get(NameFactory.RESOURCE_ADAPTER_MODULE);
908         Map JavaDoc moduleNameMap = new HashMap JavaDoc(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         //now find the gbeandata and extract the activation spec info.
916
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 JavaDoc activationSpecInfos = (Map JavaDoc) 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 JavaDoc adminObjectInterfaceName) throws DeploymentException {
938         Map JavaDoc adminObjectInfos = (Map JavaDoc) 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 JavaDoc connectionFactoryInterfaceName) throws DeploymentException {
946         Map JavaDoc managedConnectionFactoryInfos = (Map JavaDoc) 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 JavaDoc[]{"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