ilog.cpl.datasource
Class IlpAbstractAdapter

java.lang.Object
  extended by ilog.cpl.datasource.IlpAbstractAdapter
All Implemented Interfaces:
DataSourceListener, IlpRepresentationObjectMapper, EventListener
Direct Known Subclasses:
IlpAbstractHierarchyAdapter, IlpListAdapter

public abstract class IlpAbstractAdapter
extends Object
implements DataSourceListener, IlpRepresentationObjectMapper

Abstract adapter.

Provides support for the association with a data source, filtering, and JavaBean property change events.

This abstract adapter assumes that representation objects are created only when there is a data source AND a model. If one of those is removed, all representation objects are cleared.

Since:
JTGO 3.0

Constructor Summary
IlpAbstractAdapter()
          Default constructor.
IlpAbstractAdapter(IlpContext context)
          Constructor.
 
Method Summary
 void addAdapterListener(AdapterListener l)
          Adds a listener to the adapter.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Adds a PropertyChangeListener for a specific property.
protected  void addRepresentation(IlpRepresentationObject ro)
          Adds the representation object.
 void applyConfiguration(Map properties)
          Applies the given configuration to the adapter.
 void batchEnded(DataSourceEvent e)
          Called when a batch of modifications of the data source has ended.
 void batchStarted(DataSourceEvent e)
          Called when a batch of modifications of the data source has started.
protected  void beginRepresentation()
          Will start representing objects if this was not being done and there is a model and a data source.
protected  void clearIdToRepresentationObjectMap()
          Clears all the representation objects from the adapter.
protected abstract  void clearRepresentationObjects()
          Called when all representation objects should be cleared.
protected abstract  IlpRepresentationObject createRepresentationObject(IlpObject ilpObject)
          This method creates a representation object and stores it in the identifier-to-RO map.
protected  void doApplyConfiguration(Map properties)
          Applies the new configuration to this adapter.
protected  void endBatch()
          Tells the model that a temporary inhibition of events is terminated and sends the events buffered since the last call to startBatch.
protected abstract  void fillModel()
          Fills the model with the representation objects.
protected  void firePropertyChange(String property, Object oldValue, Object newValue)
          Fires a property change event.
 void fireRepresentationObjectsAdded(List representationObjects)
          Fires a representation object added event for a list of objects.
 void fireRepresentationObjectsRemoved(List representationObjects)
          Fires a representation object removed event for a list of objects.
 IlpContext getContext()
          Returns the context.
 IlpDataSource getDataSource()
          Returns the data source.
 List getExcludedClasses()
          Returns the list of excluded classes.
 IlpFilter getFilter()
          Returns the filter.
protected  Collection getPossibleRoots()
          This method returns a list of possible root objects.
 IlpRepresentationObject getRepresentationObject(IlpObject ilpObject)
          Returns the IlpRepresentationObject used to represent the given IlpObject.
 IlpRepresentationObject getRepresentationObject(Object identifier)
          Returns the IlpRepresentationObject used to represent a business object identified by the given identifier.
 Collection getRepresentationObjects()
          Returns all the representation objects.
protected  IlSynchronizationStrategy getSyncStrategy()
          Returns the synchronization strategy used by this adapter.
protected  boolean hasConfigurationChanged(Map properties)
          Checks if the configuration has changed in comparison with the current configuration.
abstract  boolean hasModel()
          Returns true if the adapter is connected to a model.
 boolean hasRepresentationObject(IlpRepresentationObject ro)
          Returns trueif the given IlpRepresentationObject is contained in this map.
 boolean hasRepresentationObjects()
          Returns true if the adapter contains representation objects.
protected  void initializeExcludedClasses()
          Initializes the predefined list of excluded classes.
protected  void initializeRepresentationObjects()
          Identifies all root objects and creates their representation, starting to feed the representation model with new objects.
 boolean isRepresenting()
          Returns true if the adapter is active, that is, representing objects from a data source in a model.
 void refilter()
          Applies the current filter to the adapter objects.
protected  void refilterObjects()
          Applies the filter to the objects that exist in the attached datasource.
 void removeAdapterListener(AdapterListener l)
          Removes a listener from the adapter.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Removes a PropertyChangeListener for a specific property.
protected  IlpRepresentationObject removeRepresentation(Object id)
          Removes the representation object that corresponds to the given identifier.
protected  void replaceExcludedClasses(List newExclusion)
          This method is called to replace the existing excluded class list with a new one.
protected  void setBatchable(IlvBatchable batchable)
          Sets the batch modification delegate used by this adapter.
 void setDataSource(IlpDataSource dataSource)
          Sets the data source.
 void setExcludedClasses(List newExclusion)
          Sets the list of business classes that should be excluded by this adapter.
 void setFilter(IlpFilter newfilter)
          Sets the filter.
protected  void startBatch()
          Tells the model temporarily not to send events.
protected  void stopRepresentation()
          Will stop representing objects.
protected  boolean testObject(IlpObject ilpObject)
          Returns true if an object of the data source should be represented.
protected  boolean testRootObject(IlpObject ilpObject)
          Returns true if an object of the data source should be represented when iterating on all data source objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ilog.cpl.datasource.DataSourceListener
objectAttributeChanged, objectsAdded, objectsRemoved, objectStructureChanged
 

Constructor Detail

IlpAbstractAdapter

public IlpAbstractAdapter(IlpContext context)
Constructor.

Creates an adapter that uses the context.

Parameters:
context - The context used by this adapter.

IlpAbstractAdapter

public IlpAbstractAdapter()
Default constructor.

Creates an adapter using the default context.

See Also:
IlpSystem.GetDefaultContext()
Method Detail

getContext

public IlpContext getContext()
Returns the context.

Returns:
The context of the adapter.

addAdapterListener

public void addAdapterListener(AdapterListener l)
Adds a listener to the adapter.

Parameters:
l - The listener to add.

removeAdapterListener

public void removeAdapterListener(AdapterListener l)
Removes a listener from the adapter.

Parameters:
l - The listener to remove.

fireRepresentationObjectsAdded

public void fireRepresentationObjectsAdded(List representationObjects)
Fires a representation object added event for a list of objects.

Parameters:
representationObjects - The representation objects that have been added. Cannot be null.

fireRepresentationObjectsRemoved

public void fireRepresentationObjectsRemoved(List representationObjects)
Fires a representation object removed event for a list of objects.

Parameters:
representationObjects - The representation objects that have been removed. Cannot be null).

getRepresentationObject

public IlpRepresentationObject getRepresentationObject(Object identifier)
Returns the IlpRepresentationObject used to represent a business object identified by the given identifier.

Parameters:
identifier - The identifier of the IlpObject for which the representation object is required.

getRepresentationObject

public IlpRepresentationObject getRepresentationObject(IlpObject ilpObject)
Returns the IlpRepresentationObject used to represent the given IlpObject.

Specified by:
getRepresentationObject in interface IlpRepresentationObjectMapper
Parameters:
ilpObject - The IlpObject for which the representation object is required.

hasRepresentationObject

public boolean hasRepresentationObject(IlpRepresentationObject ro)
Returns trueif the given IlpRepresentationObject is contained in this map.

Specified by:
hasRepresentationObject in interface IlpRepresentationObjectMapper
Parameters:
ro - The IlpRepresentationObject.

hasRepresentationObjects

public boolean hasRepresentationObjects()
Returns true if the adapter contains representation objects.


clearIdToRepresentationObjectMap

protected void clearIdToRepresentationObjectMap()
Clears all the representation objects from the adapter.


getRepresentationObjects

public Collection getRepresentationObjects()
Returns all the representation objects.


addRepresentation

protected void addRepresentation(IlpRepresentationObject ro)
Adds the representation object.

Parameters:
ro - Representation object
Since:
JTGO 3.0

removeRepresentation

protected IlpRepresentationObject removeRepresentation(Object id)
Removes the representation object that corresponds to the given identifier.

Parameters:
id - Object identifier
Since:
JTGO 3.0

isRepresenting

public boolean isRepresenting()
Returns true if the adapter is active, that is, representing objects from a data source in a model.

This is a bound property.


hasModel

public abstract boolean hasModel()
Returns true if the adapter is connected to a model.


setDataSource

public void setDataSource(IlpDataSource dataSource)
Sets the data source.

The representation objects are created if the adapter also has model. Note that the adapter also waits for a model to listen to data source events.

This is a bound property.

Parameters:
dataSource - The data source used by adapter.

getDataSource

public IlpDataSource getDataSource()
Returns the data source.

This is a bound property.

Returns:
The data source used by the adapter.

setFilter

public void setFilter(IlpFilter newfilter)
Sets the filter.

The new filter is only applied if it is different from the existing filter. To perform this validation, the method equals is used in the filter instances.

The data source objects are filtered, so only IlpObjects that pass through the filter are added to the model.

This is a bound property.

Note: This property can be customized using CSS, as illustrated below:

 Adapter {
   filter: @+filterDef;
 }
 Subobject#filterDef {
   ...
 }
 

Parameters:
newfilter - The filter to use to filter business objects. This parameter may be null, meaning the business objects are not filtered.

getFilter

public IlpFilter getFilter()
Returns the filter.

This is a bound property.

Returns:
The filter used to filter business objects.
See Also:
setFilter(IlpFilter)

setExcludedClasses

public void setExcludedClasses(List newExclusion)
Sets the list of business classes that should be excluded by this adapter.

By default, the list is empty. This means that all business objects will be converted to representation objects. However, this does not include the ones that do not match the current filter criteria.

If you specify business classes in the list, business objects from the given classes or from one of its subclasses will be automatically filtered. Their representation will not be created in the associated representation model.

The current implementation is not very efficient, as it removes all representation objects and recreates them.

Note:This property can be customized using CSS, as illustrated below:

 Adapter {
   excludedClasses: "business class A, business class B";
 }
 

To represent all classes:

 Adapter {
   excludedClasses: '';
 }
 

Parameters:
newExclusion - The list of IlpClass. Note that this list is copied to the internal list of excluded classes.
Since:
JTGO 4.0

getExcludedClasses

public List getExcludedClasses()
Returns the list of excluded classes.

It may well be an empty list.

Returns:
A copy of the internal list of excluded classes.
Since:
JTGO 4.0

initializeExcludedClasses

protected void initializeExcludedClasses()
Initializes the predefined list of excluded classes. In general, this list is empty. This method is overridden in subclasses if the specific adapter does not handle some predefined classes.


replaceExcludedClasses

protected void replaceExcludedClasses(List newExclusion)
This method is called to replace the existing excluded class list with a new one.

Parameters:
newExclusion - New exclusion list.
See Also:
setExcludedClasses(java.util.List)
Internal method or field: do not use!

batchStarted

public void batchStarted(DataSourceEvent e)
Called when a batch of modifications of the data source has started.

Specified by:
batchStarted in interface DataSourceListener
Since:
JTGO 4.0
Internal method or field: do not use!

batchEnded

public void batchEnded(DataSourceEvent e)
Called when a batch of modifications of the data source has ended.

Specified by:
batchEnded in interface DataSourceListener
Since:
JTGO 4.0
Internal method or field: do not use!

setBatchable

protected void setBatchable(IlvBatchable batchable)
Sets the batch modification delegate used by this adapter. Batch notifications sent by the data source are forwarded to this object.

Internal method or field: do not use!

startBatch

protected void startBatch()
Tells the model temporarily not to send events. After this call, the model notification events are delayed until the next call to endBatch.

This method ensures that the startBatch method of the model is called with the correct synchronization strategy; that is, in the event thread in a regular application.

Note: The adapter needs a model for this method to work.

Note: Use IlpAbstractDataSource.startBatch() instead.

Since:
JTGO 4.0
See Also:
IlpAbstractDataSource.startBatch(), endBatch()
Internal method or field: do not use!

endBatch

protected void endBatch()
Tells the model that a temporary inhibition of events is terminated and sends the events buffered since the last call to startBatch.

This method ensures that the endBatch method of the model is called with the correct synchronization strategy; that is, in the event thread in a regular application.

Note:The adapter needs a model for this method to work.

Note:Use IlpAbstractDataSource.endBatch() instead.

Since:
JTGO 4.0
See Also:
IlpAbstractDataSource.endBatch(), startBatch()
Internal method or field: do not use!

firePropertyChange

protected void firePropertyChange(String property,
                                  Object oldValue,
                                  Object newValue)
Fires a property change event.

Parameters:
property - Property that was changed
oldValue - Old value
newValue - New value
Since:
JViews 7.5

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.

Parameters:
listener - The PropertyChangeListener to be added.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Parameters:
listener - The PropertyChangeListener to be removed.

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Adds a PropertyChangeListener for a specific property. The listener will be invoked only when a call to firePropertyChange names that specific property.

Parameters:
propertyName - The name of the property to listen to.
listener - The PropertyChangeListener to be added.

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Removes a PropertyChangeListener for a specific property.

Parameters:
propertyName - The name of the property that was listened to.
listener - The PropertyChangeListener to be removed.

getSyncStrategy

protected IlSynchronizationStrategy getSyncStrategy()
Returns the synchronization strategy used by this adapter.

The synchronization strategy is used each time an object is inserted into or removed from the model.

The synchronization strategy is obtained from the context.


testObject

protected boolean testObject(IlpObject ilpObject)
Returns true if an object of the data source should be represented.

By default, it returns true if there is no filtering or if the IlpObject passes through the filter and the excluded class list.

See Also:
setFilter(ilog.cpl.util.IlpFilter), setExcludedClasses(java.util.List)

testRootObject

protected boolean testRootObject(IlpObject ilpObject)
Returns true if an object of the data source should be represented when iterating on all data source objects.

An object is represented during this iteration if this method returns true and the testObject(IlpObject) method returns true.

By default, this method returns true.


refilterObjects

protected void refilterObjects()
Applies the filter to the objects that exist in the attached datasource.

The default implementation calls clearRepresentationObject and then initializeRepresentationObject.


refilter

public void refilter()
Applies the current filter to the adapter objects.

The filter is only applied if the objects are being represented (isRepresenting()).

The default implementation calls refilterObjects.

Since:
JTGO 4.0

getPossibleRoots

protected Collection getPossibleRoots()
This method returns a list of possible root objects. These possible root objects will be checked against the filter criteria, accepted classes, excluded classes and all object possible tests in order to identify if they will be created in the representation model or not.

Returns:
Returns a new list with the business objects that will be root objects in the representation model.
Internal method or field: do not use!

stopRepresentation

protected void stopRepresentation()
Will stop representing objects. All objects currently represented are removed.


beginRepresentation

protected void beginRepresentation()
Will start representing objects if this was not being done and there is a model and a data source.


initializeRepresentationObjects

protected void initializeRepresentationObjects()
Identifies all root objects and creates their representation, starting to feed the representation model with new objects. This method is used only during initialiation, when the representation model is empty and there are no representation objects that have already been created.

See Also:
beginRepresentation()
Internal method or field: do not use!

fillModel

protected abstract void fillModel()
Fills the model with the representation objects. This method is called only when there is a model.

Internal method or field: do not use!

clearRepresentationObjects

protected abstract void clearRepresentationObjects()
Called when all representation objects should be cleared.


createRepresentationObject

protected abstract IlpRepresentationObject createRepresentationObject(IlpObject ilpObject)
This method creates a representation object and stores it in the identifier-to-RO map. Note that this method may return null in which case it does not store anything in the map.

Internal method or field: do not use!

applyConfiguration

public void applyConfiguration(Map properties)
Applies the given configuration to the adapter. This method is called by the CSS configuration to apply all of the configuration at once. As most of the adapter configuration forces the objects to be recreated, at least we try here to recreate the objects just once.

Parameters:
properties -
Since:
JTGO 4.0
Internal method or field: do not use!

hasConfigurationChanged

protected boolean hasConfigurationChanged(Map properties)
Checks if the configuration has changed in comparison with the current configuration.

Parameters:
properties -
Returns:
true if one of the properties being set is different from the current value in the adapter.
Since:
JTGO 4.0
Internal method or field: do not use!

doApplyConfiguration

protected void doApplyConfiguration(Map properties)
Applies the new configuration to this adapter.

Parameters:
properties -
Since:
JTGO 4.0
Internal method or field: do not use!


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