org.milyn
Class Smooks

java.lang.Object
  extended by org.milyn.Smooks

public class Smooks
extends Object

Smooks executor class.

Additional configurations can be carried out on the Smooks instance through the SmooksUtil class.

The basic usage scenario for this class might be as follows:

  1. Develop (or reuse) an implementation of DOMElementVisitor/SAXElementVisitor to perform some transformation/analysis operation on a message. There are a number of prebuilt and reuseable implemntations available as "Smooks Cartridges".
  2. Write a resource configuration to target the DOMElementVisitor/SAXElementVisitor implementation at the target fragment of the message being processed.
  3. Apply the logic as follows:
     Smooks smooks = new Smooks("smooks-config.xml");
     ExecutionContext execContext;
     
     execContext = smooks.createExecutionContext();
     smooks.filter(new StreamSource(...), new StreamResult(...), execContext);
     
Remember, you can implement and apply multiple DOMElementVisitors/SAXElementVisitor within the context of a single filtering operation. You can also target DOMElementVisitors/SAXElementVisitor based on target profiles, and so use a single configuration to process multiple messages by sharing profiles across your message set.

See Smooks Tutorials.

Author:
tom.fennelly@gmail.com

Constructor Summary
Smooks()
          Public Default Constructor.
Smooks(InputStream resourceConfigStream)
          Public constructor.
Smooks(String resourceURI)
          Public constructor.
 
Method Summary
 void addConfigurations(InputStream resourceConfigStream)
          Add a set of resource configurations to this Smooks instance.
 void addConfigurations(String resourceURI)
          Add a set of resource configurations to this Smooks instance.
 void addConfigurations(String baseURI, InputStream resourceConfigStream)
          Add a set of resource configurations to this Smooks instance.
 void close()
          Close this Smooks instance and all associated resources.
 ExecutionContext createExecutionContext()
          Create a ExecutionContext instance for use on this Smooks instance.
 ExecutionContext createExecutionContext(String targetProfile)
          Create a ExecutionContext instance for use on this Smooks instance.
 void filter(Source source)
          Filter the content in the supplied Source instance.
 void filter(Source source, Result result)
          Filter the content in the supplied Source instance, outputing the result to the supplied Result instance.
 void filter(Source source, Result result, ExecutionContext executionContext)
          Filter the content in the supplied Source instance, outputing the result to the supplied Result instance.
 ApplicationContext getApplicationContext()
          Get the Smooks ApplicationContext associated with this Smooks instance.
 ClassLoader getClassLoader()
          Get the ClassLoader associated with this Smooks instance.
 void setClassLoader(ClassLoader classLoader)
          Set the ClassLoader associated with this Smooks instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Smooks

public Smooks()
Public Default Constructor.

Resource configurations can be added through calls to addConfigurations(String) or addConfigurations(String,java.io.InputStream).


Smooks

public Smooks(String resourceURI)
       throws IOException,
              SAXException
Public constructor.

Adds the set of resources via the addConfigurations(String) method, which resolves the resourceURI parameter using a URIResourceLocator.

Additional resource configurations can be added through calls to addConfigurations(String) or addConfigurations(String,java.io.InputStream).

Parameters:
resourceURI - XML resource configuration stream URI.
Throws:
IOException - Error reading resource stream.
SAXException - Error parsing the resource stream.
See Also:
SmooksResourceConfiguration

Smooks

public Smooks(InputStream resourceConfigStream)
       throws IOException,
              SAXException
Public constructor.

Adds the set of resources via the addConfigurations(java.io.InputStream).

Additional resource configurations can be added through calls to addConfigurations method set.

Parameters:
resourceConfigStream - XML resource configuration stream.
Throws:
IOException - Error reading resource stream.
SAXException - Error parsing the resource stream.
See Also:
SmooksResourceConfiguration
Method Detail

getClassLoader

public ClassLoader getClassLoader()
Get the ClassLoader associated with this Smooks instance.

Returns:
The ClassLoader instance.

setClassLoader

public void setClassLoader(ClassLoader classLoader)
Set the ClassLoader associated with this Smooks instance.

Parameters:
classLoader - The ClassLoader instance.

addConfigurations

public void addConfigurations(String resourceURI)
                       throws IOException,
                              SAXException
Add a set of resource configurations to this Smooks instance.

Uses the URIResourceLocator class to load the resource.

These configurations do not overwrite previously added configurations. They are added to the list of configurations on this Smooks instance.

Parameters:
resourceURI - The URI string for the resource configuration list. See URIResourceLocator.
Throws:
IOException - Error reading resource stream.
SAXException - Error parsing the resource stream.

addConfigurations

public void addConfigurations(String baseURI,
                              InputStream resourceConfigStream)
                       throws SAXException,
                              IOException
Add a set of resource configurations to this Smooks instance.

These configurations do not overwrite previously added configurations. They are added to the list of configurations on this Smooks instance.

The base URI is required for resolving resource imports. Just specify the location of the resource file.

Parameters:
baseURI - The base URI string for the resource configuration list. See URIResourceLocator.
resourceConfigStream - The resource configuration stream.
Throws:
IOException - Error reading resource stream.
SAXException - Error parsing the resource stream.

addConfigurations

public void addConfigurations(InputStream resourceConfigStream)
                       throws SAXException,
                              IOException
Add a set of resource configurations to this Smooks instance.

Calls addConfigurations(String, java.io.InputStream) with a baseURI of "./", which is the default base URI on all URIResourceLocator instances.

Parameters:
resourceConfigStream - The resource configuration stream.
Throws:
IOException - Error reading resource stream.
SAXException - Error parsing the resource stream.

createExecutionContext

public ExecutionContext createExecutionContext()
Create a ExecutionContext instance for use on this Smooks instance.

The created context is profile agnostic and should be used where profile based targeting is not in use.

The context returned from this method is used in subsequent calls to filter(javax.xml.transform.Source,javax.xml.transform.Result,org.milyn.container.ExecutionContext). It allows access to the execution context instance before and after calls on this method. This means the caller has an opportunity to set and get data bound to the execution context (before and after the calls), providing the caller with a mechanism for interacting with the content filtering phases.

Returns:
Execution context instance.

createExecutionContext

public ExecutionContext createExecutionContext(String targetProfile)
                                        throws UnknownProfileMemberException
Create a ExecutionContext instance for use on this Smooks instance.

The created context is profile aware and should be used where profile based targeting is in use. In this case, the transfromation/analysis resources must be configured with profile targeting information.

The context returned from this method is used in subsequent calls to filter(javax.xml.transform.Source,javax.xml.transform.Result,org.milyn.container.ExecutionContext). It allows access to the execution context instance before and after calls on this method. This means the caller has an opportunity to set and get data bound to the execution context (before and after the calls), providing the caller with a mechanism for interacting with the content filtering phases.

Parameters:
targetProfile - The target profile (base profile) on behalf of whom the filtering/serialisation filter is to be executed.
Returns:
Execution context instance.
Throws:
UnknownProfileMemberException - Unknown target profile.

filter

public void filter(Source source)
            throws SmooksException
Filter the content in the supplied Source instance.

Not producing a Result.

Parameters:
source - The content Source.
Throws:
SmooksException - Failed to filter.

filter

public void filter(Source source,
                   Result result)
            throws SmooksException
Filter the content in the supplied Source instance, outputing the result to the supplied Result instance.

Parameters:
source - The content Source.
result - The content Result. To serialize the result, supply a StreamResult. To have the result returned as a DOM, supply a DOMResult.
Throws:
SmooksException - Failed to filter.

filter

public void filter(Source source,
                   Result result,
                   ExecutionContext executionContext)
            throws SmooksException
Filter the content in the supplied Source instance, outputing the result to the supplied Result instance.

Parameters:
source - The content Source.
result - The content Result. To serialize the result, supply a StreamResult. To have the result returned as a DOM, supply a DOMResult.
executionContext - The ExecutionContext for this filter operation. See createExecutionContext(String).
Throws:
SmooksException - Failed to filter.

getApplicationContext

public ApplicationContext getApplicationContext()
Get the Smooks ApplicationContext associated with this Smooks instance.

Returns:
The Smooks ApplicationContext.

close

public void close()
Close this Smooks instance and all associated resources.

Should result in the uninitialization of all allocated ContentHandler instances.



Copyright © 2008. All Rights Reserved.