org.zkoss.zk.ui.metainfo
Interface ComponentDefinition

All Superinterfaces:
java.lang.Cloneable
All Known Implementing Classes:
ComponentDefinitionImpl

public interface ComponentDefinition
extends java.lang.Cloneable

A component definition. Like class in Java, a ComponentDefinition defines the behavior of a component.

The implementation must be thread-safe, since the caller depends on it.

Author:
tomyeh

Field Summary
static ComponentDefinition ZK
          A special definition representing the zk component.
 
Method Summary
 void addMold(java.lang.String name, java.lang.String moldURI)
          Adds a mold
 void addProperty(java.lang.String name, java.lang.String value)
          Adds a property initializer.
 void applyProperties(Component comp)
          Applies the properties and custom attributes defined in this definition to the specified component.
 java.lang.Object clone()
          Clones this component definition.
 ComponentDefinition clone(LanguageDefinition langdef, java.lang.String name)
          Clones this definition and assins with the specified language definition and name.
 java.util.Map evalProperties(java.util.Map propmap, Page owner, Component parent)
          Evaluates and retrieves properties to the specified map from ComponentDefinition (and ComponentInfo).
 AnnotationMap getAnnotationMap()
          Returns the annotation map defined in this definition, or null if no annotation is ever defined.
 java.lang.Object getImplementationClass()
          Returns the class (Class) or the class name (String) that implements the component.
 LanguageDefinition getLanguageDefinition()
          Returns the language definition, or null if it is a temporty definition belonging to a page.
 java.lang.String getMacroURI()
          Returns the macro URI, or null if not a macro.
 java.util.Collection getMoldNames()
          Returns a readonly collection of mold names supported by this definition.
 java.lang.String getMoldURI(Component comp, java.lang.String name)
          Returns the URI of the mold, or null if no such mold available.
 java.lang.String getName()
          Returns name of this component definition (never null).
 boolean hasMold(java.lang.String name)
          Returns whether the specified mold exists.
 boolean isInlineMacro()
          Returns whether this is an inline macro.
 boolean isInstance(Component comp)
          Returns whether a component belongs to this definition.
 boolean isMacro()
          Returns whether this is a macro component.
 Component newInstance(Page page, java.lang.String clsnm)
          Creates an component of this definition.
 java.lang.Class resolveImplementationClass(Page page, java.lang.String clsnm)
          Resolves and returns the class that implements the component.
 void setImplementationClass(java.lang.Class cls)
          Sets the class to implements the component.
 void setImplementationClass(java.lang.String clsnm)
          Sets the class name to implements the component.
 

Field Detail

ZK

static final ComponentDefinition ZK
A special definition representing the zk component.

Method Detail

getLanguageDefinition

LanguageDefinition getLanguageDefinition()
Returns the language definition, or null if it is a temporty definition belonging to a page.


getName

java.lang.String getName()
Returns name of this component definition (never null). It is unique in the same language, LanguageDefinition, if it belongs to a language, i.e., getLanguageDefinition() is not null.


isMacro

boolean isMacro()
Returns whether this is a macro component.

See Also:
getMacroURI()

getMacroURI

java.lang.String getMacroURI()
Returns the macro URI, or null if not a macro.


isInlineMacro

boolean isInlineMacro()
Returns whether this is an inline macro. If false, you have to examine isMacro() to see whether it is a regular macro.


getImplementationClass

java.lang.Object getImplementationClass()
Returns the class (Class) or the class name (String) that implements the component.

If a string is returned, the real class may depend on which page a component will be created to. Reason: the zscript interpreter is associated with a page and it may define classes upon evaluating a page.


setImplementationClass

void setImplementationClass(java.lang.Class cls)
Sets the class to implements the component.

Note: currently, classes specified in lang.xml or lang-addon.xml must be resolved when loading the files. However, classes specified in a page (by use of class or use attributes) might be resolved later because it might be defined by zscript.


setImplementationClass

void setImplementationClass(java.lang.String clsnm)
Sets the class name to implements the component. Unlike setImplementationClass(Class), the class won't be resolved until ComponentInfo.newInstance(org.zkoss.zk.ui.Page) or getImplementationClass() is used. In other words, the class can be provided later (thru, usually, zscript).


resolveImplementationClass

java.lang.Class resolveImplementationClass(Page page,
                                           java.lang.String clsnm)
                                           throws java.lang.ClassNotFoundException
Resolves and returns the class that implements the component.

Unlike getImplementationClass(), this method will resolve a class name (String) to a class (Class), if necessary. In addition, if the clsnm argument is specified, it is used instead of getImplementationClass(). In other words, it overrides the default class.

Parameters:
clsnm - [optional] If specified, clsnm is used instead of getImplementationClass(). In other words, it overrides the default class.
page - the page that is used to resolve the implementation class. It is used only this definition is associated with a class name by setImplementationClass(String), or clsnm is not null. Note: this method won't attach the component to the specified page. It can be null if getImplementationClass() returns a Class instance, and clsnm is null.
Throws:
java.lang.ClassNotFoundException - if the class not found

isInstance

boolean isInstance(Component comp)
Returns whether a component belongs to this definition.

If resolveImplementationClass(org.zkoss.zk.ui.Page, java.lang.String) failed to resolve, true is returned!


newInstance

Component newInstance(Page page,
                      java.lang.String clsnm)
Creates an component of this definition.

Note: this method doesn't invoke applyProperties(org.zkoss.zk.ui.Component). It is caller's job to apply these properties if necessary. Since the value of a property 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).

Similarly, this method doesn't attach the component to the specified page. Developers may or may not add it to a page or a parent.

An application developer can invoke UiFactory.newComponent(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.metainfo.ComponentInfo) instead of newInstance(org.zkoss.zk.ui.Page, java.lang.String), since a deployer might customize the way to create components by providing an implementation of UiFactory. In additions, it also invokes applyProperties(org.zkoss.zk.ui.Component) assigning page/parent.

On the other hand, this method is 'low-level'. It simply resolves the implementation class by use of resolveImplementationClass(org.zkoss.zk.ui.Page, java.lang.String), and then uses it to create an instance.

Parameters:
clsnm - [optional] If specified, clsnm is used instead of getImplementationClass(). In other words, it overrides the default class.
page - the page that is used to resolve the implementation class. It is used only this definition is associated with a class name by setImplementationClass(String), or clsnm is not null. Note: this method won't attach the component to the specified page. It can be null if getImplementationClass() returns a Class instance, and clsnm is null.
Returns:
the new component (never null)

addMold

void addMold(java.lang.String name,
             java.lang.String moldURI)
Adds a mold

Parameters:
moldURI - the URI of the mold; never null nor empty. It can be an EL expression.

getMoldURI

java.lang.String getMoldURI(Component comp,
                            java.lang.String name)
Returns the URI of the mold, or null if no such mold available. If mold contains an expression, it will be evaluated first before returning.

Parameters:
name - the mold

hasMold

boolean hasMold(java.lang.String name)
Returns whether the specified mold exists.


getMoldNames

java.util.Collection getMoldNames()
Returns a readonly collection of mold names supported by this definition.


addProperty

void addProperty(java.lang.String name,
                 java.lang.String value)
Adds a property initializer. It will initialize a component when created with is definition.

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

applyProperties

void applyProperties(Component comp)
Applies the properties and custom attributes defined in this definition to the specified component.

Note: annotations are applied to the component when a component is created. So, this method doesn't and need not to copy them.


evalProperties

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

Parameters:
propmap - the map to store the retrieved properties. If null, a HashMap instance is created.
owner - the owner page; used if parent is null
parent - the parent

getAnnotationMap

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


clone

ComponentDefinition clone(LanguageDefinition langdef,
                          java.lang.String name)
Clones this definition and assins with the specified language definition and name.


clone

java.lang.Object clone()
Clones this component definition. You rarely invoke this method directly. Rather, use clone(LanguageDefinition, String).

Note: the caller usually has to change the component name, and then assign to a language definition (LanguageDefinition) or a page definition (PageDefinition).

Returns:
the new component definition by cloning from this definition.


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