KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > util > MCFConfigParserImpl


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.util;
25
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.config.serverbeans.ElementProperty;
28 import com.sun.enterprise.connectors.*;
29 import com.sun.enterprise.util.*;
30 import com.sun.logging.LogDomains;
31 import java.util.logging.*;
32 import java.util.*;
33 import java.lang.*;
34 import java.lang.reflect.*;
35 import java.io.IOException JavaDoc;
36 import org.xml.sax.SAXParseException JavaDoc;
37
38 /**
39  * This is managed connection factory configuration parser. It parses the
40  * ra.xml file for the managed connection factory specific configurations
41  * like managed connection factory javabean properties .
42  *
43  * @author Srikanth P
44  *
45  */

46
47 public class MCFConfigParserImpl implements MCFConfigParser {
48
49     static Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
50    
51     /**
52      * Default constructor.
53      *
54      */

55
56     public MCFConfigParserImpl() {
57
58     }
59
60     /* Parses the ra.xml and returns all the connection definition names.
61      * Since there is no specific connection definition attribute in the
62      * <connection-definition element>, connection factory interface is
63      * taken as the connection definition name.
64      *
65      * @param desc ConnectorDescriptor pertaining to rar.
66      * @return Array of Connection definition names.
67      * @throws ConnectorRuntimeException If moduleDir is null.
68      * If corresponding rar is not deployed.
69      *
70      */

71
72     public String JavaDoc[] getConnectionDefinitionNames(ConnectorDescriptor desc)
73                throws ConnectorRuntimeException
74     {
75
76         if(desc == null) {
77             throw new ConnectorRuntimeException("Invalid arguments");
78         }
79
80         ConnectionDefDescriptor cdd[] = ddTransformUtil.getConnectionDefs(desc);
81
82         String JavaDoc[] connDefNames = null;
83         if(cdd != null) {
84             connDefNames = new String JavaDoc[cdd.length];
85             for(int i=0;i<cdd.length;++i) {
86                 connDefNames[i] = cdd[i].getConnectionFactoryIntf();
87             }
88         }
89         return connDefNames;
90     }
91
92     /** Parses the ra.xml for the managed connection factory javabean
93      * properties. The managed connection factory to be parsed is
94      * identified by the moduleDir where ra.xml is present and the
95      * connection definition name .
96      *
97      * Connection definition name will be unique in a given ra.xml.
98      *
99      * It throws ConnectorRuntimeException if either or both the
100      * parameters are null, if corresponding rar is not deployed,
101      * if no connection definition name is found in ra.xml. If rar is deployed
102      * and connection definition name is present but no properties are
103      * present for the corresponding connection definition name,
104      * null is returned.
105      *
106      * @param desc ConnectorDescriptor pertaining to rar.
107      * @param connectionDefName connection definition name which is unique
108      * across all the <connection-definition> elements in a given rar.
109      * @return Javabean properties with the propety names and values
110      * of propeties. The property values will be the values
111      * mentioned in ra.xml if present. Otherwise it will be the
112      * default values obtained by introspecting the javabean.
113      * In both the case if no value is present, empty String is
114      * returned as the value.
115      * @throws ConnectorRuntimeException if either of the parameters are null.
116      * If corresponding rar is not deployed i.e moduleDir is invalid.
117      * If no connection definition name is found in ra.xml
118      */

119
120     public Properties getJavaBeanProps(ConnectorDescriptor desc,
121                String JavaDoc connectionDefName, String JavaDoc rarName) throws ConnectorRuntimeException
122     {
123
124         if(desc == null || connectionDefName == null) {
125             throw new ConnectorRuntimeException("Invalid arguments");
126         }
127         OutboundResourceAdapter ora =
128                       desc.getOutboundResourceAdapter();
129         if(ora == null || ora.getConnectionDefs().size() == 0) {
130             return null;
131         }
132         Set connectionDefs = ora.getConnectionDefs();
133         if(connectionDefs== null || connectionDefs.size() == 0) {
134             return null;
135         }
136         Iterator iter = connectionDefs.iterator();
137         ConnectionDefDescriptor cdd = null;
138         boolean connectionDefFound=false;
139         while(iter.hasNext()) {
140             cdd = (ConnectionDefDescriptor)iter.next();
141             if(connectionDefName.equals(cdd.getConnectionFactoryIntf())) {
142                 connectionDefFound=true;
143                 break;
144             }
145         }
146
147         if(connectionDefFound == false) {
148             _logger.log(Level.FINE,
149                     "No such connectiondefinition found in ra.xml",
150                     connectionDefName);
151             throw new ConnectorRuntimeException(
152                   "No such connectiondefinition found in ra.xml : " +
153                   connectionDefName);
154         }
155
156         /* ddVals -> Properties present in ra.xml
157         * introspectedVals -> All properties with values
158         * obtained by introspection of resource
159         * adapter javabean
160         * mergedVals -> merged props of raConfigPros and
161         * allraConfigPropsWithDefVals
162         */

163
164         Properties mergedVals = null;
165         Set ddVals = cdd.getConfigProperties();
166         String JavaDoc className = cdd.getManagedConnectionFactoryImpl();
167         if(className != null && className.length() != 0) {
168             Properties introspectedVals = configParserUtil.introspectJavaBean(
169                                className,ddVals, true, rarName);
170             mergedVals = configParserUtil.mergeProps(ddVals,introspectedVals);
171         }
172         return mergedVals;
173     }
174
175 }
176
Popular Tags