KickJava   Java API By Example, From Geeks To Geeks.

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


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.JCAResource;
27
28 import javax.management.MBeanServer JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import java.util.Iterator JavaDoc;
31
32 /**
33  * A factory for mapping DataSourceDeployer deployments to JCAResource
34  *
35  * @author Scott.Stark@jboss.org
36  * @version $Revision: 37459 $
37  */

38 public class JCAResourceFactory
39         implements ManagedObjectFactory
40 {
41    private static Logger log = Logger.getLogger(JCAResourceFactory.class);
42
43    /**
44     * Creates a JCAResource
45     *
46     * @param mbeanServer
47     * @param data A MBeanServerNotification
48     * @return the JCAResource ObjectName
49     */

50    public ObjectName JavaDoc create(MBeanServer JavaDoc mbeanServer, Object JavaDoc data)
51    {
52       if ((data instanceof DeploymentInfo) == false)
53          return null;
54
55       DeploymentInfo di = (DeploymentInfo) data;
56       ObjectName JavaDoc jsr77Name = null;
57
58       /* Get the RARDeployment service name by looking for the mbean in the
59       deployment with a name matching service=xxxDS. This relies on the naming
60       pattern created by the JCA CM deployer.
61       */

62       ObjectName JavaDoc rarDeployService = null;
63       ObjectName JavaDoc cmService = null;
64       ObjectName JavaDoc poolService = null;
65       Iterator JavaDoc iter = di.mbeans.iterator();
66       while (iter.hasNext())
67       {
68          ObjectName JavaDoc oname = (ObjectName JavaDoc) iter.next();
69          String JavaDoc name = oname.getKeyProperty("service");
70          if (name.equals("ManagedConnectionFactory") || name.endsWith("DS"))
71             rarDeployService = oname;
72          else if (name.endsWith("CM"))
73             cmService = oname;
74          else if (name.endsWith("Pool"))
75             poolService = oname;
76       }
77       if (rarDeployService == null || cmService == null)
78       {
79          log.debug("Failed to find a service=xxxDS match");
80          return null;
81       }
82
83       try
84       {
85          /* Now to tie this CM back to its rar query the rarDeployService for
86          the org.jboss.resource.RARDeployment service created by the RARDeployer.
87           */

88          ObjectName JavaDoc rarService = (ObjectName JavaDoc) mbeanServer.getAttribute(rarDeployService,
89                  "OldRarDeployment");
90          // Get the ResourceAdapter JSR77 name
91
ObjectName JavaDoc jsr77RAName = RARModuleFactory.getResourceAdapterName(rarService);
92          // Now build the JCAResource
93
String JavaDoc resName = rarDeployService.getKeyProperty("name");
94          jsr77Name = JCAResource.create(mbeanServer, resName, jsr77RAName,
95                  cmService, rarDeployService, poolService);
96       }
97       catch (Exception JavaDoc e)
98       {
99          log.debug("Failed to create JCAResource", e);
100       }
101
102       return jsr77Name;
103    }
104
105    /**
106     * Destroys the JCAResource
107     *
108     * @param mbeanServer
109     * @param data A MBeanServerNotification
110     */

111    public void destroy(MBeanServer JavaDoc mbeanServer, Object JavaDoc data)
112    {
113       if ((data instanceof DeploymentInfo) == false)
114          return;
115
116       DeploymentInfo di = (DeploymentInfo) data;
117       String JavaDoc resName = getDeploymentResName(mbeanServer, di);
118       JCAResource.destroy(mbeanServer, resName);
119    }
120
121    private String JavaDoc getDeploymentResName(MBeanServer JavaDoc mbeanServer, DeploymentInfo di)
122    {
123       String JavaDoc resName = null;
124       /* Get the RARDeployment service name by looking for the mbean in the
125       deployment with a name matching service=xxxDS. This relies on the naming
126       pattern created by the JCA CM deployer.
127       */

128       ObjectName JavaDoc rarDeployService = null;
129       Iterator JavaDoc iter = di.mbeans.iterator();
130       while (iter.hasNext())
131       {
132          ObjectName JavaDoc oname = (ObjectName JavaDoc) iter.next();
133          String JavaDoc name = oname.getKeyProperty("service");
134          if (name.equals("ManagedConnectionFactory") || name.endsWith("DS"))
135          {
136             rarDeployService = oname;
137             resName = rarDeployService.getKeyProperty("name");
138             break;
139          }
140       }
141       return resName;
142    }
143 }
144
Popular Tags