Class DefaultTextSource

java.lang.Object
ch.grengine.source.BaseSource
ch.grengine.source.DefaultTextSource
All Implemented Interfaces:
Source, TextSource

public class DefaultTextSource extends BaseSource implements TextSource
Text-based script source, default implementation of the TextSource interface.

The source ID is "/groovy/script/Script<text-hash>" resp. "/groovy/script/<text-hash>/<desired-class-name>".

The text hash is calculated as follows:

  • UTF-8 encode the script text to bytes
  • calculate the MD5 hash
  • convert the resulting bytes to a hex string

The method BaseSource.getLastModified() always returns 0.

Since:
1.0
Author:
Alain Stalder, Made in Switzerland.
  • Constructor Details

    • DefaultTextSource

      public DefaultTextSource(String text)
      constructor from script text.

      If the script text does not explicitly declare a class, the name of the compiled script class will normally be "Script<text-hash>".

      Parameters:
      text - script text
      Throws:
      NullPointerException - if text is null
      Since:
      1.0
    • DefaultTextSource

      public DefaultTextSource(String text, String desiredClassName)
      constructor from script text and desired class name.

      If the script text does not explicitly declare a class, the name of the compiled script class will normally be the given desired class name.

      Parameters:
      text - script text
      desiredClassName - desired class name
      Throws:
      NullPointerException - if text or desired class name is null
      Since:
      1.0
  • Method Details

    • toString

      public String toString()
      Description copied from interface: Source
      returns a string suitable for logging.
      Specified by:
      toString in interface Source
      Overrides:
      toString in class BaseSource
      Returns:
      a string suitable for logging
    • getText

      public String getText()
      Description copied from interface: TextSource
      gets the script text.
      Specified by:
      getText in interface TextSource
      Returns:
      script text