KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import java.util.*;
27 import java.util.logging.*;
28
29 import com.sun.enterprise.deployment.*;
30 import com.sun.enterprise.server.*;
31 import com.sun.enterprise.connectors.system.ActiveJmsResourceAdapter;
32 import com.sun.enterprise.connectors.util.*;
33
34 /**
35  * This is configuration parser service. Retrieves various configuration
36  * information from ra.xml
37  * @author Srikanth P
38  */

39
40
41 public class ConnectorConfigurationParserServiceImpl extends
42                         ConnectorServiceImpl {
43
44      
45     /**
46      * Default constructor
47      */

48
49      public ConnectorConfigurationParserServiceImpl() {
50          super();
51      }
52
53     /**
54      * Obtains the Permission string that needs to be added to the
55      * to the security policy files. These are the security permissions needed
56      * by the resource adapter implementation classes.
57      * These strings are obtained by parsing the ra.xml
58      * @param moduleName rar module Name
59      * @ConnectorRuntimeException If rar.xml parsing fails.
60      */

61
62     public String JavaDoc getSecurityPermissionSpec(String JavaDoc moduleName)
63                          throws ConnectorRuntimeException
64     {
65
66         if(moduleName == null) {
67             return null;
68         }
69         ConnectorDescriptor connectorDescriptor = getConnectorDescriptor(
70                                  moduleName);
71         Set securityPermissions = connectorDescriptor.getSecurityPermissions();
72         Iterator it = securityPermissions.iterator();
73         String JavaDoc policyString = null;
74         SecurityPermission secPerm = null;
75         String JavaDoc permissionString=null;
76         while(it.hasNext()){
77             secPerm = (SecurityPermission) it.next();
78             permissionString = secPerm.getPermission();
79             if(permissionString != null) {
80                 policyString = policyString+"\n \n"+permissionString;
81             }
82         }
83         if(policyString != null) {
84             policyString= CAUTION_MESSAGE+policyString;
85         }
86         return policyString;
87     }
88
89     /** Obtains all the Connection definition names of a rar
90      * @param rarName rar moduleName
91      * @return Array of connection definition names.
92      */

93
94     public String JavaDoc[] getConnectionDefinitionNames(String JavaDoc rarName)
95                throws ConnectorRuntimeException
96     {
97
98         ConnectorDescriptor desc = getConnectorDescriptor(rarName);
99         if(desc != null) {
100             MCFConfigParser mcfConfigParser = (MCFConfigParser)
101               ConnectorConfigParserFactory.getParser(ConnectorConfigParser.MCF);
102             return mcfConfigParser.getConnectionDefinitionNames(desc);
103         } else {
104             return null;
105         }
106     }
107   
108     /**
109      * Retrieves the Resource adapter javabean properties with default values.
110      * The default values will the values present in the ra.xml. If the
111      * value is not present in ra.xxml, javabean is introspected to obtain
112      * the default value present, if any. If intrspection fails or null is the
113      * default value, empty string is returned.
114      * If ra.xml has only the property and no value, empty string is the value
115      * returned.
116      * @param rarName rar module name
117      * @return Resource adapter javabean properties with default values.
118      * @throws ConnectorRuntimeException if property retrieval fails.
119      */

120
121     public Properties getResourceAdapterConfigProps(String JavaDoc rarName)
122                 throws ConnectorRuntimeException
123     {
124         return getConnectorConfigJavaBeans(
125                rarName,null,ConnectorConfigParser.RA);
126     }
127
128     /**
129      * Retrieves the MCF javabean properties with default values.
130      * The default values will the values present in the ra.xml. If the
131      * value is not present in ra.xxml, javabean is introspected to obtain
132      * the default value present, if any. If intrspection fails or null is the
133      * default value, empty string is returned.
134      * If ra.xml has only the property and no value, empty string is the value
135      * returned.
136      * @param rarName rar module name
137      * @return managed connection factory javabean properties with
138      * default values.
139      * @throws ConnectorRuntimeException if property retrieval fails.
140      */

141
142     public Properties getMCFConfigProps(
143      String JavaDoc rarName,String JavaDoc connectionDefName) throws ConnectorRuntimeException
144     {
145         Properties props = getConnectorConfigJavaBeans(
146                rarName,connectionDefName,ConnectorConfigParser.MCF);
147     if (rarName.equals(ConnectorConstants.DEFAULT_JMS_ADAPTER)) {
148             props.remove(ActiveJmsResourceAdapter.ADDRESSLIST);
149     }
150         return props;
151     }
152
153     /**
154      * Retrieves the admin object javabean properties with default values.
155      * The default values will the values present in the ra.xml. If the
156      * value is not present in ra.xxml, javabean is introspected to obtain
157      * the default value present, if any. If intrspection fails or null is the
158      * default value, empty string is returned.
159      * If ra.xml has only the property and no value, empty string is the value
160      * returned.
161      * @param rarName rar module name
162      * @return admin object javabean properties with
163      * default values.
164      * @throws ConnectorRuntimeException if property retrieval fails.
165      */

166
167     public Properties getAdminObjectConfigProps(
168       String JavaDoc rarName,String JavaDoc adminObjectIntf) throws ConnectorRuntimeException
169     {
170         return getConnectorConfigJavaBeans(
171                rarName,adminObjectIntf,ConnectorConfigParser.AOR);
172     }
173
174     /**
175      * Retrieves the XXX javabean properties with default values.
176      * The javabean to introspect/retrieve is specified by the type.
177      * The default values will be the values present in the ra.xml. If the
178      * value is not present in ra.xxml, javabean is introspected to obtain
179      * the default value present, if any. If intrspection fails or null is the
180      * default value, empty string is returned.
181      * If ra.xml has only the property and no value, empty string is the value
182      * returned.
183      * @param rarName rar module name
184      * @return admin object javabean properties with
185      * default values.
186      * @throws ConnectorRuntimeException if property retrieval fails.
187      */

188
189     public Properties getConnectorConfigJavaBeans(String JavaDoc rarName,
190         String JavaDoc connectionDefName,String JavaDoc type) throws ConnectorRuntimeException
191     {
192
193         ConnectorDescriptor desc = getConnectorDescriptor(rarName);
194         if(desc != null) {
195             ConnectorConfigParser ccParser =
196                      ConnectorConfigParserFactory.getParser(type);
197             return ccParser.getJavaBeanProps(desc,connectionDefName, rarName);
198         } else {
199             return null;
200         }
201     }
202
203     /**
204      * Return the ActivationSpecClass name for given rar and messageListenerType
205      * @param moduleDir The directory where rar is exploded.
206      * @param messageListenerType MessageListener type
207      * @throws ConnectorRuntimeException If moduleDir is null.
208      * If corresponding rar is not deployed.
209      */

210
211     public String JavaDoc getActivationSpecClass( String JavaDoc rarName,
212              String JavaDoc messageListenerType) throws ConnectorRuntimeException
213     {
214         ConnectorDescriptor desc = getConnectorDescriptor(rarName);
215         if(desc != null) {
216             MessageListenerConfigParser messagelistenerConfigParser =
217                  (MessageListenerConfigParser)
218                  ConnectorConfigParserFactory.getParser(
219                  ConnectorConfigParser.MSL);
220             return messagelistenerConfigParser.getActivationSpecClass(
221                        desc,messageListenerType);
222         } else {
223             return null;
224         }
225     }
226
227     /* Parses the ra.xml and returns all the Message listener types.
228      *
229      * @param rarName name of the rar module.
230      * @return Array of message listener types as strings.
231      * @throws ConnectorRuntimeException If moduleDir is null.
232      * If corresponding rar is not deployed.
233      *
234      */

235
236     public String JavaDoc[] getMessageListenerTypes(String JavaDoc rarName)
237                throws ConnectorRuntimeException
238     {
239         ConnectorDescriptor desc = getConnectorDescriptor(rarName);
240         if(desc != null) {
241             MessageListenerConfigParser messagelistenerConfigParser =
242                 (MessageListenerConfigParser)
243                 ConnectorConfigParserFactory.getParser(
244                 ConnectorConfigParser.MSL);
245             return messagelistenerConfigParser.getMessageListenerTypes(desc);
246         } else {
247             return null;
248         }
249     }
250
251     /** Parses the ra.xml for the ActivationSpec javabean
252      * properties. The ActivationSpec to be parsed is
253      * identified by the moduleDir where ra.xml is present and the
254      * message listener type.
255      *
256      * message listener type will be unique in a given ra.xml.
257      *
258      * It throws ConnectorRuntimeException if either or both the
259      * parameters are null, if corresponding rar is not deployed,
260      * if message listener type mentioned as parameter is not found in ra.xml.
261      * If rar is deployed and message listener (type mentioned) is present
262      * but no properties are present for the corresponding message listener,
263      * null is returned.
264      *
265      * @param rarName name of the rar module.
266      * @param messageListenerType message listener type.It is uniqie
267      * across all <messagelistener> sub-elements in <messageadapter>
268      * element in a given rar.
269      * @return Javabean properties with the property names and values
270      * of properties. The property values will be the values
271      * mentioned in ra.xml if present. Otherwise it will be the
272      * default values obtained by introspecting the javabean.
273      * In both the case if no value is present, empty String is
274      * returned as the value.
275      * @throws ConnectorRuntimeException if either of the parameters are null.
276      * If corresponding rar is not deployed i.e moduleDir is invalid.
277      * If messagelistener type is not found in ra.xml
278      */

279
280     public Properties getMessageListenerConfigProps(String JavaDoc rarName,
281          String JavaDoc messageListenerType)throws ConnectorRuntimeException
282     {
283         return getConnectorConfigJavaBeans(
284                rarName,messageListenerType,ConnectorConfigParser.MSL);
285     }
286
287     /** Returns the Properties object consisting of propertyname as the
288      * key and datatype as the value.
289      * @param rarName name of the rar module.
290      * @param messageListenerType message listener type.It is uniqie
291      * across all <messagelistener> sub-elements in <messageadapter>
292      * element in a given rar.
293      * @return Properties object with the property names(key) and datatype
294      * of property(as value).
295      * @throws ConnectorRuntimeException if either of the parameters are null.
296      * If corresponding rar is not deployed i.e moduleDir is invalid.
297      * If messagelistener type is not found in ra.xml
298      */

299
300     public Properties getMessageListenerConfigPropTypes(String JavaDoc rarName,
301                String JavaDoc messageListenerType) throws ConnectorRuntimeException
302     {
303         ConnectorDescriptor desc = getConnectorDescriptor(rarName);
304         if(desc != null) {
305             MessageListenerConfigParser messagelistenerConfigParser =
306                 (MessageListenerConfigParser)
307                 ConnectorConfigParserFactory.getParser(
308                 ConnectorConfigParser.MSL);
309             return messagelistenerConfigParser.getJavaBeanReturnTypes(
310                     desc, messageListenerType);
311         } else {
312             return null;
313         }
314     }
315
316     /** Obtains all the Connection definition names of a rar
317      * @param rarName rar moduleName
318      * @return Array of connection definition names.
319      */

320
321     public String JavaDoc[] getAdminObjectInterfaceNames(String JavaDoc rarName)
322                throws ConnectorRuntimeException
323     {
324
325         ConnectorDescriptor desc = getConnectorDescriptor(rarName);
326         if(desc != null) {
327             AdminObjectConfigParser adminObjectConfigParser =
328                  (AdminObjectConfigParser)
329                  ConnectorConfigParserFactory.getParser(
330                  ConnectorConfigParser.AOR);
331             return adminObjectConfigParser.getAdminObjectInterfaceNames(desc);
332         } else {
333             return null;
334         }
335     }
336
337     /**
338      * Finds the properties of a RA JavaBean bundled in a RAR
339      * without exploding the RAR
340      *
341      * @param pathToDeployableUnit a physical,accessible location of the connector module.
342      * [either a RAR for RAR-based deployments or a directory for Directory based deployments]
343      * @return A Map that is of <String RAJavaBeanPropertyName, String defaultPropertyValue>
344      * An empty map is returned in the case of a 1.0 RAR
345      */

346     public Map getRABeanProperties(String JavaDoc pathToDeployableUnit) throws ConnectorRuntimeException{
347         return RARUtils.getRABeanProperties(pathToDeployableUnit);
348     }
349 }
350
Popular Tags