Class DefaultResourceConfig
- java.lang.Object
-
- org.smooks.engine.resource.config.DefaultResourceConfig
-
- All Implemented Interfaces:
ResourceConfig
public class DefaultResourceConfig extends Object implements ResourceConfig
-
-
Field Summary
-
Fields inherited from interface org.smooks.api.resource.config.ResourceConfig
DOCUMENT_FRAGMENT_SELECTOR, SELECTOR_NONE
-
-
Constructor Summary
Constructors Constructor Description DefaultResourceConfig()
Public default constructor.DefaultResourceConfig(String selector, Properties namespaces)
Public constructor.DefaultResourceConfig(String selector, Properties namespaces, String resource)
Public constructor.DefaultResourceConfig(String selector, Properties namespaces, String profile, String resource)
Public constructor.DefaultResourceConfig(ResourceConfig resourceConfig)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangeListener(ResourceConfigChangeListener resourceConfigChangeListener)
Adds the specified change listener to the list of change listeners.void
addParameters(ResourceConfig resourceConfig)
Shallow copies parameters from anotherResourceConfig
and adds them to thisResourceConfig
.ResourceConfig
copy()
Performs a shallow clone of thisResourceConfig
.boolean
equals(Object obj)
protected void
fireChangedEvent()
byte[]
getBytes()
Returns the resource in bytes.<T> Parameter<T>
getParameter(String name, Class<T> valueClass)
Gets aparameter
by name from thisResourceConfig
.int
getParameterCount()
Get the parameter count of thisResourceConfig
.Map<String,Object>
getParameters()
Gets the parameters associated with thisResourceConfig
as aMap
.List<Parameter<?>>
getParameters(String name)
Gets all the parameters of thisResourceConfig
by name.Object
getParameterValue(String name)
<T> T
getParameterValue(String name, Class<T> valueClass)
Get the named parameter from thisResourceConfig
.<T> T
getParameterValue(String name, Class<T> valueClass, T defaultValue)
Get value of named parameter from thisResourceConfig
.List<?>
getParameterValues()
Gets allparameter
values set of thisResourceConfig
.String
getProfile()
Gets the target profile/s of thisResourceConfig
.ProfileTargetingExpression[]
getProfileTargetingExpressions()
Gets the profile targeting expressions of thisResourceConfig
.String
getResource()
Get the resource for thisResourceConfig
.String
getResourceType()
Get the resource type of thisResourceConfig
.SelectorPath
getSelectorPath()
Gets the selector in its parsed form.boolean
isInline()
Evaluates whether the resource of thisResourceConfig
is defined inline or referenced from a URI.boolean
isJavaResource()
Evaluates whether thisResourceConfig
object references a Java class.
boolean
isSystem()
Evaluates whether thisResourceConfig
is for a default resource.void
removeChangeListener(ResourceConfigChangeListener resourceConfigChangeListener)
Removes the specified change listener from the list of change listeners.void
removeParameter(String name)
Remove the named parameter thisResourceConfig
<T> Parameter<T>
setParameter(String name, String type, T value)
Adds a parameter with a specified type to thisResourceConfig
.<T> Parameter<T>
setParameter(String name, T value)
Adds a parameter to thisResourceConfig
.<T> void
setParameter(Parameter<T> parameter)
Adds a parameter to thisResourceConfig
.void
setProfile(String profile)
Sets the target profile of thisResourceConfig
.void
setResource(String resource)
Sets the resource of thisResourceConfig
.void
setResourceType(String resourceType)
Sets the resource type (e.g., "class", "xsl", "groovy", etc...)void
setSelector(String selector, Properties namespaces)
Sets the raw selector of thisResourceConfig
.void
setSelectorPath(SelectorPath selectorPath)
Sets the selector in its parsed form.void
setSystem(boolean isSystem)
Set thisResourceConfig
as a default applied resource.protected Class<?>
toJavaResource()
Returns the resource as a Java Class instance.Properties
toProperties()
Creates aProperties
instance from the parametersResourceConfig
object.String
toString()
String
toXml()
Generates an XML'ified description of this resource.
-
-
-
Constructor Detail
-
DefaultResourceConfig
public DefaultResourceConfig()
Public default constructor.- See Also:
#setSelector(String)
,setProfile(String)
,setResource(String)
,setResourceType(String)
,setParameter(String, Object)
-
DefaultResourceConfig
public DefaultResourceConfig(String selector, Properties namespaces)
Public constructor.- Parameters:
selector
- The selector definition.- See Also:
setProfile(String)
,setResource(String)
,setResourceType(String)
,setParameter(String, Object)
-
DefaultResourceConfig
public DefaultResourceConfig(ResourceConfig resourceConfig)
-
DefaultResourceConfig
public DefaultResourceConfig(String selector, Properties namespaces, String resource)
Public constructor.- Parameters:
selector
- The selector definition.resource
- The resource.- See Also:
setProfile(String)
,setResourceType(String)
,setParameter(String, Object)
-
DefaultResourceConfig
public DefaultResourceConfig(String selector, Properties namespaces, String profile, String resource)
Public constructor.- Parameters:
selector
- The selector definition.profile
- Target Profile(s). Comma separated list ofProfileTargetingExpressions
.resource
- The resource.- See Also:
setResourceType(String)
,setParameter(String, Object)
-
-
Method Detail
-
copy
public ResourceConfig copy()
Description copied from interface:ResourceConfig
Performs a shallow clone of thisResourceConfig
.- Specified by:
copy
in interfaceResourceConfig
- Returns:
- clone of this
>ResourceConfig
-
addParameters
public void addParameters(ResourceConfig resourceConfig)
Description copied from interface:ResourceConfig
Shallow copies parameters from anotherResourceConfig
and adds them to thisResourceConfig
.- Specified by:
addParameters
in interfaceResourceConfig
- Parameters:
resourceConfig
-ResourceConfig
to copy parameters from
-
setSelector
public void setSelector(String selector, Properties namespaces)
Description copied from interface:ResourceConfig
Sets the raw selector of thisResourceConfig
.- Specified by:
setSelector
in interfaceResourceConfig
- Parameters:
selector
- an expression that defines the target of this resource. Any namespaces must be bound in thenamespaces
parameter.namespaces
- namespaces bound to prefixes. The property key is the prefix while the value is the namespace.
-
setResource
public void setResource(String resource)
Description copied from interface:ResourceConfig
Sets the resource of thisResourceConfig
. Unless the resource type is set, the resource is assumed to be a Java resource.- Specified by:
setResource
in interfaceResourceConfig
- Parameters:
resource
- an identifier for the resource. This could be anything like a path, a name, etc... The meaning of this value is driven by the resource type.- See Also:
ResourceConfig.setResourceType(String)
-
isInline
public boolean isInline()
Description copied from interface:ResourceConfig
Evaluates whether the resource of thisResourceConfig
is defined inline or referenced from a URI. Note that this method also returns false if the resource is undefined (null).- Specified by:
isInline
in interfaceResourceConfig
- Returns:
true
if the resource is defined inline, otherwisefalse
- See Also:
ResourceConfig.setResource(String)
-
getProfile
public String getProfile()
Description copied from interface:ResourceConfig
Gets the target profile/s of thisResourceConfig
.- Specified by:
getProfile
in interfaceResourceConfig
- Returns:
- target profile/s
- See Also:
ResourceConfig.setProfile(String)
-
setProfile
public void setProfile(String profile)
Description copied from interface:ResourceConfig
Sets the target profile of thisResourceConfig
.- Specified by:
setProfile
in interfaceResourceConfig
- Parameters:
profile
- comma-separated list ofProfileTargetingExpressions
- See Also:
ResourceConfig.getProfile()
-
setResourceType
public void setResourceType(String resourceType)
Description copied from interface:ResourceConfig
Sets the resource type (e.g., "class", "xsl", "groovy", etc...)- Specified by:
setResourceType
in interfaceResourceConfig
- Parameters:
resourceType
- resource type- See Also:
ResourceConfig.getResourceType()
,ResourceConfig.setResource(String)
-
setSelectorPath
public void setSelectorPath(SelectorPath selectorPath)
Description copied from interface:ResourceConfig
Sets the selector in its parsed form.- Specified by:
setSelectorPath
in interfaceResourceConfig
- Parameters:
selectorPath
- selector steps- See Also:
ResourceConfig.setSelector(String, Properties)
,ResourceConfig.getSelectorPath()
-
getSelectorPath
public SelectorPath getSelectorPath()
Description copied from interface:ResourceConfig
Gets the selector in its parsed form.- Specified by:
getSelectorPath
in interfaceResourceConfig
- Returns:
- selector steps
- See Also:
ResourceConfig.setSelector(String, Properties)
,ResourceConfig.getSelectorPath()
-
getProfileTargetingExpressions
public ProfileTargetingExpression[] getProfileTargetingExpressions()
Description copied from interface:ResourceConfig
Gets the profile targeting expressions of thisResourceConfig
.- Specified by:
getProfileTargetingExpressions
in interfaceResourceConfig
- Returns:
- profile targeting expressions
-
getResource
public String getResource()
Description copied from interface:ResourceConfig
Get the resource for thisResourceConfig
.- Specified by:
getResource
in interfaceResourceConfig
- Returns:
- resource
- See Also:
ResourceConfig.setResource(String)
-
isSystem
public boolean isSystem()
Description copied from interface:ResourceConfig
Evaluates whether thisResourceConfig
is for a default resource. System resources (e.g.SystemConsumeSerializerVisitor
) are applied by default when no other resource is targeting the element.- Specified by:
isSystem
in interfaceResourceConfig
- Returns:
true
if this is a default applied resource, otherwise false- See Also:
ResourceConfig.setSystem(boolean)
-
setSystem
public void setSystem(boolean isSystem)
Description copied from interface:ResourceConfig
Set thisResourceConfig
as a default applied resource. System resources (e.g.SystemConsumeSerializerVisitor
) are applied by default when no other resource is targeting the element.- Specified by:
setSystem
in interfaceResourceConfig
- Parameters:
isSystem
- whether thisResourceConfig
is for a default resource
-
getResourceType
public String getResourceType()
Description copied from interface:ResourceConfig
Get the resource type of thisResourceConfig
. Determines the type through the following checks (in order):- Is it a Java resource. See
ResourceConfig.isJavaResource()
. If it is, return "class". - Is the resource type explicitly set on this configuration. If it is, return the value. Ala the "type" attribute on the resource element on DTD v2.0
- Return the resource path file extension e.g. "xsl".
- Specified by:
getResourceType
in interfaceResourceConfig
- Returns:
- resource type
- See Also:
ResourceConfig.getResourceType()
- Is it a Java resource. See
-
setParameter
public <T> Parameter<T> setParameter(String name, T value)
Description copied from interface:ResourceConfig
Adds a parameter to thisResourceConfig
. Multiple parameters with the same names can coexist.- Specified by:
setParameter
in interfaceResourceConfig
- Parameters:
name
- parameter namevalue
- parameter value- Returns:
- new parameter added to this
ResourceConfig
-
setParameter
public <T> Parameter<T> setParameter(String name, String type, T value)
Description copied from interface:ResourceConfig
Adds a parameter with a specified type to thisResourceConfig
. Multiple parameters with the same names can coexist.- Specified by:
setParameter
in interfaceResourceConfig
- Parameters:
name
- parameter nametype
- parameter typevalue
- parameter value- Returns:
- new parameter added to this
ResourceConfig
-
setParameter
public <T> void setParameter(Parameter<T> parameter)
Description copied from interface:ResourceConfig
Adds a parameter to thisResourceConfig
. Multiple parameters with the same names can coexist.- Specified by:
setParameter
in interfaceResourceConfig
- Parameters:
parameter
- parameter to add to thisResourceConfig
-
getParameter
public <T> Parameter<T> getParameter(String name, Class<T> valueClass)
Description copied from interface:ResourceConfig
Gets aparameter
by name from thisResourceConfig
. If more than one parameter match the name, the first parameter is returned.- Specified by:
getParameter
in interfaceResourceConfig
- Parameters:
name
- name of parameter to get- Returns:
- parameter reference, or null if not parameter does not exist
-
getParameters
public Map<String,Object> getParameters()
Description copied from interface:ResourceConfig
Gets the parameters associated with thisResourceConfig
as aMap
.- Specified by:
getParameters
in interfaceResourceConfig
- Returns:
- parameters represented as a
Map
where the key is the parameter name and the value is either aparameter
or alist
ofparameters
. The value is a list when more than one parameter has the same name
-
getParameterValues
public List<?> getParameterValues()
Description copied from interface:ResourceConfig
Gets allparameter
values set of thisResourceConfig
.- Specified by:
getParameterValues
in interfaceResourceConfig
- Returns:
list
of all theparameter
values
-
getParameters
public List<Parameter<?>> getParameters(String name)
Description copied from interface:ResourceConfig
Gets all the parameters of thisResourceConfig
by name.- Specified by:
getParameters
in interfaceResourceConfig
- Parameters:
name
- name of parameter/s to get- Returns:
list
of all theparameters
that match the given name, or null if not set
-
getParameterValue
public Object getParameterValue(String name)
- Specified by:
getParameterValue
in interfaceResourceConfig
-
getParameterValue
public <T> T getParameterValue(String name, Class<T> valueClass)
Description copied from interface:ResourceConfig
Get the named parameter from thisResourceConfig
.- Specified by:
getParameterValue
in interfaceResourceConfig
- Parameters:
name
- name of parameter to get from thisResourceConfig
valueClass
- expected value type of the parameter to get- Returns:
- parameter value, or
null
if not set
-
getParameterValue
public <T> T getParameterValue(String name, Class<T> valueClass, T defaultValue)
Description copied from interface:ResourceConfig
Get value of named parameter from thisResourceConfig
.- Specified by:
getParameterValue
in interfaceResourceConfig
- Parameters:
name
- name of parameter to get.valueClass
- expected value type of the parameter to getdefaultValue
- default value to be returned if there are no parameters in thisResourceConfig
or if the parameter is not defined- Returns:
- parameter value, or
defaultValue
if not defined
-
getParameterCount
public int getParameterCount()
Description copied from interface:ResourceConfig
Get the parameter count of thisResourceConfig
.- Specified by:
getParameterCount
in interfaceResourceConfig
- Returns:
- no. of parameters in this
ResourceConfig
-
removeParameter
public void removeParameter(String name)
Description copied from interface:ResourceConfig
Remove the named parameter thisResourceConfig
- Specified by:
removeParameter
in interfaceResourceConfig
- Parameters:
name
- name of the parameter to be removed
-
getBytes
public byte[] getBytes()
Description copied from interface:ResourceConfig
Returns the resource in bytes. If the resource content is not inlined in the configuration, it will be resolved using theURIResourceLocator
. That is, the path will be interpreted as aURI
. If the resource does not resolve to a stream producing URI, the resource string will be converted to bytes and returned.- Specified by:
getBytes
in interfaceResourceConfig
- Returns:
- resource as a byte array, or
null
if resource path isnull
or the resource does not exist
-
toJavaResource
protected Class<?> toJavaResource()
Returns the resource as a Java Class instance.- Returns:
- The Java Class instance refered to be this resource configuration, or null if the resource doesn't refer to a Java Class.
-
isJavaResource
public boolean isJavaResource()
Description copied from interface:ResourceConfig
Evaluates whether thisResourceConfig
object references a Java class.
- Specified by:
isJavaResource
in interfaceResourceConfig
- Returns:
true
if this resource configuration refers to a Java Class resource, otherwisefalse
-
addChangeListener
public void addChangeListener(ResourceConfigChangeListener resourceConfigChangeListener)
Description copied from interface:ResourceConfig
Adds the specified change listener to the list of change listeners.- Specified by:
addChangeListener
in interfaceResourceConfig
- Parameters:
resourceConfigChangeListener
-ResourceConfigChangeListener
instance to add
-
removeChangeListener
public void removeChangeListener(ResourceConfigChangeListener resourceConfigChangeListener)
Description copied from interface:ResourceConfig
Removes the specified change listener from the list of change listeners.- Specified by:
removeChangeListener
in interfaceResourceConfig
- Parameters:
resourceConfigChangeListener
-ResourceConfigChangeListener
instance to remove
-
toXml
public String toXml()
Description copied from interface:ResourceConfig
Generates an XML'ified description of this resource.- Specified by:
toXml
in interfaceResourceConfig
- Returns:
- XML'ified description of the resource
-
toProperties
public Properties toProperties()
Description copied from interface:ResourceConfig
Creates aProperties
instance from the parametersResourceConfig
object.- Specified by:
toProperties
in interfaceResourceConfig
- Returns:
- resource config parameter.
-
fireChangedEvent
protected void fireChangedEvent()
-
-