Author: thorsten
Date: Fri Jan 23 02:57:26 2009
New Revision: 736995

URL: http://svn.apache.org/viewvc?rev=736995&view=rev
Log:
Adding more javadoc to explain the purpose of the class. Enhancing factory to 
only make one instance of a contract and reuse it. Will save quite a lot of 
processing time.

Modified:
    
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java

Modified: 
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
URL: 
http://svn.apache.org/viewvc/forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java?rev=736995&r1=736994&r2=736995&view=diff
==============================================================================
--- 
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
 (original)
+++ 
forrest/branches/dispatcher_rewrite/plugins/org.apache.forrest.plugin.internal.dispatcher/src/java/org/apache/forrest/dispatcher/factories/ContractFactory.java
 Fri Jan 23 02:57:26 2009
@@ -12,6 +12,12 @@
 import org.apache.forrest.dispatcher.exception.DispatcherException;
 import org.apache.forrest.dispatcher.impl.XSLContract;
 
+/**
+ * ContractFactory that will resolve a contract by a given name.
+ * If the contract has not registered with the factory (stored in
+ * a HashMap), we assume that we have a xsl based contract. This
+ * contract we will then resolve it and initialize it. 
+ */
 public class ContractFactory {
 
   protected final Log log = LogFactory.getLog(this.getClass()
@@ -19,12 +25,18 @@
 
   private DispatcherBean config;
 
+  /**
+   * Create the factory based on the dispatcher bean.
+   * @param config the dispatcher bean where we store the current properties.
+   */
   public ContractFactory(DispatcherBean config) {
     this.config = config;
   }
 
   private Map<String, Contract> map = null;
 
+  private Contract dummyContract;
+
   /**
    * Get the register which contains all components.
    * 
@@ -63,12 +75,19 @@
        * because they are configured via spring and should be in the map at 
this
        * point in time.
        * 
+       * Since we only really need ONE instance of a contract, we will check 
whether 
+       * we already have set this up?
+       */
+      if (dummyContract == null){
+        dummyContract = new 
XSLContract(config.isAllowXmlProperties(),config.getTransFact());
+      }
+      contract = dummyContract;
+      /*
        * This means we will now try to resolve the contract via a url, which
        * will return a stream. If this stream is null it means that the
        * requested contract does not exist. Otherwise it is a xsl based
        * contract.
        */
-      contract = new 
XSLContract(config.isAllowXmlProperties(),config.getTransFact(),config.getStaxHelper());
       String uri = config.getContractUriPrefix() + name + 
config.getContractUriSufix();
       InputStream xslStream = config.getResolver().resolve(uri);
       contract.initializeFromStream(xslStream);