[ERA-CVS] src/org/jdaemon/era/grml FieldWriter.java,NONE,1.1 GenericHeaderWriter.java,NONE,1.1 Heade
Brought to you by:
jessex
Update of /cvsroot/era/src/org/jdaemon/era/grml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27794 Modified Files: CellAttributesWriter.java CellWriter.java ElementWriter.java GRMLReport.java GRMLTypes.java GenericCellAttributesWriter.java GenericCellWriter.java GenericElementCollectionWriter.java GenericElementWriter.java GenericFieldWriter.java GenericGridAttributesWriter.java GenericGridWriter.java GenericRecordWriter.java GenericRecordsetWriter.java GridAttributesWriter.java RecordWriter.java TestGRMLReport.java Added Files: FieldWriter.java GenericHeaderWriter.java HeaderWriter.java RecordWriterDescriptor.java Log Message: Finally got GRMLReport through its unit tests for import/export from a DataRepresentation. Main change has been to change the way that GridAttributes elements are added to a report. GridAttributes are now generated by Grid elements. This removes a considerable redundancy in GRMLReport which became glaringly obvious while writing the test cases. --- NEW FILE: FieldWriter.java --- /* * CellWriter.java * * Copyright (C) 2004 [iQuality Ltd.] * This program is distributed under the terms of the Lesser GNU General Public * License (v2 or later) per the included COPYING.txt file, or see www.fsf.org. * */ package org.jdaemon.era.grml; import org.jdaemon.six.ReportBuilder; import org.jdaemon.six.BuildException; /** Interface for writers which output field elements. * <P> * The GRML DTD specifies two elements types which represent the fundamental data items on a * report: field and cell. Field elements are can be arranged freely in nested groups, wheras * cell objects are contained within a rigidly defined grid. * </P><P> * The FieldWriter interface is used to write field elements within a group. In most cases the premade * GenericFieldWriter implementation should be sufficient. * </P><P> * FuekdWriter should be implemnted to output well-formed field elements to a ReportBuilder. * <P> * @author Jonathan Essex */ public interface FieldWriter extends RecordElementWriter { /** Write field to a builder. * * @param record containing data to write * @param builder builder used to output data */ public void write( Record record, ReportBuilder builder ) throws BuildException; } --- NEW FILE: GenericHeaderWriter.java --- /* * GenericHeaderWriter.java * * Created on July 13, 2004, 9:06 PM */ package org.jdaemon.era.grml; import org.jdaemon.six.ReportBuilder; import org.jdaemon.six.BuildException; import java.util.HashSet; import java.util.Iterator; /** HeaderWriter implementation. * * @author Jonathan Essex */ public class GenericHeaderWriter implements HeaderWriter { private HashSet grid_attributes; /** Creates a new instance of GenericHeaderWriter */ public GenericHeaderWriter() { this.grid_attributes = new HashSet(); } /** add a GridAttributes section to the header. * * @param writer GridAttributesWriter to add */ public void addGridAttributesWriter(GridAttributesWriter writer) { grid_attributes.add(writer); } /** Write header out to buider. * * @param builder Builder to output to. */ public void write(ReportBuilder builder) throws BuildException { Iterator i = grid_attributes.iterator(); while (i.hasNext()) ((GridAttributesWriter)i.next()).write(builder); } } --- NEW FILE: HeaderWriter.java --- /* * HeaderWriter.java * * Created on July 13, 2004, 8:50 PM */ package org.jdaemon.era.grml; import org.jdaemon.six.ReportBuilder; import org.jdaemon.six.BuildException; /** Inteface for gathering documents fragments for report header. * * @author Jonathan Essex */ public interface HeaderWriter { /** Add a grid attributes section to the report header. * * @param writer Writer for grid attributes section */ public void addGridAttributesWriter(GridAttributesWriter writer); /** Write resulting header to report builder. * * @param builder Builder to output header to */ public void write(ReportBuilder builder) throws BuildException; } --- NEW FILE: RecordWriterDescriptor.java --- /* * RecordWriterDescriptor.java * * Created on July 7, 2004, 6:31 PM */ package org.jdaemon.era.grml; import org.jdaemon.era.*; import java.util.List; import java.util.Set; import java.util.HashSet; import java.util.Iterator; import java.util.Collections; /** Class describing a RecordWriter. * * Note - maybe we could have a public interface here adding only the getGridWriters method * to the base FormattingDescriptor. Thing about this before being tempted to make this impementation * public. * * @author Jonathan Essex */ class RecordWriterDescriptor { private Set required_aggregates; private Set required_attributes; private Set grid_attributes_writers; /** Creates a new instance of RecordWriterDescriptor. */ public RecordWriterDescriptor() { required_aggregates = new HashSet(); required_attributes = new HashSet(); grid_attributes_writers = new HashSet(); } /** Get set of aggregates required by RecordWriter. * * @return a set of Aggregate objects indicating which aggregate calculations the RecordWriter requires */ public Set getRequiredAggregates() { return Collections.unmodifiableSet(required_aggregates); } /** Get set of data attributes required by RecordWriter. * * @return a set of Strings indicating which data values are required by the RecordWriter */ public Set getRequiredDataAttributes() { return Collections.unmodifiableSet(required_attributes); } /** Get the set of grid writers used by this RecordWriter. * * Note - could use a GridWriter interface here. * * @return a set of GenericGridWriter objects that are used by this RecordWriter */ public Set getGridAttributesWriters() { return Collections.unmodifiableSet(grid_attributes_writers); } /** Adds an aggregate to the required set. * * Used when building the a RecordWriterDescriptor from a record. * * @param agg Aggregate to add to required set. */ public void requireAggregate(Aggregate agg) { required_aggregates.add(agg); } /** Adds a data attribute to the required set. * * Used when building the a RecordWriterDescriptor from a record. * * @param attr Attribute to add to required set. */ public void requireDataAttribute(String attr) { required_attributes.add(attr); } /** Adds a GridWriter to the use set. * * Used when building the a RecordWriterDescriptor from a record. * * @param writer GenericGridWriter to add to use set. */ public void registerGridAttributesWriter(GridAttributesWriter writer) { grid_attributes_writers.add(writer); } /** Add grid attributes to a header. */ public void registerHeaderElements(HeaderWriter header) { Iterator i = grid_attributes_writers.iterator(); while (i.hasNext()) header.addGridAttributesWriter((GridAttributesWriter)i.next()); } } Index: CellAttributesWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/CellAttributesWriter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CellAttributesWriter.java 26 May 2004 14:45:34 -0000 1.2 --- CellAttributesWriter.java 14 Jul 2004 16:05:40 -0000 1.3 *************** *** 9,12 **** --- 9,15 ---- package org.jdaemon.era.grml; + import org.jdaemon.six.ReportBuilder; + import org.jdaemon.six.BuildException; + /** Interface for adding cell attributes elements to a grid-attributes element. * <P> *************** *** 23,27 **** * @author Jonathan Essex */ ! public interface CellAttributesWriter extends ElementWriter { ! } --- 26,35 ---- * @author Jonathan Essex */ ! public interface CellAttributesWriter { ! /** Write cell attributes out to a builder ! * ! * @param builder Builder to output cell attributes to. ! */ ! public void write(ReportBuilder builder) throws BuildException; ! }; Index: CellWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/CellWriter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CellWriter.java 14 Jun 2004 22:02:24 -0000 1.3 --- CellWriter.java 14 Jul 2004 16:05:44 -0000 1.4 *************** *** 26,30 **** * @author Jonathan Essex */ ! public interface CellWriter extends ElementWriter { /** Write cell to a builder. --- 26,30 ---- * @author Jonathan Essex */ ! public interface CellWriter extends RecordElementWriter { /** Write cell to a builder. *************** *** 34,38 **** */ public void write( Record record, ! ReportBuilder builder ) throws BuildException; } --- 34,45 ---- */ public void write( Record record, ! ReportBuilder builder ) throws BuildException; ! ! ! /** Get writer for cell attributes. ! * ! * @return A CellAttributesWriter ! */ ! public CellAttributesWriter getCellAttributesWriter(); } Index: ElementWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/ElementWriter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ElementWriter.java 13 Jun 2004 21:05:18 -0000 1.4 --- ElementWriter.java 14 Jul 2004 16:05:44 -0000 1.5 *************** *** 18,22 **** * GenericElementCollectionWriter to be inherited by various distinct types. * </p><p> ! * The interfaces RecordWriter, CellWriter, CellAttributesWriter and RecordElementWriter are all subclasses * of this interface but outisde of this package should always be treated as distinct types. Hence * this interface is not public and should not be made so. --- 18,22 ---- * GenericElementCollectionWriter to be inherited by various distinct types. * </p><p> ! * The interfaces RecordWriter, CellWriter, and RecordElementWriter are all subclasses * of this interface but outisde of this package should always be treated as distinct types. Hence * this interface is not public and should not be made so. *************** *** 33,54 **** void write(Record record, ReportBuilder builder) throws BuildException; ! /** Add any Aggregates required to a list. * ! * The write method of any ElementWriter may require certain attributes and aggregate ! * calculations to exist in the Record objects supplied to the write method. This method ! * provides a way to discover which aggregate calculations are required by this writer. * ! * @param list A set object to which Aggregate objects are added. */ ! public void buildRequiredAggregatesSet(Set list); - /** Add any data attributes required to a list. - * - * The write method of any ElementWriter may require certain attributes and aggregate - * calculations to exist in the Record objects supplied to the write method. This method - * provides a way to discover which data attributes are required by this writer. - * - * @param list A set object to which names of data attributes are added as String objects. - */ - public void buildRequiredDataAttributesSet(Set list); } --- 33,43 ---- void write(Record record, ReportBuilder builder) throws BuildException; ! /** Build RecordWriterDescriptor. * ! * Builds descriptor which is subsequently used for writing headers etc. * ! * @param descriptor object which subclasses can use to build metadata. */ ! public void buildRecordWriterDescriptor(RecordWriterDescriptor descriptor); } Index: GRMLReport.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GRMLReport.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GRMLReport.java 22 Jun 2004 08:23:32 -0000 1.9 --- GRMLReport.java 14 Jul 2004 16:05:44 -0000 1.10 *************** *** 23,27 **** import org.xml.sax.ContentHandler; ! import java.util.TreeMap; import java.util.List; import java.util.ArrayList; --- 23,27 ---- import org.xml.sax.ContentHandler; ! import java.util.HashSet; import java.util.List; import java.util.ArrayList; *************** *** 99,104 **** } - private TreeMap grid_attributes = new TreeMap(); private String class_id; /** Get an XML view of a cube. --- 99,105 ---- } private String class_id; + private HeaderWriter header_writer; + /** Get an XML view of a cube. *************** *** 131,156 **** } ! /** Write out grid attributes for this report to builder. ! * ! * Writes any grid-attributes elements (previously set with setGridAttributes) ! * for this report to the supplied builder. ! * ! * @param builder to output grid-attributes element to. ! * @throws BuildException on any error writing to builder. */ ! private void writeGridAttributes(ReportBuilder builder) throws BuildException { ! Iterator i = grid_attributes.values().iterator(); ! while (i.hasNext()) { ! ((GridAttributesWriter)i.next()).write(null, builder); ! } } - /** Set the class attributes for cells in grid elements of a given class. - * - * @param grid_attr A GridAttributesWriter object. - */ - public void addGridAttributes(GridAttributesWriter grid_attr) { - grid_attributes.put(grid_attr.getClassAttribute(), grid_attr); - } /** Apply transformations to a builder. --- 132,150 ---- } ! /** Get the header writer for this report. */ ! public HeaderWriter getHeaderWriter() { ! if (header_writer == null) { ! header_writer = new GenericHeaderWriter(); ! Iterator i = groupingsList().iterator(); ! while (i.hasNext()) { ! Grouping grouping = (Grouping)i.next(); ! ((RecordWriter)grouping.getFormatting()).registerHeaderElements(header_writer); ! } ! } ! ((RecordWriter)getDetailFormatting()).registerHeaderElements(header_writer); ! return header_writer; } /** Apply transformations to a builder. *************** *** 186,190 **** private void writeReport(Cube cube, ReportBuilder builder) throws BuildException { builder.startReport(cube.getClass().toString(), AttributeList.EMPTY); ! writeGridAttributes(builder); applyTransformations(groupingsList().iterator(), builder).writeObject(cube); builder.endReport(); --- 180,184 ---- private void writeReport(Cube cube, ReportBuilder builder) throws BuildException { builder.startReport(cube.getClass().toString(), AttributeList.EMPTY); ! getHeaderWriter().write(builder); applyTransformations(groupingsList().iterator(), builder).writeObject(cube); builder.endReport(); *************** *** 215,225 **** /** Construct a new GRMLReport object */ ! public GRMLReport(String class_id, Grouping[] groupings, RecordWriter detail_writer) { super(new ArrayList(Arrays.asList(groupings)), detail_writer); this.class_id = class_id; } public GRMLReport(String class_id) { this.class_id = class_id; } } --- 209,239 ---- /** Construct a new GRMLReport object */ ! public GRMLReport(String class_id, Grouping[] groupings, RecordWriter detail_writer) { super(new ArrayList(Arrays.asList(groupings)), detail_writer); this.class_id = class_id; } + /** Construct an empty GRMLReport object + */ public GRMLReport(String class_id) { this.class_id = class_id; } + + private static boolean equal(Object o1, Object o2) { + return (o1 == null || o2 == null) ? o1 == o2 : o1.equals(o2); + } + + /** Compare this report with another. + * + * @return true if <code>other</code> is a GRMLReport which is identical to this one. + */ + public boolean equals(Object other) { + if (other instanceof GRMLReport) { + GRMLReport other_rp = (GRMLReport)other; + return ( equal(this.class_id, other_rp.class_id) + && equal(this.getDetailFormatting(), other_rp.getDetailFormatting()) + && equal(this.groupingsList(), other_rp.groupingsList())); + } + return false; + } } Index: GRMLTypes.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GRMLTypes.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GRMLTypes.java 22 Jun 2004 08:23:32 -0000 1.4 --- GRMLTypes.java 14 Jul 2004 16:05:44 -0000 1.5 *************** *** 11,14 **** --- 11,15 ---- package org.jdaemon.era.grml; import org.jdaemon.era.*; + import org.jdaemon.era.helper.HelperTypes; import org.jdaemon.util.AttributeList; import org.jdaemon.util.data.*; *************** *** 18,22 **** import java.text.Format; ! /** Repository for Type objects in top-level ERA package. * * @author Jonathan Essex --- 19,23 ---- import java.text.Format; ! /** Repository for Type objects in GRML package. * * @author Jonathan Essex *************** *** 103,113 **** public Object read(DataRepresentation representation) throws ReadError, ObjectInstantiationError { Object value = representation.getAttribute("value"); if (value != null) { ! return new GenericCellWriter(value); } else { int attribute_type = convertAttributeType(representation.getAttribute("type")); String attribute_name = representation.getAttribute("attribute"); Format format = (Format)FormatTypes.FORMAT.get(representation,"format"); ! return new GenericCellWriter(attribute_type, attribute_name, format); } } --- 104,117 ---- public Object read(DataRepresentation representation) throws ReadError, ObjectInstantiationError { Object value = representation.getAttribute("value"); + String span_string = representation.getAttribute("span"); + String class_id = representation.getAttribute("class_id"); + int span = span_string == null ? 1 : Integer.parseInt(span_string); if (value != null) { ! return new GenericCellWriter(class_id, span, value); } else { int attribute_type = convertAttributeType(representation.getAttribute("type")); String attribute_name = representation.getAttribute("attribute"); Format format = (Format)FormatTypes.FORMAT.get(representation,"format"); ! return new GenericCellWriter(class_id, span, attribute_type, attribute_name, format); } } *************** *** 240,297 **** }; - /** Type for GenericCellAttributesWriter objects. - */ - public static final Type GENERIC_CELL_ATTRIBUTES_WRITER = new Type("CellAttributes", GenericCellAttributesWriter.class) { - - /** Reads a GenericCellAttributesWriter object from a DataRepresentation. - * - * @param representation DataRepresentation from which to read the GenericCellAttributesWriter object - * @return A new CellAttributesWriter object - */ - public Object read(DataRepresentation representation) throws ReadError, ObjectInstantiationError { - String class_id = representation.getAttribute("class"); - String span = representation.getAttribute("span"); - return new GenericCellAttributesWriter(class_id, span == null ? null : Integer.valueOf(span)); - } - - /** Writes a GenericCellAttributesWriter object to some DataRepresentation. - * - * @param representation DataRepresentation to which the GenericCellAttributesWriter object will be written - * @param object GenericCellAttributesWriter object to be written to <I>representation</I> - */ - public void write(DataRepresentation representation, Object object) throws WriteError { - GenericCellAttributesWriter writer = (GenericCellAttributesWriter)object; - representation.setAttribute("class", writer.getClassAttribute()); - if (writer.getSpanAttribute() != null) representation.setAttribute("span", writer.getSpanAttribute().toString()); - } - }; - - /** Type for GenericGridAttributesWriter objects. - */ - public static final Type GENERIC_GRID_ATTRIBUTES_WRITER = new Type("GridAttributes", GenericGridAttributesWriter.class) { - - /** Reads a GenericGridAttributesWriter object from a DataRepresentation. - * - * @param representation DataRepresentation from which to read the GenericGridAttributesWriter object - * @return A new GenericGridAttributesWriter object - */ - public Object read(DataRepresentation representation) throws ReadError, ObjectInstantiationError { - String class_id = representation.getAttribute("class"); - CellAttributesWriter[] elements = (GenericCellAttributesWriter[])CELL_ATTRIBUTES_ARRAY.get(representation, "elements"); - return new GenericGridAttributesWriter(class_id, elements); - } - - /** Writes a GenericGridAttributesWriter object to some DataRepresentation. - * - * @param representation DataRepresentation to which the GenericGridAttributesWriter object will be written - * @param object GenericGridAttributesWriter object to be written to <I>representation</I> - */ - public void write(DataRepresentation representation, Object object) throws WriteError { - GenericGridAttributesWriter writer = (GenericGridAttributesWriter)object; - representation.setAttribute("class", writer.getClassAttribute()); - CELL_ATTRIBUTES_LIST.put(representation, "elements", writer.listElements()); - } - }; - /** Type for GRMLReportWriter objects. */ --- 244,247 ---- *************** *** 338,349 **** */ public static final Type CELL_LIST = Types.listOf(GENERIC_CELL_WRITER); - - /** Array type for cell attributes elements. - */ - public static final Type CELL_ATTRIBUTES_ARRAY = Types.arrayOf(GENERIC_CELL_ATTRIBUTES_WRITER); - - /** List type for cell attribute elements. - */ - public static final Type CELL_ATTRIBUTES_LIST = Types.listOf(GENERIC_CELL_ATTRIBUTES_WRITER); } --- 288,291 ---- Index: GenericCellAttributesWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GenericCellAttributesWriter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenericCellAttributesWriter.java 22 Jun 2004 08:23:32 -0000 1.7 --- GenericCellAttributesWriter.java 14 Jul 2004 16:05:44 -0000 1.8 *************** *** 32,36 **** * @author Jonathan Essex */ ! public class GenericCellAttributesWriter extends GenericElementWriter implements CellAttributesWriter { private String class_id; --- 32,36 ---- * @author Jonathan Essex */ ! public class GenericCellAttributesWriter implements CellAttributesWriter { private String class_id; *************** *** 42,49 **** * @param span Cell span */ ! public GenericCellAttributesWriter(String class_id, Integer span) { ! super(null); this.class_id = class_id; ! this.span = span; } --- 42,48 ---- * @param span Cell span */ ! public GenericCellAttributesWriter(String class_id, int span) { this.class_id = class_id; ! this.span = span == 1 ? null : new Integer(span); } *************** *** 53,77 **** */ public GenericCellAttributesWriter(String class_id) { ! this(class_id, null); } ! /** Send end element event to builder. ! * ! * @param builder ReportBuilder to send start element event to ! * ! */ ! protected void endElement(ReportBuilder builder) throws BuildException { ! builder.endCellAttributes(); ! } ! ! /** Send start element event to builder. ! * ! * @param builder ReportBuilder to send end element event to ! * ! */ ! protected void startElement(ReportBuilder builder) throws BuildException { AttributeList list = AttributeList.EMPTY; if (span != null) list = list.addAttribute("span", span); builder.startCellAttributes(class_id, list); } --- 52,63 ---- */ public GenericCellAttributesWriter(String class_id) { ! this(class_id, 1); } ! public void write(ReportBuilder builder) throws BuildException { AttributeList list = AttributeList.EMPTY; if (span != null) list = list.addAttribute("span", span); builder.startCellAttributes(class_id, list); + builder.endCellAttributes(); } Index: GenericCellWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GenericCellWriter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GenericCellWriter.java 21 Jun 2004 16:43:26 -0000 1.6 --- GenericCellWriter.java 14 Jul 2004 16:05:44 -0000 1.7 *************** *** 36,39 **** --- 36,41 ---- */ public class GenericCellWriter extends GenericElementWriter implements CellWriter { + + private CellAttributesWriter attrs; /** Creates a new instance of GenericCellWriter to write out some static data. *************** *** 43,51 **** * writeObject method. * </P> ! * @param class_id Class Id for fields written by this writer * @param value Value to write in field. */ ! public GenericCellWriter(Object value) { super(value); } --- 45,55 ---- * writeObject method. * </P> ! * @param class_id Class Id for cells written by this writer ! * @param span No of horizontal 'units' this cell occupies in the global grid * @param value Value to write in field. */ ! public GenericCellWriter(String class_id, int span, Object value) { super(value); + attrs = new GenericCellAttributesWriter(class_id, span); } *************** *** 58,67 **** * </P> * @param class_id Class Id for fields written by this writer * @param attribute_name Name of attribute to write in this field * @param attribute_type Type of attribute to write in this field (One of Record.DATA, MAX, MIN, SUM, COUNT) * @param format format to use to write field */ ! public GenericCellWriter(int attribute_type, String attribute_name, Format format) { super(attribute_type, attribute_name, format); } --- 62,73 ---- * </P> * @param class_id Class Id for fields written by this writer + * @param span No of horizontal 'units' this cell occupies in the global grid * @param attribute_name Name of attribute to write in this field * @param attribute_type Type of attribute to write in this field (One of Record.DATA, MAX, MIN, SUM, COUNT) * @param format format to use to write field */ ! public GenericCellWriter(String class_id, int span, int attribute_type, String attribute_name, Format format) { super(attribute_type, attribute_name, format); + attrs = new GenericCellAttributesWriter(class_id, span); } *************** *** 73,81 **** * </P> * * @param class_id Class Id for fields written by this writer * @param attribute_name Name of attribute to write in this field * @param attribute_type Type of attribute to write in this field (One of Record.DATA, MAX, MIN, SUM, COUNT) */ ! public GenericCellWriter(int attribute_type, String attribute_name) { ! this(attribute_type, attribute_name, null); } --- 79,88 ---- * </P> * * @param class_id Class Id for fields written by this writer + * @param span No of horizontal 'units' this cell occupies in the global grid * @param attribute_name Name of attribute to write in this field * @param attribute_type Type of attribute to write in this field (One of Record.DATA, MAX, MIN, SUM, COUNT) */ ! public GenericCellWriter(String class_id, int span, int attribute_type, String attribute_name) { ! this(class_id, span, attribute_type, attribute_name, null); } *************** *** 109,111 **** --- 116,128 ---- } } + + /** Get writer for cell attributes. + * + * @return A CellAttributesWriter + */ + public CellAttributesWriter getCellAttributesWriter() { + return attrs; + } + + } Index: GenericElementCollectionWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GenericElementCollectionWriter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GenericElementCollectionWriter.java 13 Jun 2004 21:05:19 -0000 1.5 --- GenericElementCollectionWriter.java 14 Jul 2004 16:05:44 -0000 1.6 *************** *** 75,109 **** } ! /** Add any Aggregates required to a list. ! * ! * The write method of any ElementWriter may require certain attributes and aggregate ! * calculations to exist in the Record objects supplied to the write method. This method ! * provides a way to discover which aggregate calculations are required by this writer. * ! * @param list A set object to which Aggregate objects are added. */ ! public void buildRequiredAggregatesSet(Set list) { Iterator i = elements.iterator(); while (i.hasNext()) { ! ((ElementWriter)i.next()).buildRequiredAggregatesSet(list); } } ! ! /** Add any data attributes required to a list. ! * ! * The write method of any ElementWriter may require certain attributes and aggregate ! * calculations to exist in the Record objects supplied to the write method. This method ! * provides a way to discover which data attributes are required by this writer. ! * ! * @param list A set object to which names of data attributes are added as String objects. ! */ ! public void buildRequiredDataAttributesSet(Set list) { ! Iterator i = elements.iterator(); ! while (i.hasNext()) { ! ((ElementWriter)i.next()).buildRequiredDataAttributesSet(list); ! } ! } ! ! /** Write elements to a builder. * --- 75,89 ---- } ! /** Add information from contained elements to a descriptor. * ! * @param descriptor Descriptor to which we add the necessary information. */ ! public void buildRecordWriterDescriptor(RecordWriterDescriptor descriptor) { Iterator i = elements.iterator(); while (i.hasNext()) { ! ((ElementWriter)i.next()).buildRecordWriterDescriptor(descriptor); } } ! /** Write elements to a builder. * Index: GenericElementWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GenericElementWriter.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GenericElementWriter.java 22 Jun 2004 08:23:32 -0000 1.8 --- GenericElementWriter.java 14 Jul 2004 16:05:44 -0000 1.9 *************** *** 35,42 **** * implementations may ignore the record and go elsewhere to find data. * </P><P> ! * This interface may be implemented in order to provide new DataSources (for example, * 'current time') for cells and fields. * </P><P> ! * Note also that all current implemnetations of DataSource are basically constant * obejects which, once constructed, do not change. Implementers of new DataSources * are advised to follow this pattern. --- 35,42 ---- * implementations may ignore the record and go elsewhere to find data. * </P><P> ! * This interface may be implemented in order to provide new DataSources (for example, * 'current time') for cells and fields. * </P><P> ! * Note also that all current implemnetations of DataSource are basically constant * obejects which, once constructed, do not change. Implementers of new DataSources * are advised to follow this pattern. *************** *** 57,80 **** Object get(Record data); ! /** Add any Aggregates required to a list. ! * ! * The write method of any ElementWriter may require certain attributes and aggregate ! * calculations to exist in the Record objects supplied to the write method. This method ! * provides a way to discover which aggregate calculations are required by this writer. ! * ! * @param list A set object to which Aggregate objects are added. ! */ ! public void buildRequiredAggregatesSet(Set list); ! ! /** Add any data attributes required to a list. ! * ! * The write method of any ElementWriter may require certain attributes and aggregate ! * calculations to exist in the Record objects supplied to the write method. This method ! * provides a way to discover which data attributes are required by this writer. * ! * @param list A set object to which names of data attributes are added as String objects. */ ! public void buildRequiredDataAttributesSet(Set list); ! } --- 57,65 ---- Object get(Record data); ! /** Build metadata. * ! * @param descriptor Object to accumulate metadata */ ! public void buildRecordWriterDescriptor(RecordWriterDescriptor descriptor); } *************** *** 115,142 **** public int getAttributeType() { return attribute_type; - } - - /** Add any Aggregates required to a list. - * - * The write method of any ElementWriter may require certain attributes and aggregate - * calculations to exist in the Record objects supplied to the write method. This method - * provides a way to discover which aggregate calculations are required by this writer. - * - * @param list A set object to which Aggregate objects are added. - */ - public void buildRequiredAggregatesSet(Set list) { - if (attribute_type != Record.DATA) list.add(new Aggregate(attribute_name, attribute_type)); } ! /** Add any data attributes required to a list. ! * ! * The write method of any ElementWriter may require certain attributes and aggregate ! * calculations to exist in the Record objects supplied to the write method. This method ! * provides a way to discover which data attributes are required by this writer. * ! * @param list A set object to which names of data attributes are added as String objects. */ ! public void buildRequiredDataAttributesSet(Set list) { ! if (attribute_type != Record.DATA) list.add(attribute_name); } --- 100,112 ---- public int getAttributeType() { return attribute_type; } ! /** Build metatdata * ! * @param descriptor Object to accumulate metadata */ ! public void buildRecordWriterDescriptor(RecordWriterDescriptor descriptor) { ! if (attribute_type != Record.DATA) descriptor.requireAggregate(new Aggregate(attribute_name, attribute_type)); ! if (attribute_type != Record.DATA) descriptor.requireDataAttribute(attribute_name); } *************** *** 149,154 **** if (other instanceof AttributeDataSource) { AttributeDataSource other_ds = (AttributeDataSource)other; ! return ( this.attribute_type == other_ds.attribute_type ! && this.attribute_name.equals(other_ds.attribute_name)); } else { return false; --- 119,124 ---- if (other instanceof AttributeDataSource) { AttributeDataSource other_ds = (AttributeDataSource)other; ! return ( this.attribute_type == other_ds.attribute_type ! && this.attribute_name.equals(other_ds.attribute_name)); } else { return false; *************** *** 174,193 **** this.value = value; } - /** Add any Aggregates required to a list. - * - * Does nothing as a StaticDataSource requires no data from a record. - * - * @param list A set object to which Aggregate objects are added. - */ - public void buildRequiredAggregatesSet(Set list) { - } ! /** Add any data attributes required to a list. ! * ! * Does nothing as a StaticDataSource requires no data from a record. * ! * @param list A set object to which names of data attributes are added as String objects. */ ! public void buildRequiredDataAttributesSet(Set list) { } --- 144,153 ---- this.value = value; } ! /** Build metatdata * ! * @param descriptor Object to accumulate metadata */ ! public void buildRecordWriterDescriptor(RecordWriterDescriptor descriptor) { } *************** *** 199,205 **** * the various subclasses of GenericElementWriter (including GenericFieldWriter * and GenericCellWriter). An awful lot of code assumes that, once created, ! * a GenericFieldWriter remeains constant. * </P> ! * @return the value */ public Object getValue() { --- 159,165 ---- * the various subclasses of GenericElementWriter (including GenericFieldWriter * and GenericCellWriter). An awful lot of code assumes that, once created, ! * a GenericFieldWriter remeains constant. * </P> ! * @return the value */ public Object getValue() { *************** *** 298,323 **** } ! /** Add any Aggregates required to a list. ! * ! * The write method of this class may require certain attributes and aggregate ! * calculations to exist in the Record objects supplied to the write method. This method ! * provides a way to discover which aggregate calculations are required by this writer. ! * ! * @param list A set object to which Aggregate objects are added. ! */ ! public void buildRequiredAggregatesSet(Set list) { ! datasource.buildRequiredAggregatesSet(list); ! } ! ! /** Add any data attributes required to a list. ! * ! * The write method of this class may require certain attributes and aggregate ! * calculations to exist in the Record objects supplied to the write method. This method ! * provides a way to discover which data attributes are required by this writer. * ! * @param list A set object to which names of data attributes are added as String objects. */ ! public void buildRequiredDataAttributesSet(Set list) { ! datasource.buildRequiredDataAttributesSet(list); } --- 258,267 ---- } ! /** Build metatdata * ! * @param descriptor Object to accumulate metadata */ ! public void buildRecordWriterDescriptor(RecordWriterDescriptor descriptor) { ! datasource.buildRecordWriterDescriptor(descriptor); } *************** *** 335,349 **** * static value. Otherwise returns null. * ! * @return Static data value, or null */ ! public Object getValue() { ! if (datasource instanceof StaticDataSource) { ! return ((StaticDataSource)datasource).getValue(); ! } else { ! return null; ! } ! ! } ! /** Get the name of the record attribute written by this writer. * --- 279,293 ---- * static value. Otherwise returns null. * ! * @return Static data value, or null */ ! public Object getValue() { ! if (datasource instanceof StaticDataSource) { ! return ((StaticDataSource)datasource).getValue(); ! } else { ! return null; ! } ! ! } ! /** Get the name of the record attribute written by this writer. * *************** *** 351,364 **** * of that record attribute. Otherwise returns null. * ! * @return attribute name, or null */ ! public String getAttributeName() { ! if (datasource instanceof AttributeDataSource) { ! return ((AttributeDataSource)datasource).getAttributeName(); ! } else { ! return null; ! } ! } ! /** Get the type of the record attribute written by this writer. * --- 295,308 ---- * of that record attribute. Otherwise returns null. * ! * @return attribute name, or null */ ! public String getAttributeName() { ! if (datasource instanceof AttributeDataSource) { ! return ((AttributeDataSource)datasource).getAttributeName(); ! } else { ! return null; ! } ! } ! /** Get the type of the record attribute written by this writer. * *************** *** 366,405 **** * of that record attribute. Otherwise undefined. * ! * @return attribute type (undefined if no attribute type) */ ! public int getAttributeType() { ! if (datasource instanceof AttributeDataSource) { ! return ((AttributeDataSource)datasource).getAttributeType(); ! } else { ! return -1; ! } ! } ! ! /** Get any format applied to data before output. ! * ! * @return A format (if any) applied to data before output. ! */ ! public Format getFormat() { ! return format; ! } ! ! /** Equality operator. ! * ! * @param other Object to test for equality with this. ! * @return true if other is a GenericElementWriter with equal datasource and format. ! */ ! public boolean equals(Object other) { ! if (other instanceof GenericElementWriter) { ! GenericElementWriter other_wr = (GenericElementWriter)other; ! if (this.datasource.equals(other_wr.datasource)) { ! if (this.format == null || other_wr.format == null) { ! return this.format == other_wr.format; ! } else { ! return this.format.equals(other_wr.format); ! } ! } ! } ! return false; ! } } --- 310,349 ---- * of that record attribute. Otherwise undefined. * ! * @return attribute type (undefined if no attribute type) */ ! public int getAttributeType() { ! if (datasource instanceof AttributeDataSource) { ! return ((AttributeDataSource)datasource).getAttributeType(); ! } else { ! return -1; ! } ! } ! ! /** Get any format applied to data before output. ! * ! * @return A format (if any) applied to data before output. ! */ ! public Format getFormat() { ! return format; ! } ! ! /** Equality operator. ! * ! * @param other Object to test for equality with this. ! * @return true if other is a GenericElementWriter with equal datasource and format. ! */ ! public boolean equals(Object other) { ! if (other instanceof GenericElementWriter) { ! GenericElementWriter other_wr = (GenericElementWriter)other; ! if (this.datasource.equals(other_wr.datasource)) { ! if (this.format == null || other_wr.format == null) { ! return this.format == other_wr.format; ! } else { ! return this.format.equals(other_wr.format); ! } ! } ! } ! return false; ! } } Index: GenericFieldWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GenericFieldWriter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenericFieldWriter.java 21 Jun 2004 10:13:37 -0000 1.7 --- GenericFieldWriter.java 14 Jul 2004 16:05:44 -0000 1.8 *************** *** 35,39 **** * @author Jonathan Essex */ ! public class GenericFieldWriter extends GenericElementWriter implements RecordElementWriter { private String class_id; --- 35,39 ---- * @author Jonathan Essex */ ! public class GenericFieldWriter extends GenericElementWriter implements FieldWriter { private String class_id; Index: GenericGridAttributesWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GenericGridAttributesWriter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GenericGridAttributesWriter.java 22 Jun 2004 08:23:32 -0000 1.4 --- GenericGridAttributesWriter.java 14 Jul 2004 16:05:44 -0000 1.5 *************** *** 14,17 **** --- 14,22 ---- import org.jdaemon.util.AttributeList; + import java.util.Arrays; + import java.util.List; + import java.util.ArrayList; + import java.util.Iterator; + /** Write a grid attributes element to a report builder. * <P> *************** *** 45,52 **** * @author Jonathan Essex */ ! public class GenericGridAttributesWriter extends GenericElementCollectionWriter implements GridAttributesWriter { private String class_id; ! /** Creates a new instance of GenericGridAttributesWriter * --- 50,58 ---- * @author Jonathan Essex */ ! public class GenericGridAttributesWriter implements GridAttributesWriter { private String class_id; ! private List cell_attrs; ! /** Creates a new instance of GenericGridAttributesWriter * *************** *** 54,79 **** */ public GenericGridAttributesWriter(String class_id, CellAttributesWriter[] cell_attrs) { - super(cell_attrs); this.class_id = class_id; } ! ! /** Send end element event to builder. ! * ! * @param builder ReportBuilder to send start element event to ! * ! */ ! protected void endElement(ReportBuilder builder) throws BuildException { ! builder.endGridAttributes(); ! } ! ! /** Send start element event to builder. ! * ! * @param builder ReportBuilder to send end element event to ! * ! */ ! protected void startElement(ReportBuilder builder) throws BuildException { ! builder.startGridAttributes(class_id, AttributeList.EMPTY); ! } ! /** Get value of class attribute. * --- 60,67 ---- */ public GenericGridAttributesWriter(String class_id, CellAttributesWriter[] cell_attrs) { this.class_id = class_id; + this.cell_attrs = new ArrayList(Arrays.asList(cell_attrs)); } ! /** Get value of class attribute. * *************** *** 96,103 **** GenericGridAttributesWriter other_wr = (GenericGridAttributesWriter)other; if (this.class_id == null || other_wr.class_id == null) { ! return this.class_id == other_wr.class_id && this.listElements().equals(other_wr.listElements()); } else { ! return this.class_id.equals(other_wr.class_id) && this.listElements().equals(other_wr.listElements()); } } } --- 84,121 ---- GenericGridAttributesWriter other_wr = (GenericGridAttributesWriter)other; if (this.class_id == null || other_wr.class_id == null) { ! return this.class_id == other_wr.class_id && this.cell_attrs.equals(other_wr.cell_attrs); } else { ! return this.class_id.equals(other_wr.class_id) && this.cell_attrs.equals(other_wr.cell_attrs); } } + + + /** Hash function. + * + * @return the hash code of the class id + */ + public int hashCode() { + return class_id.hashCode(); + } + + /** Output Grid Attributes to builder. + * + * @param builder to output grid attributes to + * @throws BuildException on any error in output + */ + public void write(ReportBuilder builder) throws BuildException { + builder.startGridAttributes(class_id, AttributeList.EMPTY); + Iterator i = cell_attrs.iterator(); + while (i.hasNext()) ((CellAttributesWriter)i.next()).write(builder); + builder.endGridAttributes(); + } + + /** Add an element to the grid attributes block + * + * @param element Element to add + */ + public void addElement(CellAttributesWriter element) { + cell_attrs.add(element); + } + } Index: GenericGridWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GenericGridWriter.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GenericGridWriter.java 22 Jun 2004 08:23:32 -0000 1.5 --- GenericGridWriter.java 14 Jul 2004 16:05:44 -0000 1.6 *************** *** 14,17 **** --- 14,19 ---- import org.jdaemon.util.AttributeList; + import java.util.Iterator; + /** Generic implemntation of class to write a grid element out to a builder. * <P> *************** *** 38,41 **** --- 40,44 ---- private String class_id; + private GridAttributesWriter attrs; /** Creates a new instance of GenericGridWriter. *************** *** 53,56 **** --- 56,64 ---- super(elements); this.class_id = class_id; + + CellAttributesWriter[] cell_attrs = new CellAttributesWriter [elements.length]; + for (int i = 0; i < cell_attrs.length; i++) cell_attrs[i] = elements[i].getCellAttributesWriter(); + + this.attrs = new GenericGridAttributesWriter(class_id, cell_attrs); } *************** *** 78,81 **** --- 86,90 ---- public void addElement(CellWriter cell_writer) { super.addElement(cell_writer); + attrs.addElement(cell_writer.getCellAttributesWriter()); } *************** *** 119,122 **** return this.class_id.equals(other_wr.class_id) && this.listElements().equals(other_wr.listElements()); } ! } } --- 128,144 ---- return this.class_id.equals(other_wr.class_id) && this.listElements().equals(other_wr.listElements()); } ! } ! ! /** Register this grid writer in RecordWriterDescriptor ! */ ! public void buildRecordWriterDescriptor(RecordWriterDescriptor desc) { ! super.buildRecordWriterDescriptor(desc); ! desc.registerGridAttributesWriter(getGridAttributesWriter()); ! } ! ! /** Get a grid attributes writer describing this grid block. ! */ ! public GridAttributesWriter getGridAttributesWriter() { ! return attrs; ! } } Index: GenericRecordWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GenericRecordWriter.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GenericRecordWriter.java 21 Jun 2004 16:43:26 -0000 1.6 --- GenericRecordWriter.java 14 Jul 2004 16:05:44 -0000 1.7 *************** *** 60,63 **** --- 60,83 ---- private String class_id; + /** Metadata concenring this RecordWriter + */ + private RecordWriterDescriptor descriptor; + + /** get metadata concerning this RecordWriter + * + * @return A RecordWriterDescriptor containing info about this RecordWriter + */ + public RecordWriterDescriptor getDescriptor() { + + // So if the element list ever changes we just have to set + // descriptor to null and it will be recreated on demand. + if (descriptor == null) { + descriptor = new RecordWriterDescriptor(); + buildRecordWriterDescriptor(descriptor); + } + + return descriptor; + } + /** Creates a new instance of GenericRecordWriter. * <P> *************** *** 75,78 **** --- 95,99 ---- super(elements); this.class_id = class_id; + this.descriptor = null; } *************** *** 103,106 **** --- 124,128 ---- public void addElement(RecordElementWriter field_writer) { super.addElement(field_writer); + this.descriptor = null; } *************** *** 136,148 **** return null; } ! ! /** Get a list of the Aggregate data required by this formatting. * ! * @return a List of Aggregate objects describing the data required by this formatting */ ! public List getRequiredAggregates() { ! HashSet set = new HashSet(); ! buildRequiredAggregatesSet(set); ! return Arrays.asList(set.toArray()); } --- 158,168 ---- return null; } ! ! /** Get a list of the base data required by this formatting. * ! * @return a List of String objects containing the names of the base data fields required by this formatting. */ ! public List getRequiredDataAttributes() { ! return Arrays.asList(getDescriptor().getRequiredDataAttributes().toArray()); } *************** *** 151,160 **** * @return a List of String objects containing the names of the base data fields required by this formatting. */ ! public List getRequiredDataAttributes() { ! HashSet set = new HashSet(); ! buildRequiredDataAttributesSet(set); ! return Arrays.asList(set.toArray()); } ! /** Get the value of the class attribute for records written by this writer. * --- 171,178 ---- * @return a List of String objects containing the names of the base data fields required by this formatting. */ ! public List getRequiredAggregates() { ! return Arrays.asList(getDescriptor().getRequiredAggregates().toArray()); } ! /** Get the value of the class attribute for records written by this writer. * *************** *** 177,179 **** --- 195,202 ---- } } + + public void registerHeaderElements(HeaderWriter headerwriter) { + getDescriptor().registerHeaderElements(headerwriter); + } + } Index: GenericRecordsetWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GenericRecordsetWriter.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GenericRecordsetWriter.java 21 Jun 2004 16:43:26 -0000 1.7 --- GenericRecordsetWriter.java 14 Jul 2004 16:05:44 -0000 1.8 *************** *** 99,102 **** return this.class_id.equals(other_wr.class_id); } ! } } --- 99,116 ---- return this.class_id.equals(other_wr.class_id); } ! } ! ! /** Build descriptor for record writer. ! * ! * Does nothing here, as a recordset element is where we drop down to the next ! * level record writer - hence nothing inside a recordset element is relavent ! * to describin the record writer at the current level. ! * ! * Actually this whole 'RecordWriterDescriptor' thing sucks and I'll look at ! * tidying it up. ! * ! * @param descriptor unused ! */ ! public void buildRecordWriterDescriptor(RecordWriterDescriptor descriptor) { ! } } Index: GridAttributesWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/GridAttributesWriter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GridAttributesWriter.java 20 Jun 2004 19:56:26 -0000 1.4 --- GridAttributesWriter.java 14 Jul 2004 16:05:44 -0000 1.5 *************** *** 10,13 **** --- 10,16 ---- package org.jdaemon.era.grml; + import org.jdaemon.six.ReportBuilder; + import org.jdaemon.six.BuildException; + /** Interface for writing grid-attributes elements to a writer. * <P> *************** *** 31,35 **** * @author Jonathan Essex */ ! public interface GridAttributesWriter extends ElementWriter { /** Get value of class attribute. --- 34,38 ---- * @author Jonathan Essex */ ! public interface GridAttributesWriter { /** Get value of class attribute. *************** *** 43,45 **** --- 46,60 ---- public String getClassAttribute(); + /** Write grid attributes to builder + * + * @param builder Builder to output grid attributes element to + * @throws BuildException on any error in processing ouptut. + */ + public void write(ReportBuilder builder) throws BuildException; + + /** Add an element to the grid attributes block + * + * @param element Element to add + */ + public void addElement(CellAttributesWriter element); } Index: RecordWriter.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/RecordWriter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RecordWriter.java 13 Jun 2004 21:05:19 -0000 1.4 --- RecordWriter.java 14 Jul 2004 16:05:44 -0000 1.5 *************** *** 32,35 **** */ public void write( Record record, ! ReportBuilder builder ) throws BuildException; } --- 32,37 ---- */ public void write( Record record, ! ReportBuilder builder ) throws BuildException; ! ! public void registerHeaderElements(HeaderWriter headerwriter); } Index: TestGRMLReport.java =================================================================== RCS file: /cvsroot/era/src/org/jdaemon/era/grml/TestGRMLReport.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** TestGRMLReport.java 22 Jun 2004 08:23:32 -0000 1.12 --- TestGRMLReport.java 14 Jul 2004 16:05:44 -0000 1.13 *************** *** 10,13 **** --- 10,14 ---- import org.jdaemon.era.*; import org.jdaemon.era.helper.GroupingImpl; + import org.jdaemon.era.helper.HelperTypes; import org.jdaemon.six.*; import org.jdaemon.test.era.TestData; *************** *** 28,31 **** --- 29,33 ---- import javax.xml.transform.TransformerException; + /** Test cases for GRMLReport and related classes * *... [truncated message content] |