Author: rgardler
Date: Sat Nov 18 04:03:28 2006
New Revision: 476494

URL: http://svn.apache.org/viewvc?view=rev&rev=476494
Log:
@refactor - create controller interface and expose methods for retrieving 
readers and plugins

Added:
    
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/IController.java 
  (with props)
Modified:
    
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/Controller.java

Modified: 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/Controller.java
URL: 
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/Controller.java?view=diff&rev=476494&r1=476493&r2=476494
==============================================================================
--- 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/Controller.java 
(original)
+++ 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/Controller.java 
Sat Nov 18 04:03:28 2006
@@ -61,7 +61,7 @@
  * 
  * 
  */
-public class Controller {
+public class Controller implements IController {
 
        private final String sourceURLExtension = ".forrestSource";
 
@@ -175,18 +175,26 @@
                                sourceDocuments.size());
                for (int i = 0; i < sourceDocuments.size(); i++) {
                        final AbstractSourceDocument doc = 
sourceDocuments.get(i);
-                       AbstractInputPlugin plugin;
-                       try {
-                               plugin = (AbstractInputPlugin) 
this.context.getBean(doc
-                                               .getType());
-                       } catch (final NoSuchBeanDefinitionException e) {
-                               plugin = new PassThroughInputPlugin();
-                       }
+                       AbstractInputPlugin plugin = getInputPlugin(doc);
                        results.add((InternalDocument) plugin.process(doc));
                }
                return results;
        }
 
+       /* (non-Javadoc)
+        * @see 
org.apache.forrest.core.IController#getInputPlugin(org.apache.forrest.core.document.AbstractSourceDocument)
+        */
+       public AbstractInputPlugin getInputPlugin(final AbstractSourceDocument 
doc) {
+               AbstractInputPlugin plugin;
+               try {
+                       plugin = (AbstractInputPlugin) this.context.getBean(doc
+                                       .getType());
+               } catch (final NoSuchBeanDefinitionException e) {
+                       plugin = new PassThroughInputPlugin();
+               }
+               return plugin;
+       }
+
        /**
         * Aggregate all the internal documents into a single document and then
         * process it will the appropraite output plugin for the given 
requestURI.
@@ -207,7 +215,16 @@
                        doc = intDocs.get(0);
                }
 
-               BaseOutputPlugin plugin = new BaseOutputPlugin();
+               BaseOutputPlugin plugin = getOutputPlugin(requestURI);
+               
+               return (AbstractOutputDocument) plugin.process(doc);
+       }
+
+       /* (non-Javadoc)
+        * @see 
org.apache.forrest.core.IController#getOutputPlugin(java.net.URI)
+        */
+       public BaseOutputPlugin getOutputPlugin(final URI requestURI) {
+               BaseOutputPlugin plugin;
                final String[] names = this.context.getBeanNamesForType(plugin
                                .getClass());
                for (int i = 0; i < names.length; i = i + 1) {
@@ -221,8 +238,7 @@
                if (plugin == null) {
                        plugin = new BaseOutputPlugin();
                }
-
-               return (AbstractOutputDocument) plugin.process(doc);
+               return plugin;
        }
 
        /**
@@ -241,14 +257,22 @@
 
                for (int i = 0; i < sourceLocations.size(); i++) {
                        final Location location = sourceLocations.get(i);
-                       IReader reader;
-                       reader = (IReader) 
this.context.getBean(location.getSourceURI()
-                                       .getScheme());
+                       IReader reader = getReader(location);
                        results.add(reader.read(this.context, location));
                }
                return results;
        }
 
+       /* (non-Javadoc)
+        * @see 
org.apache.forrest.core.IController#getReader(org.apache.forrest.core.locationMap.Location)
+        */
+       public IReader getReader(final Location location) {
+               IReader reader;
+               reader = (IReader) this.context.getBean(location.getSourceURI()
+                               .getScheme());
+               return reader;
+       }
+
        /**
         * Resolve the input documents for a given request.
         * 
@@ -271,14 +295,8 @@
                return possibleLocs.get(0);
        }
 
-       /**
-        * Get the source URLs for a given request URI.
-        * 
-        * @param requestURI
-        * @return
-        * @throws IOException
-        * @throws LocationmapException
-        * @throws ProcessingException
+       /* (non-Javadoc)
+        * @see 
org.apache.forrest.core.IController#getSourceLocations(java.net.URI)
         */
        public List<Location> getSourceLocations(final URI requestURI)
                        throws IOException, LocationmapException, 
ProcessingException {
@@ -290,14 +308,8 @@
                return locs;
        }
 
-       /**
-        * Get the source documents for a given request URI.
-        * 
-        * @param requestURI
-        * @return
-        * @throws ProcessingException
-        * @throws MalformedURLException
-        * @throws IOException
+       /* (non-Javadoc)
+        * @see 
org.apache.forrest.core.IController#getSourceDocuments(java.net.URI)
         */
        public List<AbstractSourceDocument> getSourceDocuments(final URI 
requestURI)
                        throws MalformedURLException, ProcessingException {
@@ -315,14 +327,8 @@
                return sources;
        }
 
-       /**
-        * Get the internal format documents for a given request URI.
-        * 
-        * @param requestURI
-        * @return
-        * @throws ProcessingException
-        * @throws MalformedURLException
-        * @throws IOException
+       /* (non-Javadoc)
+        * @see 
org.apache.forrest.core.IController#getInternalDocuments(java.net.URI)
         */
        public List<InternalDocument> getInternalDocuments(final URI requestURI)
                        throws ProcessingException {
@@ -341,14 +347,8 @@
                return internalDocs;
        }
 
-       /**
-        * Get the output format documents for a given request URI.
-        * 
-        * @param requestURI
-        * @return
-        * @throws ProcessingException
-        * @throws MalformedURLException
-        * @throws IOException
+       /* (non-Javadoc)
+        * @see 
org.apache.forrest.core.IController#getOutputDocument(java.net.URI)
         */
        public AbstractOutputDocument getOutputDocument(final URI requestURI)
                        throws MalformedURLException, ProcessingException {

Added: 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/IController.java
URL: 
http://svn.apache.org/viewvc/forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/IController.java?view=auto&rev=476494
==============================================================================
--- 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/IController.java 
(added)
+++ 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/IController.java 
Sat Nov 18 04:03:28 2006
@@ -0,0 +1,77 @@
+package org.apache.forrest.core;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.List;
+
+import org.apache.forrest.core.document.AbstractOutputDocument;
+import org.apache.forrest.core.document.AbstractSourceDocument;
+import org.apache.forrest.core.document.InternalDocument;
+import org.apache.forrest.core.exception.LocationmapException;
+import org.apache.forrest.core.exception.ProcessingException;
+import org.apache.forrest.core.locationMap.Location;
+import org.apache.forrest.core.plugin.AbstractInputPlugin;
+import org.apache.forrest.core.plugin.BaseOutputPlugin;
+import org.apache.forrest.reader.IReader;
+
+public interface IController {
+
+       public abstract AbstractInputPlugin getInputPlugin(
+                       final AbstractSourceDocument doc);
+
+       public abstract BaseOutputPlugin getOutputPlugin(final URI requestURI);
+
+       public abstract IReader getReader(final Location location);
+
+       /**
+        * Get the source URLs for a given request URI.
+        * 
+        * @param requestURI
+        * @return
+        * @throws IOException
+        * @throws LocationmapException
+        * @throws ProcessingException
+        */
+       public abstract List<Location> getSourceLocations(final URI requestURI)
+                       throws IOException, LocationmapException, 
ProcessingException;
+
+       /**
+        * Get the source documents for a given request URI.
+        * 
+        * @param requestURI
+        * @return
+        * @throws ProcessingException
+        * @throws MalformedURLException
+        * @throws IOException
+        */
+       public abstract List<AbstractSourceDocument> getSourceDocuments(
+                       final URI requestURI) throws MalformedURLException,
+                       ProcessingException;
+
+       /**
+        * Get the internal format documents for a given request URI.
+        * 
+        * @param requestURI
+        * @return
+        * @throws ProcessingException
+        * @throws MalformedURLException
+        * @throws IOException
+        */
+       public abstract List<InternalDocument> getInternalDocuments(
+                       final URI requestURI) throws ProcessingException;
+
+       /**
+        * Get the output format documents for a given request URI.
+        * 
+        * @param requestURI
+        * @return
+        * @throws ProcessingException
+        * @throws MalformedURLException
+        * @throws IOException
+        */
+       public abstract AbstractOutputDocument getOutputDocument(
+                       final URI requestURI) throws MalformedURLException,
+                       ProcessingException;
+
+}
\ No newline at end of file

Propchange: 
forrest/trunk/whiteboard/forrest2/core/org/apache/forrest/core/IController.java
------------------------------------------------------------------------------
    svn:eol-style = native