KickJava   Java API By Example, From Geeks To Geeks.

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


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

24
25 package com.sun.enterprise.connectors.util;
26
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.config.serverbeans.ElementProperty;
29 import com.sun.enterprise.connectors.*;
30 import com.sun.enterprise.util.*;
31 import com.sun.logging.LogDomains;
32 import java.util.logging.*;
33 import java.util.*;
34 import java.lang.*;
35 import java.lang.reflect.*;
36 import java.io.IOException JavaDoc;
37 import org.xml.sax.SAXParseException JavaDoc;
38 import com.sun.enterprise.util.i18n.StringManager;
39
40 /**
41  * This is AdminObject configuration parser. It parses the ra.xml file
42  * for the admin object specific configurations like AdminObject javabeans
43  * properties .
44  *
45  * @author Srikanth P
46  *
47  */

48
49 public class AdminObjectConfigParserImpl implements AdminObjectConfigParser {
50
51     static Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
52
53     /**
54      * Default constructor.
55      *
56      */

57
58     public AdminObjectConfigParserImpl() {
59
60     }
61
62     /** Parses the ra.xml for the admin object javabean properties.
63      * The admin object to be parsed is identified by the moduleDir
64      * where ra.xml is present and the adminObject interface.
65      * Admin object interface will be unique in a given ra.xml.
66      *
67      * It throws ConnectorRuntimeException if either or both the
68      * parameters are null, if corresponding rar is not deployed,
69      * if no adminObjectInterce is found in ra.xml. If rar is deployed
70      * and admin Object interface is present but no properties are
71      * present for the corresponding adminobjectInterface, null is returned.
72      *
73      * @param desc ConnectorDescriptor pertaining to rar.
74      * @param adminObjectInterface AdminObject interface which is unique
75      * across all the admin Object elements in a given rar.
76      * @return Javabean properties with the propety names and values
77      * of propeties. The property values will be the values
78      * mentioned in ra.xml if present. Otherwise it will be the
79      * default values obtained by introspecting the javabean.
80      * In both the case if no value is present, empty String is
81      * returned as the value.
82      * @throws ConnectorRuntimeException if either of the parameters are null.
83      * If corresponding rar is not deployed i.e moduleDir is invalid.
84      * If no admin object intercface is found in ra.xml
85      */

86
87     public Properties getJavaBeanProps(ConnectorDescriptor desc,
88                String JavaDoc adminObjectInterface, String JavaDoc rarName) throws ConnectorRuntimeException
89     {
90
91         if(desc == null || adminObjectInterface == null) {
92             throw new ConnectorRuntimeException("Invalid arguments");
93         }
94
95         Set adminObjectSet = desc.getAdminObjects();
96         if(adminObjectSet== null || adminObjectSet.size() == 0) {
97             return null;
98         }
99         AdminObject adminObject = null;
100         Iterator iter = adminObjectSet.iterator();
101         Properties mergedVals = null;
102         boolean adminInterfaceFound = false;
103         while(iter.hasNext()) {
104             adminObject = (AdminObject)iter.next();
105             if(adminObjectInterface.equals(
106                            adminObject.getAdminObjectInterface())) {
107                 adminInterfaceFound = true;
108                 break;
109             }
110         }
111       
112         if(adminInterfaceFound == false) {
113             StringManager localStrings =
114                     StringManager.getManager(AdminObjectConfigParserImpl.class);
115             String JavaDoc msg = localStrings.getString(
116                     "no_adminobject_interface_found_in_raxml", adminObjectInterface);
117             _logger.log(Level.FINE, msg);
118             throw new ConnectorRuntimeException(msg);
119         }
120
121         /* ddVals -> Properties present in ra.xml
122         * introspectedVals -> All properties with values
123         * obtained by introspection of resource
124         * adapter javabean
125         * mergedVals -> merged props of raConfigPros and
126         * allraConfigPropsWithDefVals
127         */

128         Set ddVals = adminObject.getConfigProperties();
129         String JavaDoc className = adminObject.getAdminObjectClass();
130         if(className != null && className.length() != 0) {
131             Properties introspectedVals =
132                     configParserUtil.introspectJavaBean(className, ddVals);
133             mergedVals = configParserUtil.mergeProps(ddVals,introspectedVals);
134         }
135         return mergedVals;
136     }
137
138     /**
139      * gets the adminObjectInterfaceNames pertaining to a rar.
140      * @param desc ConnectorDescriptor pertaining to rar.
141      * @return Array of AdminObjectInterface names as Strings
142      * @throws ConnectorRuntimeException if parsing fails
143      */

144     public String JavaDoc[] getAdminObjectInterfaceNames(ConnectorDescriptor desc)
145                        throws ConnectorRuntimeException
146     {
147
148         if(desc == null) {
149             throw new ConnectorRuntimeException("Invalid arguments");
150         }
151
152         Set adminObjectSet = desc.getAdminObjects();
153         if(adminObjectSet == null || adminObjectSet.size() == 0) {
154             return null;
155         }
156         String JavaDoc[] adminObjectInterfaceNames = new String JavaDoc[adminObjectSet.size()];
157         Iterator it = adminObjectSet.iterator();
158         AdminObject aor = null;
159         for(int i=0;it.hasNext();++i) {
160             aor = (AdminObject) it.next();
161             adminObjectInterfaceNames[i] = aor.getAdminObjectInterface();
162         }
163         return adminObjectInterfaceNames;
164     }
165
166 }
167
Popular Tags