|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.javalid.core.AnnotationValueResolver
public class AnnotationValueResolver
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)
Class level is simply denoted by a c. Nothing should follow.
Method level is denoted by a m followed by semicolon and then the method (or more nested methods) to locate and
from there the annotation is taken. Note that these methods use expression syntax so getValue() you should write as value.
Example of both: Person,ValidateDefinition:primaryGroup,c / Person,MaxValue:value,m:someValue
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:
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.
| 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 |
|---|
public AnnotationValueResolver()
| Method Detail |
|---|
public void setRegisteredAnnotationsMap(java.util.Map<java.lang.String,java.lang.String> annotationsMap)
annotationsMap - Map containing alias,annotationClassName entries.public void setAliasesForClassMap(java.util.Map<java.lang.String,java.lang.String> aliasesMap)
aliasesMap - public java.util.Map getValue()
public void setCacheResults(boolean cacheResults)
cacheResults - Set to true to allow caching of a result for a keypublic boolean isCacheResults()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||