public abstract class BasePipeline<W,C extends W,E,M extends C> extends Object
Use of BasePipeline when developing Metawidgets is entirely optional. However, it provides a level of functionality and structure to the code which most Metawidgets will benefit from.
Specifically, BasePipeline provides support for:
org.metawidget.pipeline.w3c.W3CPipeline
, which uses
org.w3c.dom
.
BasePipeline is not Thread-safe.
Note: this class is located in org.metawidget.pipeline.base
, as opposed to just
org.metawidget.pipeline
, to make it easier to integrate GWT (which is bad at
ignoring sub-packages such as org.metawidget.pipeline.w3c
).
Constructor and Description |
---|
BasePipeline() |
Modifier and Type | Method and Description |
---|---|
void |
addInspectionResultProcessor(InspectionResultProcessor<M> inspectionResultProcessor) |
void |
addWidgetProcessor(WidgetProcessor<W,M> widgetProcessor) |
protected void |
buildCompoundWidget(E entity)
Build a compound widget by iterating through children of the given
element, calling
buildWidget and addWidget on
each. |
protected abstract M |
buildNestedMetawidget(Map<String,String> attributes) |
protected W |
buildWidget(String elementName,
Map<String,String> attributes) |
void |
buildWidgets(E inspectionResult)
Build widgets from the given XML inspection result.
|
protected abstract void |
configure() |
void |
configureOnce()
Configures the Metawidget, then sets a flag so that subsequent calls to
configureOnce do nothing. |
protected abstract String |
elementToString(E element)
Serialize the given element to an XML String.
|
protected void |
endBuild() |
protected abstract Map<String,String> |
getAdditionalAttributes(W widget)
Returns additional attributes associated with the widget.
|
protected abstract Map<String,String> |
getAttributesAsMap(E element) |
protected abstract String |
getElementName(E element) |
protected abstract E |
getFirstChildElement(E parent) |
List<InspectionResultProcessor<M>> |
getInspectionResultProcessors()
Gets the List of InspectionResultProcessors.
|
Inspector |
getInspector() |
Layout<W,C,M> |
getLayout() |
int |
getMaximumInspectionDepth() |
protected abstract E |
getNextSiblingElement(E element) |
protected abstract M |
getPipelineOwner() |
WidgetBuilder<W,M> |
getWidgetBuilder() |
List<WidgetProcessor<W,M>> |
getWidgetProcessors()
Gets the List of WidgetProcessors.
|
void |
initNestedPipeline(BasePipeline<W,C,E,M> nestedPipeline,
Map<String,String> attributes)
Copies this pipeline's values into another pipeline.
|
String |
inspect(Object toInspect,
String type,
String... names)
Inspect the given Object according to the given path, and return the
result as a String conforming to inspection-result-1.0.xsd.
|
E |
inspectAsDom(Object toInspect,
String type,
String... names)
Inspect the given Object according to the given path, and return the
result as a String conforming to inspection-result-1.0.xsd.
|
boolean |
isReadOnly() |
protected void |
layoutWidget(W widget,
String elementName,
Map<String,String> attributes)
Lays out the built and processed widget.
|
protected E |
processInspectionResult(Object inspectionResult,
Object toInspect,
String type,
String... names) |
protected W |
processWidget(W widget,
String elementName,
Map<String,String> attributes)
Process the built widget.
|
void |
removeInspectionResultProcessor(InspectionResultProcessor<M> inspectionResultProcessors) |
void |
removeWidgetProcessor(WidgetProcessor<W,M> widgetProcessor) |
void |
setInspectionResultProcessors(InspectionResultProcessor<M>... inspectionResultProcessors) |
void |
setInspector(Inspector inspector) |
void |
setLayout(Layout<W,C,M> layout)
Set the Layout to use for the Metawidget.
|
void |
setMaximumInspectionDepth(int maximumInspectionDepth)
Sets the maximum depth of inspection.
|
void |
setNeedsConfiguring() |
void |
setReadOnly(boolean readOnly) |
void |
setWidgetBuilder(WidgetBuilder<W,M> widgetBuilder) |
void |
setWidgetProcessors(WidgetProcessor<W,M>... widgetProcessors) |
protected void |
startBuild() |
protected abstract E |
stringToElement(String xml) |
public void setReadOnly(boolean readOnly)
public boolean isReadOnly()
public int getMaximumInspectionDepth()
public void setMaximumInspectionDepth(int maximumInspectionDepth)
Metawidget renders most non-primitve types by using nested Metawidgets. This value limits the number of nestings.
This can be useful in detecing cyclic references. Although BaseObjectInspector
-derived Inspectors are capable of detecting cyclic references, other Inspectors may not be.
For example, BaseXmlInspector
-derived Inspectors cannot because they only test
types, not actual objects.
maximumInspectionDepth
- 0 for top-level only, 1 for 1 level deep etc.public void setNeedsConfiguring()
public void configureOnce()
configureOnce
do nothing.
The flag can be reset by calling setNeedsConfiguring
.
public void setInspector(Inspector inspector)
public Inspector getInspector()
public List<InspectionResultProcessor<M>> getInspectionResultProcessors()
This pipeline only references a single Inspector and single WidgetBuilder. It relies on CompositeInspector and CompositeWidgetBuilder to support multiples, which allows the combination algorithm itself to be pluggable.
We use a List of InspectionResultProcessors, however, so as to be consistent with WidgetProcessors. Note ordering of InspectionResultProcessors is significant.
public void setInspectionResultProcessors(InspectionResultProcessor<M>... inspectionResultProcessors)
public void addInspectionResultProcessor(InspectionResultProcessor<M> inspectionResultProcessor)
public void removeInspectionResultProcessor(InspectionResultProcessor<M> inspectionResultProcessors)
public void setWidgetBuilder(WidgetBuilder<W,M> widgetBuilder)
public WidgetBuilder<W,M> getWidgetBuilder()
public List<WidgetProcessor<W,M>> getWidgetProcessors()
This pipeline only references a single Inspector and single WidgetBuilder. It relies on CompositeInspector and CompositeWidgetBuilder to support multiples, which allows the combination algorithm itself to be pluggable.
We cannot use this same approach for WidgetProcessors, however, because we want to support event handling. We want to allow, for example:
metawidget.addWidgetProcessor( new WidgetProcessor() {
...handle event...
}
This mechanism cannot be delegated to a CompositeWidgetProcessor, because WidgetProcessors must be immutable, and we want to allow event handlers that are non-static anonymous inner classes.
There, we use a List of WidgetProcessors. Note ordering of WidgetProcessors is significant.
public void setWidgetProcessors(WidgetProcessor<W,M>... widgetProcessors)
public void addWidgetProcessor(WidgetProcessor<W,M> widgetProcessor)
public void removeWidgetProcessor(WidgetProcessor<W,M> widgetProcessor)
public String inspect(Object toInspect, String type, String... names)
This method mirrors the Inspector
interface. Internally it looks up the
Inspector to use. It is a useful hook for subclasses wishing to inspect different Objects
using our same Inspector
.
In addition, this method runs the InspectionResultProcessors
.
public E inspectAsDom(Object toInspect, String type, String... names)
This method mirrors the DomInspector
interface. Internally it looks up the
Inspector to use. It is a useful hook for subclasses wishing to inspect different Objects
using our same Inspector
.
In addition, this method runs the InspectionResultProcessors
.
public void buildWidgets(E inspectionResult) throws Exception
Note: the BasePipeline
expects the XML to be passed in externally, rather than
fetching it itself, because some XML inspections may be asynchronous.
Exception
public void initNestedPipeline(BasePipeline<W,C,E,M> nestedPipeline, Map<String,String> attributes)
Special behaviour is:
READ_ONLY
attributes
- may be nullprotected void buildCompoundWidget(E entity) throws Exception
buildWidget
and addWidget
on
each.Exception
protected abstract String elementToString(E element)
element
- the element to serialize. May be null.protected abstract void configure()
protected void startBuild()
protected E processInspectionResult(Object inspectionResult, Object toInspect, String type, String... names)
inspectionResult
- may be a String of XML, or an E, depending on whether the
Inspector was a DomInspectorprotected abstract Map<String,String> getAdditionalAttributes(W widget)
At the very least, this method should be implemented to support returning additional attributes from stubs.
protected W processWidget(W widget, String elementName, Map<String,String> attributes)
protected abstract M buildNestedMetawidget(Map<String,String> attributes) throws Exception
Exception
protected abstract M getPipelineOwner()
protected void layoutWidget(W widget, String elementName, Map<String,String> attributes)
protected void endBuild()
Copyright © 2015. All Rights Reserved.