KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > ActiveRAFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.connectors;
25 import java.util.logging.*;
26 import javax.resource.spi.ResourceAdapter JavaDoc;
27 import com.sun.logging.LogDomains;
28 import com.sun.enterprise.deployment.ConnectorDescriptor;
29 import com.sun.enterprise.connectors.system.*;
30
31
32 /**
33  * Factory creating Active Resource adapters.
34  *
35  * @author Binod P.G
36  */

37 public class ActiveRAFactory {
38     static Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
39
40     /**
41      * Creates an active resource adapter.
42      *
43      * @param cd Deployment descriptor object for connectors.
44      * @param moduleName Module name of the resource adapter.
45      * @param loader Class Loader,
46      * @param writeSunDescriptor Boolean indicating whether sundescriptor
47      * need to be written or not.
48      * @return An instance of <code> ActiveResourceAdapter </code> object.
49      * @throws ConnectorRuntimeException.
50      */

51     public static ActiveResourceAdapter createActiveResourceAdapter(
52         ConnectorDescriptor cd, String JavaDoc moduleName, ClassLoader JavaDoc loader,
53         boolean writeSunDescriptor) throws ConnectorRuntimeException{
54
55         ActiveResourceAdapter activeResourceAdapter = null;
56         int environment = ConnectorRuntime.getRuntime().getEnviron();
57         ResourceAdapter JavaDoc ra = null;
58         String JavaDoc raClass = cd.getResourceAdapterClass();
59
60         try {
61
62             // If raClass is available, load it...
63
if (raClass != null && !raClass.equals("")) {
64                 if(environment == ConnectorRuntime.SERVER) {
65                     ra = (ResourceAdapter JavaDoc)
66                           loader.loadClass(raClass).newInstance();
67                 } else {
68                     ra = (ResourceAdapter JavaDoc)Class.forName(raClass).newInstance();
69                 }
70
71             }
72
73             /*
74              * If any special handling is required for the system resource
75              * adapter, then ActiveResourceAdapter implementation for that
76              * RA should implement additional functionality by extending
77              * ActiveInboundResourceAdapter or ActiveOutboundResourceAdapter.
78              *
79              * For example ActiveJmsResourceAdapter extends
80              * ActiveInboundResourceAdapter.
81              */

82             if (moduleName.equals(ConnectorConstants.DEFAULT_JMS_ADAPTER)) {
83                 activeResourceAdapter = new ActiveJmsResourceAdapter(
84                                                  ra,cd,moduleName,loader);
85             } else if (raClass.equals("")) {
86                 activeResourceAdapter = new ActiveOutboundResourceAdapter(
87                                  cd,moduleName,loader,writeSunDescriptor);
88             } else {
89                 activeResourceAdapter = new ActiveInboundResourceAdapter(
90                                                  ra,cd,moduleName,loader);
91             }
92          
93         } catch (ClassNotFoundException JavaDoc Ex) {
94             ConnectorRuntimeException cre = new ConnectorRuntimeException(
95                                              "Error in creating active RAR");
96             cre.initCause(Ex);
97             _logger.log(Level.SEVERE,"rardeployment.class_not_found",raClass);
98             _logger.log(Level.SEVERE,"",cre);
99             throw cre;
100         } catch (InstantiationException JavaDoc Ex) {
101             ConnectorRuntimeException cre = new ConnectorRuntimeException(
102                                              "Error in creating active RAR");
103             cre.initCause(Ex);
104             _logger.log(Level.SEVERE,"rardeployment.class_instantiation_error",
105                                     raClass);
106             _logger.log(Level.SEVERE,"",cre);
107             throw cre;
108         } catch (IllegalAccessException JavaDoc Ex) {
109             ConnectorRuntimeException cre = new ConnectorRuntimeException(
110                                              "Error in creating active RAR");
111             cre.initCause(Ex);
112             _logger.log(Level.SEVERE,"rardeployment.illegalaccess_error",
113                          raClass);
114             _logger.log(Level.SEVERE,"",cre);
115             throw cre;
116         }
117
118         return activeResourceAdapter;
119
120     }
121
122
123 }
124
Popular Tags