Home
Categories
Dictionnary
Download
Project Details
Changes Log
FAQ
License

ScriptLanguageFactory



The ScriptLanguageFactory is the class which is responsible to create scripts from the scripts text content specified in the XUL files.

Overview

The important characteristic of the ScriptLanguageFactory is that it will create scripts which will implement one specified interface. For example, if you want to create scripts which will implement the following interface:

      public interface MyScript {
        public int compute();
      }

You will have to define the following ScriptLanguageFactory:

      public class DefaultScriptLanguageFactory extends AbstractScriptLanguageFactory<MyScript> {
        protected Class<ScriptBuilder> createBuilderClass(short scriptType) {  
         create a builder which will create scripts of the specified script type
        }
      }    

scriptType parameter

The scriptType is one of the values defined in the ScriptTypes:

The ScriptBuilder

The ScriptBuilder class is the class which is responsible for creating scripts of:
  • A particular script type
  • And implementing a particular interface
For example, for the case of our MyScript interface, and for Groovy scripts, it would be:

      public class MyGroovyScriptBuilder extends AbstractScriptBuilder {
        public ScriptWrapper<MyScript> createScriptWrapper() {
          // create the GroovyScriptWrapper, see the documentation for the scriptHelper scripting library
          // (https://sourceforge.net/projects/scripthelper/)
          ScriptWrapper<MyScript>  wrapper = new GroovyScriptWrapper<MyScript> () {
          };
          // add the default imports for the javaXUL library
          addDefaultImports(wrapper);
          // set the exception listener and the script context 
          wrapper.addExceptionListener(exceptionListener);
          wrapper.setScriptContext(context);
          return wrapper;
        }
      }      

Language ScriptWrappers

Main Article: ScriptWrapper

The org.scripthelper.model.ScriptWrapper is a wrapper around a script seen as implementing an interface. See the sourceforge.net/projects/scripthelper/ for more information. The

See also


Categories: scripts

Copyright 2008-2020 Herve Girod. All Rights Reserved. Documentation and source under the LGPL licence