Class DataSourceAttribute
- java.lang.Object
-
- org.mapfish.print.attribute.DataSourceAttribute
-
- All Implemented Interfaces:
Attribute
,ConfigurationObject
public final class DataSourceAttribute extends java.lang.Object implements Attribute
This attribute represents a collection of attributes which can be used as the data source of a Jasper report's table/detail section.For example consider the case where the report should contain multiple tables or charts but the number of reports may change depending on the request. In this case the client will post a datasource attribute json object containing an array of all the table attribute objects. The
DataSourceProcessor
will process the datasource attribute and create a Jasper datasource that contains all the tables.This datasource must be used in tandem with the
DataSourceProcessor
processor (see !createDataSource processor).The json data of this attribute is special since it represents an array of attributes, each element in the array must contain all of the attributes required to satisfy the processors in the
DataSourceProcessor
.Example configuration:
datasource: !datasource table: !table map: !map width: 200 height: 100
Example request data:
[[examples=verboseExample,datasource_dynamic_tables,datasource_many_dynamictables_legend, datasource_multiple_maps,customDynamicReport,report]]datasource: [ { table: { ... // normal table attribute data }, map: { ... // normal map attribute data } }, { table: { ... // normal table attribute data }, map: { ... // normal map attribute data } } ]
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataSourceAttribute.DataSourceAttributeValue
The value class for theDataSourceAttribute
.
-
Constructor Summary
Constructors Constructor Description DataSourceAttribute()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,Attribute>
getAttributes()
Gets the attributes.java.lang.Object
getValue(Template template, java.lang.String attributeName, PObject requestJsonAttributes)
Get the attribute value.java.lang.Class
getValueType()
Get the class of the value.DataSourceAttribute.DataSourceAttributeValue
parseAttribute(Template template, PArray jsonValue)
void
printClientConfig(org.json.JSONWriter json, Template template)
Write this attribute out the the json writer so that clients can know what attributes are expected.void
setAttributes(java.util.Map<java.lang.String,Attribute> attributes)
The attributes that are acceptable by this dataSource.void
setConfigName(java.lang.String name)
Set the name of the attribute as set in the configuration file.void
setDefault(java.util.List<java.lang.Object> defaultData)
Default values for this attribute.void
validate(java.util.List<java.lang.Throwable> validationErrors, Configuration configuration)
validate that the configuration was correct.
-
-
-
Method Detail
-
setDefault
public void setDefault(java.util.List<java.lang.Object> defaultData)
Default values for this attribute. Example:attributes: datasource: !datasource attributes: name: !string {} count: !integer {} default: - name: "name" - count: 3
- Parameters:
defaultData
- The default values.
-
getAttributes
public java.util.Map<java.lang.String,Attribute> getAttributes()
Gets the attributes.- Returns:
- the attributes
-
setAttributes
public void setAttributes(java.util.Map<java.lang.String,Attribute> attributes)
The attributes that are acceptable by this dataSource. The format is the same as the template attributes section.- Parameters:
attributes
- the attributes
-
printClientConfig
public void printClientConfig(org.json.JSONWriter json, Template template) throws org.json.JSONException
Description copied from interface:Attribute
Write this attribute out the the json writer so that clients can know what attributes are expected.- Specified by:
printClientConfig
in interfaceAttribute
- Parameters:
json
- the json writer to write totemplate
- the template that this attribute is part of- Throws:
org.json.JSONException
-
setConfigName
public void setConfigName(java.lang.String name)
Description copied from interface:Attribute
Set the name of the attribute as set in the configuration file.- Specified by:
setConfigName
in interfaceAttribute
- Parameters:
name
- the name of the attribute
-
validate
public void validate(java.util.List<java.lang.Throwable> validationErrors, Configuration configuration)
Description copied from interface:ConfigurationObject
validate that the configuration was correct.- Specified by:
validate
in interfaceConfigurationObject
- Parameters:
validationErrors
- a list to add any detected errors to.configuration
- the containing configuration
-
parseAttribute
public DataSourceAttribute.DataSourceAttributeValue parseAttribute(@Nonnull Template template, @Nullable PArray jsonValue) throws org.json.JSONException
- Parameters:
template
- the containing templatejsonValue
- the json- Throws:
org.json.JSONException
-
getValueType
public java.lang.Class getValueType()
Description copied from interface:Attribute
Get the class of the value.- Specified by:
getValueType
in interfaceAttribute
- Returns:
- the value class
-
-