01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.openejb.core;
17:
18: import org.apache.openejb.core.ivm.naming.Reference;
19:
20: import javax.naming.NamingException;
21: import javax.resource.spi.ConnectionManager;
22: import javax.resource.spi.ManagedConnectionFactory;
23:
24: /*
25: This reference object is used for wrappering ManagedConnectionFactory objects that
26: manufacture resource specific connection factories. When the getObject( ) method is
27: invoked the factory is created and passed back as the return value.
28:
29: In addition, dynamic resolution and special conditions can be encapsulated
30: in the implementation object.
31:
32: */
33:
34: /**
35: * @org.apache.xbean.XBean element="connectorRef"
36: */
37: public class ConnectorReference extends Reference {
38: private ConnectionManager conMngr;
39: private ManagedConnectionFactory mngedConFactory;
40:
41: public ConnectorReference(ConnectionManager manager,
42: ManagedConnectionFactory factory) {
43: conMngr = manager;
44: mngedConFactory = factory;
45: }
46:
47: public Object getObject() throws NamingException {
48: try {
49: Object connection = mngedConFactory
50: .createConnectionFactory(conMngr);
51: return connection;
52: } catch (javax.resource.ResourceException re) {
53: throw (javax.naming.NamingException) (new javax.naming.NamingException(
54: "Could not create ConnectionFactory from "
55: + mngedConFactory.getClass()).initCause(re));
56: }
57: }
58: }
|