ilog.cpl.datasource
Class IlpDefaultDataSource

java.lang.Object
  extended by ilog.cpl.datasource.IlpAbstractDataSource
      extended by ilog.cpl.datasource.IlpDefaultDataSource
All Implemented Interfaces:
IlpDataSource, IlpMutableDataSource, AttributeValueListener, ilog.cpl.storage.internal.IlpSAXDataHandlerFactory, IlvBatchable, EventListener
Direct Known Subclasses:
IltDefaultDataSource

public class IlpDefaultDataSource
extends IlpAbstractDataSource
implements IlpMutableDataSource, AttributeValueListener

Default data sources.

A data source contains a number of IlpObjects.

A data source notifies its listener when objects get inserted or removed, or when an object gets modified.

Since:
JTGO 3.0
See Also:
IlpDataSourceLoggers.ilog_cpl_datasource

Constructor Summary
IlpDefaultDataSource()
          Default constructor.
IlpDefaultDataSource(IlpContext context)
          Constructor.
 
Method Summary
 IlpObject addBean(Object bean, Object identifier)
          Adds a bean to the data source.
protected  List addChildrenObjects(IlpObject ilpObject)
          Adds the objects that are children of the given object.
 void addObject(IlpObject ilpObject)
          Adds an object to the data source.
 void addObjects(List objects)
          Adds a list of objects to the data source.
 void attributeValueChange(AttributeValueEvent ev)
          This method is called when an attribute value of an IlpObject in the data source is changed.
 void clear()
          Clears the data source.
 IlpChild getChildInterface(Object childIdOrIlpObject)
          Returns the child interface corresponding to an object.
 Collection getChildren(IlpObject object)
          Returns the collection of children objects for the given object.
 IlpContainer getContainerInterface(Object containerIdOrIlpObject)
          Returns the container interface corresponding to an object.
 String getFileName()
          Returns the file name of the XML document opened as a result of calling the setFileName() method.
 IlpObject getFrom(IlpObject link)
          Returns the from end point of the given link object.
 IlpLinkExtremity getLinkExtremityInterface(Object linkIdOrIlpObject)
          Returns the link extremity interface corresponding to an object.
 IlpLink getLinkInterface(Object linkIdOrIlpObject)
          Returns the link interface corresponding to an object.
 Collection getLinks(IlpObject node)
          Returns the collection of links that have this node as an end point.
 IlpObject getObject(Object identifier)
          Returns the IlpObject corresponding to an identifier.
 Collection getObjects()
          Returns the data source objects contained in a collection.
 IlpObject getParent(IlpObject object)
          Returns the parent of the given object.
 IlpReferenceManager getReferenceManager()
          Returns the reference manager for the data source.
 IlpObject getTo(IlpObject link)
          Returns the to end-point of the given link object.
protected  boolean isSubscribedToObject(IlpObject ilpObject)
          Returns true if this datasource has already been subscribed to the given object.
 void output(String fileName)
          Pretty-prints the data source content to a file.
 void output(String fileName, IlpFilter filter)
          Pretty-prints the data source content to a file.
 void output(Writer out)
          Pretty-prints the data source content to a Writer.
 void output(Writer out, IlpFilter filter)
          Pretty-prints the data source content to a Writer.
 void parse(InputSource input)
          Parses an XML document.
 void parse(InputSource input, IlpFilter filter)
          Parses an XML document.
 void parse(InputSource input, IlpFilter filter, boolean validate)
          Parses an XML document.
 void parse(String uri)
          Parses an XML document from a system identifier (URI).
 void parse(String uri, IlpFilter filter)
          Parses an XML document from a system identifier (URI).
 void parse(String uri, IlpFilter filter, boolean validate)
          Parses an XML document from a system identifier (URI).
 IlpObject removeObject(Object idOrIlpObject, boolean childrenToo)
          Removes an object from the data source.
protected  void removeObjectFromParent(IlpObject ilpObject)
          Removes the given object from its current parent.
 List removeObjects(List idsOrIlpObjects, boolean childrenToo)
          Removes a list of objects from the data source.
 List removeObjects(List idsOrIlpObjects, List childrenTooList)
          Removes a list of objects from the data source.
 void setChildren(Object idOrIlpObject, List childrenIdsOrIlpObjects)
          Declares an object as having children.
 void setFileName(String fileName)
          Parses an XML file from the file name.
 void setFileName(String fileName, boolean parse)
          Sets the file name that is used by this datasource.
 void setLink(Object idOrIlpObject, Object fromIdOrIlpObject, Object toIdOrIlpObject)
          Declares an object as being a link.
 void setParent(Object idOrIlpObject, Object parentIdOrIlpObject)
          Declares an object as being the child of another.
protected  void subscribeToObject(IlpObject ilpObject)
          Register this datasource to receive attribute value change events from the given object.
protected  void unsubscribeToObject(IlpObject ilpObject)
          Unregister this datasource to receive attribute value change events from the given object.
 
Methods inherited from class ilog.cpl.datasource.IlpAbstractDataSource
addDataSourceListener, createDataHandler, endBatch, fireBatchEnded, fireBatchStarted, fireObjectAdded, fireObjectAttributeChanged, fireObjectAttributeChanged, fireObjectRemoved, fireObjectsAdded, fireObjectsRemoved, fireObjectStructureChanged, getContext, getDebugMask, getIdentifier, logMessage, removeDataSourceListener, setContext, setDebugMask, startBatch, throwException
 
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.IlpDataSource
addDataSourceListener, getContext, removeDataSourceListener
 

Constructor Detail

IlpDefaultDataSource

public IlpDefaultDataSource()
Default constructor. The data source is initialized using the default context.

See Also:
IlpSystem.GetDefaultContext()

IlpDefaultDataSource

public IlpDefaultDataSource(IlpContext context)
Constructor.

Parameters:
context - The context used by the data source.
Method Detail

getReferenceManager

public IlpReferenceManager getReferenceManager()
Returns the reference manager for the data source.

Since:
JTGO 4.0

getContainerInterface

public IlpContainer getContainerInterface(Object containerIdOrIlpObject)
Returns the container interface corresponding to an object.

Specified by:
getContainerInterface in interface IlpDataSource
Parameters:
containerIdOrIlpObject - The identifier of the object or the object itself that may be a container.
Returns:
The corresponding container interface. May be null).

getChildInterface

public IlpChild getChildInterface(Object childIdOrIlpObject)
Returns the child interface corresponding to an object.

Specified by:
getChildInterface in interface IlpDataSource
Parameters:
childIdOrIlpObject - The identifier of the object or the object itself that may be a child.
Returns:
The corresponding child interface. May be null).

getLinkInterface

public IlpLink getLinkInterface(Object linkIdOrIlpObject)
Returns the link interface corresponding to an object.

Specified by:
getLinkInterface in interface IlpDataSource
Parameters:
linkIdOrIlpObject - The identifier of the object or the object itself that may be a link.
Returns:
The corresponding link interface. May be null.

getLinkExtremityInterface

public IlpLinkExtremity getLinkExtremityInterface(Object linkIdOrIlpObject)
Returns the link extremity interface corresponding to an object.

Specified by:
getLinkExtremityInterface in interface IlpDataSource
Parameters:
linkIdOrIlpObject - The identifier of the object or the object itself that may be a link extremity.
Returns:
The corresponding link extremity interface. May be null.

getObject

public IlpObject getObject(Object identifier)
Returns the IlpObject corresponding to an identifier.

Specified by:
getObject in interface IlpDataSource
Parameters:
identifier - The identifier.
Returns:
The IlpObject corresponding to the identifier. May be null if no corresponding IlpObject can be found.

getObjects

public Collection getObjects()
Returns the data source objects contained in a collection.

The returned collection is a copy of the internal collection. You can modify it or iterate over it.

Specified by:
getObjects in interface IlpDataSource
Returns:
A collection containing the IlpObject instances of the data source.

addBean

public IlpObject addBean(Object bean,
                         Object identifier)
Adds a bean to the data source.

Parameters:
bean - The Java Bean to add. This object will be wrapped in an IlpBeansObject instance.
identifier - The object identifier.
Returns:
The IlpObject wrapping the bean and identified by identifier.
See Also:
IlpBeansObject

addObject

public void addObject(IlpObject ilpObject)
Adds an object to the data source.

Specified by:
addObject in interface IlpMutableDataSource
Parameters:
ilpObject - The object to be added to the data source.

subscribeToObject

protected void subscribeToObject(IlpObject ilpObject)
Register this datasource to receive attribute value change events from the given object.

Since:
JTGO 3.0

unsubscribeToObject

protected void unsubscribeToObject(IlpObject ilpObject)
Unregister this datasource to receive attribute value change events from the given object.

Since:
JTGO 3.0

isSubscribedToObject

protected boolean isSubscribedToObject(IlpObject ilpObject)
Returns true if this datasource has already been subscribed to the given object.

Parameters:
ilpObject - Business object
Returns:
true if the datasource is already subscribed to receive events from the given object.

addObjects

public void addObjects(List objects)
Adds a list of objects to the data source.

Specified by:
addObjects in interface IlpMutableDataSource
Parameters:
objects - The list of objects to be added to the data source.
Throws:
{@link - ilog.cpl.datasource.IlpDataSourceException} when trying to add business objects to the datasource which are either already in the datasource or which have an identifier that is already used by an existing business object. This exception is thrown only if the datasource is configured with this option.
See Also:
IlpAbstractDataSource.setDebugMask(int), IlpDataSourceException

addChildrenObjects

protected List addChildrenObjects(IlpObject ilpObject)
Adds the objects that are children of the given object. In this implementation, the children objects are not added automatically.

Parameters:
ilpObject - Business object
Returns:
Returns a list of all added objects
Since:
JViews 7.5
Internal method or field: do not use!

removeObject

public IlpObject removeObject(Object idOrIlpObject,
                              boolean childrenToo)
Removes an object from the data source.

Specified by:
removeObject in interface IlpMutableDataSource
Parameters:
idOrIlpObject - The identifier of the object, or the object to be removed from the data source.
childrenToo - If it is true, the children of the object, if there are any, will also be removed from the data source content.
Returns:
The removed object or null if the data source did not contain an object corresponding to the identifier.
Throws:
{@link - ilog.cpl.datasource.IlpDataSourceException} when trying to remove a business object which is not part of this datasource. This exception is thrown only if the datasource is configured with option to throw exceptions in case of error.
See Also:
IlpAbstractDataSource.setDebugMask(int), IlpDataSourceException

removeObjectFromParent

protected void removeObjectFromParent(IlpObject ilpObject)
Removes the given object from its current parent.

Parameters:
ilpObject - Business object
Internal method or field: do not use!

removeObjects

public List removeObjects(List idsOrIlpObjects,
                          boolean childrenToo)
Removes a list of objects from the data source.

Specified by:
removeObjects in interface IlpMutableDataSource
Parameters:
idsOrIlpObjects - A list containing the objects to be removed from the data source as identifiers or IlpObject instances.
childrenToo - If true, the child objects, if there are any, are also removed from the content of the data source.
Returns:
The list of removed objects.
Throws:
ilog.cpl.datasource.IlpDataSourceException - when trying to remove a business object which is not part of this datasource. This exception is thrown only if the datasource is configured with option to throw exceptions in case of error.
See Also:
IlpAbstractDataSource.setDebugMask(int), IlpDataSourceException

removeObjects

public List removeObjects(List idsOrIlpObjects,
                          List childrenTooList)
Removes a list of objects from the data source. This method is designed for internal use by the IlpSAXDataHandler.

Specified by:
removeObjects in interface IlpMutableDataSource
Parameters:
idsOrIlpObjects - A list containing the objects to be removed from the data source as identifiers or IlpObject instances.
childrenTooList - The list of Booleans with the same size as the identifiers list. If an element is true, the children of the objects, if any, are also removed from the data source.
Returns:
The list of removed objects.
Throws:
{@link - ilog.cpl.datasource.IlpDataSourceException} when trying to remove a business object which is not part of this datasource. This exception is thrown only if the datasource is configured with option to throw exceptions in case of error.
See Also:
IlpAbstractDataSource.setDebugMask(int), IlpDataSourceException

clear

public void clear()
Clears the data source. All IlpObject instances are removed from the data source.

Specified by:
clear in interface IlpMutableDataSource

setLink

public void setLink(Object idOrIlpObject,
                    Object fromIdOrIlpObject,
                    Object toIdOrIlpObject)
Declares an object as being a link.

As the parameters of this method can be either identifiers or IlpObject instances, the IlpAbstractDataSource.getIdentifier(Object) method can be used to retrieve the identifier in both cases.

Specified by:
setLink in interface IlpMutableDataSource
Parameters:
idOrIlpObject - The identifier of the link object or the object itself.
fromIdOrIlpObject - The identifier of the "from" end of the link, or the "from" object itself.
toIdOrIlpObject - The identifier of the "to" end of the link, or the "to" object itself.

setParent

public void setParent(Object idOrIlpObject,
                      Object parentIdOrIlpObject)
Declares an object as being the child of another.

As the parameters of this method can be either identifiers or IlpObject instances, the IlpAbstractDataSource.getIdentifier(Object) method can be used to retrieve the identifier in both cases.

Specified by:
setParent in interface IlpMutableDataSource
Parameters:
idOrIlpObject - The identifier of the child object, or the child object itself.
parentIdOrIlpObject - The identifier of the parent object, or the parent object itself.

setChildren

public void setChildren(Object idOrIlpObject,
                        List childrenIdsOrIlpObjects)
Declares an object as having children.

As the parameters of this method can be or contain either identifiers or IlpObject instances, the IlpAbstractDataSource.getIdentifier(Object) method can be used to retrieve the identifier in both cases.

Specified by:
setChildren in interface IlpMutableDataSource
Parameters:
idOrIlpObject - The identifier of the object, or the object itself, that has children.
childrenIdsOrIlpObjects - A list containing the children as identifiers or IlpObject instances.

attributeValueChange

public void attributeValueChange(AttributeValueEvent ev)
This method is called when an attribute value of an IlpObject in the data source is changed.

Specified by:
attributeValueChange in interface AttributeValueListener

parse

public void parse(InputSource input)
           throws IOException,
                  SAXException
Parses an XML document.

The application can use this method to instruct the data source to begin parsing an XML document from any valid input source (a character stream, a byte stream, or a URI).

Applications may not invoke this method while parsing is in progress. During parsing, the data source notifies its listeners of any changes.

This method is synchronous: it does not return until parsing has ended. If a client application wants to terminate parsing early, it should throw an exception.

By default, the XML document is validated.

Parameters:
input - The input source for the top level of the XML document.
Throws:
SAXException - that is any SAX exception, possibly wrapping another exception.
IOException - which is an IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
See Also:
XMLReader, InputSource, IlpDataSourceLoader, parse(InputSource, IlpFilter, boolean)

parse

public void parse(InputSource input,
                  IlpFilter filter)
           throws IOException,
                  SAXException
Parses an XML document.

The application can use this method to instruct the data source to begin parsing an XML document from any valid input source (a character stream, a byte stream, or a URI).

Applications may not invoke this method while parsing is in progress. During parsing, the data source notifies its listeners of any changes.

This method is synchronous: it does not return until parsing has ended. If a client application wants to terminate parsing early, it should throw an exception.

By default, the XML document is validated.

Parameters:
input - The input source for the top level of the XML document.
filter - The filter applied to the business objects present in the input source. A business object must be accepted by the filter in order to be added to the datasource.
Throws:
SAXException - which is any SAX exception, possibly wrapping another exception.
IOException - which is an IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
Since:
JTGO 4.0
See Also:
XMLReader, InputSource, IlpDataSourceLoader, parse(InputSource, IlpFilter, boolean)

parse

public void parse(InputSource input,
                  IlpFilter filter,
                  boolean validate)
           throws IOException,
                  SAXException
Parses an XML document.

The application can use this method to instruct the data source to begin parsing an XML document from any valid input source (a character stream, a byte stream, or a URI).

Applications may not invoke this method while parsing is in progress. During parsing, the data source notifies its listeners of any changes.

This method is synchronous: it does not return until parsing has ended. If a client application wants to terminate parsing early, it should throw an exception.

Parameters:
input - The input source for the top level of the XML document.
filter - The filter applied to the business objects present in the input source. A business object must be accepted by the filter in order to be added to the datasource.
validate - Validates or not the XML document.
Throws:
SAXException - which is any SAX exception, possibly wrapping another exception.
IOException - which is an IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
Since:
JViews 8.0
See Also:
XMLReader, InputSource, IlpDataSourceLoader

parse

public void parse(String uri)
           throws IOException,
                  SAXException
Parses an XML document from a system identifier (URI).

If the system identifier is a URL, it does not have to be fully resolved by the application before it is passed to the parser.

Parameters:
uri - The URI.
Throws:
SAXException - which is any SAX exception, possibly wrapping another exception.
IOException - which is an IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
See Also:
IlpDataSourceLoader

parse

public void parse(String uri,
                  IlpFilter filter)
           throws IOException,
                  SAXException
Parses an XML document from a system identifier (URI).

If the system identifier is a URL, it does not have to be fully resolved by the application before it is passed to the parser.

Parameters:
uri - The URI.
filter - The filter applied to the business objects present in the input source. A business object must be accepted by the filter in order to be added to the datasource.
Throws:
SAXException - which is any SAX exception, possibly wrapping another exception.
IOException - which is an IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
Since:
JTGO 4.0
See Also:
IlpDataSourceLoader

parse

public void parse(String uri,
                  IlpFilter filter,
                  boolean validate)
           throws IOException,
                  SAXException
Parses an XML document from a system identifier (URI).

If the system identifier is a URL, it does not have to be fully resolved by the application before it is passed to the parser.

Parameters:
uri - The URI.
filter - The filter applied to the business objects present in the input source. A business object must be accepted by the filter in order to be added to the datasource.
validate - Validates the XML document.
Throws:
SAXException - which is any SAX exception, possibly wrapping another exception.
IOException - which is an IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
Since:
JViews 8.0
See Also:
IlpDataSourceLoader

setFileName

public void setFileName(String fileName)
Parses an XML file from the file name. The data source is cleared before parsing the specified document.

This method performs a synchronous (that is a regular) call to parse().

All exceptions are caught. In order to handle them you should implement your own mechanism, using one of the parse() methods.

Parameters:
fileName - File name of the XML document to read. It is resolved to an absolute URL using the IlpURLAccessService. If you pass null, the data source will be cleared. If you pass the same file name as the current one of the data source, the data source will be cleared and reloaded.
See Also:
parse(String)

setFileName

public void setFileName(String fileName,
                        boolean parse)
Sets the file name that is used by this datasource.

If parse is false only the file name is changed and no parsing takes place.

If parse is true it changes the file name and parses an XML file from the file name provided. The data source is cleared before parsing the specified document.

In the latter case, this method performs a synchronous (that is a regular) call to parse().

Also all exceptions are caught. In order to handle them you should implement your own mechanism, using one of the parse() methods.

Parameters:
fileName - File name of the XML document to read. It is resolved to an absolute URL using the IlpURLAccessService. If you pass null, the data source will be cleared. If you pass the same file name as the current one of the data source, the data source will be cleared and reloaded.
parse - If true, the file will be parsed as a result of this method. Otherwise, no parsing will take place and the file name is changed accordingly.
See Also:
parse(String)

getFileName

public String getFileName()
Returns the file name of the XML document opened as a result of calling the setFileName() method.

See Also:
setFileName(String)

output

public void output(Writer out)
            throws SAXException
Pretty-prints the data source content to a Writer.

Parameters:
out - The java.io.Writer to use to write the XML output.
Throws:
SAXException

output

public void output(Writer out,
                   IlpFilter filter)
            throws SAXException
Pretty-prints the data source content to a Writer.

Parameters:
out - The java.io.Writer to use to write the XML output.
filter - The filter applied to the business objects present in the data source. A business object must be accepted by the filter in order to be present in the output.
Throws:
SAXException
Since:
JTGO 4.0

output

public void output(String fileName)
            throws SAXException,
                   IOException
Pretty-prints the data source content to a file.

Parameters:
fileName - The file name.
Throws:
SAXException
IOException

output

public void output(String fileName,
                   IlpFilter filter)
            throws SAXException,
                   IOException
Pretty-prints the data source content to a file.

Parameters:
fileName - The file name.
filter - The filter applied to the business objects present in the data source. A business object must be accepted by the filter in order to be present in the output.
Throws:
SAXException
IOException
Since:
JTGO 4.0

getParent

public IlpObject getParent(IlpObject object)
Returns the parent of the given object.

Note: This method is a convenience access to retrieve the parent information. The structural information is retrieved using the method getChildInterface.

Parameters:
object - The child object.
Returns:
The parent object if it exists, or null if a parent could not be found in this data source.
Since:
JTGO 4.0
See Also:
getChildInterface(java.lang.Object)

getChildren

public Collection getChildren(IlpObject object)
Returns the collection of children objects for the given object.

Note: This method is a convenience method to retrieve the children information. The structural information is retrieved using the method getContainerInterface.

Parameters:
object - The parent object.
Returns:
The collection of child objects, it they exist, or an empty collection if the object does not have children or if the child objects are not yet in this data source.
Since:
JTGO 4.0
See Also:
getContainerInterface(java.lang.Object)

getLinks

public Collection getLinks(IlpObject node)
Returns the collection of links that have this node as an end point.

Note: This method is a convenience method to retrieve the link information. The structural information is retrieved using the method getLinkExtremityInterface.

Parameters:
node - The end-point object.
Returns:
The collection of links, it they exist and are present in this data source, or an empty collection if this object is not a link extremity or if the links could not be found in this data source.
Since:
JTGO 4.0
See Also:
getLinkExtremityInterface(java.lang.Object)

getFrom

public IlpObject getFrom(IlpObject link)
Returns the from end point of the given link object.

Note: This method is a convenience access to retrieve the end-point information. The structural information is retrieved using the method getLinkInterface.

Parameters:
link - The link object.
Returns:
The from end-point object if it exists, or null if an end point could not be found in this data source.
Since:
JTGO 4.0
See Also:
getLinkInterface(java.lang.Object)

getTo

public IlpObject getTo(IlpObject link)
Returns the to end-point of the given link object.

Note: This method is a convenience access to retrieve the end-point information. The structural information is retrieved using the method getLinkInterface.

Parameters:
link - The link object.
Returns:
The to end-point object if it exists, or null if the to end-point could not be found in this data source.
Since:
JTGO 4.0
See Also:
getLinkInterface(java.lang.Object)


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