if (formatType == null) {
throw new IllegalArgumentException(
"A non-null format type is required"); //$NON-NLS-1$
}
ODOMElement prototype = (ODOMElement)prototypes.get(formatType);
if (prototype == null) {
FormatType.Structure structure = formatType.getStructure();
String name = formatType.getElementName();
// Double check that things won't go horribly wrong (simple
// and grid containers both need to reference the empty format,
// so the latter must be a leaf format)
if ((formatType == FormatType.EMPTY) &&
structure != FormatType.Structure.LEAF) {
throw new IllegalStateException(
"The empty format must be a leaf " + //$NON-NLS-1$
"structured format"); //$NON-NLS-1$
}
// Create the main element for the prototype
prototype = (ODOMElement)factory.element(name);
if (structure == FormatType.Structure.LEAF) {
// Leaf formats have no internal structure
} else if (structure == FormatType.Structure.SIMPLE_CONTAINER) {
// Simple containers have an empty format placeholder for child
// creation
prototype.addContent(get(FormatType.EMPTY));
// The following code block inserts default values for new
// Formats. This will eventually be required for all formats.
// However at the moment we only set the following required
// fields of the Spatial Iterators....
// - 2D Indexing Direction
// - Row Iterations
// - Column Iterations
//
// When this is extended to other formats the code should
// almost certainly be refactored out of this method.
//
// Setting defaults allows the user to build a layout without
// having to explicitly set all required fields, reducing the
// level of error feedback and facilitating faster layout
// construction.
if (formatType == FormatType.SPATIAL_FORMAT_ITERATOR) {
prototype.setAttribute(
LayoutSchemaType.
SPATIAL_ITERATOR_COLUMNS_ATTRIBUTE.getName(),
LayoutSchemaType.
SPATIAL_ITERATOR_CELLS_VALUE_VARIABLE.getName());
prototype.setAttribute(
LayoutSchemaType.
SPATIAL_ITERATOR_COLUMN_COUNT_ATTRIBUTE.getName(),
"0");
prototype.setAttribute(
LayoutSchemaType.
SPATIAL_ITERATOR_ROWS_ATTRIBUTE.getName(),
LayoutSchemaType.
SPATIAL_ITERATOR_CELLS_VALUE_VARIABLE.getName());
prototype.setAttribute(
LayoutSchemaType.
SPATIAL_ITERATOR_ROW_COUNT_ATTRIBUTE.getName(),
"0");
prototype.setAttribute(
LayoutSchemaType.
SPATIAL_ITERATOR_INDEXING_DIRECTION_ATTRIBUTE.
getName(),
LayoutSchemaType.
SPATIAL_ITERATOR_INDEXING_DIRECTION_VALUE_ACROSS_DOWN.
getName());
}
} else if (structure == FormatType.Structure.GRID) {
// Create the complex prototype structure based on the grid
// format's name
String gridName = prototype.getName();
String colName = LayoutSchemaType.getGridColumnName(gridName);
String colsName = LayoutSchemaType.getGridColumnsName(gridName);
String rowName = LayoutSchemaType.getGridRowName(gridName);
ODOMElement col = (ODOMElement)factory.element(colName);
ODOMElement cols = (ODOMElement)factory.element(colsName);
ODOMElement row = (ODOMElement)factory.element(rowName);
prototype.addContent(cols);
cols.addContent(col);
prototype.addContent(row);
row.addContent(get(FormatType.EMPTY));
} else {
throw new IllegalArgumentException(
"The given format type (" + //$NON-NLS-1$
formatType.getTypeName() +
") has an unknown structure (" + //$NON-NLS-1$