001    /**
002     *
003     * Copyright 2005 The Apache Software Foundation
004     *
005     *  Licensed under the Apache License, Version 2.0 (the "License");
006     *  you may not use this file except in compliance with the License.
007     *  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     */
017    package org.apache.geronimo.connector;
018    
019    import java.util.Hashtable;
020    import java.util.Map;
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: 430508 $ $Date: 2006-08-10 12:56:47 -0700 (Thu, 10 Aug 2006) $
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,
053                                         J2EEServer server,
054                                         J2EEApplication application,
055                                         String deploymentDescriptor,
056                                         GBeanData resourceAdapterGBeanData,
057                                         Map activationSpecInfoMap,
058                                         Map adminObjectInfoMap,
059                                         Map managedConnectionFactoryInfoMap,
060                                         String displayName,
061                                         String description,
062                                         String vendorName,
063                                         String resourceAdapterVersion,
064                                         String eisType) {
065            this.objectName = objectName;
066            ObjectName myObjectName = ObjectNameUtil.getObjectName(objectName);
067            verifyObjectName(myObjectName);
068    
069            this.resourceAdapter = resourceAdapter;
070    
071            this.server = server;
072            this.application = application;
073            this.deploymentDescriptor = deploymentDescriptor;
074    
075            this.resourceAdapterGBeanData = resourceAdapterGBeanData;
076            this.activationSpecInfoMap = activationSpecInfoMap;
077            this.adminObjectInfoMap = adminObjectInfoMap;
078            this.managedConnectionFactoryInfoMap = managedConnectionFactoryInfoMap;
079            this.description = description;
080            this.displayName = displayName;
081            this.vendorName = vendorName;
082            this.resourceAdapterVersion = resourceAdapterVersion;
083            this.eisType = eisType;
084        }
085    
086        public String getObjectName() {
087            return objectName;
088        }
089    
090        public boolean isStateManageable() {
091            return true;
092        }
093    
094        public boolean isStatisticsProvider() {
095            return false;
096        }
097    
098        public boolean isEventProvider() {
099            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    }