4. Inspectors

This chapter covers each Inspector in detail. For an explanation of how Inspectors fit into the overall architecture of Metawidget, see Chapter 2, Architecture

Throughout this chapter when we say 'returns the following attributes' this is a shorthand way of saying 'returns the following Metawidget attributes (via a piece of XML conforming to inspection-result.xsd). These are passed to the WidgetBuilder to assist with choosing appropriate widgets'. Quite which widget will be chosen is covered in Chapter 6, WidgetBuilders: it could be a JSF HtmlInputTextarea, or a Swing JTextArea, or some other widget from some other framework.

4.1 Composite Inspector

CompositeInspector (the name refers to the Composite design pattern) delegates inspection to one or more sub-inspectors, then combines the resulting DOMs. The combining algorithm works as follows. For each element:

  1. top-level elements (typically entity) with the same type attribute in both DOMs are combined

  2. child elements (typically property or action) with the same name attribute in both DOMs are combined

  3. the ordering of child elements (typically property or action) in the existing DOM is preserved. New child elements are added either at the end or immediately after the last combined child

  4. element attributes from the new DOM override ones in the existing DOM (e.g. hidden or read-only)

This algorithm should be suitable for most use cases, but one benefit of having a separate CompositeInspector is that developers can replace it with their own version, with its own combining algorithm, if required.