com.davisor.data.stream
Class CollectionDataSource

java.lang.Object
  extended bycom.davisor.data.VoidData
      extended bycom.davisor.data.stream.CollectionDataSource
All Implemented Interfaces:
Data, DataSource
Direct Known Subclasses:
ListDataBuffer

public class CollectionDataSource
extends VoidData
implements DataSource

CollectionDataSource represents a data source that uses a standard Java collection to implement a source of DataValue elements. The source also exposes the underlying collection object to allow direct collection content manipulation.

A data source has a data type that may be used to convert elements into one uniform type when data is inserted into the collection. However, arbitary data may also be placed directly into the collection. Data streams that read this source may later apply additional type conversions.

Since:
JDK1.1
See Also:
getCollection(), getStream(), Type

Field Summary
protected  java.util.Collection M_collection
          Collection data source.
 
Fields inherited from class com.davisor.data.VoidData
M_type
 
Constructor Summary
CollectionDataSource()
          Default constructor that creates an empty collection with no type.
CollectionDataSource(java.util.Collection collection)
          Creates a collection data stream source out of the given collection.
CollectionDataSource(java.util.Collection collection, Type type)
          Creates a collection data stream source out of the given collection and element type.
CollectionDataSource(java.lang.Object[] collection)
          Creates a collection data stream source out of the given array.
CollectionDataSource(java.lang.Object[] collection, Type type)
          Creates a collection data stream source out of the given array and type.
 
Method Summary
 void addAll(DataStream stream)
          Adds all elements in the given stream to this collection.
 boolean close()
          Dummy implementation.
 java.util.Collection getCollection()
          Gets the underlying collection.
 DataStream getStream()
          Gets a data stream to the data in this source.
 void setType(Type type)
          Sets the data stream element type.
 java.lang.String toString()
          Gets data buffer XML representation.
 java.lang.String toString(java.lang.String id, java.lang.String dataName)
          Returns the XML representation for the asked channel.
 
Methods inherited from class com.davisor.data.VoidData
equals, getDataValue, getType, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.davisor.data.Data
getType
 

Field Detail

M_collection

protected java.util.Collection M_collection
Collection data source.

Constructor Detail

CollectionDataSource

public CollectionDataSource()
Default constructor that creates an empty collection with no type.


CollectionDataSource

public CollectionDataSource(java.lang.Object[] collection)
                     throws InvalidDataException
Creates a collection data stream source out of the given array. The type of the data source is taken from the first array element.

Parameters:
collection - data source
Throws:
InvalidDataException - if the type of the first element cannot be determined
See Also:
CollectionDataSource(Collection)

CollectionDataSource

public CollectionDataSource(java.lang.Object[] collection,
                            Type type)
Creates a collection data stream source out of the given array and type.

Parameters:
collection - data source
type - the type of the data within the source
See Also:
CollectionDataSource(Collection,Type)

CollectionDataSource

public CollectionDataSource(java.util.Collection collection)
                     throws InvalidDataException
Creates a collection data stream source out of the given collection. The type of the data source is set to AutoType.

Parameters:
collection - data source
Throws:
InvalidDataException - if the type of the first element cannot be determined

CollectionDataSource

public CollectionDataSource(java.util.Collection collection,
                            Type type)
Creates a collection data stream source out of the given collection and element type.

Parameters:
collection - data source
type - the type of the data within the source
Method Detail

close

public boolean close()
Dummy implementation.

Specified by:
close in interface DataSource
Returns:
true;

getStream

public DataStream getStream()
                     throws InvalidDataException
Gets a data stream to the data in this source. If the data source collection contains objects that are not of the expected type, they are converted to the collection type when accessed through data streams. The original objects in the collection are, however, not changed.

Specified by:
getStream in interface DataSource
Throws:
InvalidDataException
See Also:
IteratorDataStream.IteratorDataStream(Collection,Type)

toString

public java.lang.String toString(java.lang.String id,
                                 java.lang.String dataName)
Returns the XML representation for the asked channel.

Specified by:
toString in interface DataSource
Parameters:
id - channel id
dataName - channel dataName (ignored)

toString

public java.lang.String toString()
Gets data buffer XML representation. If the data source has an explicit type, collection elements are first converted to DataValue objects with that type. The converted values are then written as XML with their DataValue.toXML() method. If the data source has no explicit type, DataValue elements found in the collection are written by invoking their DataValue.toXML() method, while other objects are written with their standard string representations, but with their special characters XML encoded. In all cases, the values are embedded in tags with the help of Strings.toXML(Object,boolean) method.

Overrides:
toString in class VoidData
See Also:
DataValue.toXML(), Strings.toXML(Object,boolean), Type.toData(Object), Type.xmlEnd(), Type.xmlStart()

addAll

public void addAll(DataStream stream)
            throws InvalidDataException
Adds all elements in the given stream to this collection.

Throws:
InvalidDataException

getCollection

public java.util.Collection getCollection()
Gets the underlying collection. All changes to the returned list object will be reflected to the content of this data stream source.


setType

public void setType(Type type)
Sets the data stream element type. The type is expected to be compatible with all elements in the stream.

Overrides:
setType in class VoidData


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.