View Javadoc

1   /**
2    *
3    * Copyright 2005 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;
18  
19  import java.util.Hashtable;
20  import java.util.Map;
21  import javax.management.ObjectName;
22  
23  import org.apache.geronimo.gbean.GBeanData;
24  import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
25  import org.apache.geronimo.kernel.ObjectNameUtil;
26  import org.apache.geronimo.management.J2EEApplication;
27  import org.apache.geronimo.management.J2EEServer;
28  import org.apache.geronimo.management.geronimo.ResourceAdapter;
29  import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
30  
31  /**
32   * @version $Rev: 430508 $ $Date: 2006-08-10 12:56:47 -0700 (Thu, 10 Aug 2006) $
33   */
34  public class ResourceAdapterModuleImpl implements ResourceAdapterModule {
35      private final J2EEServer server;
36      private final J2EEApplication application;
37      private final String deploymentDescriptor;
38      private final ResourceAdapter resourceAdapter;
39  
40      private final GBeanData resourceAdapterGBeanData;
41      private final Map activationSpecInfoMap;
42      private final Map adminObjectInfoMap;
43      private final Map managedConnectionFactoryInfoMap;
44      private final String objectName;
45      private final String displayName;
46      private final String description;
47      private final String vendorName;
48      private final String resourceAdapterVersion;
49      private final String eisType;
50  
51      public ResourceAdapterModuleImpl(String objectName,
52                                       ResourceAdapter resourceAdapter,
53                                       J2EEServer server,
54                                       J2EEApplication application,
55                                       String deploymentDescriptor,
56                                       GBeanData resourceAdapterGBeanData,
57                                       Map activationSpecInfoMap,
58                                       Map adminObjectInfoMap,
59                                       Map managedConnectionFactoryInfoMap,
60                                       String displayName,
61                                       String description,
62                                       String vendorName,
63                                       String resourceAdapterVersion,
64                                       String eisType) {
65          this.objectName = objectName;
66          ObjectName myObjectName = ObjectNameUtil.getObjectName(objectName);
67          verifyObjectName(myObjectName);
68  
69          this.resourceAdapter = resourceAdapter;
70  
71          this.server = server;
72          this.application = application;
73          this.deploymentDescriptor = deploymentDescriptor;
74  
75          this.resourceAdapterGBeanData = resourceAdapterGBeanData;
76          this.activationSpecInfoMap = activationSpecInfoMap;
77          this.adminObjectInfoMap = adminObjectInfoMap;
78          this.managedConnectionFactoryInfoMap = managedConnectionFactoryInfoMap;
79          this.description = description;
80          this.displayName = displayName;
81          this.vendorName = vendorName;
82          this.resourceAdapterVersion = resourceAdapterVersion;
83          this.eisType = eisType;
84      }
85  
86      public String getObjectName() {
87          return objectName;
88      }
89  
90      public boolean isStateManageable() {
91          return true;
92      }
93  
94      public boolean isStatisticsProvider() {
95          return false;
96      }
97  
98      public boolean isEventProvider() {
99          return true;
100     }
101 
102     public String getDeploymentDescriptor() {
103         return deploymentDescriptor;
104     }
105 
106     public String getServer() {
107         return server.getObjectName();
108     }
109 
110     public String getApplication() {
111         if (application == null) {
112             return null;
113         }
114         return application.getObjectName();
115     }
116 
117     public String[] getJavaVMs() {
118         return server.getJavaVMs();
119     }
120 
121     public String[] getResourceAdapters() {
122         return new String[]{resourceAdapter.getObjectName()};
123     }
124 
125     public GBeanData getResourceAdapterGBeanData() {
126         return resourceAdapterGBeanData;
127     }
128 
129     public Map getActivationSpecInfoMap() {
130         return activationSpecInfoMap;
131     }
132 
133     public Map getAdminObjectInfoMap() {
134         return adminObjectInfoMap;
135     }
136 
137     public Map getManagedConnectionFactoryInfoMap() {
138         return managedConnectionFactoryInfoMap;
139     }
140 
141     public String getDisplayName() {
142         return displayName;
143     }
144 
145     public String getDescription() {
146         return description;
147     }
148 
149     public String getVendorName() {
150         return vendorName;
151     }
152 
153     public String getResourceAdapterVersion() {
154         return resourceAdapterVersion;
155     }
156 
157     public String getEISType() {
158         return eisType;
159     }
160 
161     public ResourceAdapter[] getResourceAdapterInstances() {
162         return new ResourceAdapter[] {resourceAdapter};
163     }
164 
165     /**
166      * ObjectName must match this pattern:
167      * <p/>
168      * domain:j2eeType=ResourceAdapterModule,name=MyName,J2EEServer=MyServer,J2EEApplication=MyApplication
169      */
170     private void verifyObjectName(ObjectName objectName) {
171         if (objectName.isPattern()) {
172             throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName);
173         }
174         Hashtable keyPropertyList = objectName.getKeyPropertyList();
175         if (!"ResourceAdapterModule".equals(keyPropertyList.get("j2eeType"))) {
176             throw new InvalidObjectNameException("ResourceAdapterModule object name j2eeType property must be 'ResourceAdapterModule'", objectName);
177         }
178         if (!keyPropertyList.containsKey("name")) {
179             throw new InvalidObjectNameException("ResourceAdapterModule object must contain a name property", objectName);
180         }
181         if (!keyPropertyList.containsKey("J2EEServer")) {
182             throw new InvalidObjectNameException("ResourceAdapterModule object name must contain a J2EEServer property", objectName);
183         }
184         if (!keyPropertyList.containsKey("J2EEApplication")) {
185             throw new InvalidObjectNameException("ResourceAdapterModule object name must contain a J2EEApplication property", objectName);
186         }
187         if (keyPropertyList.size() != 4) {
188             throw new InvalidObjectNameException("ResourceAdapterModule object name can only have j2eeType, name, J2EEApplication, and J2EEServer properties", objectName);
189         }
190     }
191 }