org.apache.cocoon.components.flow
Class AbstractInterpreter

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.components.flow.AbstractInterpreter
All Implemented Interfaces:
Disposable, Component, Configurable, Contextualizable, LogEnabled, Serviceable, SingleThreaded, Interpreter
Direct Known Subclasses:
ApplesProcessor, CompilingInterpreter, JavaInterpreter

public abstract class AbstractInterpreter
extends AbstractLogEnabled
implements Component, Serviceable, Contextualizable, Interpreter, SingleThreaded, Configurable, Disposable

Abstract superclass for various scripting languages used by Cocoon for flow control. Defines some useful behavior like the ability to reload script files if they get modified (useful when doing development), and passing the control to Cocoon's sitemap for result page generation.

Flow intrepreters belonging to different sitemaps should be isolated. To achieve this, class implements the SingleThreaded. Since the sitemap engine looks up the flow intepreter once at sitemap build time, this ensures that each sitemap will use a different instance of this class. But that instance will handle all flow calls for a given sitemap, and must therefore be thread safe.

Since:
March 15, 2002
Version:
CVS $Id: AbstractInterpreter.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Ovidiu Predescu

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.cocoon.components.flow.Interpreter
Interpreter.Argument
 
Field Summary
protected  Context avalonContext
           
protected  long checkTime
          Interval between two checks for modified script files.
protected  Context context
           
protected  ContinuationsManager continuationsMgr
           
protected  ServiceManager manager
           
protected  ArrayList needResolve
          List of source locations that need to be resolved.
protected  boolean reloadScripts
          Whether reloading of scripts should be done.
 
Fields inherited from interface org.apache.cocoon.components.flow.Interpreter
ROLE
 
Constructor Summary
AbstractInterpreter()
           
 
Method Summary
 void configure(Configuration config)
           
 void contextualize(Context context)
           
 void dispose()
           
 void forwardTo(String uri, Object bizData, WebContinuation continuation, Redirector redirector)
          Forward the request to a Cocoon pipeline.
 String getInterpreterID()
          Get the unique ID for this interpreter, which can be used to distinguish user value scopes attached to the session.
 void process(String uri, Object biz, OutputStream out)
          Call the Cocoon sitemap for the given URI, sending the output of the eventually matched pipeline to the specified outputstream.
 void register(String source)
          Registers a source file with the interpreter.
 void service(ServiceManager sm)
          Serviceable
 void setInterpreterID(String interpreterID)
          Set the unique ID for this interpreter, which can be used to distinguish user value scopes attached to the session.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.components.flow.Interpreter
callFunction, handleContinuation
 

Field Detail

avalonContext

protected Context avalonContext

needResolve

protected ArrayList needResolve
List of source locations that need to be resolved.


context

protected Context context

manager

protected ServiceManager manager

continuationsMgr

protected ContinuationsManager continuationsMgr

reloadScripts

protected boolean reloadScripts
Whether reloading of scripts should be done. Specified through the "reload-scripts" attribute in flow.xmap.


checkTime

protected long checkTime
Interval between two checks for modified script files. Specified through the "check-time" XML attribute in flow.xmap.

Constructor Detail

AbstractInterpreter

public AbstractInterpreter()
Method Detail

setInterpreterID

public void setInterpreterID(String interpreterID)
Set the unique ID for this interpreter, which can be used to distinguish user value scopes attached to the session.

Specified by:
setInterpreterID in interface Interpreter

getInterpreterID

public String getInterpreterID()
Get the unique ID for this interpreter, which can be used to distinguish user value scopes attached to the session.

Specified by:
getInterpreterID in interface Interpreter
Returns:
a unique ID for this interpreter

configure

public void configure(Configuration config)
               throws ConfigurationException
Specified by:
configure in interface Configurable
Throws:
ConfigurationException

service

public void service(ServiceManager sm)
             throws ServiceException
Serviceable

Specified by:
service in interface Serviceable
Throws:
ServiceException

contextualize

public void contextualize(Context context)
                   throws ContextException
Specified by:
contextualize in interface Contextualizable
Throws:
ContextException

dispose

public void dispose()
Specified by:
dispose in interface Disposable

register

public void register(String source)
Registers a source file with the interpreter. Using this method an implementation keeps track of all the script files which are compiled. This allows them to reload the script files which get modified on the file system.

The parsing/compilation of a script file by an interpreter happens in two phases. In the first phase the file's location is registered in the needResolve array.

The second is possible only when a Cocoon Environment is passed to the Interpreter. This allows the file location to be resolved using Cocoon's SourceFactory class.

Once a file's location can be resolved, it is removed from the needResolve array and placed in the scripts hash table. The key in this hash table is the file location string, and the value is a DelayedRefreshSourceWrapper instance which keeps track of when the file needs to re-read.

Parameters:
source - the location of the script
See Also:
Environment, DelayedRefreshSourceWrapper

process

public void process(String uri,
                    Object biz,
                    OutputStream out)
             throws Exception
Call the Cocoon sitemap for the given URI, sending the output of the eventually matched pipeline to the specified outputstream.

Parameters:
uri - The URI for which the request should be generated.
biz - Extra data associated with the subrequest.
out - An OutputStream where the output should be written to.
Throws:
Exception - If an error occurs.

forwardTo

public void forwardTo(String uri,
                      Object bizData,
                      WebContinuation continuation,
                      Redirector redirector)
               throws Exception
Description copied from interface: Interpreter
Forward the request to a Cocoon pipeline.

Specified by:
forwardTo in interface Interpreter
Parameters:
uri - a String, the URI of the forwarded request
bizData - an Object, the business data object to be made available to the forwarded pipeline
continuation - a WebContinuation, the continuation to be called to resume the processing
redirector - a Redirector used to call views
Throws:
Exception - if an error occurs


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.