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

noreply at shibboleth.net noreply at shibboleth.net
Tue Jan 31 11:31:39 GMT 2012


Author: rdw
Date: Tue Jan 31 11:31:39 2012
New Revision: 224

URL: http://svn.shibboleth.net/view/utilities?rev=224&view=rev
Log:
Add tests and bug fixes for BasicParserPool.  These are:
  - Minor method name changes 
  - Component is now tristated (Initialized, Destroyed, Neither)
  - Search entire cache for non-GC'd DocumentBuilders before we create one
  - Also remove vestiges of JUnit from tests and replace some superceded tests
 Also Cleanup in SeralizeSupport & SchemaBuilderTest

Added:
    java-support/trunk/src/test/resources/data/net/shibboleth/utilities/java/support/xml/basicParserPoolTest.xml   (with props)
    java-support/trunk/src/test/resources/data/net/shibboleth/utilities/java/support/xml/basicParserPoolTest.xsd   (with props)
Modified:
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/BasicParserPool.java
    java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/SerializeSupport.java
    java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/xml/BasicParserPoolTest.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/BasicParserPool.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/BasicParserPool.java?rev=224&r1=223&r2=224&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/BasicParserPool.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/xml/BasicParserPool.java Tue Jan 31 11:31:39 2012
@@ -38,6 +38,7 @@
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
 import net.shibboleth.utilities.java.support.annotation.constraint.NullableElements;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.component.DestroyedComponentException;
 import net.shibboleth.utilities.java.support.component.InitializableComponent;
 import net.shibboleth.utilities.java.support.component.UninitializedComponentException;
 import net.shibboleth.utilities.java.support.component.UnmodifiableComponent;
@@ -80,6 +81,9 @@
     /** Flag to track whether pool is in the initialized state. */
     private boolean initialized;
 
+    /** Flag to track whether pool is in the destroyed state. */
+    private boolean destroyed;
+
     /** Factory used to create new builders. */
     private DocumentBuilderFactory builderFactory;
 
@@ -154,6 +158,9 @@
         if (initialized) {
             throw new ComponentInitializationException("Parser pool was already initialized");
         }
+        if (destroyed) {
+            throw new DestroyedComponentException("Parser pool has been destroyed");
+        }
 
         try {
             final DocumentBuilderFactory newFactory = DocumentBuilderFactory.newInstance();
@@ -197,25 +204,45 @@
     
     /** {@inheritDoc} */
     public boolean isDestroyed() {
-        return !initialized;
+        return destroyed;
     }
 
     /** {@inheritDoc} */
     public synchronized void destroy() {
         builderPool.clear();
-        initialized = false;
-    }
-
-    /** {@inheritDoc} */
-    @Nonnull public DocumentBuilder getBuilder() throws XMLParserException {
+        destroyed = true;
+    }
+    
+    /** Helper method to test class state. */
+    private void checkInitializedNotDestroyed() {
         if (!initialized) {
             throw new UninitializedComponentException("Parser pool has not been initialized");
         }
+        if (destroyed) {
+            throw new DestroyedComponentException("Parser pool has been destroyed");
+        }        
+    }
+
+    /** Helper method to test class state.
+     * @param message helpful error;
+     */
+    private void checkNotInitializedNotDestroyed(String message) {
+        if (initialized) {
+            throw new UnmodifiableComponentException("Parser pool has been initialized: " + message);
+        }
+        if (destroyed) {
+            throw new DestroyedComponentException("Parser pool has been destroyed" + message);
+        }        
+    }
+
+    /** {@inheritDoc} */
+    @Nonnull public DocumentBuilder getBuilder() throws XMLParserException {
+        checkInitializedNotDestroyed();
 
         DocumentBuilder builder = null;
 
         synchronized (builderPool) {
-            if (!builderPool.isEmpty()) {
+            while (builder == null && !builderPool.isEmpty()) {
                 builder = builderPool.pop().get();
             }
         }
@@ -235,9 +262,7 @@
 
     /** {@inheritDoc} */
     public void returnBuilder(@Nullable final DocumentBuilder builder) {
-        if (!initialized) {
-            throw new UninitializedComponentException("Parser pool has not been initialized");
-        }
+        checkInitializedNotDestroyed();
 

[... 961 lines stripped ...]


More information about the commits mailing list