Class JavaSource

  • All Implemented Interfaces:
    Source
    Direct Known Subclasses:
    JavaSourceWithoutEventStream

    public class JavaSource
    extends FilterSource
    Java Filtration/Transformation Source.

    Controlling Event Stream Generation

    The Java Objects used to create this source can be used to generate a stream of SAX events, which can then be analysed by Smooks in the normal manner. Generation of the SAX event stream can also be turned off via the setEventStreamRequired(boolean) method, or by configuring the 'http://www.smooks.org/sax/features/generate-java-event-stream' feature on the reader in the Smoooks configuration as follows:
     <reader>
         <features>
             <setOff feature="http://www.smooks.org/sax/features/generate-java-event-stream" />
         </features>
     </reader>
     
    Turning off event stream generation can make sense in many situations. In some use cases event stream generation may add no value and may just reduces performance e.g. where you simply wish to apply a template to the supplied Java Object(s).

    Smooks must generate at least 1 event to which configured resources can be targeted (e.g. a templating resource). When event stream generation is turned off, Smooks simply generates what we call a "Null Source" document event. In XML, it could be represented as "<nullsource-document/>". So when event stream generation is turned off, simply target resources at "nullsource-document" or "#document".

    Author:
    tom.fennelly@gmail.com
    • Constructor Detail

      • JavaSource

        public JavaSource​(Object sourceObject)
        Construct a JavaSource from the supplied source object.
        Parameters:
        sourceObject - The source object.
      • JavaSource

        public JavaSource​(String objectName,
                          Object sourceObject)
        Construct a JavaSource from the supplied source object.
        Parameters:
        objectName - The object name the sourceObject is known under
        sourceObject - The source object.
      • JavaSource

        public JavaSource​(List<Object> sourceObjects)
        Construct a JavaSource from the supplied source object.
        Parameters:
        sourceObjects - The source object list.
    • Method Detail

      • isEventStreamRequired

        public boolean isEventStreamRequired()
        Is SAX event stream generation required for the processing of this JavaSource.

        Default is true.

        Returns:
        True if SAX event stream generation is required, otherwise false.
      • setEventStreamRequired

        public void setEventStreamRequired​(boolean eventStreamRequired)
        Turn on/off SAX event stream generation for the processing of this JavaSource.
        Parameters:
        eventStreamRequired - True if SAX event stream generation is required, otherwise false.
      • getSourceObjects

        public List<Object> getSourceObjects()
        Get the source object list.
        Returns:
        The source object list.
      • getBeans

        public Map<String,​Object> getBeans()
        Get the input bean map for the transform.
        Returns:
        The bean map.
      • setBeans

        public void setBeans​(Map<String,​Object> beans)
        Set the input bean map for the transform.
        Parameters:
        beans - The bean map.