KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > j2ee > factory > RARModuleFactory


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.management.j2ee.factory;
23
24 import org.jboss.deployment.DeploymentInfo;
25 import org.jboss.logging.Logger;
26 import org.jboss.management.j2ee.ResourceAdapter;
27 import org.jboss.management.j2ee.ResourceAdapterModule;
28 import org.jboss.resource.metadata.ConnectorMetaData;
29
30 import javax.management.MBeanServer JavaDoc;
31 import javax.management.ObjectName JavaDoc;
32 import java.util.HashMap JavaDoc;
33
34 /**
35  * A factory for mapping RARDeployer deployments to ResourceAdaptorModules
36  *
37  * @author Scott.Stark@jboss.org
38  * @version $Revision: 37459 $
39  */

40 public class RARModuleFactory
41         implements ManagedObjectFactory
42 {
43    private static Logger log = Logger.getLogger(RARModuleFactory.class);
44    private static HashMap JavaDoc moduleServiceToMgmtMap = new HashMap JavaDoc();
45    private HashMap JavaDoc deploymentToModuleNameMap = new HashMap JavaDoc();
46
47    static ObjectName JavaDoc getResourceAdapterName(ObjectName JavaDoc rarService)
48    {
49       ObjectName JavaDoc jsr77Name = (ObjectName JavaDoc) moduleServiceToMgmtMap.get(rarService);
50       return jsr77Name;
51    }
52
53    /**
54     * Create JSR-77 EJBModule
55     *
56     * @param server the MBeanServer context
57     * @param data arbitrary data associated with the creation context
58     */

59    public ObjectName JavaDoc create(MBeanServer JavaDoc mbeanServer, Object JavaDoc data)
60    {
61       if ((data instanceof DeploymentInfo) == false)
62          return null;
63
64       DeploymentInfo di = (DeploymentInfo) data;
65       ConnectorMetaData metaData = (ConnectorMetaData) di.metaData;
66
67       // Create the ResourceAdapterModule
68
String JavaDoc rarName = di.shortName;
69       ObjectName JavaDoc rarService = di.deployedObject;
70       ObjectName JavaDoc jsr77ModuleName = ResourceAdapterModule.create(mbeanServer,
71               (di.parent == null ? null : di.parent.shortName),
72               rarName,
73               di.localUrl);
74       deploymentToModuleNameMap.put(di, jsr77ModuleName);
75       log.debug("Created module: " + jsr77ModuleName);
76
77       // Create the ResourceAdapter
78
ObjectName JavaDoc jsr77RAName = ResourceAdapter.create(mbeanServer,
79               metaData.getDescription().getDisplayName(), jsr77ModuleName, rarService);
80       // Register a mapping from the RARDeployment service to the ResourceAdapter
81
moduleServiceToMgmtMap.put(rarService, jsr77RAName);
82
83       return jsr77ModuleName;
84    }
85
86    /**
87     * Destroy JSR-77 EJBModule
88     *
89     * @param server the MBeanServer context
90     * @param data arbitrary data associated with the creation context
91     */

92    public void destroy(MBeanServer JavaDoc mbeanServer, Object JavaDoc data)
93    {
94       if ((data instanceof DeploymentInfo) == false)
95          return;
96
97       DeploymentInfo di = (DeploymentInfo) data;
98       ConnectorMetaData metaData = (ConnectorMetaData) di.metaData;
99       ObjectName JavaDoc jsr77Name = (ObjectName JavaDoc) deploymentToModuleNameMap.get(di);
100
101       ResourceAdapter.destroy(mbeanServer, metaData.getDescription().getDisplayName());
102       log.debug("Destroy module: " + jsr77Name);
103       if (jsr77Name != null)
104       {
105          ResourceAdapterModule.destroy(mbeanServer, jsr77Name);
106       }
107    }
108
109 }
110
Popular Tags