org.zkoss.zk.ui.metainfo.impl
Class AnnotationHelper

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

public class AnnotationHelper
extends java.lang.Object

A helper class used to parse annotations.

How to use:

  1. Invoke add(java.lang.String, java.util.Map) 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, org.zkoss.util.resource.Location) to update the annotations to the specified component info.

Since:
3.0.0
Author:
tomyeh

Constructor Summary
AnnotationHelper()
           
 
Method Summary
 void add(java.lang.String annotName, java.util.Map<java.lang.String,java.lang.String[]> annotAttrs)
          Adds an annotation definition.
 void addByCompoundValue(java.lang.String cval, Location loc)
          Adds annotation by specifying the content in the compound format.
 void applyAnnotations(ComponentInfo compInfo, java.lang.String propName, boolean clear, Location loc)
          Applies the annotations defined in this helper to the specified instance definition.
 void applyAnnotations(Component comp, java.lang.String propName, boolean clear)
          Applies the annotations defined in this helper to the specified component.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationHelper

public AnnotationHelper()
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 in addByCompoundValue(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)
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.
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)

Format 2 (deprecated, 5.0 and before):
@{annot-name(att1-name=att1-value, att2-name=att2-value) annot2-name (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 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:
NullPointException - if val is null.
Since:
6.0.0

applyAnnotations

public void applyAnnotations(ComponentInfo compInfo,
                             java.lang.String propName,
                             boolean clear,
                             Location loc)
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
loc - the location information of the annotation in the document, or null if not available.
Since:
6.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 update
propName - the property name
clear - whether to clear all definitions before returning
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) or addByCompoundValue(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)).


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo