KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  *
3  * Copyright 2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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.util.Hashtable JavaDoc;
20 import javax.management.MalformedObjectNameException JavaDoc;
21 import javax.management.ObjectName JavaDoc;
22
23 import org.apache.geronimo.gbean.GBeanInfo;
24 import org.apache.geronimo.gbean.GBeanInfoBuilder;
25 import org.apache.geronimo.j2ee.management.J2EEApplication;
26 import org.apache.geronimo.j2ee.management.J2EEServer;
27 import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
28 import org.apache.geronimo.j2ee.management.impl.Util;
29 import org.apache.geronimo.kernel.Kernel;
30 import org.apache.geronimo.kernel.jmx.JMXUtil;
31
32 /**
33  * @version $Rev: 56022 $ $Date: 2004-10-29 22:16:18 -0700 (Fri, 29 Oct 2004) $
34  */

35 public class ResourceAdapterModuleImpl {
36     private final Kernel kernel;
37     private final String JavaDoc baseName;
38     private final J2EEServer server;
39     private final J2EEApplication application;
40     private final String JavaDoc deploymentDescriptor;
41
42     public ResourceAdapterModuleImpl(Kernel kernel, String JavaDoc objectName, J2EEServer server, J2EEApplication application, String JavaDoc deploymentDescriptor) {
43         ObjectName JavaDoc myObjectName = JMXUtil.getObjectName(objectName);
44         verifyObjectName(myObjectName);
45
46         // build the base name used to query the server for child modules
47
Hashtable JavaDoc keyPropertyList = myObjectName.getKeyPropertyList();
48         String JavaDoc name = (String JavaDoc) keyPropertyList.get("name");
49         String JavaDoc j2eeServerName = (String JavaDoc) keyPropertyList.get("J2EEServer");
50         String JavaDoc j2eeApplicationName = (String JavaDoc) keyPropertyList.get("J2EEApplication");
51         baseName = myObjectName.getDomain() + ":J2EEServer=" + j2eeServerName + ",J2EEApplication=" + j2eeApplicationName + ",ResouceAdapterModule=" + name + ",";
52
53         this.kernel = kernel;
54         this.server = server;
55         this.application = application;
56         this.deploymentDescriptor = deploymentDescriptor;
57     }
58
59     public String JavaDoc getDeploymentDescriptor() {
60         return deploymentDescriptor;
61     }
62
63     public String JavaDoc getServer() {
64         return server.getObjectName();
65     }
66
67     public String JavaDoc getApplication() {
68         if (application == null) {
69             return null;
70         }
71         return application.getObjectName();
72     }
73
74     public String JavaDoc[] getJavaVMs() {
75         return server.getJavaVMs();
76     }
77
78     public String JavaDoc[] getResourceAdapters() throws MalformedObjectNameException JavaDoc {
79         return Util.getObjectNames(kernel, baseName, new String JavaDoc[]{"ResourceAdapter"});
80     }
81
82     /**
83      * ObjectName must match this pattern:
84      * <p/>
85      * domain:j2eeType=ResourceAdapterModule,name=MyName,J2EEServer=MyServer,J2EEApplication=MyApplication
86      */

87     private void verifyObjectName(ObjectName JavaDoc objectName) {
88         if (objectName.isPattern()) {
89             throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName);
90         }
91         Hashtable JavaDoc keyPropertyList = objectName.getKeyPropertyList();
92         if (!"ResourceAdapterModule".equals(keyPropertyList.get("j2eeType"))) {
93             throw new InvalidObjectNameException("ResourceAdapterModule object name j2eeType property must be 'ResourceAdapterModule'", objectName);
94         }
95         if (!keyPropertyList.containsKey("name")) {
96             throw new InvalidObjectNameException("ResourceAdapterModule object must contain a name property", objectName);
97         }
98         if (!keyPropertyList.containsKey("J2EEServer")) {
99             throw new InvalidObjectNameException("ResourceAdapterModule object name must contain a J2EEServer property", objectName);
100         }
101         if (!keyPropertyList.containsKey("J2EEApplication")) {
102             throw new InvalidObjectNameException("ResourceAdapterModule object name must contain a J2EEApplication property", objectName);
103         }
104         if (keyPropertyList.size() != 4) {
105             throw new InvalidObjectNameException("ResourceAdapterModule object name can only have j2eeType, name, J2EEApplication, and J2EEServer properties", objectName);
106         }
107     }
108
109     public static final GBeanInfo GBEAN_INFO;
110
111     static {
112         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(ResourceAdapterModuleImpl.class);
113         infoFactory.addReference("J2EEServer", J2EEServer.class);
114         infoFactory.addReference("J2EEApplication", J2EEApplication.class);
115
116         infoFactory.addAttribute("deploymentDescriptor", String JavaDoc.class, true);
117
118         infoFactory.addAttribute("kernel", Kernel.class, false);
119         infoFactory.addAttribute("objectName", String JavaDoc.class, false);
120         infoFactory.addAttribute("server", String JavaDoc.class, false);
121         infoFactory.addAttribute("application", String JavaDoc.class, false);
122         infoFactory.addAttribute("javaVMs", String JavaDoc[].class, false);
123         infoFactory.addAttribute("resourceAdapters", String JavaDoc[].class, false);
124
125         infoFactory.setConstructor(new String JavaDoc[]{
126             "kernel",
127             "objectName",
128             "J2EEServer",
129             "J2EEApplication",
130             "deploymentDescriptor"});
131
132         GBEAN_INFO = infoFactory.getBeanInfo();
133     }
134
135     public static GBeanInfo getGBeanInfo() {
136         return GBEAN_INFO;
137     }
138 }
139
Popular Tags