org.apache.cocoon.components.flow
abstract public class: AbstractInterpreter [javadoc |
source]
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.cocoon.components.flow.AbstractInterpreter
All Implemented Interfaces:
org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.thread.SingleThreaded, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.context.Contextualizable, Interpreter
Direct Known Subclasses:
CompilingInterpreter, SchemeInterpreter, JavaScriptInterpreter, FOM_JavaScriptInterpreter, ApplesProcessor, JavaInterpreter
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 org.apache.avalon.framework.thread.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.
- author:
< - a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu
- since:
March - 15, 2002
- version:
CVS - $Id: AbstractInterpreter.java 433543 2006-08-22 06:22:54Z crossley $
| Field Summary |
|---|
| protected Context | avalonContext | |
| protected ArrayList | needResolve | List of source locations that need to be resolved. |
| protected Context | context | |
| protected ServiceManager | manager | |
| protected ContinuationsManager | continuationsMgr | |
| protected boolean | reloadScripts | Whether reloading of scripts should be done. Specified through
the "reload-scripts" attribute in flow.xmap. |
| protected long | checkTime | Interval between two checks for modified script files. Specified
through the "check-time" XML attribute in flow.xmap. |
| Method from org.apache.cocoon.components.flow.AbstractInterpreter Detail: |
public void configure(Configuration config) throws ConfigurationException {
reloadScripts = config.getChild("reload-scripts").getValueAsBoolean(false);
checkTime = config.getChild("check-time").getValueAsLong(1000L);
}
|
public void contextualize(Context context) throws ContextException {
this.avalonContext = context;
this.context = (Context)context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
}
|
public void dispose() {
if ( this.manager != null ) {
this.manager.release( this.continuationsMgr );
this.continuationsMgr = null;
this.manager = null;
}
}
|
public void forwardTo(String uri,
Object bizData,
WebContinuation continuation,
Redirector redirector) throws Exception {
if (SourceUtil.indexOfSchemeColon(uri) == -1) {
uri = "cocoon:/" + uri;
Map objectModel = ContextHelper.getObjectModel(this.avalonContext);
FlowHelper.setWebContinuation(objectModel, continuation);
FlowHelper.setContextObject(objectModel, bizData);
if (redirector.hasRedirected()) {
throw new IllegalStateException("Pipeline has already been processed for this request");
}
// this is a hint for the redirector
objectModel.put("cocoon:forward", "true");
redirector.redirect(false, uri);
} else {
throw new Exception("uri is not allowed to contain a scheme (cocoon:/ is always automatically used)");
}
}
|
public String getInterpreterID() {
return this.instanceID;
}
Get the unique ID for this interpreter, which can be used to distinguish user value scopes
attached to the session. |
public void process(String uri,
Object biz,
OutputStream out) throws Exception {
// FIXME (SW): should we deprecate this method in favor of PipelineUtil?
PipelineUtil pipeUtil = new PipelineUtil();
try {
pipeUtil.contextualize(this.avalonContext);
pipeUtil.service(this.manager);
pipeUtil.processToStream(uri, biz, out);
} finally {
pipeUtil.dispose();
}
}
Call the Cocoon sitemap for the given URI, sending the output of the
eventually matched pipeline to the specified outputstream. |
public void register(String source) {
synchronized (this) {
needResolve.add(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. |
public void service(ServiceManager sm) throws ServiceException {
this.manager = sm;
this.continuationsMgr = (ContinuationsManager)sm.lookup(ContinuationsManager.ROLE);
}
|
public void setInterpreterID(String interpreterID) {
this.instanceID = interpreterID;
}
Set the unique ID for this interpreter, which can be used to distinguish user value scopes
attached to the session. |