Interface ResourceConfig

  • All Known Implementing Classes:
    DefaultResourceConfig

    public interface ResourceConfig
    A configuration for a Smooks resource.

    ResourceConfig controls the behaviour of a Smooks resource, including:

    • which event/s from the input stream target the resource
    • the parameters injected into the resource
    • the type of resource that is instantiated

    A ResourceConfig can be configured through Java code but it is easier to configure through XML. The following are a few sample configurations. Explanations follow the samples.

    Basic Sample

     <?xml version='1.0'?>
     <smooks-resource-list xmlns="https://www.smooks.org/xsd/smooks-2.0.xsd">
          <resource-config selector="order/order-header">
              <resource type="xsl">/com/acme/transform/OrderHeaderTransformer.xsl</resource>
          </resource-config>
    
          <resource-config selector="order-items/order-item">
              <resource>com.acme.transform.MyJavaOrderItemTransformer</resource>
          </resource-config>
     </smooks-resource-list>
     
    The resource-config XML element maps directly to an instance of ResourceConfig.

    More Complex Sample with Profiling

     <?xml version='1.0'?>
     <smooks-resource-list xmlns="https://www.smooks.org/xsd/smooks-2.0.xsd">
          <profiles>
              <profile base-profile="message-exchange-1" sub-profiles="message-producer-A, message-consumer-B" />
              <profile base-profile="message-exchange-2" sub-profiles="message-producer-A, message-consumer-C" />
          </profiles>
    
     (1)  <resource-config selector="order/order-header" target-profile="message-producer-A">
              <resource>com.acme.transform.AddIdentityInfo</resource>
          </resource-config>
    
     (2)  <resource-config selector="order-items/order-item" target-profile="message-consumer-B">
              <resource>com.acme.transform.MyJavaOrderItemTransformer</resource>
              <param name="execution-param-X">param-value-forB</param>
          </resource-config>
    
     (3)  <resource-config selector="order-items/order-item" target-profile="message-consumer-C">
              <resource>com.acme.transform.MyJavaOrderItemTransformer</resource>
              <param name="execution-param-X">param-value-forC</param>
          </resource-config>
    
     </smooks-resource-list>

    The first resource is targeted for both "message-exchange-1" and "message-exchange-2" profiles. The second resource is only targeted for "message-exchange-1" profile and the third resource only for "message-exchange-2" profile (see Smooks.createExecutionContext(String)).

    Attribute Definitions

    • target-profile: a list of one or more profile targeting expressions (supports wildcards "*").

    • selector: selector string. Used by Smooks to lookup a resource config. This is typically an input fragment name (partial XPath support). This attribute supports a list of comma separated selectors, allowing you to target a single resource at multiple selector (e.g. fragments). Where the resource is a Visitor implementation, the selector is treated as an XPath expression (full XPath spec not supported), otherwise the selector value is treated as an opaque value.

      Example selectors:

      1. For a Visitor, use the target fragment name e.g. "order", "address", "address/name", "item[2]/price[text() = 99.99]" etc. Also supports wildcard based fragment selection (i.e., "*"). See the User Guide for more details on setting selectors for Visitor type resources.
      2. "#document" is a special selector that targets a resource at the "document" fragment i.e. the whole document, or document root node fragment.
      3. Targeting a specific SmooksXMLReader at a specific profile.
    • Method Detail

      • setExtendedConfigNS

        @Deprecated
        void setExtendedConfigNS​(String extendedConfigNS)
        Deprecated.
      • addParameters

        void addParameters​(ResourceConfig resourceConfig)
      • setResource

        void setResource​(String resource)
      • isInline

        boolean isInline()
      • getTargetProfile

        String getTargetProfile()
      • setTargetProfile

        void setTargetProfile​(String targetProfile)
      • setResourceType

        void setResourceType​(String resourceType)
      • setSelectorPath

        void setSelectorPath​(SelectorPath selectorPath)
      • getResource

        String getResource()
      • isDefaultResource

        boolean isDefaultResource()
      • setDefaultResource

        void setDefaultResource​(boolean defaultResource)
      • getResourceType

        String getResourceType()
      • setParameter

        <T> void setParameter​(Parameter<T> parameter)
      • getParameterValues

        List<?> getParameterValues()
      • getParameterValue

        Object getParameterValue​(String name)
      • getParameterValue

        <T> T getParameterValue​(String name,
                                Class<T> valueClass)
      • getParameterValue

        <T> T getParameterValue​(String name,
                                Class<T> valueClass,
                                T defaultValue)
      • getParameterCount

        int getParameterCount()
      • removeParameter

        void removeParameter​(String name)
      • isXmlDef

        boolean isXmlDef()
      • getBytes

        byte[] getBytes()
      • isJavaResource

        boolean isJavaResource()