001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.connector;
017:
018: import java.util.Hashtable;
019: import java.util.Map;
020:
021: import javax.management.ObjectName;
022:
023: import org.apache.geronimo.gbean.GBeanData;
024: import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
025: import org.apache.geronimo.kernel.ObjectNameUtil;
026: import org.apache.geronimo.management.J2EEApplication;
027: import org.apache.geronimo.management.J2EEServer;
028: import org.apache.geronimo.management.geronimo.ResourceAdapter;
029: import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
030:
031: /**
032: * @version $Rev: 550546 $ $Date: 2007-06-25 09:52:11 -0700 (Mon, 25 Jun 2007) $
033: */
034: public class ResourceAdapterModuleImpl implements ResourceAdapterModule {
035: private final J2EEServer server;
036: private final J2EEApplication application;
037: private final String deploymentDescriptor;
038: private final ResourceAdapter resourceAdapter;
039:
040: private final GBeanData resourceAdapterGBeanData;
041: private final Map activationSpecInfoMap;
042: private final Map adminObjectInfoMap;
043: private final Map managedConnectionFactoryInfoMap;
044: private final String objectName;
045: private final String displayName;
046: private final String description;
047: private final String vendorName;
048: private final String resourceAdapterVersion;
049: private final String eisType;
050:
051: public ResourceAdapterModuleImpl(String objectName,
052: ResourceAdapter resourceAdapter, J2EEServer server,
053: J2EEApplication application, String deploymentDescriptor,
054: GBeanData resourceAdapterGBeanData,
055: Map activationSpecInfoMap, Map adminObjectInfoMap,
056: Map managedConnectionFactoryInfoMap, String displayName,
057: String description, String vendorName,
058: String resourceAdapterVersion, String eisType) {
059: this .objectName = objectName;
060: ObjectName myObjectName = ObjectNameUtil
061: .getObjectName(objectName);
062: verifyObjectName(myObjectName);
063:
064: this .resourceAdapter = resourceAdapter;
065:
066: this .server = server;
067: this .application = application;
068: this .deploymentDescriptor = deploymentDescriptor;
069:
070: this .resourceAdapterGBeanData = resourceAdapterGBeanData;
071: this .activationSpecInfoMap = activationSpecInfoMap;
072: this .adminObjectInfoMap = adminObjectInfoMap;
073: this .managedConnectionFactoryInfoMap = managedConnectionFactoryInfoMap;
074: this .description = description;
075: this .displayName = displayName;
076: this .vendorName = vendorName;
077: this .resourceAdapterVersion = resourceAdapterVersion;
078: this .eisType = eisType;
079: }
080:
081: public String getObjectName() {
082: return objectName;
083: }
084:
085: public boolean isStateManageable() {
086: return true;
087: }
088:
089: public boolean isStatisticsProvider() {
090: return false;
091: }
092:
093: public boolean isEventProvider() {
094: return true;
095: }
096:
097: public String getDeploymentDescriptor() {
098: return deploymentDescriptor;
099: }
100:
101: public String getServer() {
102: return server.getObjectName();
103: }
104:
105: public String getApplication() {
106: if (application == null) {
107: return null;
108: }
109: return application.getObjectName();
110: }
111:
112: public String[] getJavaVMs() {
113: return server.getJavaVMs();
114: }
115:
116: public String[] getResourceAdapters() {
117: return new String[] { resourceAdapter.getObjectName() };
118: }
119:
120: public GBeanData getResourceAdapterGBeanData() {
121: return resourceAdapterGBeanData;
122: }
123:
124: public Map getActivationSpecInfoMap() {
125: return activationSpecInfoMap;
126: }
127:
128: public Map getAdminObjectInfoMap() {
129: return adminObjectInfoMap;
130: }
131:
132: public Map getManagedConnectionFactoryInfoMap() {
133: return managedConnectionFactoryInfoMap;
134: }
135:
136: public String getDisplayName() {
137: return displayName;
138: }
139:
140: public String getDescription() {
141: return description;
142: }
143:
144: public String getVendorName() {
145: return vendorName;
146: }
147:
148: public String getResourceAdapterVersion() {
149: return resourceAdapterVersion;
150: }
151:
152: public String getEISType() {
153: return eisType;
154: }
155:
156: public ResourceAdapter[] getResourceAdapterInstances() {
157: return new ResourceAdapter[] { resourceAdapter };
158: }
159:
160: /**
161: * ObjectName must match this pattern:
162: * <p/>
163: * domain:j2eeType=ResourceAdapterModule,name=MyName,J2EEServer=MyServer,J2EEApplication=MyApplication
164: */
165: private void verifyObjectName(ObjectName objectName) {
166: if (objectName.isPattern()) {
167: throw new InvalidObjectNameException(
168: "ObjectName can not be a pattern", objectName);
169: }
170: Hashtable keyPropertyList = objectName.getKeyPropertyList();
171: if (!"ResourceAdapterModule".equals(keyPropertyList
172: .get("j2eeType"))) {
173: throw new InvalidObjectNameException(
174: "ResourceAdapterModule object name j2eeType property must be 'ResourceAdapterModule'",
175: objectName);
176: }
177: if (!keyPropertyList.containsKey("name")) {
178: throw new InvalidObjectNameException(
179: "ResourceAdapterModule object must contain a name property",
180: objectName);
181: }
182: if (!keyPropertyList.containsKey("J2EEServer")) {
183: throw new InvalidObjectNameException(
184: "ResourceAdapterModule object name must contain a J2EEServer property",
185: objectName);
186: }
187: if (!keyPropertyList.containsKey("J2EEApplication")) {
188: throw new InvalidObjectNameException(
189: "ResourceAdapterModule object name must contain a J2EEApplication property",
190: objectName);
191: }
192: if (keyPropertyList.size() != 4) {
193: throw new InvalidObjectNameException(
194: "ResourceAdapterModule object name can only have j2eeType, name, J2EEApplication, and J2EEServer properties",
195: objectName);
196: }
197: }
198: }
|