org.carrot2.core.controller.loaders
Class BeanShellFactoryDescriptionLoader

java.lang.Object
  extended by org.carrot2.core.controller.loaders.BeanShellFactoryDescriptionLoader
All Implemented Interfaces:
ComponentFactoryLoader

public class BeanShellFactoryDescriptionLoader
extends Object
implements ComponentFactoryLoader

A ComponentFactoryLoader for creating component factories from a BeanShell script. The provided BeanShell script must return an instance of LoadedComponentFactory class. This class contains the essential information needed to use the factory.

BeanShell scripts are very versatile; the controller uses BeanShell 2.0-series, which includes support for dynamic class creation.

An example component factory script may look as shown below:

 factory = new LocalComponentFactory() {
     public LocalComponent getInstance() {
            LocalComponent c = new StubOutputComponent();
            c.setProperty("property", "value");
                return c;
     }
 };
        
 return new LoadedComponentFactory("stub-output", factory); 
 

A bug in BeanShell 2.0b1 prevents scripts that declare new classes (named or anonymous) from being evaluated more than once (a "duplicated class definition" error is thrown). Normal scenario of using the controller is to add processes only once and in such case, the scripts may declare new classes that override methods of their Java super classes.

Version:
$Revision: 2122 $
Author:
Dawid Weiss

Constructor Summary
BeanShellFactoryDescriptionLoader()
           
 
Method Summary
 LoadedComponentFactory load(InputStream dataStream)
          Loads a component factory from the data stream.
 void setGlobals(Map globalVars)
          Sets a map of global variables registered in the beanshell interpreter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanShellFactoryDescriptionLoader

public BeanShellFactoryDescriptionLoader()
Method Detail

setGlobals

public void setGlobals(Map globalVars)
Sets a map of global variables registered in the beanshell interpreter. Any previous value is replaced with the new one.


load

public LoadedComponentFactory load(InputStream dataStream)
                            throws IOException,
                                   ComponentInitializationException
Loads a component factory from the data stream. The stream is converted to character data using UTF-8 encoding.

Specified by:
load in interface ComponentFactoryLoader
Parameters:
dataStream - The data stream to load from.
Returns:
Returns the factory and its associated data as LoadedComponentFactory object.
Throws:
IOException - If an i/o error occurs.
ComponentInitializationException


Copyright (c) Dawid Weiss, Stanislaw Osinski