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
refNameattribute. - By specifying the class of the required bean; for this purpose the
attributes
refClass,refClassName, andrefClassLoaderare available, which gather the information needed for aClassDescDataobject. - By specifying a constant value for the dependency; to achieve this the
constant value can be set using the
valueattribute. Optionally the class of the value can be specified (to cause an automatic conversion). For this use case the attributesvalueClass,valueClassName, andvalueClassLoaderare 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 thevarattribute 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 protectedDependencyTag()Creates a new instance ofDependencyTag.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DependencycreateDependency()Creates theDependencybased on the values of the attributes.protected DependencycreateValueDependency()Creates the dependency when a direct value is set.protected DependencygetDependency()Returns theDependencydefined by this tag.ClassDescDatagetRefClassData()Returns the class description data for the specification of a class dependency.StringgetRefName()Returns the name of the dependent bean.ValueDatagetValueData()Returns the data object with information about the tag's (constant) value.StringgetVar()Returns the name of the local variable to be used as dependency.protected booleanhasDependency()Checks whether a dependency is defined by this tag.protected intprocessDependencyDefinitions()Evaluates the definitions of the dependency.protected voidsetDependency(Dependency dep)Sets the internal dependency.voidsetRefClass(Class<?> c)Set method for the refClass attribute.voidsetRefClassLoader(String s)Set method for the refClassLoader attribute.voidsetRefClassName(String s)Set method for the refClassName attribute.voidsetRefName(String refName)Set method of the refName attribute.voidsetValue(Object value)Set method for the value attribute.voidsetValueClass(Class<?> cls)Set method for the valueClass attribute.voidsetValueClassLoader(String loader)Set method for the valueClassLoader attribute.voidsetValueClassName(String clsName)Set method for the valueClassName attribute.voidsetVar(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:
setValuein 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.JellyTagExceptionEvaluates 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 theDependencybased 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
Dependencydefined 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 theDependencydefined by this tag. If this dependency has not yet been created,createDependency()is called. Otherwise the existingDependencyobject is returned.- Returns:
- the
Dependencydefined 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 theValueDataobject.- Returns:
- the dependency referring to the constant value
- Throws:
org.apache.commons.jelly.JellyTagException- if creation of the dependency causes an error
-
-