public class ComponentDefinitionImpl extends java.lang.Object implements ComponentDefinition, java.io.Serializable
ComponentDefinition
.
Note: it is not thread safe. Thus, it is better to clone()
and then modifying the cloned instance if you want to change it
concurrently.
Constructor and Description |
---|
ComponentDefinitionImpl(LanguageDefinition langdef,
PageDefinition pgdef,
java.lang.String name,
java.lang.Class<? extends Component> cls)
Constructs a native component, i.e., a component implemented by
a Java class.
|
ComponentDefinitionImpl(LanguageDefinition langdef,
PageDefinition pgdef,
java.lang.String name,
java.lang.String clsnm)
Constructs a native component, i.e., a component implemented by
a Java class.
|
Modifier and Type | Method and Description |
---|---|
void |
addAnnotation(java.lang.String propName,
java.lang.String annotName,
java.util.Map<java.lang.String,java.lang.String[]> annotAttrs,
Location loc)
Adds an annotation to the specified property of this component
definition.
|
void |
addCustomAttribute(java.lang.String name,
java.lang.String value)
Adds a custom attribute.
|
void |
addMold(java.lang.String name,
java.lang.String widgetClass)
Adds a mold.
|
void |
addProperty(java.lang.String name,
java.lang.String value)
Adds a property initializer.
|
void |
applyAttributes(Component comp)
Applies the custom attributes defined in this definition
to the specified component.
|
void |
applyProperties(Component comp)
Applies the properties 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 assigns with the specified language
definition and name.
|
java.util.Map<java.lang.String,java.lang.Object> |
evalProperties(java.util.Map<java.lang.String,java.lang.Object> 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 |
getApply()
Returns the apply attribute that is a list of
Composer class
names or EL expressions returning classes, class names or composer
instances, or null if no apply attribute. |
java.lang.String |
getCurrentDirectory()
Returns the current directory which is used to convert
a relative URI to absolute, or null if not available.
|
java.net.URL |
getDeclarationURL()
Returns the URL where this component definition is declared, or
null if not available.
|
java.lang.String |
getDefaultWidgetClass(Component comp)
Returns the default widget class, 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 temporary definition
belonging to a page.
|
java.lang.String |
getMacroURI()
Returns the macro URI, or null if not a macro.
|
java.util.Collection<java.lang.String> |
getMoldNames()
Returns a readonly collection of the names of the mold.
|
java.lang.String |
getName()
Returns name of this component definition (never null).
|
ExValue[] |
getParsedApply()
Return the parsed expressions of the apply attribute.
|
java.lang.String |
getTextAs()
Returns the property name to which the text enclosed within
the element (associated with this component definition) is assigned to.
|
java.lang.String |
getWidgetClass(Component comp,
java.lang.String moldName)
Returns the widget class associated with specified mold,
or the default widget class (
ComponentDefinition.getWidgetClass(org.zkoss.zk.ui.Component, java.lang.String) ) if not available. |
boolean |
hasMold(java.lang.String name)
Returns whether the specified mold exists.
|
boolean |
isBlankPreserved()
Returns whether to preserve the blank text.
|
boolean |
isChildAllowedInTextAs()
Returns if a child is allowed in the text-as area.
|
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.
|
boolean |
isShadowElement()
Returns whether this is a shadow element.
|
Component |
newInstance(java.lang.Class<? extends Component> cls)
Creates an component of this definition.
|
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<? extends Component> cls,
java.lang.String macroURI,
boolean inline)
Constructs a macro component definition.
|
static ComponentDefinition |
newNativeDefinition(LanguageDefinition langdef,
java.lang.String name,
java.lang.Class<? extends Component> cls)
Constructs a native component definition.
|
static ComponentDefinition |
newShadowDefinition(LanguageDefinition langdef,
PageDefinition pgdef,
java.lang.String name,
java.lang.Class<? extends Component> cls,
java.lang.String templateURI)
Constructs a shadow component definition.
|
java.lang.Class<?> |
resolveImplementationClass(Page page,
java.lang.String clsnm)
Resolves and returns the class that implements the component.
|
void |
setApply(java.lang.String apply)
Sets the apply attribute that is is a list of
Composer class
or EL expressions returning classes, class names or composer instances. |
void |
setBlankPreserved(boolean preserve)
Sets whether to preserve the blank text.
|
void |
setChildAllowedInTextAs(boolean allowed)
Sets whether the child component is allowed within the element.
|
void |
setCurrentDirectory(java.lang.String curdir)
Sets the current directory which is used to convert
a relative URI to absolute.
|
void |
setDeclarationURL(java.net.URL url)
Sets the URI where this definition is declared.
|
void |
setDefaultWidgetClass(java.lang.String widgetClass)
Sets the default widget class.
|
void |
setImplementationClass(java.lang.Class<? extends Component> 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() |
public ComponentDefinitionImpl(LanguageDefinition langdef, PageDefinition pgdef, java.lang.String name, java.lang.Class<? extends Component> 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.public ComponentDefinitionImpl(LanguageDefinition langdef, PageDefinition pgdef, java.lang.String name, java.lang.String clsnm)
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.clsnm
- the implementation class.public static final ComponentDefinition newShadowDefinition(LanguageDefinition langdef, PageDefinition pgdef, java.lang.String name, java.lang.Class<? extends Component> cls, java.lang.String templateURI)
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.templateURI
- the URI of the ZUML page to representing this shadow, like macroURI.public static final ComponentDefinition newMacroDefinition(LanguageDefinition langdef, PageDefinition pgdef, java.lang.String name, java.lang.Class<? extends Component> 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.macroURI
- the URI of the ZUML page to representing this macro.public static final ComponentDefinition newNativeDefinition(LanguageDefinition langdef, java.lang.String name, java.lang.Class<? extends Component> 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 propName, java.lang.String annotName, java.util.Map<java.lang.String,java.lang.String[]> annotAttrs, Location loc)
propName
- the property name.
If null, the annotation is associated with the whole component rather than
a particular property.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).loc
- the location information of the annotation in
the document, or null if not available.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 void setBlankPreserved(boolean preserve)
Default: false.
isBlankPreserved()
public void setChildAllowedInTextAs(boolean allowed)
ComponentDefinition.getTextAs()
.public void setDeclarationURL(java.net.URL url)
url
- the URL. If null, it means not available.public LanguageDefinition getLanguageDefinition()
ComponentDefinition
getLanguageDefinition
in interface ComponentDefinition
public java.lang.String getName()
ComponentDefinition
LanguageDefinition
,
if it belongs to a language, i.e.,
ComponentDefinition.getLanguageDefinition()
is not null.getName
in interface ComponentDefinition
public java.lang.String getTextAs()
ComponentDefinition
Default: 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 Notice that it is valid to have XML fragment, including XML elements,
within the element. For example,
If the component allows child components, it is better not to try
XML fragment as the plain text. And then, it shall return true
in 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>
...
<html>
<ul>
<li forEach="apple, orange">${each}</li>
</ul>
</html>
ComponentDefinition.isChildAllowedInTextAs()
. Example, A
.
getTextAs
in interface ComponentDefinition
ComponentDefinition.isChildAllowedInTextAs()
public boolean isChildAllowedInTextAs()
ComponentDefinition
ComponentDefinition.getTextAs()
is not null.
If true, the text enclosed within the element is considered as
text only if there is no other XML element.
For example, <div> in the following example won't be considered as text. Rather, a div component will be created.
<a>
<div>...</div>
</a>
Default: false.
isChildAllowedInTextAs
in interface ComponentDefinition
ComponentDefinition.getTextAs()
public boolean isBlankPreserved()
ComponentDefinition
Default: false.
isBlankPreserved
in interface ComponentDefinition
public boolean isMacro()
ComponentDefinition
isMacro
in interface ComponentDefinition
ComponentDefinition.getMacroURI()
public java.lang.String getMacroURI()
ComponentDefinition
getMacroURI
in interface ComponentDefinition
public boolean isInlineMacro()
ComponentDefinition
ComponentDefinition.isMacro()
to see whether it
is a regular macro.isInlineMacro
in interface ComponentDefinition
public boolean isNative()
ComponentDefinition
isNative
in interface ComponentDefinition
LanguageDefinition.getNativeDefinition()
public java.lang.Object getImplementationClass()
ComponentDefinition
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.
getImplementationClass
in interface ComponentDefinition
public void setImplementationClass(java.lang.Class<? extends Component> cls)
ComponentDefinition
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
in interface ComponentDefinition
public void setImplementationClass(java.lang.String clsnm)
ComponentDefinition
ComponentDefinition.setImplementationClass(Class)
, the class won't
be resolved until ComponentInfo.newInstance(org.zkoss.zk.ui.Page, org.zkoss.zk.ui.Component)
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)
ComponentDefinition
Note: 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, org.zkoss.zk.ui.Component)
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 ComponentDefinition
page
- 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 Component newInstance(java.lang.Class<? extends Component> cls)
ComponentDefinition
ComponentDefinition.newInstance(Page, String)
. They are the same
except this method accepts the class directly,
while ComponentDefinition.newInstance(Page, String)
invokes
ComponentDefinition.resolveImplementationClass(org.zkoss.zk.ui.Page, java.lang.String)
to resolve the class first.newInstance
in interface ComponentDefinition
public boolean isInstance(Component comp)
ComponentDefinition
If 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
ComponentDefinition
Unlike 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 ComponentDefinition
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 specified
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 java.lang.String getApply()
ComponentDefinition
Composer
class
names or EL expressions returning classes, class names or composer
instances, or null if no apply attribute.getApply
in interface ComponentDefinition
ComponentDefinition.getParsedApply()
public void setApply(java.lang.String apply)
ComponentDefinition
Composer
class
or EL expressions returning classes, class names or composer instances.setApply
in interface ComponentDefinition
apply
- the attribute this is a list of Composer
class
or EL expressions
El expressions are allowed, but self means the parent, if available;
or page, if no parent at all. (Note: the component is not created yet
when the apply attribute is evaluated).public ExValue[] getParsedApply()
ComponentDefinition
getParsedApply
in interface ComponentDefinition
ComponentDefinition.getApply()
public java.net.URL getDeclarationURL()
ComponentDefinition
getDeclarationURL
in interface ComponentDefinition
public void addProperty(java.lang.String name, java.lang.String value)
ComponentDefinition
addProperty
in interface ComponentDefinition
name
- the member name. The component must have a valid setter
for it.value
- the value. It might contain expressions (${}).public void applyProperties(Component comp)
ComponentDefinition
Note: annotations are applied to the component when a component is created. So, this method doesn't and need not to copy them.
Also notice that, since 5.0.7, custom-attributes are applied automatically
in the constructor of AbstractComponent(boolean)
(by invoking ComponentDefinition.applyAttributes(org.zkoss.zk.ui.Component)
,
so they are always available no matter this method is called or not.
applyProperties
in interface ComponentDefinition
public void applyAttributes(Component comp)
ComponentDefinition
It is called automatically in
AbstractComponent(boolean)
, so
you rarely need to invoke this method.
applyAttributes
in interface ComponentDefinition
public java.util.Map<java.lang.String,java.lang.Object> evalProperties(java.util.Map<java.lang.String,java.lang.Object> propmap, Page owner, Component parent)
ComponentDefinition
evalProperties
in interface ComponentDefinition
propmap
- 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 parentpublic void addMold(java.lang.String name, java.lang.String widgetClass)
ComponentDefinition
addMold
in interface ComponentDefinition
name
- the mold name.widgetClass
- the widget class (a.k.a., name).
Ignored if null.public boolean hasMold(java.lang.String name)
ComponentDefinition
hasMold
in interface ComponentDefinition
public java.util.Collection<java.lang.String> getMoldNames()
ComponentDefinition
getMoldNames
in interface ComponentDefinition
public java.lang.String getWidgetClass(Component comp, java.lang.String moldName)
ComponentDefinition
ComponentDefinition.getWidgetClass(org.zkoss.zk.ui.Component, java.lang.String)
) if not available.
The returned widget class includes the package name (JavaScript class).getWidgetClass
in interface ComponentDefinition
comp
- the component used to evaluate EL expression, if any,
when retrieving the widget class. Ignored if null.moldName
- the mold namepublic java.lang.String getDefaultWidgetClass(Component comp)
ComponentDefinition
getDefaultWidgetClass
in interface ComponentDefinition
comp
- the component used to evaluate EL expression, if any,
when retrieving the widget class. Ignored if null.public void setDefaultWidgetClass(java.lang.String widgetClass)
ComponentDefinition
setDefaultWidgetClass
in interface ComponentDefinition
widgetClass
- the name of the widget class (JavaScript class),
including the package name.public boolean isShadowElement()
ComponentDefinition
isShadowElement
in interface ComponentDefinition
LanguageDefinition.getShadowDefinition(java.lang.String)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object clone()
ComponentDefinition
ComponentDefinition.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 ComponentDefinition
clone
in class java.lang.Object
public ComponentDefinition clone(LanguageDefinition langdef, java.lang.String name)
ComponentDefinition
clone
in interface ComponentDefinition
Copyright © 2005-2021 Potix Corporation. All Rights Reserved.