KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > j2ee > ResourceAdapter


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;
23
24 import org.jboss.logging.Logger;
25
26 import javax.management.MBeanServer JavaDoc;
27 import javax.management.MalformedObjectNameException JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29 import java.util.Hashtable JavaDoc;
30
31 /**
32  * Root class of the JBoss JSR-77 implementation of ResourceAdapter.
33  *
34  * @author <a HREF="mailto:mclaugs@comcast.net">Scott McLaughlin</a>.
35  * @version $Revision: 40550 $
36  */

37 public class ResourceAdapter extends J2EEManagedObject
38    implements ResourceAdapterMBean
39 {
40    // Constants -----------------------------------------------------
41

42    // Attributes ----------------------------------------------------
43
private static Logger log = Logger.getLogger(ResourceAdapter.class);
44
45    /**
46     * The JBoss RAR service MBean name
47     */

48    private ObjectName JavaDoc rarServiceName;
49    
50    /**
51     * The JSR77 JCAResource associated with this adapter
52     */

53    private ObjectName JavaDoc jcaResourceName;
54
55    // Static --------------------------------------------------------
56

57    public static ObjectName JavaDoc create(MBeanServer JavaDoc mbeanServer, String JavaDoc displayName,
58                                    ObjectName JavaDoc jsr77ParentName, ObjectName JavaDoc rarServiceName)
59    {
60       ObjectName JavaDoc jsr77Name = null;
61       try
62       {
63          ResourceAdapter adapter = new ResourceAdapter(displayName, jsr77ParentName,
64                  rarServiceName);
65          jsr77Name = adapter.getObjectName();
66          mbeanServer.registerMBean(adapter, jsr77Name);
67          log.debug("Created JSR-77 ResourceAdapter: " + displayName);
68       }
69       catch (Exception JavaDoc e)
70       {
71          log.debug("Could not create JSR-77 ResourceAdapter: " + displayName, e);
72       }
73       return jsr77Name;
74    }
75
76    public static void destroy(MBeanServer JavaDoc mbeanServer, String JavaDoc displayName)
77    {
78       try
79       {
80          J2EEManagedObject.removeObject(mbeanServer,
81                  J2EEDomain.getDomainName() + ":" +
82                  J2EEManagedObject.TYPE + "=" + J2EETypeConstants.ResourceAdapter + "," +
83                  "name=" + displayName + "," +
84                  "*");
85       }
86       catch (Exception JavaDoc e)
87       {
88          log.error("Could not destroy JSR-77 ResourceAdapter: " + displayName, e);
89       }
90    }
91
92    // Constructors --------------------------------------------------
93

94    /**
95     * @param displayName The ra.xml/connector/display-name value
96     * @param jsr77ParentName ObjectName of the ResourceAdaptorModule
97     */

98    public ResourceAdapter(String JavaDoc displayName, ObjectName JavaDoc jsr77ParentName,
99                           ObjectName JavaDoc rarServiceName)
100            throws MalformedObjectNameException JavaDoc,
101            InvalidParentException
102    {
103       super(J2EETypeConstants.ResourceAdapter, displayName, jsr77ParentName);
104       this.rarServiceName = rarServiceName;
105    }
106
107    /**
108     * @jmx:managed-attribute
109     */

110    public ObjectName JavaDoc getJBossServiceName()
111    {
112       return rarServiceName;
113    }
114
115    /**
116     * @jmx:managed-attribute
117     */

118    public ObjectName JavaDoc getJcaResource()
119    {
120       return jcaResourceName;
121    }
122    /**
123     * @jmx:managed-attribute
124     */

125    public ObjectName JavaDoc getjcaResource()
126    {
127       return jcaResourceName;
128    }
129
130    // java.lang.Object overrides --------------------------------------
131

132    public String JavaDoc toString()
133    {
134       return "ResourceAdapter { " + super.toString() + " } []";
135    }
136
137    public void addChild(ObjectName JavaDoc j2eeName)
138    {
139       String JavaDoc j2eeType = J2EEManagedObject.getType(j2eeName);
140       if (J2EETypeConstants.JCAResource.equals(j2eeType))
141       {
142          jcaResourceName = j2eeName;
143       }
144    }
145
146    public void removeChild(ObjectName JavaDoc j2eeName)
147    {
148       String JavaDoc j2eeType = J2EEManagedObject.getType(j2eeName);
149       if (J2EETypeConstants.JCAResource.equals(j2eeType))
150       {
151          jcaResourceName = null;
152       }
153    }
154
155    // Package protected ---------------------------------------------
156

157    // Protected -----------------------------------------------------
158

159    /**
160     * @return A hashtable with the Resource-Adapter-Module, J2EE-Application and J2EE-Server as parent
161     */

162    protected Hashtable JavaDoc getParentKeys(ObjectName JavaDoc pParent)
163    {
164       Hashtable JavaDoc lReturn = new Hashtable JavaDoc();
165       Hashtable JavaDoc lProperties = pParent.getKeyPropertyList();
166       lReturn.put(J2EETypeConstants.ResourceAdapterModule, lProperties.get("name"));
167       // J2EE-Application and J2EE-Server is already parent of J2EE-Application therefore lookup
168
// the name by the J2EE-Server type
169
lReturn.put(J2EETypeConstants.J2EEApplication, lProperties.get(J2EETypeConstants.J2EEApplication));
170       lReturn.put(J2EETypeConstants.J2EEServer, lProperties.get(J2EETypeConstants.J2EEServer));
171
172       return lReturn;
173    }
174
175    // Private -------------------------------------------------------
176

177    // Inner classes -------------------------------------------------
178

179 }
180
Popular Tags