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.outbound;
017:
018: import java.util.Hashtable;
019:
020: import javax.management.ObjectName;
021:
022: import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
023: import org.apache.geronimo.kernel.ObjectNameUtil;
024: import org.apache.geronimo.management.geronimo.JCAConnectionFactory;
025: import org.apache.geronimo.management.geronimo.JCAManagedConnectionFactory;
026:
027: /**
028: * @version $Rev: 550546 $ $Date: 2007-06-25 09:52:11 -0700 (Mon, 25 Jun 2007) $
029: */
030: public class JCAConnectionFactoryImpl implements JCAConnectionFactory {
031: private final String objectName;
032: private final JCAManagedConnectionFactory managedConnectionFactory;
033:
034: public JCAConnectionFactoryImpl(String objectName,
035: JCAManagedConnectionFactory managedConnectionFactory) {
036: // todo do we really need to do this at runtime - shouldn't the builder set this up correctly?
037: ObjectName myObjectName = ObjectNameUtil
038: .getObjectName(objectName);
039: verifyObjectName(myObjectName);
040:
041: this .objectName = objectName;
042: this .managedConnectionFactory = managedConnectionFactory;
043: }
044:
045: public String getManagedConnectionFactory() {
046: return managedConnectionFactory.getObjectName();
047: }
048:
049: public JCAManagedConnectionFactory getManagedConnectionFactoryInstance() {
050: return managedConnectionFactory;
051: }
052:
053: public String getObjectName() {
054: return objectName;
055: }
056:
057: public boolean isStateManageable() {
058: return false;
059: }
060:
061: public boolean isStatisticsProvider() {
062: return false;
063: }
064:
065: public boolean isEventProvider() {
066: return false;
067: }
068:
069: /**
070: * ObjectName must match this pattern:
071: * <p/>
072: * domain:j2eeType=JCAConnectionFactory,name=MyName,J2EEServer=MyServer,JCAResource=MyJCAResource
073: */
074: private void verifyObjectName(ObjectName objectName) {
075: if (objectName.isPattern()) {
076: throw new InvalidObjectNameException(
077: "ObjectName can not be a pattern", objectName);
078: }
079: Hashtable keyPropertyList = objectName.getKeyPropertyList();
080: if (!"JCAConnectionFactory".equals(keyPropertyList
081: .get("j2eeType"))) {
082: throw new InvalidObjectNameException(
083: "JCAConnectionFactory object name j2eeType property must be 'JCAConnectionFactory'",
084: objectName);
085: }
086: if (!keyPropertyList.containsKey("name")) {
087: throw new InvalidObjectNameException(
088: "JCAConnectionFactory object must contain a name property",
089: objectName);
090: }
091: if (!keyPropertyList.containsKey("J2EEServer")) {
092: throw new InvalidObjectNameException(
093: "JCAConnectionFactory object name must contain a J2EEServer property",
094: objectName);
095: }
096: if (!keyPropertyList.containsKey("JCAResource")) {
097: throw new InvalidObjectNameException(
098: "JCAResource object name must contain a JCAResource property",
099: objectName);
100: }
101: // if (keyPropertyList.size() != 4) {
102: // throw new InvalidObjectNameException("JCAConnectionFactory object name can only have j2eeType, name, JCAResource, and J2EEServer properties", objectName);
103: // }
104: }
105: }
|