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     */
017    package org.apache.geronimo.connector;
018    
019    import java.util.Hashtable;
020    import java.util.Map;
021    
022    import javax.management.ObjectName;
023    
024    import org.apache.geronimo.gbean.GBeanData;
025    import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
026    import org.apache.geronimo.kernel.ObjectNameUtil;
027    import org.apache.geronimo.management.J2EEApplication;
028    import org.apache.geronimo.management.J2EEServer;
029    import org.apache.geronimo.management.geronimo.ResourceAdapter;
030    import org.apache.geronimo.management.geronimo.ResourceAdapterModule;
031    
032    /**
033     * @version $Rev: 550546 $ $Date: 2007-06-25 12:52:11 -0400 (Mon, 25 Jun 2007) $
034     */
035    public class ResourceAdapterModuleImpl implements ResourceAdapterModule {
036        private final J2EEServer server;
037        private final J2EEApplication application;
038        private final String deploymentDescriptor;
039        private final ResourceAdapter resourceAdapter;
040    
041        private final GBeanData resourceAdapterGBeanData;
042        private final Map activationSpecInfoMap;
043        private final Map adminObjectInfoMap;
044        private final Map managedConnectionFactoryInfoMap;
045        private final String objectName;
046        private final String displayName;
047        private final String description;
048        private final String vendorName;
049        private final String resourceAdapterVersion;
050        private final String eisType;
051    
052        public ResourceAdapterModuleImpl(String objectName,
053                                         ResourceAdapter resourceAdapter,
054                                         J2EEServer server,
055                                         J2EEApplication application,
056                                         String deploymentDescriptor,
057                                         GBeanData resourceAdapterGBeanData,
058                                         Map activationSpecInfoMap,
059                                         Map adminObjectInfoMap,
060                                         Map managedConnectionFactoryInfoMap,
061                                         String displayName,
062                                         String description,
063                                         String vendorName,
064                                         String resourceAdapterVersion,
065                                         String eisType) {
066            this.objectName = objectName;
067            ObjectName myObjectName = ObjectNameUtil.getObjectName(objectName);
068            verifyObjectName(myObjectName);
069    
070            this.resourceAdapter = resourceAdapter;
071    
072            this.server = server;
073            this.application = application;
074            this.deploymentDescriptor = deploymentDescriptor;
075    
076            this.resourceAdapterGBeanData = resourceAdapterGBeanData;
077            this.activationSpecInfoMap = activationSpecInfoMap;
078            this.adminObjectInfoMap = adminObjectInfoMap;
079            this.managedConnectionFactoryInfoMap = managedConnectionFactoryInfoMap;
080            this.description = description;
081            this.displayName = displayName;
082            this.vendorName = vendorName;
083            this.resourceAdapterVersion = resourceAdapterVersion;
084            this.eisType = eisType;
085        }
086    
087        public String getObjectName() {
088            return objectName;
089        }
090    
091        public boolean isStateManageable() {
092            return true;
093        }
094    
095        public boolean isStatisticsProvider() {
096            return false;
097        }
098    
099        public boolean isEventProvider() {
100            return true;
101        }
102    
103        public String getDeploymentDescriptor() {
104            return deploymentDescriptor;
105        }
106    
107        public String getServer() {
108            return server.getObjectName();
109        }
110    
111        public String getApplication() {
112            if (application == null) {
113                return null;
114            }
115            return application.getObjectName();
116        }
117    
118        public String[] getJavaVMs() {
119            return server.getJavaVMs();
120        }
121    
122        public String[] getResourceAdapters() {
123            return new String[]{resourceAdapter.getObjectName()};
124        }
125    
126        public GBeanData getResourceAdapterGBeanData() {
127            return resourceAdapterGBeanData;
128        }
129    
130        public Map getActivationSpecInfoMap() {
131            return activationSpecInfoMap;
132        }
133    
134        public Map getAdminObjectInfoMap() {
135            return adminObjectInfoMap;
136        }
137    
138        public Map getManagedConnectionFactoryInfoMap() {
139            return managedConnectionFactoryInfoMap;
140        }
141    
142        public String getDisplayName() {
143            return displayName;
144        }
145    
146        public String getDescription() {
147            return description;
148        }
149    
150        public String getVendorName() {
151            return vendorName;
152        }
153    
154        public String getResourceAdapterVersion() {
155            return resourceAdapterVersion;
156        }
157    
158        public String getEISType() {
159            return eisType;
160        }
161    
162        public ResourceAdapter[] getResourceAdapterInstances() {
163            return new ResourceAdapter[] {resourceAdapter};
164        }
165    
166        /**
167         * ObjectName must match this pattern:
168         * <p/>
169         * domain:j2eeType=ResourceAdapterModule,name=MyName,J2EEServer=MyServer,J2EEApplication=MyApplication
170         */
171        private void verifyObjectName(ObjectName objectName) {
172            if (objectName.isPattern()) {
173                throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName);
174            }
175            Hashtable keyPropertyList = objectName.getKeyPropertyList();
176            if (!"ResourceAdapterModule".equals(keyPropertyList.get("j2eeType"))) {
177                throw new InvalidObjectNameException("ResourceAdapterModule object name j2eeType property must be 'ResourceAdapterModule'", objectName);
178            }
179            if (!keyPropertyList.containsKey("name")) {
180                throw new InvalidObjectNameException("ResourceAdapterModule object must contain a name property", objectName);
181            }
182            if (!keyPropertyList.containsKey("J2EEServer")) {
183                throw new InvalidObjectNameException("ResourceAdapterModule object name must contain a J2EEServer property", objectName);
184            }
185            if (!keyPropertyList.containsKey("J2EEApplication")) {
186                throw new InvalidObjectNameException("ResourceAdapterModule object name must contain a J2EEApplication property", objectName);
187            }
188            if (keyPropertyList.size() != 4) {
189                throw new InvalidObjectNameException("ResourceAdapterModule object name can only have j2eeType, name, J2EEApplication, and J2EEServer properties", objectName);
190            }
191        }
192    }