org.zkoss.zk.ui.metainfo
Class ComponentInfo

java.lang.Object
  extended by org.zkoss.zk.ui.metainfo.NodeInfo
      extended by org.zkoss.zk.ui.metainfo.ComponentInfo
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, Condition
Direct Known Subclasses:
NativeInfo

public class ComponentInfo
extends NodeInfo
implements java.lang.Cloneable, Condition, java.io.Externalizable

Represents a componennt instance defined in a ZUML page.

Though serializable, we can restore getPageDefinition() correctly after deserialized.

Note:it is not thread-safe.

It is serializable.

Author:
tomyeh
See Also:
Serialized Form

Constructor Summary
ComponentInfo()
          This constructor is used only for Externalizable.
ComponentInfo(NodeInfo parent, ComponentDefinition compdef)
          Constructs the info about how to create a component that is not a dynamic tag.
ComponentInfo(NodeInfo parent, ComponentDefinition compdef, java.lang.String tag)
          Constructs the information about how to create component.
 
Method Summary
 void addAnnotation(java.lang.String annotName, java.util.Map annotAttrs)
          Associates an annotation to this component info.
 void addAnnotation(java.lang.String propName, java.lang.String annotName, java.util.Map annotAttrs)
          Adds an annotation to the specified proeprty of this component info.
 void addEventHandler(java.lang.String name, ZScript zscript, ConditionImpl cond)
          Adds an event handler.
 void addProperty(java.lang.String name, java.lang.String value, ConditionImpl cond)
          Adds a property initializer.
 void applyProperties(Component comp)
          Applies the event handlers, annotations, properties and custom attributes to the specified component.
 java.lang.Object clone()
          Clones this info.
 java.util.Map evalProperties(java.util.Map propmap, Page owner, Component parent, boolean defIncluded)
          Evaluates and retrieves properties to the specified map from ComponentDefinition (and ComponentInfo).
 AnnotationMap getAnnotationMap()
          Returns the annotation map defined in this info, or null if no annotation is ever defined.
 java.lang.String getApply()
          Returns the apply attribute that is the class that implements Composer, an instance of it or null.
 ComponentDefinition getComponentDefinition()
          Returns the component definition, or null if it is PageDefinition.
 Composer getComposer(Page page)
          Returns the composer for this info, or null if not available.
protected  EvaluatorRef getEvaluatorRef()
          Returns the evaluator reference (never null).
 ForEach getForEach(Page page, Component comp)
          Returns the forEach object if the forEach attribute is defined (or setForEach(java.lang.String, java.lang.String, java.lang.String) is called).
 java.lang.String getForward()
          Returns the forward condition that controls how to forward an event, that is received by the component created by this info, to another component.
 java.lang.String getFulfill()
          Returns the fulfill condition that controls when to create the child components, or null if the child components are created at the time when the page is loaded.
 java.lang.String getImplementationClass()
          Returns the class name (String) that implements the component.
 LanguageDefinition getLanguageDefinition()
          Returns the language definition that getComponentDefinition() belongs to, or null if the component definition is temporary.
 PageDefinition getPageDefinition()
          Returns the page definition, or null if not available.
 NodeInfo getParent()
          Returns the parent, or null if no parent.
 java.util.List getProperties()
          Returns a readonly list of properties (Property) (never null).
 java.lang.String getTag()
          Returns the tag name, or null if no tag name.
 java.lang.String getTextAs()
          Returns the property name to which the text enclosed within the element (associated with this component definition) is assigned to.
 boolean isEffective(Component comp)
          Used to evaluate whether it is effective.
 boolean isEffective(Page page)
          Used to evaluate whether it is effective.
 Component newInstance(Page page)
          Creates an component based on this info (never null).
 void readExternal(java.io.ObjectInput in)
          Don't override this method.
 java.lang.Class resolveImplementationClass(Page page)
          Resolves and returns the class for the component represented by this info (never null).
 void setApply(java.lang.String apply)
          Sets the apply attribute that is used to initialize the component.
 void setCondition(ConditionImpl cond)
          Sets the effectiveness condition.
 void setForEach(java.lang.String expr, java.lang.String begin, java.lang.String end)
          Sets the forEach attribute, which is usually an expression.
 void setForward(java.lang.String forward)
          Sets the forward condition that controls when to forward an event receiving by this component to another component.
 void setFulfill(java.lang.String fulfill)
          Sets the fulfill condition that controls when to create the child components.
 void setImplementationClass(java.lang.String clsnm)
          Sets the class name to implements the component.
 void setParent(NodeInfo parent)
          Sets the parent.
 java.lang.String toString()
           
 boolean withForEach()
          Returns whether the forEach condition is defined.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class org.zkoss.zk.ui.metainfo.NodeInfo
appendChild, appendChild, appendChild, appendChild, getChildren, removeChild, removeChild, removeChild, removeChild
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ComponentInfo

public ComponentInfo(NodeInfo parent,
                     ComponentDefinition compdef,
                     java.lang.String tag)
Constructs the information about how to create component.

Parameters:
parent - the parent; never null.
compdef - the component definition; never null
tag - the tag name; Note: if component implements DynamicTag, this argument must be specified. If DynamicTag is not implemented, this argument must be null.

ComponentInfo

public ComponentInfo(NodeInfo parent,
                     ComponentDefinition compdef)
Constructs the info about how to create a component that is not a dynamic tag.

Parameters:
parent - the parent; never null.

ComponentInfo

public ComponentInfo()
This constructor is used only for Externalizable. Don't call it, otherwise.

Since:
3.0.0
Method Detail

getLanguageDefinition

public LanguageDefinition getLanguageDefinition()
Returns the language definition that getComponentDefinition() belongs to, or null if the component definition is temporary.


getComponentDefinition

public ComponentDefinition getComponentDefinition()
Returns the component definition, or null if it is PageDefinition.


getTag

public java.lang.String getTag()
Returns the tag name, or null if no tag name.

Since:
3.0.0

setParent

public void setParent(NodeInfo parent)
Sets the parent.


getTextAs

public java.lang.String getTextAs()
Returns the property name to which the text enclosed within the element (associated with this component definition) is assigned to.

Default: null (means to create a Label component as the child)

Since:
3.0.0
See Also:
ComponentDefinition.getTextAs()

getFulfill

public java.lang.String getFulfill()
Returns the fulfill condition that controls when to create the child components, or null if the child components are created at the time when the page is loaded.

Default: null.

If not null, the child components specified in NodeInfo.getChildren() are created, when the event sepcified in the fulfill condition is received at the first time.

It is the value specified in the fulfill attribute.

Since:
2.4.0

setFulfill

public void setFulfill(java.lang.String fulfill)
Sets the fulfill condition that controls when to create the child components.

If not null, the child components specified in NodeInfo.getChildren() are created, when the event sepcified in the fulfill condition is received at the first time.

Parameters:
fulfill - the fulfill condition. There are several forms: "eventName", "targetId.evetName", "id1/id2.evetName", and "${elExpr}.eventName"
Since:
2.4.0

getComposer

public Composer getComposer(Page page)
Returns the composer for this info, or null if not available. It evaluates the value returned by getApply().

Since:
3.0.0
See Also:
getApply()

getApply

public java.lang.String getApply()
Returns the apply attribute that is the class that implements Composer, an instance of it or null.

Since:
3.0.0
See Also:
getComposer(org.zkoss.zk.ui.Page)

setApply

public void setApply(java.lang.String apply)
Sets the apply attribute that is used to initialize the component.

Parameters:
apply - the attribute which must be the class that implements Composer, an instance of it, or null. El expressions are allowed, but self means the page (after all, the component is not created yet).
Since:
3.0.0

getForward

public java.lang.String getForward()
Returns the forward condition that controls how to forward an event, that is received by the component created by this info, to another component.

Default: null.

If not null, when the component created by this info receives the event specified in the forward condition, it will forward it to the target component, which is also specified in the forward condition.

Since:
3.0.0
See Also:
setForward(java.lang.String)

setForward

public void setForward(java.lang.String forward)
Sets the forward condition that controls when to forward an event receiving by this component to another component.

The basic format:
onEvent1=id1/id2.onEvent2

It means when onEvent1 is received, onEvent2 will be posted to the component with the specified path (id1/id2).

If onEvent1 is omitted, it is assumed to be onClick (and the equal sign need not to be specified. If the path is omitted, it is assumed to be the space owner Component.getSpaceOwner().

For example, "onOK" means "onClick=onOK".

You can specify several forward conditions by separating them with comma as follows:

onChanging=onChanging,onChange=onUpdate,onOK

Parameters:
forward - the forward condition. There are several forms: "onEvent1", "target.onEvent1" and "onEvent1(target.onEvent2)", where target could be "id", "id1/id2" or "${elExpr}". The EL expression must return either a path or a reference to a component.
Since:
3.0.0

getProperties

public java.util.List getProperties()
Returns a readonly list of properties (Property) (never null).

Since:
2.4.0

addProperty

public void addProperty(java.lang.String name,
                        java.lang.String value,
                        ConditionImpl cond)
Adds a property initializer. It will initialize a component when created with this info.

Parameters:
name - the member name. The component must have a valid setter for it.
value - the value. It might contain expressions (${}).

addEventHandler

public void addEventHandler(java.lang.String name,
                            ZScript zscript,
                            ConditionImpl cond)
Adds an event handler.

Parameters:
name - the event name.
zscript - the script.

setCondition

public void setCondition(ConditionImpl cond)
Sets the effectiveness condition.


getForEach

public ForEach getForEach(Page page,
                          Component comp)
Returns the forEach object if the forEach attribute is defined (or setForEach(java.lang.String, java.lang.String, java.lang.String) is called).

If comp is not null, both pagedef and page are ignored. If comp is null, page must be specified.

Parameters:
page - the page. It is used only if comp is null.
comp - the component.
Returns:
the forEach object to iterate this info multiple times, or null if this info shall be interpreted only once.

setForEach

public void setForEach(java.lang.String expr,
                       java.lang.String begin,
                       java.lang.String end)
Sets the forEach attribute, which is usually an expression.

Parameters:
expr - the expression to return a collection of objects, or null/empty to denote no iteration.

withForEach

public boolean withForEach()
Returns whether the forEach condition is defined.

Since:
3.0.0

getImplementationClass

public java.lang.String getImplementationClass()
Returns the class name (String) that implements the component.


setImplementationClass

public void setImplementationClass(java.lang.String clsnm)
Sets the class name to implements the component.


newInstance

public Component newInstance(Page page)
Creates an component based on this info (never null).

Like ComponentDefinition.newInstance(org.zkoss.zk.ui.Page, java.lang.String), this method doesn't invoke applyProperties(org.zkoss.zk.ui.Component). It is caller's job to invoke them if necessary. Since the value of properties might depend on the component tree, it is better to assign the component with a proper parent before calling applyProperties(org.zkoss.zk.ui.Component).


resolveImplementationClass

public java.lang.Class resolveImplementationClass(Page page)
                                           throws java.lang.ClassNotFoundException
Resolves and returns the class for the component represented by this info (never null).

Unlike getImplementationClass(), this method will resolve a class name (String) to a class (Class), if necessary.

Parameters:
page - the page to check whether the class is defined in its interpreters. Ignored if null. This method will search the class loader of the current thread. If not found, it will search the interpreters of the specifed page (Page.getLoadedInterpreters()). Note: this method won't attach the component to the specified page.
Throws:
java.lang.ClassNotFoundException - if the class not found
Since:
3.0.0

getAnnotationMap

public AnnotationMap getAnnotationMap()
Returns the annotation map defined in this info, or null if no annotation is ever defined.


applyProperties

public void applyProperties(Component comp)
Applies the event handlers, annotations, properties and custom attributes to the specified component.

It also invokes ComponentDefinition.applyProperties(org.zkoss.zk.ui.Component).

Since:
3.0.0

evalProperties

public java.util.Map evalProperties(java.util.Map propmap,
                                    Page owner,
                                    Component parent,
                                    boolean defIncluded)
Evaluates and retrieves properties to the specified map from ComponentDefinition (and ComponentInfo).

Parameters:
propmap - the map to store the retrieved properties (String name, Object value). If null, a HashMap instance is created.
owner - the owner page; used if parent is null
parent - the parent component (may be null)
defIncluded - whether to call ComponentDefinition.evalProperties(java.util.Map, org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Component).

addAnnotation

public void addAnnotation(java.lang.String annotName,
                          java.util.Map annotAttrs)
Associates an annotation to this component info.

Parameters:
annotName - the annotation name (never null, nor empty).
annotAttrs - a map of attributes, or null if no attribute at all. The attribute must be in a pair of strings (String name, String value).

addAnnotation

public void addAnnotation(java.lang.String propName,
                          java.lang.String annotName,
                          java.util.Map annotAttrs)
Adds an annotation to the specified proeprty of this component info.

Parameters:
propName - the property name (never nul, nor empty).
annotName - the annotation name (never null, nor empty).
annotAttrs - a map of attributes, or null if no attribute at all. The attribute must be in a pair of strings (String name, String value).

isEffective

public boolean isEffective(Component comp)
Description copied from interface: Condition
Used to evaluate whether it is effective.

Specified by:
isEffective in interface Condition
Parameters:
comp - used as the self variable. Ignored if null.

isEffective

public boolean isEffective(Page page)
Description copied from interface: Condition
Used to evaluate whether it is effective.

Specified by:
isEffective in interface Condition
Parameters:
page - used as the self variable. Ignored if null.

getPageDefinition

public PageDefinition getPageDefinition()
Description copied from class: NodeInfo
Returns the page definition, or null if not available.

Specified by:
getPageDefinition in class NodeInfo

getParent

public NodeInfo getParent()
Description copied from class: NodeInfo
Returns the parent, or null if no parent.

Specified by:
getParent in class NodeInfo

getEvaluatorRef

protected EvaluatorRef getEvaluatorRef()
Description copied from class: NodeInfo
Returns the evaluator reference (never null).

This method is used only for implementation only.

Specified by:
getEvaluatorRef in class NodeInfo

clone

public java.lang.Object clone()
Clones this info. After cloned, getParent() is null.

Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

writeExternal

public final void writeExternal(java.io.ObjectOutput out)
                         throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public final void readExternal(java.io.ObjectInput in)
                        throws java.io.IOException,
                               java.lang.ClassNotFoundException
Don't override this method. Rather, override readMembers(java.io.ObjectInput).

Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException
Since:
3.0.0


Copyright © 2005-2007 Potix Corporation. All Rights Reserved.