[gatein-commits] gatein SVN: r6732 - components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jun 24 08:13:42 EDT 2011


Author: chris.laprun at jboss.com
Date: 2011-06-24 08:13:42 -0400 (Fri, 24 Jun 2011)
New Revision: 6732

Modified:
   components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java
Log:
- GTNPORTAL-1938: Added ability to configure consumers from an InputStream.

Modified: components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java
===================================================================
--- components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java	2011-06-24 08:43:41 UTC (rev 6731)
+++ components/wsrp/branches/2.0.x/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java	2011-06-24 12:13:42 UTC (rev 6732)
@@ -50,9 +50,15 @@
 
    /** . */
    private static final String defaultWSRPLocation = "conf/wsrp-consumers-config.xml";
+   private InputStream configurationIS;
 
    private EntityResolver entityResolver;
 
+   public XMLConsumerRegistry(InputStream configurationInputStream)
+   {
+      configurationIS = configurationInputStream;
+   }
+
    public EntityResolver getEntityResolver()
    {
       return entityResolver;
@@ -65,51 +71,51 @@
 
    public void reloadConsumers()
    {
-      URL defaultWSRPURL = Thread.currentThread().getContextClassLoader().getResource(defaultWSRPLocation);
-      if (defaultWSRPURL != null)
+
+      if (configurationIS == null)
       {
-         InputStream inputStream;
+         URL defaultWSRPURL = Thread.currentThread().getContextClassLoader().getResource(defaultWSRPLocation);
          try
          {
-            inputStream = defaultWSRPURL.openStream();
+            configurationIS = defaultWSRPURL.openStream();
          }
          catch (IOException e)
          {
             throw new RuntimeException("Couldn't open default XML WSRP Consumer configuration file", e);
          }
+      }
 
-         Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
-         ObjectModelFactory factory = new XMLWSRPConsumerFactory(this);
-         if (entityResolver == null)
-         {
-            log.debug("Could not obtain entity resolver for XMLConsumerRegistry");
-            entityResolver = new NullEntityResolver();
-         }
+      Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+      ObjectModelFactory factory = new XMLWSRPConsumerFactory(this);
+      if (entityResolver == null)
+      {
+         log.debug("Could not obtain entity resolver for XMLConsumerRegistry");
+         entityResolver = new NullEntityResolver();
+      }
+      try
+      {
+         unmarshaller.setEntityResolver(entityResolver);
+         initConsumers((SortedMap<String, WSRPConsumer>)unmarshaller.unmarshal(configurationIS, factory, null));
+      }
+      catch (JBossXBException e)
+      {
+         throw new RuntimeException("Couldn't set unmarshall WSRP Consumers configuration", e);
+      }
+
+      for (WSRPConsumer consumer : getConsumers())
+      {
+
+         ProducerInfo producerInfo = consumer.getProducerInfo();
          try
          {
-            unmarshaller.setEntityResolver(entityResolver);
-            initConsumers((SortedMap<String, WSRPConsumer>)unmarshaller.unmarshal(inputStream, factory, null));
+            // try to activate the consumer
+            activateConsumer(consumer);
          }
-         catch (JBossXBException e)
+         catch (Exception e)
          {
-            throw new RuntimeException("Couldn't set unmarshall WSRP Consumers configuration", e);
+            producerInfo.setActive(false);
+            updateProducerInfo(producerInfo);
          }
-
-         for (WSRPConsumer consumer : getConsumers())
-         {
-
-            ProducerInfo producerInfo = consumer.getProducerInfo();
-            try
-            {
-               // try to activate the consumer 
-               activateConsumer(consumer);
-            }
-            catch (Exception e)
-            {
-               producerInfo.setActive(false);
-               updateProducerInfo(producerInfo);
-            }
-         }
       }
    }
 



More information about the gatein-commits mailing list