Class UseBeanTag
- java.lang.Object
-
- org.apache.commons.jelly.TagSupport
-
- org.apache.commons.jelly.DynaTagSupport
-
- org.apache.commons.jelly.MapTagSupport
-
- org.apache.commons.jelly.tags.core.UseBeanTag
-
- All Implemented Interfaces:
DynaTag
,BeanSource
,Tag
- Direct Known Subclasses:
UseListTag
public class UseBeanTag extends MapTagSupport implements BeanSource
A tag which instantiates an instance of the given class and then sets the properties on the bean. The class can be specified via aClass
instance or a String which will be used to load the class using either the current thread's context class loader or the class loader used to load this Jelly library. This tag can be used it as follows,<j:useBean var="person" class="com.acme.Person" name="James" location="${loc}"/> <j:useBean var="order" class="${orderClass}" amount="12" price="123.456"/>
- Version:
- $Revision: 155420 $
- Author:
- James Strachan
-
-
Field Summary
-
Fields inherited from class org.apache.commons.jelly.TagSupport
body, context, parent
-
-
Constructor Summary
Constructors Constructor Description UseBeanTag()
UseBeanTag(Class defaultClass)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addIgnoreProperty(String name)
Adds a name to the Set of property names that will be skipped when setting bean properties.protected Class
convertToClass(Object classObject)
Attempts to convert the given object to a Class instance.void
doTag(XMLOutput output)
Evaluates this tag after all the tags properties have been initialized.Object
getBean()
protected Class
getDefaultClass()
Allows derived classes to provide a default bean implementation classprotected Set
getIgnorePropertySet()
boolean
isIgnoreUnknownProperties()
protected Class
loadClass(String className)
Loads the given class using the default class loading mechanism which is to try use the current Thread's context class loader first otherise use the class loader which loaded this class.protected Object
newInstance(Class theClass, Map attributes, XMLOutput output)
Creates a new instance of the given class, which by default will invoke the default constructor.protected void
processBean(String var, Object bean)
By default this will export the bean using the given variable if it is defined.protected void
setBean(Object bean)
Allow derived classes to programatically set the beanprotected void
setBeanProperties(Object bean, Map attributes)
Sets the properties on the bean.void
setIgnoreUnknownProperties(boolean ignoreUnknownProps)
If this tag finds an attribute in the XML that's not ignored byignoreProperties
and isn't a bean property, should it throw an exception?protected void
validateBeanProperties(Object bean, Map attributes)
IfisIgnoreUnknownProperties()
returns true, make sure that every non-ignored (seeaddIgnoreProperty(String)
) property matches a writable property on the target bean.-
Methods inherited from class org.apache.commons.jelly.MapTagSupport
createAttributes, getAttributes, setAttribute
-
Methods inherited from class org.apache.commons.jelly.DynaTagSupport
getAttributeType
-
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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.jelly.Tag
getBody, getContext, getParent, invokeBody, setBody, setContext, setParent
-
-
-
-
Constructor Detail
-
UseBeanTag
public UseBeanTag()
-
UseBeanTag
public UseBeanTag(Class defaultClass)
-
-
Method Detail
-
getBean
public Object getBean()
- Specified by:
getBean
in interfaceBeanSource
- Returns:
- the bean that has just been created
-
doTag
public void doTag(XMLOutput output) throws JellyTagException
Description copied from interface:Tag
Evaluates this tag after all the tags properties have been initialized.- Specified by:
doTag
in interfaceTag
- Throws:
JellyTagException
-
setBean
protected void setBean(Object bean)
Allow derived classes to programatically set the bean
-
convertToClass
protected Class convertToClass(Object classObject) throws MissingAttributeException, ClassNotFoundException
Attempts to convert the given object to a Class instance. If the classObject is already a Class it will be returned otherwise it will be converted to a String and loaded using the default class loading mechanism.
-
loadClass
protected Class loadClass(String className) throws ClassNotFoundException
Loads the given class using the default class loading mechanism which is to try use the current Thread's context class loader first otherise use the class loader which loaded this class.- Throws:
ClassNotFoundException
-
newInstance
protected Object newInstance(Class theClass, Map attributes, XMLOutput output) throws JellyTagException
Creates a new instance of the given class, which by default will invoke the default constructor. Derived tags could do something different here.- Throws:
JellyTagException
-
setBeanProperties
protected void setBeanProperties(Object bean, Map attributes) throws JellyTagException
Sets the properties on the bean. Derived tags could implement some custom type conversion etc.This method ignores all property names in the Set returned by
getIgnorePropertySet()
.- Throws:
JellyTagException
-
validateBeanProperties
protected void validateBeanProperties(Object bean, Map attributes) throws JellyTagException
IfisIgnoreUnknownProperties()
returns true, make sure that every non-ignored (seeaddIgnoreProperty(String)
) property matches a writable property on the target bean.- Parameters:
bean
- the bean to validateattributes
- the list of properties to validate- Throws:
JellyTagException
- when a property is not writeable
-
processBean
protected void processBean(String var, Object bean) throws JellyTagException
By default this will export the bean using the given variable if it is defined. This Strategy method allows derived tags to process the beans in different ways such as to register this bean with its parent tag etc.- Throws:
JellyTagException
-
getDefaultClass
protected Class getDefaultClass()
Allows derived classes to provide a default bean implementation class
-
addIgnoreProperty
protected void addIgnoreProperty(String name)
Adds a name to the Set of property names that will be skipped when setting bean properties. In other words, names added here won't be set into the bean if they're present in the attribute Map.- Parameters:
name
-
-
getIgnorePropertySet
protected Set getIgnorePropertySet()
- Returns:
- the Set of property names that should be ignored when setting the properties of the bean.
-
isIgnoreUnknownProperties
public boolean isIgnoreUnknownProperties()
- Returns:
- See Also:
setIgnoreUnknownProperties(boolean)
-
setIgnoreUnknownProperties
public void setIgnoreUnknownProperties(boolean ignoreUnknownProps)
If this tag finds an attribute in the XML that's not ignored byignoreProperties
and isn't a bean property, should it throw an exception?- Parameters:
ignoreUnknownProps
- SetsignoreUnknownProperties
.
-
-