ilog.cpl.model
Class IlpDefaultObject

java.lang.Object
  extended by ilog.cpl.model.IlpDefaultObject
All Implemented Interfaces:
IlpAttributeValueHolder, IlpObject
Direct Known Subclasses:
IltAlarm, IltObject

public class IlpDefaultObject
extends Object
implements IlpObject

Defines a default implementation for IlpObject instances. This class can be used as a default instance to add objects to a data source.

Note: Despite being a concrete class implementing IlpObject, this class does not have a corresponding IlpClass descriptor. Therefore it cannot be directly used in XML. But objects defined in XML using a syntax like

<classes> <class> <name>MyClass</name> </class> </classes> <addObject id="MyObject #5"> <class>MyClass</class> </addObject> will in fact be represented as instances of IlpDefaultObject.

Since:
JTGO 3.0

Field Summary
 
Fields inherited from interface ilog.cpl.model.IlpAttributeValueHolder
VALUE_NOT_SET
 
Constructor Summary
protected IlpDefaultObject()
          Default constructor used for serialization
  IlpDefaultObject(IlpClass ilpClass, Object identifier)
          Constructor.
  IlpDefaultObject(IlpClass ilpClass, Object identifier, boolean initializeAttributeValues)
          Constructor.
 
Method Summary
 void addAttributeValueListener(AttributeValueListener l)
          Adds a listener to attribute value changes.
 void fireEvent(AttributeValueEvent ev)
          Fires the given event to all listeners.
 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.
 Object getAttributeValueByName(String name)
          Deprecated. Please use getAttributeValue instead.
 Object getIdentifier()
          Returns the identifier of the IlpObject.
 IlpClass getIlpClass()
          Retrieves the IlpClass corresponding to this object.
protected  Map getLocalAttributeValues()
          Called only during serialization in IltObject
protected  IlpObjectSupport getObjectSupport()
           
 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 initializeDefaultValues()
          This method initializes the attribute values of the object with the default attribute values, if there are any.
 void removeAttributeValueListener(AttributeValueListener l)
          Removes the given listener to the attribute value changes.
 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.
 void setAttributeValueByName(String name, Object value)
          Deprecated. Please use setAttributeValue instead.
protected  void setLocalAttributeValues(Map values)
          Called only during deserialization in IltObject
protected  void setObjectSupport(IlpObjectSupport s)
          Called only during deserialization in IltObject
 String toString()
          Returns an identifier as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IlpDefaultObject

protected IlpDefaultObject()
Default constructor used for serialization


IlpDefaultObject

public IlpDefaultObject(IlpClass ilpClass,
                        Object identifier)
Constructor. It stores the IlpClass defining this object and initializes the attribute values using the default values of the IlpAttributes.

Parameters:
ilpClass - The IlpClass of this object.
identifier - The identifier of this instance. See IlpIDGenerator for a simple identifier generator and IlpObject.getIdentifier() for the constraints on identifiers.

IlpDefaultObject

public IlpDefaultObject(IlpClass ilpClass,
                        Object identifier,
                        boolean initializeAttributeValues)
Constructor.

Parameters:
ilpClass - The IlpClass of this object.
identifier - The identifier of this instance. See IlpIDGenerator for a simple identifier generator and IlpObject.getIdentifier() for the constraints on identifiers.
initializeAttributeValues - Indicates whether the object should be initialized using the default attribute values.
Method Detail

getIdentifier

public Object getIdentifier()
Returns the identifier of the IlpObject. This identifier is an Object that can be used to identify and retrieve this IlpObject. It must be unique.

Specified by:
getIdentifier in interface IlpObject
Returns:
The identifier of the IlpObject.
See Also:
IlpTypeConverter

getIlpClass

public IlpClass getIlpClass()
Retrieves the IlpClass corresponding to this object.

Specified by:
getIlpClass in interface IlpObject
Returns:
The IlpClass corresponding to this object.

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 whose value is to be retrieved.
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 will be created and added to the local attribute model, if possible. 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 whose value is set.
value - The new value of the attribute or VALUE_NOT_SET to remove the value of the attribute.
Throws:
IllegalArgumentException - if the value of the attribute cannot be modified.

addAttributeValueListener

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

Specified by:
addAttributeValueListener in interface IlpAttributeValueHolder

removeAttributeValueListener

public void removeAttributeValueListener(AttributeValueListener l)
Removes the given listener to the attribute value changes.

Specified by:
removeAttributeValueListener in interface IlpAttributeValueHolder

fireEvent

public void fireEvent(AttributeValueEvent ev)
Fires the given event to all listeners.

Specified by:
fireEvent in interface IlpAttributeValueHolder

getAttributeValueByName

public Object getAttributeValueByName(String name)
Deprecated. Please use getAttributeValue instead.

Returns the value of an attribute of this object.

Parameters:
name - The name of the attribute whose value is to be retrieved.
Returns:
The value of the attribute or VALUE_NOT_SET if no value has been set.
Deprecated Since:
JTGO 4.0

setAttributeValueByName

public void setAttributeValueByName(String name,
                                    Object value)
Deprecated. Please use setAttributeValue instead.

Sets the value of an attribute of this object. If the attribute does not exist, a default attribute with the given name will be created and added to the local attribute model.

Parameters:
name - The name of the attribute whose value is to be changed.
value - The new value of the attribute or VALUE_NOT_SET to remove the value of the attribute.
Throws:
IllegalArgumentException - if the value of the attribute cannot be modified.
Deprecated Since:
JTGO 4.0

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 is created and added to the local attribute model, if possible. Note: For the new value to be taken into account, an object that is different from the initial one 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 value of the attribute cannot be modified.
Since:
JTGO 4.0

initializeDefaultValues

public void initializeDefaultValues()
This method initializes the attribute values of the object with the default attribute values, if there are any. Note that this method does not reset an attribute value that has been set to its default value. It will change the attributes that have a default value (which is not VALUE_NOT_SET) AND that have not been set in another way, using, for example, setAttributeValue.

Specified by:
initializeDefaultValues in interface IlpObject

toString

public String toString()
Returns an identifier as a string.

Overrides:
toString in class Object

getLocalAttributeValues

protected Map getLocalAttributeValues()
Called only during serialization in IltObject

Internal method or field: do not use!

setLocalAttributeValues

protected void setLocalAttributeValues(Map values)
Called only during deserialization in IltObject

Internal method or field: do not use!

setObjectSupport

protected void setObjectSupport(IlpObjectSupport s)
Called only during deserialization in IltObject

Internal method or field: do not use!

getObjectSupport

protected IlpObjectSupport getObjectSupport()
Internal method or field: do not use!


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