org.javalid.core
Class AnnotationValueResolver

java.lang.Object
  extended by org.javalid.core.AnnotationValueResolver

public class AnnotationValueResolver
extends java.lang.Object

This is a special class for resolving annotation values, it is not used directly by the framework (currently). But is here specially for you, the user to make yours life easier.

You can use this class to retrieve values from annotations that ship with this framework, but you can add your own custom annotations as well if needed. An example if you have a business object e.g. Person where you have an attribute firstName and annotated it with the annotation 'MaxLength', with this class you can - on runtime - retrieve the value from within your (JSF) page. Any page that supports ordinary expression resolving. In our example in your page you would do something like: #{myAnnotationResolverName.value['Person,MaxLength:value,m:firstName']}
Person is the alias for your Person class (which you can add to this class), MaxLength:value is the alias for the annotation you wish to read followed by the property to retrieve from the annotation, m:firstName means that a method must be read (the m), with property firstName. Thus summarized: the resolver must find the MaxLength annotation on the method getFirstName() on the Person class and from that annotation retrieve value().

The formal syntax to use as key is (comma separates parts): AliasObjectToCheck,AnnotationAlias:method,c|(m:method)

This class should be instantiated, by doing so the default annotations of the framework are registered (e.g. ValidateDefinition,JvGroup,NotNull etc). Each one of them is aliased as follows (alias / annotation):

Class level annotations:

Method / field level annotations:

You can add custom annotations by calling: setRegisteredAnnotationsMap(Map<String,String> annotationsMap) where the key of the map is the alias, and the value is the fully qualified class name of your annotation.

To register your business objects use: setAliasesForClassMap(Map<String,String> aliasesMap) where the key of the map is the alias for your business object, and value the fully qualified class name of your business object.

If you use invalid syntax or whatever weird stuff, a JvException is raised telling you what went wrong.

Since:
1.0
Version:
1.0
Author:
M.Reuvers

Constructor Summary
AnnotationValueResolver()
           
 
Method Summary
 java.util.Map getValue()
          Use this map to retrieve an annotation value.
 boolean isCacheResults()
          Is the class allowed to cache results.
 void setAliasesForClassMap(java.util.Map<java.lang.String,java.lang.String> aliasesMap)
          Register your business objects you need access to from within your (JSF) pages.
 void setCacheResults(boolean cacheResults)
          Set to true if caching of results is allowed
 void setRegisteredAnnotationsMap(java.util.Map<java.lang.String,java.lang.String> annotationsMap)
          Register custom annotations here, they are added if found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationValueResolver

public AnnotationValueResolver()
Method Detail

setRegisteredAnnotationsMap

public void setRegisteredAnnotationsMap(java.util.Map<java.lang.String,java.lang.String> annotationsMap)
Register custom annotations here, they are added if found.

Parameters:
annotationsMap - Map containing alias,annotationClassName entries.

setAliasesForClassMap

public void setAliasesForClassMap(java.util.Map<java.lang.String,java.lang.String> aliasesMap)
Register your business objects you need access to from within your (JSF) pages.

Parameters:
aliasesMap -

getValue

public java.util.Map getValue()
Use this map to retrieve an annotation value. As key use the syntax described (see class docs).

Returns:
Value resolved or null if not found

setCacheResults

public void setCacheResults(boolean cacheResults)
Set to true if caching of results is allowed

Parameters:
cacheResults - Set to true to allow caching of a result for a key

isCacheResults

public boolean isCacheResults()
Is the class allowed to cache results. A result is a value resolved for a certain key, and then stored in cache.

Returns:
If allowed or not