[utilities COMMIT] in /java-support/trunk/src: main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java...

noreply at shibboleth.net noreply at shibboleth.net
Fri Feb 20 17:25:10 EST 2015


Author: putmanb
Date: Fri Feb 20 17:25:10 2015
New Revision: 760

URL: http://svn.shibboleth.net/view/utilities?rev=760&view=rev
Log:
JSPT-52: In SchemaBuilder add overloaded setSchemas which is more Spring-friendly.
Due to generics erasure, had to actually call the method setSchemaResources.
Properly implement @NullableElements in both methods will null checks.
Take off erroneous @NullableElements on method params which are not collections.
Had to pull in copy of ResourceHelper from spring-extensions for testing, since can't declare a circular dependency.  

Added:
    java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/resource/ResourceTestHelper.java   (with props)
Modified:
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java
    java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/xml/SchemaBuilderTest.java

Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java?rev=760&r1=759&r2=760&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SchemaBuilder.java Fri Feb 20 17:25:10 2015
@@ -17,6 +17,7 @@
 
 package net.shibboleth.utilities.java.support.xml;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -38,6 +39,7 @@
 import net.shibboleth.utilities.java.support.annotation.constraint.NullableElements;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import net.shibboleth.utilities.java.support.resource.Resource;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -201,10 +203,32 @@
 
         resetSchemas();
         for (final Source schemaSource : schemaSources) {
-            addSchema(schemaSource);
-        }
-    }
-    
+            if (schemaSource != null) {
+                addSchema(schemaSource);
+            }
+        }
+    }
+    
+    /**
+     * Set the schemas to load from the given schema resources (replaces any previously added).
+     * 
+     * <p>If the caller wishes to ensure the schemas are loaded in a particular order,
+     * the {@link Collection} implementation provided must be one that preserves order.
+     * The method will add the sources in the order returned by the collection.</p>
+     * 
+     * @param schemaResources schema resources
+     */
+    @Nonnull public void setSchemaResources(@Nonnull @NullableElements final Collection<Resource> schemaResources) {
+        Constraint.isNotNull(schemaResources, "Schema resources cannot be null");
+
+        resetSchemas();
+        for (final Resource schemaResource : schemaResources) {
+            if (schemaResource != null) {
+                addSchema(schemaResource);
+            }
+        }
+    }
+
     /**
      * Add schemas from the given schema input streams.
      * 
@@ -212,7 +236,7 @@
      * 
      * @return this builder
      */
-    @Nonnull public SchemaBuilder addSchema(@Nonnull @NullableElements final InputStream schemaSource) {
+    @Nonnull public SchemaBuilder addSchema(@Nonnull final InputStream schemaSource) {
         Constraint.isNotNull(schemaSource, "Schema source input stream cannot be null");
 
         addSchema(new StreamSource(schemaSource));
@@ -227,10 +251,29 @@
      * 
      * @return this builder
      */
-    @Nonnull public SchemaBuilder addSchema(@Nonnull @NullableElements final Source schemaSource) {
+    @Nonnull public SchemaBuilder addSchema(@Nonnull final Source schemaSource) {
         Constraint.isNotNull(schemaSource, "Schema source inputstreams can not be null");
 
         sources.add(schemaSource);
+
+        return this;
+    }
+    
+    /**
+     * Add schemas from the given schema resource.
+     * 
+     * @param resource schema input resource
+     * 
+     * @return this builder
+     */
+    @Nonnull public SchemaBuilder addSchema(@Nonnull final Resource resource) {
+        Constraint.isNotNull(resource, "Schema resource cannot be null");
+
+        try {
+            addSchema(resource.getInputStream());
+        } catch (IOException e) {
+            log.error("IO error adding schema from resource: {}", resource.getDescription(), e);
+        }
 
         return this;
     }

Modified: java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/xml/SchemaBuilderTest.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/xml/SchemaBuilderTest.java?rev=760&r1=759&r2=760&view=diff
==============================================================================

[... 40 lines stripped ...]


More information about the commits mailing list