KickJava   Java API By Example, From Geeks To Geeks.

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


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 message listener configuration parser. It parses the
40  * ra.xml file for the message listener specific configurations
41  * like activationSpec javabean properties, message listener types .
42  *
43  * @author Srikanth P
44  *
45  */

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

56
57     public MessageListenerConfigParserImpl() {
58
59     }
60
61     /**
62      * Return the ActivationSpecClass name for given rar and messageListenerType
63      * @param desc ConnectorDescriptor pertaining to rar.
64      * @param messageListenerType MessageListener type
65      * @throws ConnectorRuntimeException If moduleDir is null.
66      * If corresponding rar is not deployed.
67      */

68
69     public String JavaDoc getActivationSpecClass( ConnectorDescriptor desc,
70              String JavaDoc messageListenerType) throws ConnectorRuntimeException
71     {
72         if(desc == null) {
73             throw new ConnectorRuntimeException("Invalid arguments");
74         }
75
76         MessageListener messageListeners[] =
77                ddTransformUtil.getMessageListeners(desc);
78
79         String JavaDoc messageListenerClass = null;
80         String JavaDoc[] messageListenerTypes = null;
81         if(messageListeners != null) {
82             messageListenerTypes = new String JavaDoc[messageListeners.length];
83             for(int i=0;i<messageListeners.length;++i) {
84                 if(messageListenerType.equals(
85                            messageListeners[i].getMessageListenerType())){
86                     return messageListeners[i].getActivationSpecClass();
87                 }
88             }
89         }
90         return null;
91     }
92
93     /* Parses the ra.xml and returns all the Message listener types.
94      *
95      * @param desc ConnectorDescriptor pertaining to rar.
96      * @return Array of message listener types as strings.
97      * @throws ConnectorRuntimeException If moduleDir is null.
98      * If corresponding rar is not deployed.
99      *
100      */

101
102     public String JavaDoc[] getMessageListenerTypes(ConnectorDescriptor desc)
103                throws ConnectorRuntimeException
104     {
105
106         if(desc == null) {
107             throw new ConnectorRuntimeException("Invalid arguments");
108         }
109
110         MessageListener messageListeners[] =
111                ddTransformUtil.getMessageListeners(desc);
112
113         String JavaDoc[] messageListenerTypes = null;
114         if(messageListeners != null) {
115             messageListenerTypes = new String JavaDoc[messageListeners.length];
116             for(int i=0;i<messageListeners.length;++i) {
117                 messageListenerTypes[i] =
118                            messageListeners[i].getMessageListenerType();
119             }
120         }
121         return messageListenerTypes;
122     }
123
124     /** Parses the ra.xml for the ActivationSpec javabean
125      * properties. The ActivationSpec to be parsed is
126      * identified by the moduleDir where ra.xml is present and the
127      * message listener type.
128      *
129      * message listener type will be unique in a given ra.xml.
130      *
131      * It throws ConnectorRuntimeException if either or both the
132      * parameters are null, if corresponding rar is not deployed,
133      * if message listener type mentioned as parameter is not found in ra.xml.
134      * If rar is deployed and message listener (type mentioned) is present
135      * but no properties are present for the corresponding message listener,
136      * null is returned.
137      *
138      * @param desc ConnectorDescriptor pertaining to rar.
139      * @param messageListenerType message listener type.It is uniqie
140      * across all <messagelistener> sub-elements in <messageadapter>
141      * element in a given rar.
142      * @return Javabean properties with the property names and values
143      * of properties. The property values will be the values
144      * mentioned in ra.xml if present. Otherwise it will be the
145      * default values obtained by introspecting the javabean.
146      * In both the case if no value is present, empty String is
147      * returned as the value.
148      * @throws ConnectorRuntimeException if either of the parameters are null.
149      * If corresponding rar is not deployed i.e moduleDir is invalid.
150      * If messagelistener type is not found in ra.xml
151      */

152
153     public Properties getJavaBeanProps(ConnectorDescriptor desc,
154                String JavaDoc messageListenerType, String JavaDoc rarName) throws ConnectorRuntimeException
155     {
156
157         if(desc == null || messageListenerType == null) {
158             throw new ConnectorRuntimeException("Invalid arguments");
159         }
160        
161         MessageListener allMessageListeners[] =
162                ddTransformUtil.getMessageListeners(desc);
163
164         MessageListener messageListener = null;
165         for(int i=0;i<allMessageListeners.length;++i) {
166             if(messageListenerType.equals(
167                     allMessageListeners[i].getMessageListenerType())) {
168                 messageListener = allMessageListeners[i];
169             }
170         }
171
172         if(messageListener == null) {
173             _logger.log(Level.FINE,
174                     "No such MessageListener found in ra.xml",
175                     messageListenerType);
176             throw new ConnectorRuntimeException(
177                   "No such MessageListener found in ra.xml : " +
178                   messageListenerType);
179         }
180
181         /* ddVals -> Properties present in ra.xml
182         * introspectedVals -> All properties with values
183         * obtained by introspection of resource
184         * adapter javabean
185         * mergedVals -> merged props of raConfigPros and
186         * allraConfigPropsWithDefVals
187         */

188
189         Properties mergedVals = null;
190         Set ddVals = messageListener.getConfigProperties();
191         String JavaDoc className = messageListener.getActivationSpecClass();
192         if(className != null && className.length() != 0) {
193             Properties introspectedVals = configParserUtil.introspectJavaBean(
194                                className,ddVals);
195             mergedVals = configParserUtil.mergeProps(ddVals,introspectedVals);
196         }
197         return mergedVals;
198     }
199
200     /** Returns the Properties object consisting of propertyname as the
201      * key and datatype as the value.
202      * @param moduleDir The directory where rar is exploded.
203      * @param messageListenerType message listener type.It is uniqie
204      * across all <messagelistener> sub-elements in <messageadapter>
205      * element in a given rar.
206      * @return Properties object with the property names(key) and datatype
207      * of property(as value).
208      * @throws ConnectorRuntimeException if either of the parameters are null.
209      * If corresponding rar is not deployed i.e moduleDir is invalid.
210      * If messagelistener type is not found in ra.xml
211      */

212     public Properties getJavaBeanReturnTypes(ConnectorDescriptor desc,
213                String JavaDoc messageListenerType) throws ConnectorRuntimeException
214     {
215
216         if(desc == null || messageListenerType == null) {
217             throw new ConnectorRuntimeException("Invalid arguments");
218         }
219
220         MessageListener allMessageListeners[] =
221                ddTransformUtil.getMessageListeners(desc);
222
223         MessageListener messageListener = null;
224         for(int i=0;i<allMessageListeners.length;++i) {
225             if(messageListenerType.equals(
226                     allMessageListeners[i].getMessageListenerType())) {
227                 messageListener = allMessageListeners[i];
228             }
229         }
230
231         if(messageListener == null) {
232             _logger.log(Level.FINE,
233                     "No such MessageListener found in ra.xml",
234                     messageListenerType);
235             throw new ConnectorRuntimeException(
236                   "No such MessageListener found in ra.xml : " +
237                   messageListenerType);
238         }
239
240         /* ddVals -> Properties present in ra.xml
241         * introspectedVals -> All properties with values
242         * obtained by introspection of resource
243         * adapter javabean
244         * mergedVals -> merged props of raConfigPros and
245         * allraConfigPropsWithDefVals
246         */

247
248         Properties mergedVals = null;
249         Set ddVals = messageListener.getConfigProperties();
250         String JavaDoc className = messageListener.getActivationSpecClass();
251         if(className != null && className.length() != 0) {
252             Properties introspectedVals =
253                configParserUtil.introspectJavaBeanReturnTypes(className,ddVals);
254             mergedVals = configParserUtil.mergePropsReturnTypes(
255                                               ddVals,introspectedVals);
256         }
257         return mergedVals;
258     }
259 }
260
Popular Tags