Class AnnotationHelper
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an annotation definition.voidaddByCompoundValue(String cval, org.zkoss.util.resource.Location loc) Adds annotation by specifying the content in the compound format.voidapplyAnnotations(Component comp, String propName, boolean clear) Applies the annotations defined in this helper to the specified component.voidapplyAnnotations(AnnotationMap annots, String propName, boolean clear) Applies the annotations defined in this helper to the specified annotation map.voidapplyAnnotations(ComponentInfo compInfo, String propName, boolean clear) Applies the annotations defined in this helper to the specified instance definition.voidapplyAnnotations(ShadowInfo compInfo, String propName, boolean clear) Applies the annotations defined in this helper to the specified instance definition.booleanclear()Clears the annotations defined in this helper.static booleanisAnnotation(String val) Test if the given value is an annotation.static String[]parseAttributeValue(String val, org.zkoss.util.resource.Location loc) Parses the attribute value.voidsetIgnoreAnnotNamespace(boolean ignoreAnnotNamespace) Sets whether to ignore annotation namespace.booleanWhether to ignore annotation namespace.
-
Constructor Details
-
AnnotationHelper
public AnnotationHelper()
-
-
Method Details
-
isAnnotation
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(String annotName, Map<String, String[]> annotAttrs, org.zkoss.util.resource.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
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
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:
NullPointerException- if val is null.- Since:
- 6.0.0
-
applyAnnotations
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:
-
applyAnnotations
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:
-
applyAnnotations
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:
-
applyAnnotations
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
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
-