KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > ResourceAdapterWrapper


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
18 package org.apache.geronimo.connector;
19
20 import javax.resource.ResourceException JavaDoc;
21 import javax.resource.spi.ActivationSpec JavaDoc;
22 import javax.resource.spi.BootstrapContext JavaDoc;
23 import javax.resource.spi.ResourceAdapter JavaDoc;
24 import javax.resource.spi.ResourceAdapterAssociation JavaDoc;
25 import javax.resource.spi.ResourceAdapterInternalException JavaDoc;
26 import javax.resource.spi.endpoint.MessageEndpointFactory JavaDoc;
27 import javax.transaction.xa.XAResource JavaDoc;
28
29 /**
30  * Dynamic GBean wrapper around a ResourceAdapter object, exposing the config-properties as
31  * GBean attributes.
32  *
33  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
34  */

35 public class ResourceAdapterWrapper implements ResourceAdapter JavaDoc {
36
37     private final String JavaDoc resourceAdapterClass;
38
39     private final BootstrapContext bootstrapContext;
40
41     protected final ResourceAdapter JavaDoc resourceAdapter;
42
43
44     /**
45      * default constructor for enhancement proxy endpoint
46      */

47     public ResourceAdapterWrapper() {
48         this.resourceAdapterClass = null;
49         this.bootstrapContext = null;
50         this.resourceAdapter = null;
51     }
52
53     public ResourceAdapterWrapper(String JavaDoc resourceAdapterClass,
54             BootstrapContext bootstrapContext,
55             ClassLoader JavaDoc cl) throws InstantiationException JavaDoc, IllegalAccessException JavaDoc, ClassNotFoundException JavaDoc {
56         this.resourceAdapterClass = resourceAdapterClass;
57         this.bootstrapContext = bootstrapContext;
58         Class JavaDoc clazz = cl.loadClass(resourceAdapterClass);
59         resourceAdapter = (ResourceAdapter JavaDoc) clazz.newInstance();
60     }
61     
62     public ResourceAdapterWrapper(ResourceAdapter JavaDoc resourceAdapter, BootstrapContext bootstrapContext) {
63         this.resourceAdapterClass = resourceAdapter.getClass().getName();
64         this.bootstrapContext = bootstrapContext;
65         this.resourceAdapter = resourceAdapter;
66     }
67
68     public String JavaDoc getResourceAdapterClass() {
69         return resourceAdapterClass;
70     }
71
72     public void registerResourceAdapterAssociation(final ResourceAdapterAssociation JavaDoc resourceAdapterAssociation) throws ResourceException JavaDoc {
73         resourceAdapterAssociation.setResourceAdapter(resourceAdapter);
74     }
75
76     public void start(BootstrapContext ctx) throws ResourceAdapterInternalException JavaDoc {
77         throw new IllegalStateException JavaDoc("Don't call this");
78     }
79
80     public void stop() {
81         throw new IllegalStateException JavaDoc("Don't call this");
82     }
83
84     //endpoint handling
85
public void endpointActivation(final MessageEndpointFactory JavaDoc messageEndpointFactory, final ActivationSpec JavaDoc activationSpec) throws ResourceException JavaDoc {
86         resourceAdapter.endpointActivation(messageEndpointFactory, activationSpec);
87     }
88
89     public void endpointDeactivation(final MessageEndpointFactory JavaDoc messageEndpointFactory, final ActivationSpec JavaDoc activationSpec) {
90         resourceAdapter.endpointDeactivation(messageEndpointFactory, activationSpec);
91     }
92
93     public XAResource JavaDoc[] getXAResources(ActivationSpec JavaDoc[] specs) throws ResourceException JavaDoc {
94         return resourceAdapter.getXAResources(specs);
95     }
96
97     public void doStart() throws Exception JavaDoc {
98         resourceAdapter.start(bootstrapContext);
99     }
100
101     public void doStop() {
102         resourceAdapter.stop();
103     }
104
105     public void doFail() {
106         resourceAdapter.stop();
107     }
108
109 }
110
Popular Tags