|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.zkoss.zk.ui.metainfo.impl.ComponentDefinitionImpl
public class ComponentDefinitionImpl
An implementation of ComponentDefinition.
Note: it is not thread safe. Thus, it is better to clone(org.zkoss.zk.ui.metainfo.LanguageDefinition, java.lang.String)
and then modifying the cloned instance if you want to change it
concurrently.
| Field Summary |
|---|
| Fields inherited from interface org.zkoss.zk.ui.metainfo.ComponentDefinition |
|---|
ZK |
| Constructor Summary | |
|---|---|
ComponentDefinitionImpl(LanguageDefinition langdef,
PageDefinition pgdef,
java.lang.String name,
java.lang.Class cls)
Constructs a native component, i.e., a component implemented by a Java class. |
|
| Method Summary | |
|---|---|
void |
addAnnotation(java.lang.String annotName,
java.util.Map annotAttrs)
Associates an annotation to this component definition. |
void |
addAnnotation(java.lang.String propName,
java.lang.String annotName,
java.util.Map annotAttrs)
Adds an annotation to the specified proeprty of this component definition. |
void |
addCustomAttribute(java.lang.String name,
java.lang.String value)
Adds a custom attribute. |
void |
addMold(java.lang.String name,
ComponentRenderer renderer)
Adds a mold based on ComponentRenderer. |
void |
addMold(java.lang.String name,
java.lang.String moldURI)
Adds a mold based on an URI. |
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. |
AnnotationMap |
getAnnotationMap()
Returns the annotation map defined in this definition, or null if no annotation is ever defined. |
java.lang.String |
getCurrentDirectory()
Returns the current directory which is used to convert a relative URI to absolute, or null if not available. |
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.Object |
getMoldURI(Component comp,
java.lang.String name)
Returns the URI (String) or an instance of ComponentRenderer
of the mold, or null if no such mold available. |
java.lang.String |
getName()
Returns name of this component definition (never null). |
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 |
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. |
boolean |
isNative()
Returns whether this is used for the native namespace. |
Component |
newInstance(Page page,
java.lang.String clsnm)
Creates an component of this definition. |
static ComponentDefinition |
newMacroDefinition(LanguageDefinition langdef,
PageDefinition pgdef,
java.lang.String name,
java.lang.Class cls,
java.lang.String macroURI,
boolean inline)
Constructs a macro component definition. |
static ComponentDefinition |
newNativeDefinition(LanguageDefinition langdef,
java.lang.String name,
java.lang.Class cls)
Constructs a native component definition. |
java.lang.Class |
resolveImplementationClass(Page page,
java.lang.String clsnm)
Resolves and returns the class that implements the component. |
void |
setCurrentDirectory(java.lang.String curdir)
Sets the current directory which is used to convert a relative URI to absolute. |
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. |
void |
setTextAs(java.lang.String propnm)
Sets the property name to which the text enclosed within the element (associated with this component definition) is assigned to. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ComponentDefinitionImpl(LanguageDefinition langdef,
PageDefinition pgdef,
java.lang.String name,
java.lang.Class cls)
Note; if both langdef and pgdef are null, it must be a reserved component.
langdef - the language definition. It is null if it is defined
as part of a page definitionpgdef - the page definition. It is null if it is defined
as part of a language definition.
doesn't belong to any language.cls - the implementation class.| Method Detail |
|---|
public static final ComponentDefinition newMacroDefinition(LanguageDefinition langdef,
PageDefinition pgdef,
java.lang.String name,
java.lang.Class cls,
java.lang.String macroURI,
boolean inline)
langdef - the language definition. It is null if it is defined
as part of a page definitionpgdef - the page definition. It is null if it is defined
as part of a language definition.
public static final ComponentDefinition newNativeDefinition(LanguageDefinition langdef,
java.lang.String name,
java.lang.Class cls)
langdef - the language definition. It cannot be null.
public void addCustomAttribute(java.lang.String name,
java.lang.String value)
public void addAnnotation(java.lang.String annotName,
java.util.Map annotAttrs)
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).
public void addAnnotation(java.lang.String propName,
java.lang.String annotName,
java.util.Map annotAttrs)
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).public java.lang.String getCurrentDirectory()
public void setCurrentDirectory(java.lang.String curdir)
curdir - the current directory; null to ignore.public void setTextAs(java.lang.String propnm)
Default: null (means to create a Label component)
propnm - the property name. If empty (""), null is assumed.getTextAs()public LanguageDefinition getLanguageDefinition()
ComponentDefinition
getLanguageDefinition in interface ComponentDefinitionpublic java.lang.String getName()
ComponentDefinitionLanguageDefinition,
if it belongs to a language, i.e.,
ComponentDefinition.getLanguageDefinition() is not null.
getName in interface ComponentDefinitionpublic java.lang.String getTextAs()
ComponentDefinitionDefault: null (means to create a Label component as the child)
For example, if ComponentDefinition.getTextAs() returns null, then
a Label component is created as a child of comp
with the "Hi Text" value in the following example:
<comp>
Hi Text
</comp>
In other words, it is equivalent to
<comp>
<label value="Hi Text"/>
</comp>
On the other hand, if It is also the same as
To enable it, you can declare
ComponentDefinition.getTextAs() returns a non-empty string,
say, "content", then
"Hi Text" is assigned to the content property of comp.
In other words, it is equivalent to
<comp content="Hi Text"/>
</comp><comp>
<attribute name="content"/>
Hi Text
</attribute>
</comp>text-as in
the component definition in lang.xml or lang-addon.xml:
<component>
<component-name>html</component-name>
<text-as>content</text-as>
...
getTextAs in interface ComponentDefinition
public boolean isMacro()
ComponentDefinition
isMacro in interface ComponentDefinitionComponentDefinition.getMacroURI()public java.lang.String getMacroURI()
ComponentDefinition
getMacroURI in interface ComponentDefinitionpublic boolean isInlineMacro()
ComponentDefinitionComponentDefinition.isMacro() to see whether it
is a regular macro.
isInlineMacro in interface ComponentDefinitionpublic boolean isNative()
ComponentDefinition
isNative in interface ComponentDefinitionLanguageDefinition.getNativeDefinition()public java.lang.Object getImplementationClass()
ComponentDefinitionIf 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.
getImplementationClass in interface ComponentDefinitionpublic void setImplementationClass(java.lang.Class cls)
ComponentDefinitionNote: 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 in interface ComponentDefinitionpublic void setImplementationClass(java.lang.String clsnm)
ComponentDefinitionComponentDefinition.setImplementationClass(Class), the class won't
be resolved until ComponentInfo.newInstance(org.zkoss.zk.ui.Page) or ComponentDefinition.getImplementationClass()
is used. In other words, the class can be provided later
(thru, usually, zscript).
setImplementationClass in interface ComponentDefinition
public Component newInstance(Page page,
java.lang.String clsnm)
ComponentDefinitionNote: this method doesn't invoke ComponentDefinition.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 ComponentDefinition.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 ComponentDefinition.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 ComponentDefinition.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 ComponentDefinition.resolveImplementationClass(org.zkoss.zk.ui.Page, java.lang.String),
and then uses it to create an instance.
newInstance in interface ComponentDefinitionpage - the page that is used to resolve the implementation
class. It is used only this definition is associated
with a class name by ComponentDefinition.setImplementationClass(String),
or clsnm is not null.
Note: this method won't attach the component to the specified page.
It can be null if ComponentDefinition.getImplementationClass() returns a Class
instance, and clsnm is null.clsnm - [optional] If specified, clsnm is used instead of
ComponentDefinition.getImplementationClass().
In other words, it overrides the default class.
public boolean isInstance(Component comp)
ComponentDefinitionIf ComponentDefinition.resolveImplementationClass(org.zkoss.zk.ui.Page, java.lang.String) failed to resolve,
true is returned!
isInstance in interface ComponentDefinition
public java.lang.Class resolveImplementationClass(Page page,
java.lang.String clsnm)
throws java.lang.ClassNotFoundException
ComponentDefinitionUnlike ComponentDefinition.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 ComponentDefinition.getImplementationClass().
In other words, it overrides the default class.
resolveImplementationClass in interface ComponentDefinitionpage - 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.clsnm - [optional] If specified, clsnm is used instead of
ComponentDefinition.getImplementationClass().
In other words, it overrides the default class.
java.lang.ClassNotFoundException - if the class not foundpublic AnnotationMap getAnnotationMap()
ComponentDefinition
getAnnotationMap in interface ComponentDefinition
public void addProperty(java.lang.String name,
java.lang.String value)
ComponentDefinition
addProperty in interface ComponentDefinitionname - the member name. The component must have a valid setter
for it.value - the value. It might contain expressions (${}).public void applyProperties(Component comp)
ComponentDefinitionNote: annotations are applied to the component when a component is created. So, this method doesn't and need not to copy them.
applyProperties in interface ComponentDefinition
public java.util.Map evalProperties(java.util.Map propmap,
Page owner,
Component parent)
ComponentDefinition
evalProperties in interface ComponentDefinitionpropmap - the map to store the retrieved properties.
If null, a HashMap instance is created.
(String name, Object value).owner - the owner page; used if parent is nullparent - the parent
public void addMold(java.lang.String name,
java.lang.String moldURI)
ComponentDefinition
addMold in interface ComponentDefinitionmoldURI - an URI of the mold; never null nor empty.
If it starts with "class:", the following substring is assumed to be
the class name of ComponentRenderer, and then it invokes
ComponentDefinition.addMold(String, ComponentRenderer).
If not staring with "class:", it is pure an URI, and it may
contain XEL expressions.
public void addMold(java.lang.String name,
ComponentRenderer renderer)
ComponentDefinitionComponentRenderer.
addMold in interface ComponentDefinitionrenderer - a component renderer. It is shared
by all component instances belonging to this definition.
public java.lang.Object getMoldURI(Component comp,
java.lang.String name)
ComponentDefinitionComponentRenderer
of the mold, or null if no such mold available.
In other words, if a String instance is returned, it is the URI
of the mold. If a ComponentRenderer
instance is returned, it is the object responsible to handle
the generation of the component's output.
If the mold URI contains an expression, it will be evaluated first before returning.
getMoldURI in interface ComponentDefinitionname - the mold
ComponentRenderer,
as of release 3.0.0AbstractComponent.redraw(java.io.Writer)public boolean hasMold(java.lang.String name)
ComponentDefinition
hasMold in interface ComponentDefinitionpublic java.util.Collection getMoldNames()
ComponentDefinition
getMoldNames in interface ComponentDefinition
public ComponentDefinition clone(LanguageDefinition langdef,
java.lang.String name)
ComponentDefinition
clone in interface ComponentDefinitionpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.Object clone()
ComponentDefinitionComponentDefinition.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).
clone in interface ComponentDefinitionclone in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||