KickJava   Java API By Example, From Geeks To Geeks.

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


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
30 /**
31  * Root class of the JBoss JSR-77 implementation of
32  * {@link javax.management.j2ee.JDBCDataSource JDBCDataSource}.
33  *
34  * @author <a HREF="mailto:andreas@jboss.org">Andreas Schaefer</a>
35  * @version $Revision: 40550 $
36  */

37 public class JDBCDriver extends J2EEManagedObject
38    implements JDBCDriverMBean
39 {
40    // Constants -----------------------------------------------------
41
private static Logger log = Logger.getLogger(JDBCDriver.class);
42
43    // Attributes ----------------------------------------------------
44

45    // Static --------------------------------------------------------
46

47    public static ObjectName JavaDoc create(MBeanServer JavaDoc pServer, String JavaDoc pName, ObjectName JavaDoc pService)
48    {
49       ObjectName JavaDoc lServer = null;
50       try
51       {
52          lServer = (ObjectName JavaDoc) pServer.queryNames(new ObjectName JavaDoc(J2EEDomain.getDomainName() + ":" +
53                  J2EEManagedObject.TYPE + "=" + J2EETypeConstants.J2EEServer + "," +
54                  "*"),
55                  null).iterator().next();
56       }
57       catch (Exception JavaDoc e)
58       {
59          log.error("Could not create JSR-77 JNDI: " + pName, e);
60          return null;
61       }
62       try
63       {
64          // Now create the JNDI Representant
65
return pServer.createMBean("org.jboss.management.j2ee.JDBCDriver",
66                  null,
67                  new Object JavaDoc[]{
68                     pName,
69                     lServer
70                  },
71                  new String JavaDoc[]{
72                     String JavaDoc.class.getName(),
73                     ObjectName JavaDoc.class.getName()
74                  }).getObjectName();
75       }
76       catch (Exception JavaDoc e)
77       {
78          log.error("Could not create JSR-77 JNDI: " + pName, e);
79          return null;
80       }
81    }
82
83    public static void destroy(MBeanServer JavaDoc pServer, String JavaDoc pName)
84    {
85       try
86       {
87          // Find the Object to be destroyed
88
ObjectName JavaDoc lSearch = new ObjectName JavaDoc(J2EEDomain.getDomainName() + ":" +
89                  J2EEManagedObject.TYPE + "=" + J2EETypeConstants.JDBCDriver + "," +
90                  "name=" + pName + "," +
91                  "*");
92          ObjectName JavaDoc lJNDI = (ObjectName JavaDoc) pServer.queryNames(lSearch,
93                  null).iterator().next();
94          // Now remove the J2EEApplication
95
pServer.unregisterMBean(lJNDI);
96       }
97       catch (Exception JavaDoc e)
98       {
99          log.error("Could not destroy JSR-77 JNDI: " + pName, e);
100       }
101    }
102
103    // Constructors --------------------------------------------------
104

105    /**
106     * @param pName Name of the JDBCDataSource
107     * @throws InvalidParameterException If list of nodes or ports was null or empty
108     */

109    public JDBCDriver(String JavaDoc pName, ObjectName JavaDoc pServer)
110            throws
111            MalformedObjectNameException JavaDoc,
112            InvalidParentException
113    {
114       super(J2EETypeConstants.JDBCDriver, pName, pServer);
115    }
116
117    // Public --------------------------------------------------------
118

119    // org.jboss.ServiceMBean overrides ------------------------------------
120

121    // java.lang.Object overrides ------------------------------------
122

123    public String JavaDoc toString()
124    {
125       return "JDBCDriver { " + super.toString() + " } [ " +
126               " ]";
127    }
128
129    // Package protected ---------------------------------------------
130

131    // Protected -----------------------------------------------------
132

133    // Private -------------------------------------------------------
134

135    // Inner classes -------------------------------------------------
136

137 }
138
Popular Tags