jacquard 1.12.0 by The Web Engineering Factory and Toolworks

uk.co.weft.domutil
Class ElementGenerator

java.lang.Object
  extended byuk.co.weft.htform.ResourceConsumerImpl
      extended byuk.co.weft.domutil.NodeGeneratorImpl
          extended byuk.co.weft.domutil.MaybeParseGenerator
              extended byuk.co.weft.domutil.ElementGenerator
All Implemented Interfaces:
NodeGenerator, ResourceConsumer
Direct Known Subclasses:
ContextElementGenerator, DateGenerator, InvariantGenerator, InvariantTextGenerator, LabelledValueGenerator, ListGenerator, ListItemGenerator, ResultsAsTableGenerator.ClickToOrderGenerator, ResultsAsTableGenerator.RecogniseLinksGenerator, ResultsBodyGenerator, ResultSetGenerator, RichDiaryGenerator, RichDiaryGenerator.ActorGenerator, RichDiaryGenerator.DayGenerator, RichDiaryGenerator.EventGenerator, RichDiaryGenerator.LocationGenerator, WikiElementGenerator, WithSettableThumbPrefixImpl, XHTMLBodyGeneratorImpl, XHTMLDocumentGenerator.XHTMLDocumentRootGenerator, XHTMLDocumentGenerator.XHTMLHeadGenerator, XHTMLFormGenerator.FormAsBodyGenerator

public class ElementGenerator
extends MaybeParseGenerator
implements NodeGenerator

an ElementGenerator is an superclass for things which generate [X|HT]ML elements. The behaviour of this class is subtle and may seem perverse, but it's actually handy. By default, if ElementGenerator has no sub generators added to it, it will generate nodes with content only, which will be parsed from the value associated with its token in the context. If it has subgenerators, it will generate elements containing the elements generated by its subgenerators only, but no content parsed from the value.

Version:
$Revision: 1.22.4.6 $ This revision: $Author: simon $
Author:
Simon Brooke

Field Summary
protected  boolean childrenAndContent
          if I have child generaters, do I generate node content? By default I don't, for reasons discussed in the documentation above
protected  java.util.Vector generators
          My generators for attributes and elements
protected  java.lang.String keyname
          the name of the key field in that data store, if any
protected  java.util.Hashtable mapping
          A mapping which tells me what generators to use for particular object types
protected  java.lang.String storename
          the name of the data store (at this stage, a database table) I wrap, if any
protected  java.lang.String token
          the token I will look for in the context to provide the value for the element I generate
 
Fields inherited from class uk.co.weft.domutil.MaybeParseGenerator
embeddedMarkup
 
Fields inherited from class uk.co.weft.domutil.NodeGeneratorImpl
debug, name, namespaceURI
 
Fields inherited from class uk.co.weft.htform.ResourceConsumerImpl
resourceBundleName
 
Fields inherited from interface uk.co.weft.domutil.NodeGenerator
NAMESPACEURIMAGICTOKEN
 
Fields inherited from interface uk.co.weft.htform.ResourceConsumer
RESOURCEBUNDLEMAGICTOKEN
 
Constructor Summary
ElementGenerator()
          no args constructor; recommend you don't use this, but it makes it easier to write subclasses
ElementGenerator(java.lang.String name)
          constructor: fix up my name
ElementGenerator(java.lang.String name, java.lang.String token)
          constructor: generally, the name of the value to extract from the context is the same as the name of the element, but this constructor handles the case where it isn't.
ElementGenerator(java.lang.String name, java.lang.String token, java.lang.String storename)
          constructor: we often generate elements from data stores, for example database tables.
ElementGenerator(java.lang.String name, java.lang.String token, java.lang.String storename, java.lang.String keyname)
          constructor: we often generate elements from data stores, for example database tables.
ElementGenerator(java.lang.String name, java.lang.String token, java.lang.String storename, java.lang.String keyname, boolean childrenAndContent)
          constructor: we often generate elements from data stores, for example database tables.
 
Method Summary
 ElementGenerator addGenerator(NodeGenerator generator)
          add a generator to my generators, either for a child element or for an attribute
protected  void doinit(Context config)
          Do any actual configuration required by this element.
protected  void fetchDetail(Context context)
          fetch the detail of the item indicated by this context into this context
 Node generate(Document doc, Context c)
          construct an element with my name and attach my attributes and children.
 Node generate(Document doc, java.lang.Object obj)
          Construct an element representing this object with my name
 Node generate(Document doc, java.lang.Object obj, java.lang.String tag)
          Construct an element representing this object with this name
protected  java.lang.Object getTokenValue(Context c)
          subclasses can specialise this to mung the value in arbitrary ways.
 void init(Context config)
          Initialise me and any children I already have at initialisation time.
 void register(java.lang.Class valueType, ElementGenerator generator)
          Register an ElementGenerator to handle values of class valueType.
 void setChildrenAndContent(boolean childrenAndContent)
           
 
Methods inherited from class uk.co.weft.domutil.MaybeParseGenerator
allowEmbeddedMarkup, maybeParse
 
Methods inherited from class uk.co.weft.domutil.NodeGeneratorImpl
getName, getNamespaceURI, setDebug, setNamespaceURI
 
Methods inherited from class uk.co.weft.htform.ResourceConsumerImpl
getContextOrResource, getResource, getResourceOrContext, getResourceString, grs, grs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface uk.co.weft.domutil.NodeGenerator
getName, getNamespaceURI, setDebug
 

Field Detail

mapping

protected java.util.Hashtable mapping
A mapping which tells me what generators to use for particular object types


keyname

protected java.lang.String keyname
the name of the key field in that data store, if any


storename

protected java.lang.String storename
the name of the data store (at this stage, a database table) I wrap, if any


token

protected java.lang.String token
the token I will look for in the context to provide the value for the element I generate


generators

protected java.util.Vector generators
My generators for attributes and elements


childrenAndContent

protected boolean childrenAndContent
if I have child generaters, do I generate node content? By default I don't, for reasons discussed in the documentation above

Constructor Detail

ElementGenerator

public ElementGenerator()
no args constructor; recommend you don't use this, but it makes it easier to write subclasses


ElementGenerator

public ElementGenerator(java.lang.String name)
constructor: fix up my name


ElementGenerator

public ElementGenerator(java.lang.String name,
                        java.lang.String token)
constructor: generally, the name of the value to extract from the context is the same as the name of the element, but this constructor handles the case where it isn't. This creates a generator for simple elements whose tag name is the value of name, and who's value is the value of token on the generate-time context.

Parameters:
name - the tag name of the element I will generate
token - the token I will look up in the context to find the value for the element I generate.

ElementGenerator

public ElementGenerator(java.lang.String name,
                        java.lang.String token,
                        java.lang.String storename)
constructor: we often generate elements from data stores, for example database tables.

Parameters:
name - the tag name of the element I will generate
token - the token I will look up in the context to find the value for the element I generate, and also the name of the keyfield in the data store.
storename - the name of the data store in which to look

ElementGenerator

public ElementGenerator(java.lang.String name,
                        java.lang.String token,
                        java.lang.String storename,
                        java.lang.String keyname)
constructor: we often generate elements from data stores, for example database tables.

Parameters:
name - the tag name of the element I will generate
token - the token I will look up in the context to find the value for the element I generate
storename - the name of the data store in which to look
keyname - the name of the keyfield in that store

ElementGenerator

public ElementGenerator(java.lang.String name,
                        java.lang.String token,
                        java.lang.String storename,
                        java.lang.String keyname,
                        boolean childrenAndContent)
constructor: we often generate elements from data stores, for example database tables.

Parameters:
name - the tag name of the element I will generate
token - the token I will look up in the context to find the value for the element I generate
storename - the name of the data store in which to look
keyname - the name of the keyfield in that store
childrenAndContent - if true, then generate my content from both the value of my token in the context and from my added generators. Otherwise, if I have added generators, generate content from them only; if not, generate content from the value only. See documentation.
Method Detail

setChildrenAndContent

public void setChildrenAndContent(boolean childrenAndContent)
Parameters:
childrenAndContent - The childrenAndContent to set.

addGenerator

public ElementGenerator addGenerator(NodeGenerator generator)
add a generator to my generators, either for a child element or for an attribute

Parameters:
generator - the generator to add
Returns:
myself in order to allow daisy-chaining of adds.

generate

public Node generate(Document doc,
                     Context c)
              throws GenerationException,
                     DOMException
construct an element with my name and attach my attributes and children. Specialise for elements with more complex internal structure

Specified by:
generate in interface NodeGenerator
Specified by:
generate in class NodeGeneratorImpl
Parameters:
doc - the document in which this element is to be created.
c - the context in which this generation takes place
Returns:
the element created.
Throws:
GenerationException - may throw a GenerationException if the generation cannot be completed.
DOMException - will be passed through if Xerces barfs

generate

public Node generate(Document doc,
                     java.lang.Object obj,
                     java.lang.String tag)
              throws GenerationException,
                     DOMException
Construct an element representing this object with this name

Parameters:
doc - the document in which this element is to be created.
obj - the object to represent in the generated element
tag - the name for this element
Returns:
the element created.
Throws:
GenerationException - may throw a GenerationException if the generation cannot be completed.
DOMException - will be passed through if Xerces barfs

generate

public Node generate(Document doc,
                     java.lang.Object obj)
              throws GenerationException,
                     DOMException
Construct an element representing this object with my name

Parameters:
doc - the document in which this element is to be created.
Returns:
the element created.
Throws:
GenerationException - may throw a GenerationException if the generation cannot be completed.
DOMException - will be passed through if Xerces barfs

init

public void init(Context config)
          throws InitialisationException
Initialise me and any children I already have at initialisation time. Note that if you add children after initialisation time (and they need to be initialised) it is your responsibility to initialise them explicitly. Currently not used but potentially powerful, Note there should normally be no need to specialise this method (which simply recurses through this node and its children calling doinit( Context) - specialise doinit( Context) instead.

Specified by:
init in interface NodeGenerator
Specified by:
init in class NodeGeneratorImpl
Parameters:
config - a context containing configuration information.
Throws:
InitialisationException
Since:
Jacquard 1.8.0

register

public void register(java.lang.Class valueType,
                     ElementGenerator generator)
Register an ElementGenerator to handle values of class valueType. This is in effect a second line of defence mechanism for generation; if I have child- or attribute-generators added using addGenerator(), I won't use the generator registered using register().

Parameters:
valueType - the class for which the generator I'm registering should be used
generator - the generator to use for values of this class

getTokenValue

protected java.lang.Object getTokenValue(Context c)
subclasses can specialise this to mung the value in arbitrary ways. Ugly. you probably don't want to mess with this.

Parameters:
c - the context in which this generation takes place

doinit

protected void doinit(Context config)
Do any actual configuration required by this element. Default sets up debugging flag; specialise if needed. This is the better one to specialise (rather than init( Context)) if you can do without the InitialisationException; it would have been better design to have this also throw an InitialisationException and for init( Context) to be private.

Parameters:
config - a context containing configuration information.
Since:
Jacquard 1.8.0
See Also:
init(Context)

fetchDetail

protected void fetchDetail(Context context)
                    throws GenerationException
fetch the detail of the item indicated by this context into this context

Throws:
GenerationException

jacquard 1.12.0 by The Web Engineering Factory and Toolworks