Source Code Cross Referenced for XMLReader.java in  » ESB » open-esb » com » sun » jbi » binding » jms » config » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » open esb » com.sun.jbi.binding.jms.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)XMLReader.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.binding.jms.config;
030:
031:        import com.sun.jbi.StringTranslator;
032:
033:        import com.sun.jbi.binding.jms.JMSBindingContext;
034:
035:        import com.sun.org.apache.xpath.internal.XPathAPI;
036:
037:        import java.io.InputStream;
038:
039:        import java.util.ArrayList;
040:        import java.util.Collection;
041:
042:        import java.util.logging.Logger;
043:
044:        import javax.jbi.JBIException;
045:
046:        import javax.xml.parsers.DocumentBuilder;
047:        import javax.xml.parsers.DocumentBuilderFactory;
048:
049:        import org.w3c.dom.Document;
050:        import org.w3c.dom.Element;
051:
052:        import org.w3c.dom.NodeList;
053:        import org.w3c.dom.Text;
054:
055:        /**
056:         * This configuration reader implementation maps a physical XML file
057:         * representation to a ConfigReader's tree representation. Users instantiate
058:         * an instance of XMLReader to read a XML configuration file and use the
059:         * ConfigElement and ConfigReader's interfaces to read the configuration data.
060:         * For e.g: To read the loglevel from XML file containing
061:         * <pre> <code>
062:         *       &lt;jmsbinding&gt;
063:         *          &lt;loglevel&gt;INFO&lt;/loglevel&gt;
064:         *       &lt;/jmsbinding&gt;
065:         * </code> </pre>
066:         * the user would have to write the following code
067:         * <pre> <code>
068:         *   String logLevel = xmlReader.getConfigurationValue("/jmsbinding/loglevel");
069:         * </code> </pre>
070:         *
071:         * @author Sun Microsystems Inc.
072:         */
073:        public class XMLReader {
074:            /**
075:             * Representation of the configuration file as a DOM object.
076:             */
077:            private Element mRootElement;
078:
079:            /**
080:             * Handle to the logger instance.
081:             */
082:            private Logger mLogger;
083:
084:            /**
085:             * Internal handle to the string translator.
086:             */
087:            private StringTranslator mStringTranslator;
088:
089:            /**
090:             * Creates a new instance of XMLReader.
091:             */
092:            public XMLReader() {
093:                mLogger = JMSBindingContext.getInstance().getLogger();
094:                mStringTranslator = JMSBindingContext.getInstance()
095:                        .getStringTranslator();
096:            }
097:
098:            /**
099:             * This returns the configuration element value as a config element.
100:             *
101:             * @param elementName - Configuration element name.
102:             *
103:             * @return the configuration element value as a config element.
104:             */
105:            public ConfigElement getConfigurationElement(String elementName) {
106:                ConfigElement result = null;
107:
108:                if (mRootElement != null) {
109:                    try {
110:                        Element configElement = (Element) XPathAPI
111:                                .selectSingleNode(mRootElement, elementName);
112:
113:                        if (configElement != null) {
114:                            result = new XMLConfigElement(configElement);
115:                        }
116:                    } catch (Exception exp) {
117:                        exp.printStackTrace();
118:                        result = null;
119:                    }
120:                }
121:
122:                return result;
123:            }
124:
125:            /**
126:             * This returns the configuration element value as a config element array.
127:             *
128:             * @param elementName - Configuration element name.
129:             *
130:             * @return the configuration element values as a config element array.
131:             */
132:            public Collection getConfigurationElementList(String elementName) {
133:                Collection result = new ArrayList();
134:
135:                if (mRootElement != null) {
136:                    try {
137:                        NodeList configElementList = XPathAPI.selectNodeList(
138:                                mRootElement, elementName);
139:
140:                        for (int i = 0; i < configElementList.getLength(); i++) {
141:                            result.add(new XMLConfigElement(
142:                                    (Element) configElementList.item(i)));
143:                        }
144:                    } catch (Exception exp) {
145:                        ;
146:                    }
147:                }
148:
149:                return result;
150:            }
151:
152:            /**
153:             * This returns the configuration element value as a config element array.
154:             *
155:             * @param base is the base element from where the search is to begin.
156:             * @param elementName - Configuration element name.
157:             *
158:             * @return the configuration element values as a config element array.
159:             */
160:            public Collection getConfigurationElementList(Element base,
161:                    String elementName) {
162:                Collection result = new ArrayList();
163:
164:                if (mRootElement != null) {
165:                    try {
166:                        NodeList configElementList = XPathAPI.selectNodeList(
167:                                base, elementName);
168:
169:                        for (int i = 0; i < configElementList.getLength(); i++) {
170:                            result.add(new XMLConfigElement(
171:                                    (Element) configElementList.item(i)));
172:                        }
173:                    } catch (Exception exp) {
174:                        ;
175:                    }
176:                }
177:
178:                return result;
179:            }
180:
181:            /**
182:             * This returns the configuration element value as a string. It returns the
183:             * first node value if there are more than one.
184:             *
185:             * @param elementName - Configuration element name.
186:             *
187:             * @return the configuration element value as a string.
188:             */
189:            public String getConfigurationValue(String elementName) {
190:                String result = null;
191:
192:                if (mRootElement != null) {
193:                    try {
194:                        Element configElement = (Element) XPathAPI
195:                                .selectSingleNode(mRootElement, elementName);
196:
197:                        if (configElement != null) {
198:                            Text textNode = (Text) configElement
199:                                    .getFirstChild();
200:                            result = textNode.getData();
201:                        }
202:                    } catch (Exception exp) {
203:                        ;
204:                    }
205:                }
206:
207:                return result;
208:            }
209:
210:            /**
211:             * This returns a configuration element values as a string array.
212:             *
213:             * @param elementName - Configuration element name.
214:             *
215:             * @return the configuration element values as a string array.
216:             */
217:            public Collection getConfigurationValueList(String elementName) {
218:                Collection result = new ArrayList();
219:
220:                if (mRootElement != null) {
221:                    try {
222:                        NodeList configElementList = XPathAPI.selectNodeList(
223:                                mRootElement, elementName);
224:
225:                        for (int i = 0; i < configElementList.getLength(); i++) {
226:                            Element textElement = (Element) configElementList
227:                                    .item(i);
228:                            Text textNode = (Text) textElement.getFirstChild();
229:                            result.add(textNode.getData());
230:                        }
231:                    } catch (Exception exp) {
232:                        result = null;
233:                    }
234:                }
235:
236:                return result;
237:            }
238:
239:            /**
240:             * Reads the configuration file and stores the content as a DOM object.
241:             *
242:             * @param doc - configuration file name.
243:             *
244:             * @throws JBIException - if the reader cannot be initialized.
245:             */
246:            void init(Document doc) throws JBIException {
247:                try {
248:                    mRootElement = doc.getDocumentElement();
249:                } catch (Exception exception) {
250:                    exception.printStackTrace();
251:
252:                    JBIException jbiException = new JBIException(exception
253:                            .getMessage());
254:                    jbiException.initCause(exception);
255:                    throw jbiException;
256:                }
257:            }
258:
259:            /**
260:             * Reads the input stream and stores the content as a DOM object.
261:             *
262:             * @param fileStream - input file stream.
263:             *
264:             * @throws JBIException jbi exception.
265:             */
266:            void init(InputStream fileStream) throws JBIException {
267:                try {
268:                    DocumentBuilderFactory builderFactory = DocumentBuilderFactory
269:                            .newInstance();
270:                    DocumentBuilder documentBuilder = builderFactory
271:                            .newDocumentBuilder();
272:                    Document configDocument = documentBuilder.parse(fileStream);
273:                    mRootElement = configDocument.getDocumentElement();
274:                } catch (Exception exception) {
275:                    JBIException jbiException = new JBIException(exception
276:                            .getMessage());
277:                    jbiException.initCause(exception);
278:                    throw jbiException;
279:                }
280:            }
281:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.