org.omnaest.utils.beans.adapter.source
Annotation Type PropertyNameTemplate


@Documented
@Retention(value=RUNTIME)
@Target(value={METHOD,TYPE})
public @interface PropertyNameTemplate

A PropertyNameTemplate allows to declare a mapping template string which is normally used to map methods of interfaces to properties of an underlying structure.

The annotation can be put to Class types as well as to properties and to Methods. If the Annotation is present at all locations the same time, the Annotation on the Method is preferred on the Annotation of the property and that is preferred to the Class Annotation.

The template syntax offers to ways of dynamic behavior:

Be aware, that the index counting of the {0} replacer starts at 0 and maps to the first additional parameter. This means that a regular parameter e.g. for a setter method is not captured by this and the counting will start with the second parameter of a setter method.This ensures, that getters and setter can share one PropertyNameTemplate. Furthermore ensure that all additional parameters are compatible to String.valueOf(Object).

Example:
 @PropertyNameTemplate("{propertyname}_class")
 public interface ExampleInterface
 {
   
   //This will map to "field_class" because of the class type annotation
   public void setField( String value );
   
   //This will map to "field_class" because of the class type annotation
   public String getField();
   
   //This will map to "fieldWithTemplateAndMore" because of the property annotation
   @PropertyNameTemplate("{propertyname}AndMore")
   public void setFieldWithTemplate( String value );
   
   //This will map to "fieldWithTemplateAndMore" because of the property annotation of the corresponding setter
   public String getFieldWithTemplate();
   
   //This will map to "fieldWithTemplateAndAdditionalArgumentsAndMore_abc_" for the given tagValue "abc". 
   //The name template of the corresponding getter is ignored. The "{0}" token is replaced by the given tag value.
   //Notice that the index position 0 maps to the second argument here, since this is a setter and the first parameter is the value to set.
   @PropertyNameTemplate("{propertyname}AndMore_{0}_")
   public void setFieldWithTemplateAndAdditionalArguments( String value, String tagValue );
   
   //This will map to "fieldWithTemplateAndAdditionalArgumentsAndMore(abc)" for the given tagValue "abc". 
   //The name template of the corresponding setter is ignored. The "{0}" token is replaced by the given tag value.
   @PropertyNameTemplate("{propertyname}AndMore({0})")
   public String getFieldWithTemplateAndAdditionalArguments( String tagValue );
 }
 

Author:
Omnaest
See Also:
additionalArgumentConverterTypes()

Required Element Summary
 String value
           
 
Optional Element Summary
 Class<? extends ElementConverter<?,String>>[] additionalArgumentConverterTypes
          This declares ElementConverters which will be used to convert any additionally given template parameter into a String.
 

Element Detail

value

public abstract String value

additionalArgumentConverterTypes

public abstract Class<? extends ElementConverter<?,String>>[] additionalArgumentConverterTypes
This declares ElementConverters which will be used to convert any additionally given template parameter into a String. The array index of the ElementConverter types will correspond to the {0},{1},... placeholder definitions.

Returns:
Default:
{}


Copyright © 2013. All Rights Reserved.