org.progeeks.jfreechart
Class MetaDatasetProducer

java.lang.Object
  extended by org.progeeks.jfreechart.MetaDatasetProducer
All Implemented Interfaces:
de.laures.cewolf.DatasetProducer, java.io.Serializable
Direct Known Subclasses:
CategoryDatasetProducer, XYDatasetProducer

public abstract class MetaDatasetProducer
extends java.lang.Object
implements de.laures.cewolf.DatasetProducer, java.io.Serializable

Abstract class for creating jfreechart Datasets from different types of input data without having to create new DatasetProducers for each class of input data that you want to render. The input data can either be a true Java class or a MetaClass. Data should be passed as a List of objects to the produceDataset method. Another varient of produceDataset that takes a Map is also available for use with cewolf.

All MetaDatasetProducers have at least one field - the seriesNameProperty. This is the property of the data class that tells the producer how to divide up the data into different series.

It is possible to specify a property of a property (a "sub-property") of the data class for any field. That is, if a data class Foo has a property "myBar" which returns a class Bar, and Bar has a "name" property, you can use that value in the seriesProperty by specifying "myBar.name" in the configuration.

Warning if using with cewolf: If you create a sub-class of this one, do not write it to pre-set the data it will use to produce the Dataset (like with a tag). You must send the data in as parameter(s) to produceDataset. The reason is that in a web environment with cewolf, produceDataset is called from a different thread than the one which originally renders the . The tag is what does it through the cewolf servlet. Thus, since there is only one instance for each MetaDatasetProducer configuration, if multiple requests come in for a page at the same time with different data (or you try to draw two charts on the same page with the same MetaDatasetProducer), if you pre-set the data, whatever was the last object set will be used to generate all the charts.

A workaround to this could be to store data in an internal map and pass the key to the data as the parameter to produceDataset so that it knows which set to work with. Once rendered, the class would just remove the data from the map. This would be useful if the data was not Serializable and so could not be passed as a parameter.

Version:
$Revision: 1.13 $
Author:
esword
See Also:
Serialized Form

Field Summary
protected  boolean addValues
           
protected  boolean dataClassIsMetaClass
           
protected  MetaClass dataMetaClass
           
protected  java.lang.String dataObjectClass
           
protected  java.lang.String defaultSeriesName
           
protected  java.util.List filteredSeries
           
protected static Log log
           
static java.lang.String PARAM_DATA
          Common key value for the main data list that will be worked on when passed in the params map to produceDataset.
static java.lang.String PARAM_EXISTING_DATASET
          Common key value for any existing data set which should be added to rather than creating an entirely new one
protected  java.lang.String producerId
           
protected  java.lang.String seriesNameProperty
           
protected  boolean storeOriginalData
           
 
Fields inherited from interface de.laures.cewolf.DatasetProducer
PRODUCER_ATTRIBUTE_NAME
 
Constructor Summary
MetaDatasetProducer()
           
 
Method Summary
 MetaObject createMetaObject()
          Create a new metaObject using the default data MetaClass.
static MetaClass findOrCreateMetaClass(java.lang.Object dataObject)
          Find or create a meta class for the given class of object.
 java.lang.String getDataObjectClass()
           
 java.lang.String getDefaultSeriesName()
          If no seriesNameProperty is set, all data items will be placed in a single series with the name "Default Series."
 java.util.List getFilteredSeries()
           
static MetaObject getMetaObject(java.lang.Object dataObject)
          Creates a MetaObject from the parameter.
 java.lang.Object getOriginalData(org.jfree.chart.entity.ChartEntity entity)
          Attempts to retrieve the object in the datalist that corresponds to the ChartEntity.
 java.lang.String getProducerId()
           
 java.lang.Object getPropertyValue(MetaObject obj, java.lang.String propName)
          Retrieve a value for a meta-object's property.
 java.lang.String getSeriesNameProperty()
           
 boolean getStoreOriginalData()
          Set to true if the object that was the source of values for a datapoint should be stored so that it may be retrieved with getOriginalData(ChartEntity).
 boolean hasExpired(java.util.Map params, java.util.Date since)
           
protected  void init()
          Validates input settings, sets up dynamic time unit classes, and creates data meta class.
 boolean isAddValues()
          If true, when adding a data item to a series, the producer will first check to see if data already exists for the corresponding domain value (XYPlots) or category (CategoryPlots).
 java.lang.Object produceDataset(java.util.List dataList)
           
 java.lang.Object produceDataset(java.util.List dataList, org.jfree.data.general.Dataset existingData)
           
abstract  java.lang.Object produceDataset(java.util.Map params)
           
 void setAddValues(boolean addValues)
           
 void setDataObjectClass(java.lang.String dataObjectClass)
           
 void setDefaultSeriesName(java.lang.String defaultSeriesName)
           
 void setFilteredSeries(java.util.List filteredSeries)
           
 void setProducerId(java.lang.String id)
          Unique ID for this object
 void setSeriesNameProperty(java.lang.String seriesNameProperty)
           
 void setStoreOriginalData(boolean storeOriginalData)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final Log log

PARAM_DATA

public static final java.lang.String PARAM_DATA
Common key value for the main data list that will be worked on when passed in the params map to produceDataset.

See Also:
Constant Field Values

PARAM_EXISTING_DATASET

public static final java.lang.String PARAM_EXISTING_DATASET
Common key value for any existing data set which should be added to rather than creating an entirely new one

See Also:
Constant Field Values

producerId

protected java.lang.String producerId

dataObjectClass

protected java.lang.String dataObjectClass

seriesNameProperty

protected java.lang.String seriesNameProperty

addValues

protected boolean addValues

filteredSeries

protected java.util.List filteredSeries

defaultSeriesName

protected java.lang.String defaultSeriesName

storeOriginalData

protected boolean storeOriginalData

dataMetaClass

protected MetaClass dataMetaClass

dataClassIsMetaClass

protected boolean dataClassIsMetaClass
Constructor Detail

MetaDatasetProducer

public MetaDatasetProducer()
Method Detail

init

protected void init()
             throws java.lang.Exception
Validates input settings, sets up dynamic time unit classes, and creates data meta class.

Throws:
java.lang.Exception

getMetaObject

public static MetaObject getMetaObject(java.lang.Object dataObject)
Creates a MetaObject from the parameter. If the parameter is already a MetaObject, just return it.

Parameters:
dataObject -

findOrCreateMetaClass

public static MetaClass findOrCreateMetaClass(java.lang.Object dataObject)
Find or create a meta class for the given class of object.

Parameters:
dataObject -

createMetaObject

public MetaObject createMetaObject()
Create a new metaObject using the default data MetaClass.


getPropertyValue

public java.lang.Object getPropertyValue(MetaObject obj,
                                         java.lang.String propName)
Retrieve a value for a meta-object's property. The property could potentially be "nested" - it could be the property of a property of the object.

Returns:
the encoded value if successful or null if the value cannot be retrieved or an error occurs.

produceDataset

public abstract java.lang.Object produceDataset(java.util.Map params)
                                         throws de.laures.cewolf.DatasetProduceException
Specified by:
produceDataset in interface de.laures.cewolf.DatasetProducer
Throws:
de.laures.cewolf.DatasetProduceException
See Also:
DatasetProducer.produceDataset(java.util.Map)

produceDataset

public java.lang.Object produceDataset(java.util.List dataList)
                                throws de.laures.cewolf.DatasetProduceException
Throws:
de.laures.cewolf.DatasetProduceException

produceDataset

public java.lang.Object produceDataset(java.util.List dataList,
                                       org.jfree.data.general.Dataset existingData)
                                throws de.laures.cewolf.DatasetProduceException
Throws:
de.laures.cewolf.DatasetProduceException

getOriginalData

public java.lang.Object getOriginalData(org.jfree.chart.entity.ChartEntity entity)
Attempts to retrieve the object in the datalist that corresponds to the ChartEntity. This routine will only work if setStoreOriginalData(boolean)is true.

Parameters:
entity - Normally, an item indicating where a user clicked in the chart accorsing to series, X/Y value or category value. A "non-data" entity (like a LegendItemEntity) could also be passed in, but in that case the routine will return a null.
Returns:
The corresponding data object or null if a match can't be made.

hasExpired

public boolean hasExpired(java.util.Map params,
                          java.util.Date since)
Specified by:
hasExpired in interface de.laures.cewolf.DatasetProducer
See Also:
DatasetProducer.hasExpired(java.util.Map, java.util.Date)

getProducerId

public java.lang.String getProducerId()
Specified by:
getProducerId in interface de.laures.cewolf.DatasetProducer
See Also:
DatasetProducer.getProducerId()

setProducerId

public void setProducerId(java.lang.String id)
Unique ID for this object

Parameters:
id - The id to set.
See Also:
DatasetProducer.getProducerId()

getDataObjectClass

public java.lang.String getDataObjectClass()
Returns:
Returns the dataType.

setDataObjectClass

public void setDataObjectClass(java.lang.String dataObjectClass)
Parameters:
dataObjectClass - The dataObjectClass to set.

getSeriesNameProperty

public java.lang.String getSeriesNameProperty()
Returns:
Returns the seriesNameProperty.

getFilteredSeries

public java.util.List getFilteredSeries()
Returns:
Returns the filteredSeries.

setSeriesNameProperty

public void setSeriesNameProperty(java.lang.String seriesNameProperty)
Parameters:
seriesNameProperty - The seriesNameProperty to set.

setFilteredSeries

public void setFilteredSeries(java.util.List filteredSeries)
Parameters:
filteredSeries - The filteredSeries to set.

isAddValues

public boolean isAddValues()
If true, when adding a data item to a series, the producer will first check to see if data already exists for the corresponding domain value (XYPlots) or category (CategoryPlots). If data does exist, the producer will add the new value to the existing value rather than replace it. This allows users to produce charts that summarize information in datasets, such as how many datapoints there were in a certain period. Default is true.

Returns:
Returns the addValues.

setAddValues

public void setAddValues(boolean addValues)
Parameters:
addValues - The addValues to set.

getDefaultSeriesName

public java.lang.String getDefaultSeriesName()
If no seriesNameProperty is set, all data items will be placed in a single series with the name "Default Series." This name may be overriden by setting this property.

Returns:
Returns the defaultSeriesName.

setDefaultSeriesName

public void setDefaultSeriesName(java.lang.String defaultSeriesName)
Parameters:
defaultSeriesName - The defaultSeriesName to set.

getStoreOriginalData

public boolean getStoreOriginalData()
Set to true if the object that was the source of values for a datapoint should be stored so that it may be retrieved with getOriginalData(ChartEntity). Default is true.

Returns:
Returns the storeOriginalData.

setStoreOriginalData

public void setStoreOriginalData(boolean storeOriginalData)
Parameters:
storeOriginalData - The storeOriginalData to set.


Copyright © 2002-2003 Paul Speed. All Rights Reserved.