public class IlpDefaultDataSource extends IlpAbstractDataSource implements IlpMutableDataSource, AttributeValueListener
A data source contains a number of IlpObject
s.
A data source notifies its listener when objects get inserted or removed, or when an object gets modified.
IlpDataSourceLoggers.ilog_cpl_datasource
Constructor and Description |
---|
IlpDefaultDataSource()
Default constructor.
|
IlpDefaultDataSource(IlpContext context)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
IlpObject |
addBean(Object bean,
Object identifier)
Adds a bean to the data source.
|
protected List<IlpObject> |
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<? extends IlpObject> 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<IlpObject> |
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<IlpObject> |
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<IlpObject> |
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.
|
List<IlpObject> |
getRootObjects()
Returns the objects that have no parent information in 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)
Deprecated.
Use
output(String, String, IlpFilter) instead. |
void |
output(String fileName,
IlpFilter filter)
Deprecated.
Use
output(String, String, IlpFilter) instead. |
void |
output(String fileName,
String charsetName,
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<IlpObject> |
removeObjects(List<Object> idsOrIlpObjects,
boolean childrenToo)
Removes a list of objects from the data source.
|
List<IlpObject> |
removeObjects(List<Object> idsOrIlpObjects,
List<Boolean> childrenTooList)
Removes a list of objects from the data source.
|
void |
setChildren(Object idOrIlpObject,
List<? extends Object> 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.
|
addDataSourceListener, createDataHandler, endBatch, fireBatchEnded, fireBatchStarted, fireObjectAdded, fireObjectAttributeChanged, fireObjectAttributeChanged, fireObjectRemoved, fireObjectsAdded, fireObjectsRemoved, fireObjectStructureChanged, getContext, getDebugMask, getIdentifier, logMessage, removeDataSourceListener, setContext, setDebugMask, startBatch, throwException
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addDataSourceListener, getContext, removeDataSourceListener
public IlpDefaultDataSource()
IlpSystem.GetDefaultContext()
public IlpDefaultDataSource(IlpContext context)
context
- The context used by the data source.public IlpReferenceManager getReferenceManager()
public IlpContainer getContainerInterface(Object containerIdOrIlpObject)
getContainerInterface
in interface IlpDataSource
containerIdOrIlpObject
- The identifier of the object or the object
itself that may be a container.null
).public IlpChild getChildInterface(Object childIdOrIlpObject)
getChildInterface
in interface IlpDataSource
childIdOrIlpObject
- The identifier of the object or the object
itself that may be a child.null
).public IlpLink getLinkInterface(Object linkIdOrIlpObject)
getLinkInterface
in interface IlpDataSource
linkIdOrIlpObject
- The identifier of the object or the object
itself that may be a link.null
.public IlpLinkExtremity getLinkExtremityInterface(Object linkIdOrIlpObject)
getLinkExtremityInterface
in interface IlpDataSource
linkIdOrIlpObject
- The identifier of the object or the object
itself that may be a link extremity.null
.public IlpObject getObject(Object identifier)
IlpObject
corresponding to an identifier.getObject
in interface IlpDataSource
identifier
- The identifier.IlpObject
corresponding to the identifier. May
be null
if no corresponding IlpObject
can be found.public Collection<IlpObject> getObjects()
The returned collection is a copy of the internal collection. You can modify it or iterate over it.
getObjects
in interface IlpDataSource
IlpObject
instances of
the data source.public List<IlpObject> getRootObjects()
getRootObjects
in interface IlpDataSource
IlpObject
s of the data source.public IlpObject addBean(Object bean, Object identifier)
bean
- The Java Bean to add. This object will be wrapped in an
IlpBeansObject
instance.identifier
- The object identifier.IlpObject
wrapping the bean
and
identified by identifier
.IlpBeansObject
public void addObject(IlpObject ilpObject)
addObject
in interface IlpMutableDataSource
ilpObject
- The object to be added to the data source.protected void subscribeToObject(IlpObject ilpObject)
protected void unsubscribeToObject(IlpObject ilpObject)
protected boolean isSubscribedToObject(IlpObject ilpObject)
true
if this datasource has already been
subscribed to the given object.ilpObject
- Business objecttrue
if the datasource is already subscribed
to receive events from the given object.public void addObjects(List<? extends IlpObject> objects)
addObjects
in interface IlpMutableDataSource
objects
- The list of objects to be added to the data source.{@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.IlpAbstractDataSource.setDebugMask(int)
,
IlpDataSourceException
protected List<IlpObject> addChildrenObjects(IlpObject ilpObject)
ilpObject
- Business objectpublic IlpObject removeObject(Object idOrIlpObject, boolean childrenToo)
removeObject
in interface IlpMutableDataSource
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.null
if the data source did
not contain an object corresponding to the identifier.{@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.IlpAbstractDataSource.setDebugMask(int)
,
IlpDataSourceException
protected void removeObjectFromParent(IlpObject ilpObject)
ilpObject
- Business objectpublic List<IlpObject> removeObjects(List<Object> idsOrIlpObjects, boolean childrenToo)
removeObjects
in interface IlpMutableDataSource
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.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.IlpAbstractDataSource.setDebugMask(int)
,
IlpDataSourceException
public List<IlpObject> removeObjects(List<Object> idsOrIlpObjects, List<Boolean> childrenTooList)
IlpSAXDataHandler
.removeObjects
in interface IlpMutableDataSource
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.{@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.IlpAbstractDataSource.setDebugMask(int)
,
IlpDataSourceException
public void clear()
IlpObject
instances are removed from the data source.clear
in interface IlpMutableDataSource
public void setLink(Object idOrIlpObject, Object fromIdOrIlpObject, Object toIdOrIlpObject)
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.
setLink
in interface IlpMutableDataSource
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.public void setParent(Object idOrIlpObject, Object parentIdOrIlpObject)
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.
setParent
in interface IlpMutableDataSource
idOrIlpObject
- The identifier of the child object, or the
child object itself.parentIdOrIlpObject
- The identifier of the parent object, or the
parent object itself.public void setChildren(Object idOrIlpObject, List<? extends Object> childrenIdsOrIlpObjects)
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.
setChildren
in interface IlpMutableDataSource
idOrIlpObject
- The identifier of the object, or the
object itself, that has children.childrenIdsOrIlpObjects
- A list containing the children as
identifiers or IlpObject
instances.public void attributeValueChange(AttributeValueEvent ev)
IlpObject
in the data source is changed.attributeValueChange
in interface AttributeValueListener
public void parse(InputSource input) throws IOException, SAXException
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.
input
- The input source for the top level of the XML document.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.XMLReader
,
InputSource
,
IlpDataSourceLoader
,
parse(InputSource, IlpFilter, boolean)
public void parse(InputSource input, IlpFilter filter) throws IOException, SAXException
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.
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.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.XMLReader
,
InputSource
,
IlpDataSourceLoader
,
parse(InputSource, IlpFilter, boolean)
public void parse(InputSource input, IlpFilter filter, boolean validate) throws IOException, SAXException
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.
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.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.XMLReader
,
InputSource
,
IlpDataSourceLoader
public void parse(String uri) throws IOException, SAXException
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.
uri
- The URI.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.IlpDataSourceLoader
public void parse(String uri, IlpFilter filter) throws IOException, SAXException
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.
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.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.IlpDataSourceLoader
public void parse(String uri, IlpFilter filter, boolean validate) throws IOException, SAXException
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.
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.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.IlpDataSourceLoader
public void setFileName(String fileName)
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.
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(String)
public void setFileName(String fileName, boolean parse)
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.
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.parse(String)
public String getFileName()
setFileName()
method.setFileName(String)
public void output(Writer out) throws SAXException
Pretty-prints the data source content to a Writer
.
To specify an encoding, you should use OutputStreamWriter
or
a subclass.
out
- The java.io.Writer
to use to write the XML output.SAXException
public void output(Writer out, IlpFilter filter) throws SAXException
Pretty-prints the data source content to a Writer
.
To specify an encoding, you should use OutputStreamWriter
or
a subclass.
out
- The java.io.Writer
to use to write the XML output.filter
- The IlpFilter
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.SAXException
@Deprecated public void output(String fileName) throws SAXException, IOException
output(String, String, IlpFilter)
instead.fileName
- The file name.SAXException
IOException
@Deprecated public void output(String fileName, IlpFilter filter) throws SAXException, IOException
output(String, String, IlpFilter)
instead.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.SAXException
IOException
public void output(String fileName, String charsetName, IlpFilter filter) throws SAXException, IOException, UnsupportedEncodingException
fileName
- The file name.charsetName
- The
charset
name to be used as the encoding pseudo-attribute in the
XML declaration. UTF-8
is assumed otherwise.filter
- The filter applied to the business objects
present in the data source, or null
if no
filter is needed. A business object must be accepted by the
filter in order to be present in the output.SAXException
IOException
UnsupportedEncodingException
public IlpObject getParent(IlpObject object)
Note: This method is a convenience access to retrieve
the parent information. The structural information is retrieved
using the method getChildInterface
.
object
- The child object.null
if a parent
could not be found in this data source.getChildInterface(java.lang.Object)
public Collection<IlpObject> getChildren(IlpObject object)
Note: This method is a convenience method to retrieve
the children information. The structural information is retrieved using the
method getContainerInterface
.
object
- The parent object.getContainerInterface(java.lang.Object)
public Collection<IlpObject> getLinks(IlpObject node)
Note: This method is a convenience method to retrieve
the link information. The structural information is retrieved using the
method getLinkExtremityInterface
.
node
- The end-point object.getLinkExtremityInterface(java.lang.Object)
public IlpObject getFrom(IlpObject link)
Note: This method is a convenience access to retrieve
the end-point information. The structural information is retrieved
using the method getLinkInterface
.
link
- The link object.null
if an end point could not be found in this data source.getLinkInterface(java.lang.Object)
public IlpObject getTo(IlpObject link)
Note: This method is a convenience access to retrieve
the end-point information. The structural information is retrieved
using the method getLinkInterface
.
link
- The link object.null
if
the to end-point could not be found in this data source.getLinkInterface(java.lang.Object)
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.