multivalent

Class Layer

public class Layer extends Behavior

Special behavior type that groups (1) behaviors (which can be nested Layer's) and (2) data trees of ESISNodes, and dispatches (round robin) protocol events over its collection. Every Document has at least one Layer to implement genre and document-specific functionality, and the Root's Layer holds all-document/pan-genre system functionality. Some behaviors store data in the trees; for instance, multipage documents store pagewise behaviors, and Note stores its content.

Layers are loaded from and saved to hubs, in which the case a constituant behavior's logical name is the tag or generic identifier (GI) and its attributes the tag's attributes; trees are stored as is. Because of this, behavior logical names are normalized to all lowercase. Behaviors are distinguished from data by a BEHAVIOR attribute.

Dispatches round robin (non-tree) protocols (restore, build, save, semantic events, ...) by recursing over the component behaviors. Tree-based protocols (format, paint, low-level events, ...) are handled elsewhere, by the document tree.

Works with Multipage as follows. Stores hub encompassing all pages in data tree keyed by page number. On buildBefore, if PAGE attribute on document, clears behaviors and instantiates relevant portion. Likewise, on "closedDocumentPage", saves current behaviors to data tree. Still loads full on MSG_OPENED and saves everything to disk on "closedDocument".

Version: $Revision: 1.17 $ $Date: 2003/06/02 05:07:21 $

See Also: Multipage

Field Summary
static StringATTR_ACTIVE
static StringBASE
Standard name for layer that holds media adaptor for primary document.
static StringMSG_LOAD
Load a layer as specified in a hub document, such as genre-specific behaviors or a set of annotations.
static StringPERSONAL
Layer names are given by String's and usually known by convention, but some are defined, such as PERSONAL for personal annotations.
static StringPREFIX
static StringSCRATCH
Standard name for layer that holds behaviors that have no semantic standing in the document.
static StringSHARED
Standard name for layer that holds behaviors shared among other behaviors, although any layer can be shared by asking for the right name.
static StringSYSTEM
Layer names are given by String's and usually known by convention, but some are defined, such as PERSONAL for personal annotations.
Method Summary
protected voidaddAux(ESISNode e)
Add ESISNode tree to aux trees, if not already there (not a multilist).
voidaddBehavior(Behavior be)
A Behavior can only be in one layer at a time, so if it's already in a layer, it's removed from that layer first.
intauxSize()
Number of auxiliary trees (often 0).
voidbuildAfter(Document doc)
Iterates over component Behaviors (Layer is a subclass of Behavior), lowest priority to highest.
voidbuildBefore(Document doc)
Iterates over component Behaviors (Layer is a subclass of Behavior), highest priority to lowest, if layer is active.
voidbuildBeforeAfter(Document doc)
booleancheckRep()
voidclear()
Clears everything, behaviors and aux.
voidclearBehaviors()
Removes all active behaviors from Layer, destroy()'ing in the process.
voiddestroy()
Iterates over component Behaviors (including nested Layer's), highest priority to lowest.
voiddump()
voiddump(int level)
BehaviorfindBehavior(String path)
Given a layer pathname, find nested layer.
ColorgetAnnoColor()
FontgetAnnoFont()
ESISNodegetAux(String tag)
Returns tree of aux tree data with passed tag.
ESISNodegetAux(String attrname, String attrval)
Returns tree of aux tree data with attribute name = val.
BehaviorgetBehavior(int index)
BehaviorgetBehavior(String logicalname)
Get behavior of given logical name, null if doesn't exist.
BehaviorgetBehavior(String logicalname, String classname)
Get (first) behavior of given logical name.
BrowsergetBrowser()
End of Layer chain.
DocumentgetDocument()
Often end of Layer chain.
static LayergetInstance(String logicalname, Document doc)
Constructs top-most Layer of Layers in a Document.
LayergetInstance(String logicalname)
Constructs empty layer with given name, unless one by that name already exists, in which case that existing Layer is returned.
booleanisActive()
booleanisEditable()
For now, a layer is editable if its name is "personal".
protected voidremoveAux(ESISNode e)
protected voidremoveAux(String attrname, String attrval)
voidremoveBehavior(Behavior be)
Remove behavior from Layer as soon as pending semanticEvent roundrobins completed; if none, then remove immediately.
voidrestore(ESISNode n, Map<String,Object> attr, Layer layer)
voidrestoreChildren(ESISNode n, Layer layer)
Override definition in Behavior to keep immediate subtrees that aren't behaviors.
ESISNodesave()
Iterate over auxiliary non-behavior trees, then component Behaviors highest priority to lowest.
booleansemanticEventAfter(SemanticEvent se, String msg)
Iterates over component Behaviors, lowest priority to highest.
booleansemanticEventBefore(SemanticEvent se, String msg)
Iterates over component Behaviors (including nested Layer's), highest priority to lowest.
voidsetActive(boolean active)
If a Layer is not active, all its component behaviors are still instantiated but not invoked during protocols.
intsize()

Field Detail

ATTR_ACTIVE

public static final String ATTR_ACTIVE

BASE

public static final String BASE
Standard name for layer that holds media adaptor for primary document.

MSG_LOAD

public static final String MSG_LOAD
Load a layer as specified in a hub document, such as genre-specific behaviors or a set of annotations.

"loadLayer": arg= java.net.URI location of hub

PERSONAL

public static final String PERSONAL
Layer names are given by String's and usually known by convention, but some are defined, such as PERSONAL for personal annotations.

PREFIX

public static final String PREFIX

SCRATCH

public static final String SCRATCH
Standard name for layer that holds behaviors that have no semantic standing in the document.

SHARED

public static final String SHARED
Standard name for layer that holds behaviors shared among other behaviors, although any layer can be shared by asking for the right name.

SYSTEM

public static final String SYSTEM
Layer names are given by String's and usually known by convention, but some are defined, such as PERSONAL for personal annotations.

Method Detail

addAux

protected void addAux(ESISNode e)
Add ESISNode tree to aux trees, if not already there (not a multilist).

addBehavior

public void addBehavior(Behavior be)
A Behavior can only be in one layer at a time, so if it's already in a layer, it's removed from that layer first. Behaviors added to layer during a protocol are ignored until the protocol (both before and after phases) cpmpletes in this Layer.

auxSize

public int auxSize()
Number of auxiliary trees (often 0).

buildAfter

public void buildAfter(Document doc)
Iterates over component Behaviors (Layer is a subclass of Behavior), lowest priority to highest.

buildBefore

public void buildBefore(Document doc)
Iterates over component Behaviors (Layer is a subclass of Behavior), highest priority to lowest, if layer is active. If in multipage document, first clear current behaviors and instantiate those for new page, if any, regardless of active state.

buildBeforeAfter

public void buildBeforeAfter(Document doc)

checkRep

public boolean checkRep()

clear

public void clear()
Clears everything, behaviors and aux.

clearBehaviors

public void clearBehaviors()
Removes all active behaviors from Layer, destroy()'ing in the process. Also used in Anno/Wipe.

destroy

public void destroy()
Iterates over component Behaviors (including nested Layer's), highest priority to lowest.

dump

public void dump()

dump

public void dump(int level)

findBehavior

public Behavior findBehavior(String path)
Given a layer pathname, find nested layer.

getAnnoColor

public Color getAnnoColor()

getAnnoFont

public Font getAnnoFont()

getAux

public ESISNode getAux(String tag)
Returns tree of aux tree data with passed tag.

getAux

public ESISNode getAux(String attrname, String attrval)
Returns tree of aux tree data with attribute name = val. If attrval == null, anything matches.

getBehavior

public Behavior getBehavior(int index)

getBehavior

public Behavior getBehavior(String logicalname)
Get behavior of given logical name, null if doesn't exist.

getBehavior

public Behavior getBehavior(String logicalname, String classname)
Get (first) behavior of given logical name. If one doesn't exist, create with passed class name. To create a behavior regardless if one by that name already existes, use Behavior. To get all behaviors of given logical name, iterate over the list yourself from 0 .. size()-1 with getBehavior(int).

getBrowser

public Browser getBrowser()
End of Layer chain.

getDocument

public Document getDocument()
Often end of Layer chain.

getInstance

public static Layer getInstance(String logicalname, Document doc)
Constructs top-most Layer of Layers in a Document.

getInstance

public Layer getInstance(String logicalname)
Constructs empty layer with given name, unless one by that name already exists, in which case that existing Layer is returned. Construction of a new layer nests within this layer. New layer is populated from all hubs by that name in all JARs and the uer's home directory; if there are no hubs, the result is an empty layer.

See Also: getBehavior

isActive

public boolean isActive()

isEditable

public boolean isEditable()
For now, a layer is editable if its name is "personal".

removeAux

protected void removeAux(ESISNode e)

removeAux

protected void removeAux(String attrname, String attrval)

removeBehavior

public void removeBehavior(Behavior be)
Remove behavior from Layer as soon as pending semanticEvent roundrobins completed; if none, then remove immediately.

restore

public void restore(ESISNode n, Map<String,Object> attr, Layer layer)

restoreChildren

public void restoreChildren(ESISNode n, Layer layer)
Override definition in Behavior to keep immediate subtrees that aren't behaviors.

save

public ESISNode save()
Iterate over auxiliary non-behavior trees, then component Behaviors highest priority to lowest. Trees go first as they may have information needed by behaviors to follow. If document is multipage, as indicated by a MediaAdapator.PAGE attribute in Document, then stuff aux.

semanticEventAfter

public boolean semanticEventAfter(SemanticEvent se, String msg)
Iterates over component Behaviors, lowest priority to highest.

semanticEventBefore

public boolean semanticEventBefore(SemanticEvent se, String msg)
Iterates over component Behaviors (including nested Layer's), highest priority to lowest. On MSG_CLOSEPAGE for isEditable() documents, first saves active behaviors for that page to aux in memory (behaviors are moved from aux to active in buildBefore). (Low-level eventBefore/After is a tree-based protocol, so it's not seen by Layer.)

setActive

public void setActive(boolean active)
If a Layer is not active, all its component behaviors are still instantiated but not invoked during protocols. Layer directly controls build and semanticEvent, and without build there should be no attachments to the document tree for format, paint, .... Useful to disable Debugging layer, various annotation layers.

size

public int size()