The interface
IlpObject defines instances of business
classes. These instances (business objects) contain values for the
attributes defined by the corresponding class. They also have an
attribute group that can be the
IlpClass itself or an extension allowing you
to define new attributes at the object level.
Each business object must be assigned to an identifier when it is
created. The identifier must be unique (even across data sources);
it is used to identify and retrieve the
IlpObject
. The object identifier can be of any type, as long as it satisfies
the following constraints:
The identifier must be convertible to
String
, through an
IlpTypeConverter installed in the
IlpContext. The
IlpDefaultTypeConverter uses the
Object.toString()
method to convert objects of unknown types to
String
. The
String
that results from this conversion must be unique.
It must be possible to create or retrieve the identifier
Object
, given the corresponding
String
, by using the
IlpTypeConverter installed in the
IlpContext. The
IlpDefaultTypeConverter uses a constructor
with a single
String
argument to create instances of unknown types.
The identifier
Object
itself must not be an instance of
IlpObject.
Note the following recommendations:
Ideally the identifier should be implemented as a simple object
in order to perform a fast comparison. For the sake of
simplicity, it is recommended to use simple objects, such as
Number
or
String
, which already satisfy the constraints listed above.
If you are using your own Java™ class as identifier, the
public boolean equals(Object obj)
method of the identifier class should be overridden to perform
an efficient comparison of identifier instances. The
public int hashcode()
method should also be overridden and must be consistent with the
public boolean equals(Object obj)
implementation.
An identifier generator can be used to generate the object
identifiers in a consistent manner. A predefined identifier
generator is available in
ilog.cpl.util.
IlpIDGenerator.
Note that once the proper implementation for the
IlpTypeConverter is created (normally you do
this by subclassing
IlpDefaultTypeConverter), you can register it
with the
IlpContext
implementation as follows:
IlpContext context = ...;
context.addService(IlpTypeConverter.class, new CustomTypeConverter(context));
For more information about how to customize and extend the behavior
of the default type converter, refer to
Type converter and to
Complex types.
Retrieve
the object identifier
Retrieve
the corresponding business class
Set/get the attribute values, retrieve the attribute group and
notify interested listeners, according to the interface
IlpAttributeHolder
JViews TGO provides the
following convenience implementations of this interface that you
can use directly when building your application:
IlpDefaultObject—Default object instance
created given a class and an identifier.
IlpBeansObject—Provides a wrapper for an
existing JavaBean™ instance, which will allow it to be handled
as a dynamic object.
IlpObjectSupport—Provides a default
implementation for all
IlpObject
methods. If your Java classes do not follow the JavaBeans
pattern and you cannot create your business objects by
inheriting from
IlpDefaultObject, you can write your own
implementation of the
IlpObject
interface by using the class
IlpObjectSupport.