ilog.cpl.model
Class IlpAttributeValueHolderSupport

java.lang.Object
  extended by ilog.cpl.model.IlpAttributeValueChangeSupport
      extended by ilog.cpl.model.IlpAttributeValueHolderSupport
All Implemented Interfaces:
AttributeValueListener, IlpAttributeValueHolder, EventListener
Direct Known Subclasses:
IlpObjectSupport

public class IlpAttributeValueHolderSupport
extends IlpAttributeValueChangeSupport
implements IlpAttributeValueHolder, AttributeValueListener

This class models a default implementation for attribute holders.

Since:
JTGO 3.0

Field Summary
 
Fields inherited from interface ilog.cpl.model.IlpAttributeValueHolder
VALUE_NOT_SET
 
Constructor Summary
IlpAttributeValueHolderSupport(IlpAttributeValueHolder source, IlpAttributeGroup model)
          Creates a new attribute holder based on the given model.
IlpAttributeValueHolderSupport(IlpAttributeValueHolder source, IlpAttributeGroup model, IlpAttributeValueHolder defaultHolder)
          Creates a new attribute holder based on the given model.
 
Method Summary
 void addAttributeValueListener(AttributeValueListener l)
          Adds a listener to attribute value changes.
 void attributeValueChange(AttributeValueEvent ev)
          This method is called when an attribute value of the underlying attribute holder is modified.
 IlpAttributeGroup getAttributeGroup()
          Returns the model that defines which attributes are allowed in this instance.
 Object getAttributeValue(IlpAttribute a)
          Retrieves the value of an attribute of this object.
 Object getAttributeValue(String name)
          Returns the value of an attribute of this object.
 boolean hasAttributeValue(IlpAttribute a)
          Returns true if the requested attribute is part of the attribute group of this instance and if a value has been set for this attribute.
 void recomputeDependentAttributes(IlpAttribute a)
          Verifies if any of the computed attributes in the computed attribute list depend on the given attribute.
 void removeAttributeValueListener(AttributeValueListener l)
          Removes the given listener from the attribute value change notifications.
 void setAttributeValue(IlpAttribute attribute, Object value)
          Sets the value of an attribute of this object.
 void setAttributeValue(String name, Object value)
          Sets the value of an attribute of this object.
 
Methods inherited from class ilog.cpl.model.IlpAttributeValueChangeSupport
fireAttributeChange, fireEvent, getSource, hasAttributeValueNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ilog.cpl.model.IlpAttributeValueHolder
fireEvent
 

Constructor Detail

IlpAttributeValueHolderSupport

public IlpAttributeValueHolderSupport(IlpAttributeValueHolder source,
                                      IlpAttributeGroup model)
Creates a new attribute holder based on the given model.

Parameters:
source - The IlpAttributeValueHolder that delegates its method to this support class.
model - The attribute model.

IlpAttributeValueHolderSupport

public IlpAttributeValueHolderSupport(IlpAttributeValueHolder source,
                                      IlpAttributeGroup model,
                                      IlpAttributeValueHolder defaultHolder)
Creates a new attribute holder based on the given model.

Parameters:
source - This is the real IlpAttributeValueHolder.
model - This is the attribute model which defines the valid attributes for this holder.
defaultHolder - This is a secondary IlpAttributeValueHolder in which to look if the attribute is not set locally.
Method Detail

getAttributeGroup

public IlpAttributeGroup getAttributeGroup()
Returns the model that defines which attributes are allowed in this instance.

Specified by:
getAttributeGroup in interface IlpAttributeValueHolder

getAttributeValue

public Object getAttributeValue(IlpAttribute a)
Retrieves the value of an attribute of this object.

Specified by:
getAttributeValue in interface IlpAttributeValueHolder
Parameters:
a - The attribute.
Returns:
The value of the attribute or VALUE_NOT_SET if no value has been set.

hasAttributeValue

public boolean hasAttributeValue(IlpAttribute a)
Returns true if the requested attribute is part of the attribute group of this instance and if a value has been set for this attribute.

Specified by:
hasAttributeValue in interface IlpAttributeValueHolder

setAttributeValue

public void setAttributeValue(IlpAttribute attribute,
                              Object value)
Sets the value of an attribute of this object. If the attribute does not exist, a default attribute with the given name may possibly be created and added to the local attribute model. Note: For the new value to be taken into account an object different from the initial object must be set.

   Object value = o.getAttributeValue(attribute);

   // Incorrect: the value is stored in the same object. The change is not
   // taken into account.
   value.modify();
   o.setAttributeValue(attribute,value);

   // Correct: the new value is stored in a new object. The change is taken
   // into account.
   value = value.clone();  // Returns a new object
   value.modify();
   o.setAttributeValue(attribute,value);
 

Specified by:
setAttributeValue in interface IlpAttributeValueHolder
Parameters:
attribute - The attribute.
value - The new value of the attribute or VALUE_NOT_SET to remove the value of the attribute.
Throws:
IllegalArgumentException - if the attribute cannot have its value modified.

getAttributeValue

public Object getAttributeValue(String name)
Returns the value of an attribute of this object.

Specified by:
getAttributeValue in interface IlpAttributeValueHolder
Parameters:
name - The name of the attribute.
Returns:
The value of the attribute or VALUE_NOT_SET if no value has been set.
Since:
JTGO 4.0

setAttributeValue

public void setAttributeValue(String name,
                              Object value)
Sets the value of an attribute of this object. If the attribute does not exist, a default attribute with the given name may be created and added to the local attribute model. Note: For the new value to be taken into account an object different from the initial object must be set.

   Object value = o.getAttributeValue(name);

   // Incorrect: the value is stored in the same object. The change is not
   // taken into account.
   value.modify();
   o.setAttributeValue(name,value);

   // Correct: the new value is stored in a new object. The change is taken
   // into account.
   value = value.clone();  // Returns a new object
   value.modify();
   o.setAttributeValue(name,value);
 

Specified by:
setAttributeValue in interface IlpAttributeValueHolder
Parameters:
name - The name of the attribute.
value - The new value of the attribute or VALUE_NOT_SET to remove the value of the attribute.
Throws:
IllegalArgumentException - if the attribute cannot have its value modified.
Since:
JTGO 4.0

attributeValueChange

public void attributeValueChange(AttributeValueEvent ev)
This method is called when an attribute value of the underlying attribute holder is modified.

Specified by:
attributeValueChange in interface AttributeValueListener
Parameters:
ev - The attribute value event to be fired.

addAttributeValueListener

public void addAttributeValueListener(AttributeValueListener l)
Adds a listener to attribute value changes.

Specified by:
addAttributeValueListener in interface IlpAttributeValueHolder
Overrides:
addAttributeValueListener in class IlpAttributeValueChangeSupport

removeAttributeValueListener

public void removeAttributeValueListener(AttributeValueListener l)
Removes the given listener from the attribute value change notifications.

Specified by:
removeAttributeValueListener in interface IlpAttributeValueHolder
Overrides:
removeAttributeValueListener in class IlpAttributeValueChangeSupport

recomputeDependentAttributes

public void recomputeDependentAttributes(IlpAttribute a)
Verifies if any of the computed attributes in the computed attribute list depend on the given attribute. If so, the computed attribute is removed from the list and its value will be only calculated next time the user calls getAttributeValue.

Internal method or field: do not use!


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.