Class AnnotationHelper

java.lang.Object
org.zkoss.zk.ui.metainfo.impl.AnnotationHelper

public class AnnotationHelper extends Object
A helper class used to parse annotations.

How to use:

  1. Invoke add(java.lang.String, java.util.Map<java.lang.String, java.lang.String[]>, org.zkoss.util.resource.Location) or addByCompoundValue(java.lang.String, org.zkoss.util.resource.Location) to add annotations to this helper.
  2. 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 Details

    • AnnotationHelper

      public AnnotationHelper()
  • Method Details

    • isAnnotation

      public static boolean isAnnotation(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 in addByCompoundValue(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

      public void addByCompoundValue(String cval, org.zkoss.util.resource.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 2
      loc - the location information of the value for displaying better error message. Ignored if null.
      Since:
      6.0.0
    • parseAttributeValue

      public static String[] parseAttributeValue(String val, org.zkoss.util.resource.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:
      NullPointerException - if val is null.
      Since:
      6.0.0
    • applyAnnotations

      public void applyAnnotations(ComponentInfo compInfo, String propName, boolean clear)
      Applies the annotations defined in this helper to the specified instance definition.
      Parameters:
      compInfo - the instance definition to update
      propName - the property name
      clear - whether to clear all definitions before returning
      Since:
      6.0.1
      See Also:
    • applyAnnotations

      public void applyAnnotations(ShadowInfo compInfo, String propName, boolean clear)
      Applies the annotations defined in this helper to the specified instance definition.
      Parameters:
      compInfo - the instance definition to update
      propName - the property name
      clear - whether to clear all definitions before returning
      Since:
      8.0.0
      See Also:
    • applyAnnotations

      public void applyAnnotations(Component comp, String propName, boolean clear)
      Applies the annotations defined in this helper to the specified component.
      Parameters:
      comp - the component to update
      propName - the property name
      clear - whether to clear all definitions before returning
      See Also:
    • applyAnnotations

      public void applyAnnotations(AnnotationMap annots, 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 name
      clear - whether to clear all definitions before returning
      Since:
      6.0.1
      See Also:
    • clear

      public boolean clear()
      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