org.szegedi.expose.model
Class ReflectionUtilities

java.lang.Object
  |
  +--org.szegedi.expose.model.ReflectionUtilities

public final class ReflectionUtilities
extends java.lang.Object

Utility class that provides generic services to reflection classes. It handles all polymorphism issues in the wrap(Object) and unwrap(Object) methods.

Version:
1.0
Author:
Attila Szegedi, attila@szegedi.org

Field Summary
static boolean WRAP_AS_OBJECT
          Use in the wrap() method to override logic for determining whether the parameter should be wrapped as a TemplateScalarModel or as a TemplateHashModel, and force wrapping into hash model.
static boolean WRAP_AS_SCALAR
          Use in the wrap() method to override logic for determining whether the parameter should be wrapped as a TemplateScalarModel or as a TemplateHashModel, and force wrapping into scalar.
 
Method Summary
static boolean isScalar(java.lang.Class clazz)
          Determines whether the object of this class should be wrapped into a SimpleScalar (true), or into a descendant of ReflectionObjectModelBase (false).
static boolean isScalar(java.lang.Object object)
          Determines whether the object should be wrapped into a SimpleScalar (true), or into a descendant of ReflectionObjectModelBase (false).
static java.lang.Object unwrap(java.lang.Object model)
          Attempts to unwrap a model into underlying object.
static freemarker.template.TemplateModel wrap(java.lang.Object object)
          Wraps the object with a template model that is most specific for the object's class.
static freemarker.template.TemplateModel wrap(java.lang.Object object, boolean asScalar)
          Wraps the object with a template model that is most specific for the object's class, just as wrap(Object) would, however it can force wrapping into scalar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WRAP_AS_SCALAR

public static final boolean WRAP_AS_SCALAR
Use in the wrap() method to override logic for determining whether the parameter should be wrapped as a TemplateScalarModel or as a TemplateHashModel, and force wrapping into scalar.

WRAP_AS_OBJECT

public static final boolean WRAP_AS_OBJECT
Use in the wrap() method to override logic for determining whether the parameter should be wrapped as a TemplateScalarModel or as a TemplateHashModel, and force wrapping into hash model.
Method Detail

isScalar

public static final boolean isScalar(java.lang.Class clazz)
Determines whether the object of this class should be wrapped into a SimpleScalar (true), or into a descendant of ReflectionObjectModelBase (false). All classes representing primitive types, as well as String and Boolean qualify.

isScalar

public static final boolean isScalar(java.lang.Object object)
Determines whether the object should be wrapped into a SimpleScalar (true), or into a descendant of ReflectionObjectModelBase (false). Convenience method for isScalar(Class) that deals with object being null. All classes representing primitive types, as well as String and Boolean qualify.

wrap

public static final freemarker.template.TemplateModel wrap(java.lang.Object object)
Wraps the object with a template model that is most specific for the object's class. Specifically:

wrap

public static final freemarker.template.TemplateModel wrap(java.lang.Object object,
                                                           boolean asScalar)
Wraps the object with a template model that is most specific for the object's class, just as wrap(Object) would, however it can force wrapping into scalar. (I.e. ReflectionMethodModel uses this when it knows that its return type is a primitive type wrapper).
Parameters:
object - the object to wrap
asScalar. - If WRAP_AS_SCALAR, the object will be wrapped into a scalar (in case it is neither a Boolean nor a String, its toString() value is wrapped). If WRAP_AS_OBJECT, the object will be wrapped into ReflectionObjectModel even if it is a String or Boolean.

unwrap

public static final java.lang.Object unwrap(java.lang.Object model)
                                     throws freemarker.template.TemplateModelException
Attempts to unwrap a model into underlying object. It can unwrap ReflectionObjectModelBase and ReflectionScalarModel instances, as well a generic TemplateScalarModel into a String. All other objects are returned unchanged.