Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Default imports



By default scripts will have the following default imports: It is possible to add custom default imports to the scripts in the ScriptWrapper interface.

Adding custom default imports

There are two ways to add custom default imports: The addImports(...) method accept both path for classes or for packages[1]
There is a limitation for package import for Python script
. For example the following construct is valid:
      wrapper.addImports("java.util.List", "my.package.*"); 
Note that it is possible to clear the default import declarations previously set on a wrapper by ScriptWrapper.clearImports().

Examples

The two following examples add a default import for the java.util.List interface.

By Overriding

      ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() {
        protected Set<lt;String> getCustomDefaultImports() {
          Set<String> set = new TreeSet<>();
          set.add("java.util.List");
          return set;
        }
      };

      Script Script = wrapper.getScript();
      File file = new File(<our script file>);
      wrapper.installScript(file);

By setting the imports declarations externally

      ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() {
      };
      wrapper.addImports("java.util.List");

      Script Script = wrapper.getScript();
      File file = new File(<our script file>);
      wrapper.installScript(file);

Notes

  1. ^ There is a limitation for package import for Python script

Categories: api

Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence