Package org.oddjob.arooa.beanutils
Class MagicBeanDescriptorFactory
java.lang.Object
org.oddjob.arooa.beanutils.MagicBeanDescriptorFactory
- All Implemented Interfaces:
ArooaDescriptorFactory
- Author:
- rob
Description
Define Magic Beans. Magic Beans are beans who's properties can be defined dynamically. Magic beans are useful when you want to collect information in one bean so it can be kept together.Example
Creating a magic bean that define some file information.
This is an outer Oddjob configuration file that creates the descriptor
that defines properties for a filespec element.
<oddjob id="this">
<job>
<oddjob file="${this.dir}/MagicBeansInner.xml">
<descriptorFactory>
<arooa:magic-beans namespace="oddjob:magic" prefix="magic" xmlns:arooa="http://rgordon.co.uk/oddjob/arooa">
<definitions>
<is element="filespec">
<properties>
<is name="description" type="java.lang.String"/>
<is name="file" type="java.io.File" configured="ATTRIBUTE"/>
<is name="maxSize" type="java.lang.Long"/>
</properties>
</is>
</definitions>
</arooa:magic-beans>
</descriptorFactory>
</oddjob>
</job>
</oddjob>
The nested inner Oddjob configuration uses a list of filespec
magic beans to define information for a For Each job.
<oddjob>
<job>
<foreach>
<values>
<list>
<values>
<magic:filespec description="Big File" file="/files/big" maxSize="1000000" xmlns:magic="oddjob:magic"/>
<magic:filespec description="Medium File" file="/files/medium" maxSize="20000" xmlns:magic="oddjob:magic"/>
<magic:filespec description="Small File" file="/files/small" maxSize="3000" xmlns:magic="oddjob:magic"/>
</values>
</list>
</values>
<configuration>
<xml>
<foreach id="each">
<job>
<echo>
Checking ${each.current.description} (${each.current.file})
less than ${each.current.maxSize} bytes...</echo>
</job>
</foreach>
</xml>
</configuration>
</foreach>
</job>
</oddjob>
The example will display the following when ran:
Checking Big File (\files\big) less than 1000000 bytes... Checking Medium File (\files\medium) less than 20000 bytes... Checking Small File (\files\small) less than 3000 bytes...
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateDescriptor(ClassLoader classLoader) Create an ArooaDescriptor.getDefinitions(int index) voidsetDefinitions(int index, MagicBeanDefinition def) voidsetNamespace(URI namespace) voidtoString()
-
Constructor Details
-
MagicBeanDescriptorFactory
public MagicBeanDescriptorFactory()
-
-
Method Details
-
createDescriptor
Description copied from interface:ArooaDescriptorFactoryCreate an ArooaDescriptor.- Specified by:
createDescriptorin interfaceArooaDescriptorFactory- Parameters:
classLoader- The classLoader to use.- Returns:
- An ArooaDescriptor. May be null.
-
setDefinitions
-
getDefinitions
-
getNamespace
-
setNamespace
-
getPrefix
-
setPrefix
-
toString
-