Class DependencyTag
- java.lang.Object
-
- org.apache.commons.jelly.TagSupport
-
- net.sf.jguiraffe.gui.builder.di.tags.DependencyTag
-
- All Implemented Interfaces:
ValueSupport
,org.apache.commons.jelly.Tag
- Direct Known Subclasses:
ElementTag
,EntryKeyTag
,EntryTag
,FactoryTag
,InvocationTargetTag
,ParameterTag
,SetPropertyTag
public abstract class DependencyTag extends org.apache.commons.jelly.TagSupport implements ValueSupport
A base class for tag handler classes that support the definition of a dependency.
This base class supports multiple ways of defining a dependency to another bean:
- By specifying the name of the affected bean; this can be done using the
refName
attribute. - By specifying the class of the required bean; for this purpose the
attributes
refClass
,refClassName
, andrefClassLoader
are available, which gather the information needed for aClassDescData
object. - By specifying a constant value for the dependency; to achieve this the
constant value can be set using the
value
attribute. Optionally the class of the value can be specified (to cause an automatic conversion). For this use case the attributesvalueClass
,valueClassName
, andvalueClassLoader
are responsible, which again fill the properties of aClassDescData
. - If this dependency is defined in the scope of a
ChainedInvocation
, it is possible to create a dependency to a local variable. Use thevar
attribute in this case.
The class checks whether the definition of the dependency is consistent. This means that only a single way of specifying a dependency can be used.
- Version:
- $Id: DependencyTag.java 207 2012-02-09 07:30:13Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DependencyTag()
Creates a new instance ofDependencyTag
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Dependency
createDependency()
Creates theDependency
based on the values of the attributes.protected Dependency
createValueDependency()
Creates the dependency when a direct value is set.protected Dependency
getDependency()
Returns theDependency
defined by this tag.ClassDescData
getRefClassData()
Returns the class description data for the specification of a class dependency.String
getRefName()
Returns the name of the dependent bean.ValueData
getValueData()
Returns the data object with information about the tag's (constant) value.String
getVar()
Returns the name of the local variable to be used as dependency.protected boolean
hasDependency()
Checks whether a dependency is defined by this tag.protected int
processDependencyDefinitions()
Evaluates the definitions of the dependency.protected void
setDependency(Dependency dep)
Sets the internal dependency.void
setRefClass(Class<?> c)
Set method for the refClass attribute.void
setRefClassLoader(String s)
Set method for the refClassLoader attribute.void
setRefClassName(String s)
Set method for the refClassName attribute.void
setRefName(String refName)
Set method of the refName attribute.void
setValue(Object value)
Set method for the value attribute.void
setValueClass(Class<?> cls)
Set method for the valueClass attribute.void
setValueClassLoader(String loader)
Set method for the valueClassLoader attribute.void
setValueClassName(String clsName)
Set method for the valueClassName attribute.void
setVar(String var)
Set method of the var attribute.-
Methods inherited from class org.apache.commons.jelly.TagSupport
findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
-
-
-
-
Method Detail
-
getValueData
public ValueData getValueData()
Returns the data object with information about the tag's (constant) value.- Returns:
- the value data object
-
getRefClassData
public ClassDescData getRefClassData()
Returns the class description data for the specification of a class dependency.- Returns:
- the class description data for a class dependency
-
getRefName
public String getRefName()
Returns the name of the dependent bean.- Returns:
- the name reference
-
setRefName
public void setRefName(String refName)
Set method of the refName attribute.- Parameters:
refName
- the attribute's value
-
setRefClass
public void setRefClass(Class<?> c)
Set method for the refClass attribute.- Parameters:
c
- the attribute's value
-
setRefClassName
public void setRefClassName(String s)
Set method for the refClassName attribute.- Parameters:
s
- the attribute's value
-
setRefClassLoader
public void setRefClassLoader(String s)
Set method for the refClassLoader attribute.- Parameters:
s
- the attribute's value
-
setValue
public void setValue(Object value)
Set method for the value attribute.- Specified by:
setValue
in interfaceValueSupport
- Parameters:
value
- the attribute's value
-
setValueClass
public void setValueClass(Class<?> cls)
Set method for the valueClass attribute.- Parameters:
cls
- the attribute's value
-
setValueClassName
public void setValueClassName(String clsName)
Set method for the valueClassName attribute.- Parameters:
clsName
- the attribute's value
-
setValueClassLoader
public void setValueClassLoader(String loader)
Set method for the valueClassLoader attribute.- Parameters:
loader
- the attribute's value
-
getVar
public String getVar()
Returns the name of the local variable to be used as dependency. This way of defining a dependency is available only if the current dependency is in the scope of a chained invocation.- Returns:
- the local variable to be used as dependency
-
setVar
public void setVar(String var)
Set method of the var attribute.- Parameters:
var
- the attribute's value
-
processDependencyDefinitions
protected int processDependencyDefinitions() throws org.apache.commons.jelly.JellyTagException
Evaluates the definitions of the dependency. The return value is number of found definitions (for performing a validity check). If there is exactly one definition, the dependency is created and stored by invokingsetDependency(Dependency)
.- Returns:
- the number of found dependency definitions
- Throws:
org.apache.commons.jelly.JellyTagException
- if the creation of the dependency causes an error
-
createDependency
protected Dependency createDependency() throws org.apache.commons.jelly.JellyTagException
Creates theDependency
based on the values of the attributes. This method also checks for consistency of the defined properties and throws an exception if something is strange.- Returns:
- the
Dependency
defined by this tag's attributes - Throws:
org.apache.commons.jelly.JellyTagException
- if the attributes are not consistent
-
getDependency
protected Dependency getDependency() throws org.apache.commons.jelly.JellyTagException
Returns theDependency
defined by this tag. If this dependency has not yet been created,createDependency()
is called. Otherwise the existingDependency
object is returned.- Returns:
- the
Dependency
defined by this tag - Throws:
org.apache.commons.jelly.JellyTagException
- if the tag is incorrectly used or an error occurred
-
setDependency
protected void setDependency(Dependency dep)
Sets the internal dependency. This method is called when the tag's dependency could be successfully created. It stores the dependency in an internal field where it can be directly accessed fromgetDependency()
.- Parameters:
dep
- the dependency to store
-
hasDependency
protected boolean hasDependency()
Checks whether a dependency is defined by this tag.- Returns:
- a flag whether a dependency is defined
-
createValueDependency
protected Dependency createValueDependency() throws org.apache.commons.jelly.JellyTagException
Creates the dependency when a direct value is set. This method is called byprocessDependencyDefinitions()
when a value for this tag is set. The base implementation delegates to thecreateValueDependency()
method of theValueData
object.- Returns:
- the dependency referring to the constant value
- Throws:
org.apache.commons.jelly.JellyTagException
- if creation of the dependency causes an error
-
-