geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1161728 - /geronimo/bundles/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
Date Thu, 25 Aug 2011 20:13:44 GMT
Author: dblevins
Date: Thu Aug 25 20:13:44 2011
New Revision: 1161728

URL: http://svn.apache.org/viewvc?rev=1161728&view=rev
Log:
Inline validation-mapping-1.0.xsd as well

Modified:
    geronimo/bundles/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java

Modified: geronimo/bundles/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
URL: http://svn.apache.org/viewvc/geronimo/bundles/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java?rev=1161728&r1=1161727&r2=1161728&view=diff
==============================================================================
--- geronimo/bundles/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
(original)
+++ geronimo/bundles/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
Thu Aug 25 20:13:44 2011
@@ -54,6 +54,10 @@ import org.xml.sax.SAXException;
 @SuppressWarnings("restriction")
 public class ValidationParser {
     private static final String DEFAULT_VALIDATION_XML_FILE = "META-INF/validation.xml";
+
+    private static final String VALIDATION_CONFIGURATION_XSD = "META-INF/validation-configuration-1.0.xsd";
+    private static final String VALIDATION_MAPPING_XSD = "META-INF/validation-mapping-1.0.xsd";
+
     private static final Logger log = LoggerFactory.getLogger(ValidationParser.class);
     private final String validationXmlFile;
 
@@ -91,7 +95,7 @@ public class ValidationParser {
 
             log.debug("{} found.", validationXmlFile);
 
-            Schema schema = getSchema();
+            Schema schema = getSchema(new ValidationConfigurationSchemaSource());
             JAXBContext jc = JAXBContext.newInstance(ValidationConfigType.class);
             Unmarshaller unmarshaller = jc.createUnmarshaller();
             unmarshaller.setSchema(schema);
@@ -129,12 +133,12 @@ public class ValidationParser {
     /**
      * Get a Schema object from the specified resource name.
      * @return {@link Schema}
+     * @param schemaSource
      */
-    private Schema getSchema() {
+    private static Schema getSchema(Source schemaSource) {
         SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-        Source source = new ValidationSchemaSource();
         try {
-            return sf.newSchema(source);
+            return sf.newSchema(schemaSource);
         } catch (SAXException e) {
             e.printStackTrace();
             return null;
@@ -147,6 +151,13 @@ public class ValidationParser {
      * @return {@link Schema}
      */
     static Schema getSchema(String xsd) {
+        if (VALIDATION_CONFIGURATION_XSD.equals(xsd)) return getSchema(new ValidationConfigurationSchemaSource());
+        if (VALIDATION_MAPPING_XSD.equals(xsd)) return getSchema(new ValidationMappingSchemaSource());
+
+        return getSchemaFromClasspath(xsd);
+    }
+
+    private static Schema getSchemaFromClasspath(String xsd) {
         ClassLoader loader = PrivilegedActions.getClassLoader(ValidationParser.class);
         SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
         URL schemaUrl = loader.getResource(xsd);
@@ -257,9 +268,9 @@ public class ValidationParser {
         }
     }
 
-    private static final class ValidationSchemaSource extends StreamSource {
+    private static final class ValidationConfigurationSchemaSource extends StreamSource {
 
-        private ValidationSchemaSource() {
+        private ValidationConfigurationSchemaSource() {
             super(new StringReader(xsd()));
         }
 
@@ -293,4 +304,167 @@ public class ValidationParser {
                     "</xs:schema>";
         }
     }
+
+    private static final class ValidationMappingSchemaSource extends StreamSource {
+
+        private ValidationMappingSchemaSource() {
+            super(new StringReader(xsd()));
+        }
+
+        private static String xsd() {
+            return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                    "<xs:schema attributeFormDefault=\"unqualified\"\n" +
+                    "           elementFormDefault=\"qualified\"\n" +
+                    "           targetNamespace=\"http://jboss.org/xml/ns/javax/validation/mapping\"\n"
+
+                    "           xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" +
+                    "           version=\"1.0\">\n" +
+                    "    <xs:element name=\"constraint-mappings\"\n" +
+                    "                type=\"map:constraint-mappingsType\"\n" +
+                    "                xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "\n" +
+                    "    <xs:complexType name=\"payloadType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"xs:string\" name=\"value\" maxOccurs=\"unbounded\"
minOccurs=\"0\"/>\n" +
+                    "        </xs:sequence>\n" +
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"groupsType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"xs:string\" name=\"value\" maxOccurs=\"unbounded\"
minOccurs=\"0\"/>\n" +
+                    "        </xs:sequence>\n" +
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"groupSequenceType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"xs:string\" name=\"value\" maxOccurs=\"unbounded\"
minOccurs=\"0\"/>\n" +
+                    "        </xs:sequence>\n" +
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"constraint-mappingsType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"xs:string\" name=\"default-package\"
minOccurs=\"0\"/>\n" +
+                    "            <xs:element type=\"map:beanType\"\n" +
+                    "                        name=\"bean\"\n" +
+                    "                        maxOccurs=\"unbounded\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "            <xs:element type=\"map:constraint-definitionType\"\n"
+
+                    "                        name=\"constraint-definition\"\n" +
+                    "                        maxOccurs=\"unbounded\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "        </xs:sequence>\n" +
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"validated-byType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"xs:string\" name=\"value\" maxOccurs=\"unbounded\"
minOccurs=\"0\"/>\n" +
+                    "        </xs:sequence>\n" +
+                    "        <xs:attribute type=\"xs:boolean\" name=\"include-existing-validators\"
use=\"optional\"/>\n" +
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"constraintType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"xs:string\" name=\"message\" minOccurs=\"0\"/>\n"
+
+                    "            <xs:element type=\"map:groupsType\"\n" +
+                    "                        name=\"groups\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "            <xs:element type=\"map:payloadType\"\n" +
+                    "                        name=\"payload\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>
           \n" +
+                    "            <xs:element type=\"map:elementType\"\n" +
+                    "                        name=\"element\"\n" +
+                    "                        maxOccurs=\"unbounded\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "        </xs:sequence>\n" +
+                    "        <xs:attribute type=\"xs:string\" name=\"annotation\" use=\"required\"/>\n"
+
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"elementType\" mixed=\"true\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"xs:string\" name=\"value\" maxOccurs=\"unbounded\"
minOccurs=\"0\"/>\n" +
+                    "            <xs:element type=\"map:annotationType\"\n" +
+                    "                        name=\"annotation\"\n" +
+                    "                        maxOccurs=\"unbounded\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "        </xs:sequence>\n" +
+                    "        <xs:attribute type=\"xs:string\" name=\"name\" use=\"required\"/>\n"
+
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"classType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"map:groupSequenceType\" \n" +
+                    "                        name=\"group-sequence\" \n" +
+                    "                        minOccurs=\"0\" \n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "            <xs:element type=\"map:constraintType\"\n" +
+                    "                        name=\"constraint\"\n" +
+                    "                        maxOccurs=\"unbounded\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "        </xs:sequence>\n" +
+                    "        <xs:attribute type=\"xs:boolean\" name=\"ignore-annotations\"
use=\"optional\"/>\n" +
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"beanType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"map:classType\"\n" +
+                    "                        name=\"class\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\">\n"
+
+                    "            </xs:element>\n" +
+                    "            <xs:element type=\"map:fieldType\"\n" +
+                    "                        name=\"field\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        maxOccurs=\"unbounded\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "            <xs:element type=\"map:getterType\"\n" +
+                    "                        name=\"getter\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        maxOccurs=\"unbounded\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "        </xs:sequence>\n" +
+                    "        <xs:attribute type=\"xs:string\" name=\"class\" use=\"required\"/>\n"
+
+                    "        <xs:attribute type=\"xs:boolean\" name=\"ignore-annotations\"
use=\"optional\"/>\n" +
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"annotationType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"map:elementType\"\n" +
+                    "                        name=\"element\"\n" +
+                    "                        maxOccurs=\"unbounded\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "        </xs:sequence>\n" +
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"getterType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"xs:string\" name=\"valid\" minOccurs=\"0\"
fixed=\"\"/>\n" +
+                    "            <xs:element type=\"map:constraintType\"\n" +
+                    "                        name=\"constraint\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        maxOccurs=\"unbounded\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "        </xs:sequence>\n" +
+                    "        <xs:attribute type=\"xs:string\" name=\"name\" use=\"required\"/>\n"
+
+                    "        <xs:attribute type=\"xs:boolean\" name=\"ignore-annotations\"
use=\"optional\"/>\n" +
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"constraint-definitionType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"map:validated-byType\"\n" +
+                    "                        name=\"validated-by\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "        </xs:sequence>\n" +
+                    "        <xs:attribute type=\"xs:string\" name=\"annotation\" use=\"required\"/>\n"
+
+                    "    </xs:complexType>\n" +
+                    "    <xs:complexType name=\"fieldType\">\n" +
+                    "        <xs:sequence>\n" +
+                    "            <xs:element type=\"xs:string\" name=\"valid\" minOccurs=\"0\"
fixed=\"\"/>\n" +
+                    "            <xs:element type=\"map:constraintType\"\n" +
+                    "                        name=\"constraint\"\n" +
+                    "                        minOccurs=\"0\"\n" +
+                    "                        maxOccurs=\"unbounded\"\n" +
+                    "                        xmlns:map=\"http://jboss.org/xml/ns/javax/validation/mapping\"/>\n"
+
+                    "        </xs:sequence>\n" +
+                    "        <xs:attribute type=\"xs:string\" name=\"name\" use=\"required\"/>\n"
+
+                    "        <xs:attribute type=\"xs:boolean\" name=\"ignore-annotations\"
use=\"optional\"/>\n" +
+                    "    </xs:complexType>\n" +
+                    "</xs:schema>";
+        }
+    }
 }



Mime
View raw message