net.sf.jameleon.function
Class AttributeBroker

java.lang.Object
  extended by net.sf.jameleon.function.AttributeBroker

public class AttributeBroker
extends Object

The AttributeBroker class is used to copy values from a JellyContext or the script directory to instance variables in an Attributable.


Field Summary
protected  Map attributes
          A List of attributes or instance variables of the consumer
protected  Attributable consumer
          The instance of the Attributable to which the values will be transfered to
static boolean NOT_REQUIRED
           
static boolean OPTIONAL
           
static boolean REQUIRED
           
 
Constructor Summary
AttributeBroker(Attributable consumer)
          An Attributable is required to instaniate this class.
 
Method Summary
 Map getAttributes()
          Gets the attributes registered for this Attributable
 Object getAttributeValue(Attribute attr, JellyContext context)
          Gets the real-time value of attr for the consumer
protected  Object getAttributeValueFromInstance(Attribute attr)
           
 Field getConsumerField(Attribute attr)
           
protected  Object getValueFromContext(JellyContext context, String contextName, String defaultValue)
          Attempts to get the value for the given key (contextName) from the context.
 void registerAttribute(Attribute attr)
          Add an attribute to the list of instance variables supported by the consumer
 void setConsumerAttribute(Attribute attr, Object objValue)
          Sets the instance variable of the Attributable to the value with the correct type.
 void setConsumerAttributeAsObject(Field f, Object objValue)
           
 void setConsumerAttributeAsPrimitive(Field f, Object objValue)
           
 void setUp()
          Calls the Attributable.describeAttributes() method.
 void transferAttributes(JellyContext context)
          Copy all variables from the context (JellyContext) to instances variables registered in the Attributable instance.
 void validate(JellyContext context)
          Validates that all context variables marked as required are set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

consumer

protected Attributable consumer
The instance of the Attributable to which the values will be transfered to


attributes

protected Map attributes
A List of attributes or instance variables of the consumer


REQUIRED

public static final boolean REQUIRED
See Also:
Constant Field Values

NOT_REQUIRED

public static final boolean NOT_REQUIRED
See Also:
Constant Field Values

OPTIONAL

public static final boolean OPTIONAL
See Also:
Constant Field Values
Constructor Detail

AttributeBroker

public AttributeBroker(Attributable consumer)
An Attributable is required to instaniate this class.

Method Detail

getAttributes

public Map getAttributes()
Gets the attributes registered for this Attributable


registerAttribute

public void registerAttribute(Attribute attr)
Add an attribute to the list of instance variables supported by the consumer


setUp

public void setUp()
Calls the Attributable.describeAttributes() method. This needs to be called before anything else is called


transferAttributes

public void transferAttributes(JellyContext context)
Copy all variables from the context (JellyContext) to instances variables registered in the Attributable instance.

Parameters:
context - - The context that stores the Attributable-independent key/value pairs which will be used to set the instance variables of the Attributable to.

validate

public void validate(JellyContext context)
              throws MissingAttributeException
Validates that all context variables marked as required are set.

Parameters:
context - The JellyContext of the tag.
Throws:
MissingAttributeException - if any required attributes were not set.

getValueFromContext

protected Object getValueFromContext(JellyContext context,
                                     String contextName,
                                     String defaultValue)
Attempts to get the value for the given key (contextName) from the context. If a value is not found from the context, then a defaultValue is used.

Parameters:
context - - A JellyContext of key/value pairs.
contextName - - The key from the context
defaultValue - - A value to return only if the variable is not set in the context.
Returns:
The value for the given context variable.

getAttributeValue

public Object getAttributeValue(Attribute attr,
                                JellyContext context)
Gets the real-time value of attr for the consumer

Parameters:
attr - - The attr that represents the property's value to be returned.
Returns:
The real-time value of the attribute.

getConsumerField

public Field getConsumerField(Attribute attr)

getAttributeValueFromInstance

protected Object getAttributeValueFromInstance(Attribute attr)

setConsumerAttribute

public void setConsumerAttribute(Attribute attr,
                                 Object objValue)
Sets the instance variable of the Attributable to the value with the correct type.

Parameters:
attr - - The Attribute representing the variable to set.
objValue - - The value to the instance variable to.

setConsumerAttributeAsPrimitive

public void setConsumerAttributeAsPrimitive(Field f,
                                            Object objValue)

setConsumerAttributeAsObject

public void setConsumerAttributeAsObject(Field f,
                                         Object objValue)


Copyright © 2003-2008 Christian Hargraves. All Rights Reserved.