Source Code Cross Referenced for ConfigFileValidator.java in  » ESB » open-esb » com » sun » jbi » common » 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.common 
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:         * @(#)ConfigFileValidator.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.common;
030:
031:        import org.w3c.dom.Document;
032:        import org.xml.sax.SAXException;
033:        import org.xml.sax.SAXParseException;
034:        import org.xml.sax.helpers.DefaultHandler;
035:
036:        import java.io.IOException;
037:
038:        import java.util.logging.Logger;
039:
040:        import javax.xml.parsers.DocumentBuilder;
041:        import javax.xml.parsers.DocumentBuilderFactory;
042:        import javax.xml.parsers.ParserConfigurationException;
043:
044:        /*
045:         * ConfigFileValidator.java
046:         *
047:         * SUN PROPRIETARY/CONFIDENTIAL.
048:         * This software is the proprietary information of Sun Microsystems, Inc.
049:         * Use is subject to license terms.
050:         *
051:         */
052:
053:        /**
054:         * This class is uses to validate the configuration file supplied during deployment
055:         * conforms to the schema.
056:         *
057:         * @author Sun Microsystems, Inc.
058:         */
059:        public final class ConfigFileValidator extends DefaultHandler {
060:            /**
061:             * Parser setting.
062:             */
063:            static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
064:
065:            /**
066:             * Parser setting.
067:             */
068:            static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
069:
070:            /**
071:             * Parser setting.
072:             */
073:            static final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
074:
075:            /**
076:             * Document object generated after parsing.
077:             */
078:            private Document mDocument;
079:
080:            /**
081:             * Factory object for document.
082:             */
083:            private DocumentBuilderFactory mFactory = null;
084:
085:            /**
086:             *    
087:             */
088:            private Exception mException;
089:
090:            /**
091:             * Logger object.
092:             */
093:            private Logger mLog;
094:
095:            /**
096:             * Stores the error message , if any.
097:             */
098:            private String mErrorMsg = "";
099:
100:            /**
101:             * Name of the file to parse.
102:             */
103:            private String mFileName;
104:
105:            /**
106:             * Name of the schema file.
107:             */
108:            private String mSchemaFile;
109:
110:            /**
111:             * Flag to denote validity.
112:             */
113:            private boolean mValid = true;
114:
115:            /**
116:             * Creates a new ConfigFileValidator object.
117:             *
118:             * @param schema schema file name
119:             * @param xmlfile xml file name
120:             */
121:            public ConfigFileValidator(String schema, String xmlfile) {
122:                mFactory = DocumentBuilderFactory.newInstance();
123:                mFactory.setNamespaceAware(true);
124:                mFactory.setValidating(false);
125:                mSchemaFile = schema;
126:                mFileName = xmlfile;
127:                mLog = Logger.getLogger(this .getClass().getPackage().getName());
128:            }
129:
130:            /**
131:             * Returns the document object obtained as a result of parsing.
132:             *
133:             * @return document object
134:             */
135:            public Document getDocument() {
136:                return mDocument;
137:            }
138:
139:            /**
140:             * Returns the error message if any.
141:             *
142:             * @return String error message.
143:             */
144:            public String getError() {
145:                return mErrorMsg;
146:            }
147:
148:            /**
149:             * DOCUMENT ME!
150:             *
151:             * @return NOT YET DOCUMENTED
152:             */
153:            public Exception getException() {
154:                return mException;
155:            }
156:
157:            /**
158:             * Returns true if the file conforms to schema.
159:             *
160:             * @return valid / invalid
161:             */
162:            public boolean isValid() {
163:                return mValid;
164:            }
165:
166:            /**
167:             * sets the parser as validating or non-validating.
168:             */
169:            public void setValidating() {
170:                setAttributes();
171:            }
172:
173:            /**
174:             * Handler method for the parser.
175:             *
176:             * @param se sax parse exception object.
177:             */
178:            public void error(SAXParseException se) {
179:                mLog.severe(se.getMessage());
180:                setError(getError() + "\n\t" + "Line:" + se.getLineNumber()
181:                        + ", Column:" + se.getColumnNumber() + ":"
182:                        + se.getMessage());
183:                setException(se);
184:                mValid = false;
185:            }
186:
187:            /**
188:             * Handler method for the parser.
189:             *
190:             * @param se SAXPrse exception.
191:             */
192:            public void fatalError(SAXParseException se) {
193:                mLog.severe(getError() + "\n\t" + "Line:" + se.getLineNumber()
194:                        + ",Column:" + se.getColumnNumber() + ":"
195:                        + se.getMessage());
196:                setError(se.getMessage());
197:                setException(se);
198:                mValid = false;
199:            }
200:
201:            /**
202:             * This method has to be invoked to check the validity of the input document.
203:             */
204:            public void validate() {
205:                parse();
206:            }
207:
208:            /**
209:             * Handler method for the parser.
210:             *
211:             * @param se SAXParseexception.
212:             */
213:            public void warning(SAXParseException se) {
214:                mLog.warning(se.getLineNumber() + ":" + se.getColumnNumber()
215:                        + ":" + se.getMessage());
216:            }
217:
218:            /**
219:             * Sets the attributes of the parser.
220:             */
221:            private void setAttributes() {
222:                mFactory.setValidating(true);
223:
224:                try {
225:                    mFactory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
226:                    mFactory.setAttribute(JAXP_SCHEMA_SOURCE, mSchemaFile);
227:                    mFactory.setIgnoringElementContentWhitespace(true);
228:                    mFactory.setNamespaceAware(true);
229:                } catch (IllegalArgumentException iae) {
230:                    setError(iae.getMessage());
231:                    setException(iae);
232:                    mValid = false;
233:                    iae.printStackTrace();
234:                }
235:            }
236:
237:            /**
238:             * Used to set error message if occurs during parsing.
239:             *
240:             * @param msg error message that occurred.
241:             */
242:            private void setError(String msg) {
243:                mErrorMsg = msg;
244:            }
245:
246:            /**
247:             * DOCUMENT ME!
248:             *
249:             * @param e NOT YET DOCUMENTED
250:             */
251:            private void setException(Exception e) {
252:                mException = e;
253:            }
254:
255:            /**
256:             * Parses the input XML file.
257:             */
258:            private void parse() {
259:                DocumentBuilder builder = null;
260:
261:                try {
262:                    builder = mFactory.newDocumentBuilder();
263:                } catch (ParserConfigurationException pce) {
264:                    mLog.severe(pce.getMessage());
265:                    setError(pce.getMessage());
266:                    setException(pce);
267:                    mValid = false;
268:                }
269:
270:                builder.setErrorHandler(this );
271:
272:                try {
273:                    mDocument = builder.parse(mFileName);
274:                } catch (SAXException se) {
275:                    mLog.severe("Cannot parse file " + mFileName);
276:                    mLog.severe(se.getMessage());
277:                    setError("Cannot Parse " + "\n" + se.getMessage());
278:                    setException(se);
279:                    se.printStackTrace();
280:                    mValid = false;
281:                } catch (IOException ioe) {
282:                    mLog.severe(ioe.getMessage());
283:                    setError("Cannot parse " + "\n" + ioe.getMessage());
284:                    setException(ioe);
285:                    ioe.printStackTrace();
286:                    mValid = false;
287:                }
288:            }
289:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.