[jboss-svn-commits] JBL Code SVN: r8307 - labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 13 17:48:40 EST 2006
Author: ddegroff
Date: 2006-12-13 17:48:38 -0500 (Wed, 13 Dec 2006)
New Revision: 8307
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidatorImpl.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/jbossesb.xsd
Removed:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidation.java
Log:
Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidation.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidation.java 2006-12-13 22:47:13 UTC (rev 8306)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidation.java 2006-12-13 22:48:38 UTC (rev 8307)
@@ -1,226 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.soa.esb.listeners.config;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashSet;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-import javax.xml.XMLConstants;
-
-import org.apache.log4j.Logger;
-
-import org.w3c.dom.Document;
-
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
-/**
- * A Helper classes used to validate xml files against supplied schemas.
- *
- * @author $Revision$
- * $Id$
- */
-public class XmlValidation implements XmlValidator {
-
- /**
- * Our Logger
- */
- private Logger log = Logger.getLogger(this.getClass());
-
- private InputSource xmlSource, validationSource;
-
- /**
- * The path separator
- */
- private static String SEP = System.getProperty("file.separator");
-
- private boolean isValid = true;
-
- private Collection<String> validationResults = new HashSet<String>();
-
- private Document xmlDocument;
-
- public XmlValidation() {
- }
-
- public XmlValidation(InputSource xmlSource) {
- setXMLDocument(xmlSource);
- }
-
- /**
- * Validation method used to validate an xml file against a default xsd (jbossesb.xsd).
- * @param xmlSource The xml input source to be validated.
- * @return Boolean true/false indicating successful validation.
- * @throws XmlValidatorException Failure during validation.
- */
- public boolean validate(InputSource xmlSource) throws XmlValidatorException {
- boolean isValid = false;
-
- try {
- SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Source schemaFile = new StreamSource(getClass().getResourceAsStream("jbossesb.xsd"));
- Schema schema = factory.newSchema(schemaFile);
-
- // Request validation
- Validator validator = schema.newValidator();
- // Register the error handler
- validator.setErrorHandler(new XmlErrorHandler());
-
- try {
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder parser = builderFactory.newDocumentBuilder();
-
- validator.validate(new DOMSource(parser.parse(xmlSource)));
- isValid = true;
- } catch (SAXException e) {
- log.error("Failed to validate xml",e);
- throw e;
- } catch (ParserConfigurationException e) {
- log.error("ParserConfigurationException occurred: " + e.getMessage());
- } catch (IOException e) {
- log.error("IOException occurred: " + e.getMessage());
- }
- } catch (SAXException e) {
- log.error("SAXException occurred: " + e.getMessage());
- }
-
- return isValid;
- }
-
- /**
- * Validation method used to validate an xml input source against an xsd input source.
- * @param xmlSource The xml input source to be validated.
- * @param validationSource The schema input source to validate against.
- * @return Boolean true/false indicating successful validation.
- * @throws Exception Failure during validation.
- */
- public boolean validate(InputSource xmlSource, InputSource validationSource) throws XmlValidatorException {
- boolean isValid = false;
-
- setXMLDocument(xmlSource);
-
- try {
- SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema schema = factory.newSchema((Source)validationSource);
- // Request validation
- Validator validator = schema.newValidator();
- // Register the error handler
- validator.setErrorHandler(new XmlErrorHandler());
-
- try {
- validator.validate(new DOMSource(xmlDocument));
- isValid = true;
- } catch (SAXException e) {
- log.error("Failed to validate xml",e);
- throw e;
- } catch (IOException e) {
- log.error("IOException occurred: " + e.getMessage());
- }
- } catch (SAXException e) {
- log.error("SAXException occurred: " + e.getMessage());
- }
-
- return isValid;
- }
-
- class XmlErrorHandler implements ErrorHandler {
- public void warning(SAXParseException exception) throws SAXException {
- // Bring things to a crashing halt
- validationResults.add("**Parsing Warning**" +
- " Line: " +
- exception.getLineNumber() +
- " URI: " +
- exception.getSystemId() +
- " Message: " +
- exception.getMessage());
- throw new SAXException("Warning encountered");
- }
-
- public void error(SAXParseException exception) throws SAXException {
- // Bring things to a crashing halt
- validationResults.add("**Parsing Error**" +
- " Line: " +
- exception.getLineNumber() +
- " URI: " +
- exception.getSystemId() +
- " Message: " +
- exception.getMessage());
- log.error("**Parsing Error**" +
- " Line: " +
- exception.getLineNumber() +
- " URI: " +
- exception.getSystemId() +
- " Message: " +
- exception.getMessage());
- }
-
- public void fatalError(SAXParseException exception) throws SAXException {
- // Bring things to a crashing halt
- validationResults.add("**Parsing Fatal Error**" +
- " Line: " +
- exception.getLineNumber() +
- " URI: " +
- exception.getSystemId() +
- " Message: " +
- exception.getMessage());
- throw new SAXException("Fatal Error encountered");
- }
- }
-
- public Collection<String> getValidationResults() {
- return validationResults;
- }
-
- public void setXMLDocument(InputSource xmlSource) {
- try {
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder parser = builderFactory.newDocumentBuilder();
-
- xmlDocument = parser.parse(xmlSource);
- log.info(xmlDocument.toString());
- } catch (SAXException e) {
- System.err.println(e);
- } catch (ParserConfigurationException e) {
- System.err.println(e);
- } catch (IOException e) {
- System.err.println(e);
- }
- }
-
- public Document getXMLDocument() {
- return xmlDocument;
- }
-
-}
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidatorImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidatorImpl.java 2006-12-13 22:47:13 UTC (rev 8306)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/XmlValidatorImpl.java 2006-12-13 22:48:38 UTC (rev 8307)
@@ -0,0 +1,237 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.config;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+import javax.xml.XMLConstants;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+/**
+ * A Helper classes used to validate xml files against supplied schemas.
+ *
+ * @author $Revision$
+ * $Id$
+ */
+public class XmlValidatorImpl implements XmlValidator {
+
+ /**
+ * Our Logger
+ */
+ private Logger log = Logger.getLogger(this.getClass());
+
+ private InputSource xmlSource, validationSource;
+
+ /**
+ * The path separator
+ */
+ private static String SEP = System.getProperty("file.separator");
+
+ private boolean isValid = true;
+
+ private Collection<String> validationResults = new HashSet();
+
+ private Document xmlDocument;
+
+ public XmlValidatorImpl() {
+ }
+
+ public XmlValidatorImpl(InputSource xmlSource) {
+ setXMLDocument(xmlSource);
+ }
+
+ /**
+ * Validation method used to validate an xml file against a default xsd (jbossesb.xsd).
+ * @param xmlSource The xml input source to be validated.
+ * @return Boolean true/false indicating successful validation.
+ * @throws XmlValidatorException Failure during validation.
+ */
+ public boolean validate(InputSource xmlSource) throws XmlValidatorException {
+
+ try {
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = builderFactory.newDocumentBuilder();
+ xmlDocument = parser.parse(xmlSource);
+ } catch (SAXException e) {
+ log.error("Failed to validate xml",e);
+ isValid = false;
+ } catch (ParserConfigurationException e) {
+ log.error("ParserConfigurationException occurred: " + e.getMessage());
+ isValid = false;
+ } catch (IOException e) {
+ log.error("IOException occurred: " + e.getMessage());
+ isValid = false;
+ }
+
+ SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Source schemaFile = new StreamSource("jbossesb.xsd");
+ Schema schema = null;
+
+ try {
+ schema = factory.newSchema(schemaFile);
+ } catch (SAXException e) {
+ log.error("Failed to validate xml",e);
+ isValid = false;
+ }
+
+ // Request validation
+ Validator validator = schema.newValidator();
+
+ // Register the error handler
+ validator.setErrorHandler(new XmlErrorHandler());
+
+ try {
+ validator.validate(new DOMSource(xmlDocument));
+ } catch (SAXException e) {
+ log.error("Failed to validate xml",e);
+ isValid = false;
+ } catch (IOException e) {
+ log.error("IOException occurred: " + e.getMessage());
+ isValid = false;
+ }
+
+ log.error("validate() - validationResults.size() = "+validationResults.size());
+ return isValid;
+ }
+
+ /**
+ * Validation method used to validate an xml input source against an xsd input source.
+ * @param xmlSource The xml input source to be validated.
+ * @param validationSource The schema input source to validate against.
+ * @return Boolean true/false indicating successful validation.
+ * @throws Exception Failure during validation.
+ */
+ public boolean validate(InputSource xmlSource, InputSource validationSource) throws XmlValidatorException {
+
+ Schema schema = null;
+
+ try {
+ SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ if (validationSource == null) {
+ Source schemaFile = new StreamSource("jbossesb.xsd");
+ try {
+ schema = factory.newSchema(schemaFile);
+ } catch (SAXException e) {
+ log.error("Failed to validate xml",e);
+ isValid = false;
+ }
+ }
+ else {
+ schema = factory.newSchema((Source)validationSource);
+ }
+ // Request validation
+ Validator validator = schema.newValidator();
+ // Register the error handler
+ validator.setErrorHandler(new XmlErrorHandler());
+
+ try {
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = builderFactory.newDocumentBuilder();
+ xmlDocument = parser.parse(xmlSource);
+
+ validator.validate(new DOMSource(xmlDocument));
+ } catch (SAXException e) {
+ log.error("Failed to validate xml",e);
+ isValid = false;
+ } catch (ParserConfigurationException e) {
+ log.error("ParserConfigurationException occurred: " + e.getMessage());
+ isValid = false;
+ } catch (IOException e) {
+ log.error("IOException occurred: " + e.getMessage());
+ isValid = false;
+ }
+ } catch (SAXException e) {
+ log.error("SAXException occurred: " + e.getMessage());
+ isValid = false;
+ }
+
+ return isValid;
+ }
+
+ class XmlErrorHandler implements ErrorHandler {
+ public void warning(SAXParseException exception) throws SAXException {
+ // Bring things to a crashing halt
+ validationResults.add("WARNING-"+exception.getSystemId()+"-"+exception.getLineNumber()+":"+exception.getMessage());
+ log.error("WARNING-"+exception.getSystemId()+"-"+exception.getLineNumber()+":"+exception.getMessage());
+ }
+
+ public void error(SAXParseException exception) throws SAXException {
+ // Bring things to a crashing halt
+ validationResults.add("ERROR-"+exception.getSystemId()+"-"+exception.getLineNumber()+":"+exception.getMessage());
+ log.error(validationResults.size()+"-ERROR-"+exception.getSystemId()+"-"+exception.getLineNumber()+":"+exception.getMessage());
+ isValid = false;
+ }
+
+ public void fatalError(SAXParseException exception) throws SAXException {
+ // Bring things to a crashing halt
+ validationResults.add("FATAL-"+exception.getSystemId()+"-"+exception.getLineNumber()+":"+exception.getMessage());
+ log.error("FATAL-"+exception.getSystemId()+"-"+exception.getLineNumber()+":"+exception.getMessage());
+ isValid = false;
+ }
+ }
+
+ public Collection<String> getValidationResults() {
+ log.error("getValidationResults() = "+validationResults.size());
+ return validationResults;
+ }
+
+ public void setXMLDocument(InputSource xmlSource) {
+ try {
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder parser = builderFactory.newDocumentBuilder();
+
+ xmlDocument = parser.parse(xmlSource);
+ log.info(xmlDocument.toString());
+ } catch (SAXException e) {
+ System.err.println(e);
+ } catch (ParserConfigurationException e) {
+ System.err.println(e);
+ } catch (IOException e) {
+ System.err.println(e);
+ }
+ }
+
+ public Document getXMLDocument() {
+ return xmlDocument;
+ }
+
+}
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/jbossesb.xsd
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/jbossesb.xsd 2006-12-13 22:47:13 UTC (rev 8306)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/jbossesb.xsd 2006-12-13 22:48:38 UTC (rev 8307)
@@ -0,0 +1,145 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<!--Generated by Turbo XML 2.4.1.100. Conforms to w3c http://www.w3.org/2001/XMLSchema-->
+<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
+ elementFormDefault = "qualified">
+ <xsd:element name = "jbossesb">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref = "hosts"/>
+ <xsd:element ref = "servers"/>
+ <xsd:element ref = "buses"/>
+ <xsd:element ref = "services"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "hosts">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref = "host" maxOccurs = "unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "host">
+ <xsd:complexType>
+ <xsd:attribute name = "name" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "dnsName" use = "required">
+ <xsd:simpleType>
+ <xsd:restriction base = "xsd:NMTOKEN">
+ <xsd:enumeration value = "localhost"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "servers">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref = "server" maxOccurs = "unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "server">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref = "properties" minOccurs="0"/>
+ </xsd:sequence>
+ <xsd:attribute name = "name" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "host" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "appserver" use = "required" type = "xsd:string"/>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "properties">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref = "property" maxOccurs = "unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "property">
+ <xsd:complexType>
+ <xsd:attribute name = "name" use = "required">
+ <xsd:simpleType>
+ <xsd:restriction base = "xsd:NMTOKEN">
+ <xsd:enumeration value = "java.naming.factory.initial"/>
+ <xsd:enumeration value = "java.naming.provider.url"/>
+ <xsd:enumeration value = "java.naming.factory.url.pkgs"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:attribute>
+ <xsd:attribute name = "value" use = "required">
+ <xsd:simpleType>
+ <xsd:restriction base = "xsd:NMTOKEN">
+ <xsd:enumeration value = "org.jnp.interfaces.NamingContextFactory"/>
+ <xsd:enumeration value = "localhost:1099"/>
+ <xsd:enumeration value = "org.jboss.naming:org.jnp.interfaces"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "buses">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref = "bus" maxOccurs = "unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "bus">
+ <xsd:complexType>
+ <xsd:attribute name = "password" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "name" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "resourceType" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "userName" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "server" use = "required" type = "xsd:string"/>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "services">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref = "service"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "service">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref = "listeners"/>
+ <xsd:element ref = "actions"/>
+ </xsd:sequence>
+ <xsd:attribute name = "name" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "description" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "category" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "class" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "server" use = "required" type = "xsd:string"/>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "listeners">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref = "listener" maxOccurs = "unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "listener">
+ <xsd:complexType>
+ <xsd:attribute name = "bus" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "description" use = "required" type = "xsd:string"/>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "actions">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref = "action"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name = "action">
+ <xsd:complexType>
+ <xsd:attribute name = "service-category" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "name" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "service-name" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "class" use = "required" type = "xsd:string"/>
+ <xsd:attribute name = "process" use = "required" type = "xsd:string"/>
+ </xsd:complexType>
+ </xsd:element>
+</xsd:schema>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list