KickJava   Java API By Example, From Geeks To Geeks.

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


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.ObjectName JavaDoc;
21
22 import org.apache.geronimo.gbean.GBeanInfo;
23 import org.apache.geronimo.gbean.GBeanInfoBuilder;
24 import org.apache.geronimo.j2ee.management.J2EEServer;
25 import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
26 import org.apache.geronimo.kernel.jmx.JMXUtil;
27
28 /**
29  * @version $Rev: 56022 $ $Date: 2004-10-29 22:16:18 -0700 (Fri, 29 Oct 2004) $
30  */

31 public class JCAConnectionFactoryImpl {
32     private final J2EEServer server;
33     private final String JavaDoc managedConnectionFactory;
34
35     public JCAConnectionFactoryImpl(String JavaDoc objectName, J2EEServer server, String JavaDoc managedConnectionFactory) {
36         ObjectName JavaDoc myObjectName = JMXUtil.getObjectName(objectName);
37         verifyObjectName(myObjectName);
38
39         this.server = server;
40         this.managedConnectionFactory = managedConnectionFactory;
41     }
42
43     public String JavaDoc getServer() {
44         return server.getObjectName();
45     }
46
47     public String JavaDoc getManagedConnectionFactory() {
48         return managedConnectionFactory;
49     }
50
51     /**
52      * ObjectName must match this pattern:
53      * <p/>
54      * domain:j2eeType=JCAConnectionFactory,name=MyName,J2EEServer=MyServer,JCAResource=MyJCAResource
55      */

56     private void verifyObjectName(ObjectName JavaDoc objectName) {
57         if (objectName.isPattern()) {
58             throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName);
59         }
60         Hashtable JavaDoc keyPropertyList = objectName.getKeyPropertyList();
61         if (!"JCAConnectionFactory".equals(keyPropertyList.get("j2eeType"))) {
62             throw new InvalidObjectNameException("JCAConnectionFactory object name j2eeType property must be 'JCAConnectionFactory'", objectName);
63         }
64         if (!keyPropertyList.containsKey("name")) {
65             throw new InvalidObjectNameException("JCAConnectionFactory object must contain a name property", objectName);
66         }
67         if (!keyPropertyList.containsKey("J2EEServer")) {
68             throw new InvalidObjectNameException("JCAConnectionFactory object name must contain a J2EEServer property", objectName);
69         }
70         if (!keyPropertyList.containsKey("JCAResource")) {
71             throw new InvalidObjectNameException("JCAResource object name must contain a JCAResource property", objectName);
72         }
73 // if (keyPropertyList.size() != 4) {
74
// throw new InvalidObjectNameException("JCAConnectionFactory object name can only have j2eeType, name, JCAResource, and J2EEServer properties", objectName);
75
// }
76
}
77
78     public static final GBeanInfo GBEAN_INFO;
79
80     static {
81         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(JCAConnectionFactoryImpl.class);
82         infoFactory.addReference("J2EEServer", J2EEServer.class);
83
84         infoFactory.addAttribute("objectName", String JavaDoc.class, false);
85         infoFactory.addAttribute("server", String JavaDoc.class, false);
86         infoFactory.addAttribute("managedConnectionFactory", String JavaDoc.class, true);
87
88         infoFactory.setConstructor(new String JavaDoc[]{"objectName", "J2EEServer", "managedConnectionFactory"});
89
90         GBEAN_INFO = infoFactory.getBeanInfo();
91     }
92
93     public static GBeanInfo getGBeanInfo() {
94         return GBEAN_INFO;
95     }
96 }
97
Popular Tags