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