org.oddjob.arooa.beanutils
Class MagicBeanDescriptorFactory

java.lang.Object
  extended by org.oddjob.arooa.beanutils.MagicBeanDescriptorFactory
All Implemented Interfaces:
ArooaDescriptorFactory

public class MagicBeanDescriptorFactory
extends Object
implements ArooaDescriptorFactory

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...
 
Author:
rob

Constructor Summary
MagicBeanDescriptorFactory()
           
 
Method Summary
 ArooaDescriptor createDescriptor(ClassLoader classLoader)
          Create an ArooaDesciptor.
 MagicBeanDefinition getDefinitions(int index)
           
 URI getNamespace()
           
 String getPrefix()
           
 void setDefinitions(int index, MagicBeanDefinition def)
           
 void setNamespace(URI namespace)
           
 void setPrefix(String prefix)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MagicBeanDescriptorFactory

public MagicBeanDescriptorFactory()
Method Detail

createDescriptor

public ArooaDescriptor createDescriptor(ClassLoader classLoader)
Description copied from interface: ArooaDescriptorFactory
Create an ArooaDesciptor.

Specified by:
createDescriptor in interface ArooaDescriptorFactory
Parameters:
classLoader - The classLoader to use.
Returns:
An ArooaDescriptor. May be null.

setDefinitions

public void setDefinitions(int index,
                           MagicBeanDefinition def)

getDefinitions

public MagicBeanDefinition getDefinitions(int index)

getNamespace

public URI getNamespace()

setNamespace

public void setNamespace(URI namespace)

getPrefix

public String getPrefix()

setPrefix

public void setPrefix(String prefix)

toString

public String toString()
Overrides:
toString in class Object