Class AnnotationHelper
- java.lang.Object
-
- org.zkoss.zk.ui.metainfo.impl.AnnotationHelper
-
public class AnnotationHelper extends java.lang.Object
A helper class used to parse annotations.How to use:
- Invoke
add(java.lang.String, java.util.Map<java.lang.String, java.lang.String[]>, org.zkoss.util.resource.Location)
oraddByCompoundValue(java.lang.String, org.zkoss.util.resource.Location)
to add annotations to this helper. - After annotations are all added, invoke
applyAnnotations(org.zkoss.zk.ui.metainfo.ComponentInfo, java.lang.String, boolean)
to update the annotations to the specified component info.
- Since:
- 3.0.0
- Author:
- tomyeh
- Invoke
-
-
Constructor Summary
Constructors Constructor Description AnnotationHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.lang.String annotName, java.util.Map<java.lang.String,java.lang.String[]> annotAttrs, Location loc)
Adds an annotation definition.void
addByCompoundValue(java.lang.String cval, Location loc)
Adds annotation by specifying the content in the compound format.void
applyAnnotations(Component comp, java.lang.String propName, boolean clear)
Applies the annotations defined in this helper to the specified component.void
applyAnnotations(AnnotationMap annots, java.lang.String propName, boolean clear)
Applies the annotations defined in this helper to the specified annotation map.void
applyAnnotations(ComponentInfo compInfo, java.lang.String propName, boolean clear)
Applies the annotations defined in this helper to the specified instance definition.void
applyAnnotations(ShadowInfo compInfo, java.lang.String propName, boolean clear)
Applies the annotations defined in this helper to the specified instance definition.boolean
clear()
Clears the annotations defined in this helper.static boolean
isAnnotation(java.lang.String val)
Test if the given value is an annotation.static java.lang.String[]
parseAttributeValue(java.lang.String val, Location loc)
Parses the attribute value.void
setIgnoreAnnotNamespace(boolean ignoreAnnotNamespace)
Sets whether to ignore annotation namespace.boolean
shouldIgnoreAnnotNamespace()
Whether to ignore annotation namespace.
-
-
-
Method Detail
-
isAnnotation
public static boolean isAnnotation(java.lang.String val)
Test if the given value is an annotation. In other words, it returns true if the value matches one of two kinds of format described inaddByCompoundValue(java.lang.String, org.zkoss.util.resource.Location)
.- Parameters:
val
- the value.- Since:
- 6.0.0
-
add
public void add(java.lang.String annotName, java.util.Map<java.lang.String,java.lang.String[]> annotAttrs, Location loc)
Adds an annotation definition. The annotation's attributes must be parsed into a map (annotAttrs).- Parameters:
annotName
- the annotation name.annotAttrs
- a map of attributes of the annotation. If null, it means no attribute at all.loc
- the location information of the annotation in the document, or null if not available.- See Also:
addByCompoundValue(java.lang.String, org.zkoss.util.resource.Location)
-
addByCompoundValue
public void addByCompoundValue(java.lang.String cval, Location loc)
Adds annotation by specifying the content in the compound format.There are two formats:
Format 1 (recommended, since 6.0):
@annot-name(att1-name=att1-value, att2-name=att2-value) @annot-name() @default(annot3-attrs)
In the first format, it must be a list of annotations separated by space. And, each annotation is in the format of
@annot-name(key=value, value, key=value)
. That is, it starts with the annotation's name and a parenthesis to enclose any number of key and value pairs (key is optional). The annotation's names must be composed of letters, numbers, the underscore_
, the dash-
and the dollar sign$
. The names may only begin with a letter, the underscore or a dollar sign. In additions, all characters are preserved, including the single and double quotes.- Parameters:
cval
- the compound value to check. This method assumes that cval starts with @ and the length is larger than 2loc
- the location information of the value for displaying better error message. Ignored if null.- Since:
- 6.0.0
-
parseAttributeValue
public static java.lang.String[] parseAttributeValue(java.lang.String val, Location loc)
Parses the attribute value. If the value starts with { and ends with }, an array of String is returned. Otherwise, the value is returned directly (without any processing).- Parameters:
val
- the value. This method assumes val has been trimmed before the call.loc
- the location information of the value for displaying better error message. Ignored if null.- Throws:
java.lang.NullPointerException
- if val is null.- Since:
- 6.0.0
-
applyAnnotations
public void applyAnnotations(ComponentInfo compInfo, java.lang.String propName, boolean clear)
Applies the annotations defined in this helper to the specified instance definition.- Parameters:
compInfo
- the instance definition to updatepropName
- the property nameclear
- whether to clear all definitions before returning- Since:
- 6.0.1
- See Also:
clear()
-
applyAnnotations
public void applyAnnotations(ShadowInfo compInfo, java.lang.String propName, boolean clear)
Applies the annotations defined in this helper to the specified instance definition.- Parameters:
compInfo
- the instance definition to updatepropName
- the property nameclear
- whether to clear all definitions before returning- Since:
- 8.0.0
- See Also:
clear()
-
applyAnnotations
public void applyAnnotations(Component comp, java.lang.String propName, boolean clear)
Applies the annotations defined in this helper to the specified component.- Parameters:
comp
- the component to updatepropName
- the property nameclear
- whether to clear all definitions before returning- See Also:
clear()
-
applyAnnotations
public void applyAnnotations(AnnotationMap annots, java.lang.String propName, boolean clear)
Applies the annotations defined in this helper to the specified annotation map.- Parameters:
annots
- the annotation map where the annotations are added.propName
- the property nameclear
- whether to clear all definitions before returning- Since:
- 6.0.1
- See Also:
clear()
-
clear
public boolean clear()
Clears the annotations defined in this helper.The annotations are defined by
add(java.lang.String, java.util.Map<java.lang.String, java.lang.String[]>, org.zkoss.util.resource.Location)
oraddByCompoundValue(java.lang.String, org.zkoss.util.resource.Location)
.- Returns:
- true if one or more annotation definitions are defined
(thru
add(java.lang.String, java.util.Map<java.lang.String, java.lang.String[]>, org.zkoss.util.resource.Location)
).
-
shouldIgnoreAnnotNamespace
public boolean shouldIgnoreAnnotNamespace()
Whether to ignore annotation namespace.- Returns:
- true if should ignore annotation namespace.
- Since:
- 8.5.2
-
setIgnoreAnnotNamespace
public void setIgnoreAnnotNamespace(boolean ignoreAnnotNamespace)
Sets whether to ignore annotation namespace.- Parameters:
ignoreAnnotNamespace
- whether to ignore annotation namespace- Since:
- 8.5.2
-
-