aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1701097 - in /aries/trunk/blueprint: blueprint-core/pom.xml blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java
Date Thu, 03 Sep 2015 18:34:56 GMT
Author: dkulp
Date: Thu Sep  3 18:34:55 2015
New Revision: 1701097

URL: http://svn.apache.org/r1701097
Log:
[ARIES-1395] Support validation of structure only, not data content
Patch from Aki Yoshida applied

Modified:
    aries/trunk/blueprint/blueprint-core/pom.xml
    aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
    aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java

Modified: aries/trunk/blueprint/blueprint-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/pom.xml?rev=1701097&r1=1701096&r2=1701097&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/pom.xml (original)
+++ aries/trunk/blueprint/blueprint-core/pom.xml Thu Sep  3 18:34:55 2015
@@ -91,7 +91,7 @@
         </aries.osgi.include.resource>
         <blueprint.annotation.api.version>1.0.0</blueprint.annotation.api.version>
         <blueprint.api.version>1.0.0</blueprint.api.version>
-        <blueprint.parser.version>1.3.0</blueprint.parser.version>
+        <blueprint.parser.version>1.3.2-SNAPSHOT</blueprint.parser.version>
         <proxy.api.version>1.0.0</proxy.api.version>
         <proxy.impl.version>1.0.3</proxy.impl.version>
         <quiesce.api.version>1.0.0</quiesce.api.version>

Modified: aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java?rev=1701097&r1=1701096&r2=1701097&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
(original)
+++ aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintContainerImpl.java
Thu Sep  3 18:34:55 2015
@@ -94,6 +94,9 @@ import org.osgi.service.blueprint.reflec
 import org.osgi.service.blueprint.reflect.Target;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 /**
  * TODO: javadoc
@@ -147,7 +150,7 @@ public class BlueprintContainerImpl
     private Map<String, List<SatisfiableRecipe>> satisfiables;
     private long timeout = 5 * 60 * 1000;
     private boolean waitForDependencies = true;
-    private boolean xmlValidation = true;
+    private String xmlValidation;
     private ScheduledFuture timeoutFuture;
     private final AtomicBoolean scheduled = new AtomicBoolean();
     private List<ServiceRecipe> services;
@@ -220,11 +223,9 @@ public class BlueprintContainerImpl
             waitForDependencies = Boolean.parseBoolean(graceperiod);
         }
 
-        String xmlValidationDirective = paths.get(0).getDirective(BlueprintConstants.XML_VALIDATION);
-        if (xmlValidationDirective != null) {
-            LOGGER.debug("Xml-validation directive: {}", xmlValidationDirective);
-            xmlValidation = Boolean.parseBoolean(xmlValidationDirective);
-        }
+        xmlValidation = paths.get(0).getDirective(BlueprintConstants.XML_VALIDATION);
+        // enabled if null or "true"; structure-only if "structure"; disabled otherwise
+        LOGGER.debug("Xml-validation directive: {}", xmlValidation);
     }
 
     public void schedule() {
@@ -244,7 +245,7 @@ public class BlueprintContainerImpl
             this.processors = new ArrayList<Processor>();
             timeout = 5 * 60 * 1000;
             waitForDependencies = true;
-            xmlValidation = true;
+            xmlValidation = null;
             if (handlerSet != null) {
                 handlerSet.removeListener(this);
                 handlerSet.destroy();
@@ -317,8 +318,10 @@ public class BlueprintContainerImpl
                             return;
                         }
                         resetComponentDefinitionRegistry();
-                        if (xmlValidation) {
+                        if (xmlValidation == null || "true".equals(xmlValidation)) {
                             parser.validate(handlerSet.getSchema());
+                        } else if ("structure".equals(xmlValidation)) {
+                            parser.validate(handlerSet.getSchema(), new ValidationHandler());
                         }
                         parser.populate(handlerSet, componentDefinitionRegistry);
                         state = State.Populated;
@@ -942,4 +945,26 @@ public class BlueprintContainerImpl
             ExecutionContext.Holder.setContext(origContext);
         }
     }
+
+    // this could be parameterized/customized, but for now, hard-coded for ignoring datatype
validation
+    private static class ValidationHandler implements ErrorHandler {
+        @Override
+        public void warning(SAXParseException exception) throws SAXException {
+            // ignore
+        }
+        @Override
+        public void error(SAXParseException exception) throws SAXException {
+            final String cvctext = exception.getMessage(); 
+            if (cvctext != null && 
+                (cvctext.startsWith("cvc-datatype-valid.1") || cvctext.startsWith("cvc-attribute.3")))
{
+                return;
+            }
+            throw exception;
+        }
+
+        @Override
+        public void fatalError(SAXParseException exception) throws SAXException {
+            throw exception;
+        }
+    }
 }

Modified: aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java?rev=1701097&r1=1701096&r2=1701097&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java
(original)
+++ aries/trunk/blueprint/blueprint-parser/src/main/java/org/apache/aries/blueprint/parser/Parser.java
Thu Sep  3 18:34:55 2015
@@ -88,6 +88,7 @@ import org.w3c.dom.EntityReference;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
+import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
 
 /**
@@ -308,8 +309,15 @@ public class Parser {
     }
 
     public void validate(Schema schema) {
+        validate(schema, null);
+    }
+
+    public void validate(Schema schema, ErrorHandler errorHandler) {
         try {
             Validator validator = schema.newValidator();
+            if (errorHandler != null) {
+                validator.setErrorHandler(errorHandler);
+            }
             for (Document doc : this.documents) {
                 validator.validate(new DOMSource(doc));
             }
@@ -1411,5 +1419,4 @@ public class Parser {
         }
         return documentBuilderFactory;
     }
-
 }



Mime
View raw message