com.github.jknack.handlebars.context
Class MemberValueResolver<M extends Member>

java.lang.Object
  extended by com.github.jknack.handlebars.context.MemberValueResolver<M>
Type Parameters:
M - The member type.
All Implemented Interfaces:
ValueResolver
Direct Known Subclasses:
FieldValueResolver, MethodValueResolver

public abstract class MemberValueResolver<M extends Member>
extends Object
implements ValueResolver

A specialization of ValueResolver that is built on top of reflections API. It use an internal cache for saving members.

Since:
0.1.1
Author:
edgar.espina

Field Summary
 
Fields inherited from interface com.github.jknack.handlebars.ValueResolver
UNRESOLVED, VALUE_RESOLVERS
 
Constructor Summary
MemberValueResolver()
           
 
Method Summary
protected  M find(Class<?> clazz, String name)
          Find a Member in the given class.
protected abstract  Object invokeMember(M member, Object context)
          Invoke the member in the given context.
protected  boolean isPrivate(M member)
          True if the member is private.
protected  boolean isProtected(M member)
          True if the member is protected.
protected  boolean isPublic(M member)
          True if the member is public.
protected  boolean isStatic(M member)
          True if the member is static.
abstract  boolean matches(M member, String name)
          True, if the member matches the one we look for.
protected abstract  String memberName(M member)
          Get the name for the given member.
protected abstract  Set<M> members(Class<?> clazz)
          List all the possible members for the given class.
protected  Set<M> membersFromCache(Class<?> clazz)
          List all the possible members for the given class.
 Set<Map.Entry<String,Object>> propertySet(Object context)
          List all the properties and their values for the given object.
 Object resolve(Object context, String name)
          Resolve the attribute's name in the context object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemberValueResolver

public MemberValueResolver()
Method Detail

resolve

public final Object resolve(Object context,
                            String name)
Description copied from interface: ValueResolver
Resolve the attribute's name in the context object. If a ValueResolver.UNRESOLVED is returned, the context stack will continue with the next value resolver in the chain.

Specified by:
resolve in interface ValueResolver
Parameters:
context - The context object. Not null.
name - The attribute's name. Not null.
Returns:
A ValueResolver.UNRESOLVED is returned, the context stack will continue with the next value resolver in the chain. Otherwise, it returns the associated value.

find

protected final M find(Class<?> clazz,
                       String name)
Find a Member in the given class.

Parameters:
clazz - The context's class.
name - The attribute's name.
Returns:
A Member or null.

invokeMember

protected abstract Object invokeMember(M member,
                                       Object context)
Invoke the member in the given context.

Parameters:
member - The class member.
context - The context object.
Returns:
The resulting value.

matches

public abstract boolean matches(M member,
                                String name)
True, if the member matches the one we look for.

Parameters:
member - The class Member.
name - The attribute's name.
Returns:
True, if the member matches the one we look for.

isPublic

protected boolean isPublic(M member)
True if the member is public.

Parameters:
member - The member object.
Returns:
True if the member is public.

isPrivate

protected boolean isPrivate(M member)
True if the member is private.

Parameters:
member - The member object.
Returns:
True if the member is private.

isProtected

protected boolean isProtected(M member)
True if the member is protected.

Parameters:
member - The member object.
Returns:
True if the member is protected.

isStatic

protected boolean isStatic(M member)
True if the member is static.

Parameters:
member - The member object.
Returns:
True if the member is statuc.

members

protected abstract Set<M> members(Class<?> clazz)
List all the possible members for the given class.

Parameters:
clazz - The base class.
Returns:
All the possible members for the given class.

membersFromCache

protected Set<M> membersFromCache(Class<?> clazz)
List all the possible members for the given class.

Parameters:
clazz - The base class.
Returns:
All the possible members for the given class.

propertySet

public Set<Map.Entry<String,Object>> propertySet(Object context)
Description copied from interface: ValueResolver
List all the properties and their values for the given object.

Specified by:
propertySet in interface ValueResolver
Parameters:
context - The context object. Not null.
Returns:
All the properties and their values for the given object.

memberName

protected abstract String memberName(M member)
Get the name for the given member.

Parameters:
member - A class member.
Returns:
The member's name.


Copyright © 2012. All Rights Reserved.