KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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.outbound;
18
19 import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
20 import org.apache.geronimo.kernel.ObjectNameUtil;
21 import org.apache.geronimo.management.geronimo.JCAConnectionFactory;
22 import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
23
24 import javax.management.ObjectName JavaDoc;
25 import java.util.Hashtable JavaDoc;
26
27 /**
28  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
29  */

30 public class JCAConnectionFactoryImpl implements JCAConnectionFactory {
31     private final String JavaDoc objectName;
32     private final JCAManagedConnectionFactory managedConnectionFactory;
33
34     public JCAConnectionFactoryImpl(String JavaDoc objectName, JCAManagedConnectionFactory managedConnectionFactory) {
35         // todo do we really need to do this at runtime - shouldn't the builder set this up correctly?
36
ObjectName JavaDoc myObjectName = ObjectNameUtil.getObjectName(objectName);
37         verifyObjectName(myObjectName);
38
39         this.objectName = objectName;
40         this.managedConnectionFactory = managedConnectionFactory;
41     }
42
43     public String JavaDoc getManagedConnectionFactory() {
44         return managedConnectionFactory.getObjectName();
45     }
46
47     public JCAManagedConnectionFactory getManagedConnectionFactoryInstance() {
48         return managedConnectionFactory;
49     }
50
51     public String JavaDoc getObjectName() {
52         return objectName;
53     }
54
55     public boolean isStateManageable() {
56         return false;
57     }
58
59     public boolean isStatisticsProvider() {
60         return false;
61     }
62
63     public boolean isEventProvider() {
64         return false;
65     }
66
67     /**
68      * ObjectName must match this pattern:
69      * <p/>
70      * domain:j2eeType=JCAConnectionFactory,name=MyName,J2EEServer=MyServer,JCAResource=MyJCAResource
71      */

72     private void verifyObjectName(ObjectName JavaDoc objectName) {
73         if (objectName.isPattern()) {
74             throw new InvalidObjectNameException("ObjectName can not be a pattern", objectName);
75         }
76         Hashtable JavaDoc keyPropertyList = objectName.getKeyPropertyList();
77         if (!"JCAConnectionFactory".equals(keyPropertyList.get("j2eeType"))) {
78             throw new InvalidObjectNameException("JCAConnectionFactory object name j2eeType property must be 'JCAConnectionFactory'", objectName);
79         }
80         if (!keyPropertyList.containsKey("name")) {
81             throw new InvalidObjectNameException("JCAConnectionFactory object must contain a name property", objectName);
82         }
83         if (!keyPropertyList.containsKey("J2EEServer")) {
84             throw new InvalidObjectNameException("JCAConnectionFactory object name must contain a J2EEServer property", objectName);
85         }
86         if (!keyPropertyList.containsKey("JCAResource")) {
87             throw new InvalidObjectNameException("JCAResource object name must contain a JCAResource property", objectName);
88         }
89 // if (keyPropertyList.size() != 4) {
90
// throw new InvalidObjectNameException("JCAConnectionFactory object name can only have j2eeType, name, JCAResource, and J2EEServer properties", objectName);
91
// }
92
}
93 }
94
Popular Tags