Java Doc for BeansWrapper.java in  » Template-Engine » freemarker-2.3.10 » freemarker » ext » beans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Template Engine » freemarker 2.3.10 » freemarker.ext.beans 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   freemarker.ext.beans.BeansWrapper

All known Subclasses:   freemarker.ext.rhino.RhinoWrapper,  freemarker.template.DefaultObjectWrapper,
BeansWrapper
public class BeansWrapper implements ObjectWrapper(Code)
Utility class that provides generic services to reflection classes. It handles all polymorphism issues in the BeansWrapper.wrap(Object) and BeansWrapper.unwrap(TemplateModel) methods.
author:
   Attila Szegedi
version:
   $Id: BeansWrapper.java,v 1.91.2.13 2007/04/02 13:08:59 szegedia Exp $


Field Summary
final public static  intEXPOSE_ALL
     At this level of exposure, all methods and properties of the wrapped objects are exposed to the template.
final public static  intEXPOSE_NOTHING
     At this level of exposure, no bean properties and methods are exposed. Only map items, resource bundle items, and objects retrieved through the generic get method (on objects of classes that have a generic get method) can be retrieved through the hash interface.
final public static  intEXPOSE_PROPERTIES_ONLY
     At this level of exposure, only property getters are exposed. Additionally, property getters that map to unsafe methods are not exposed (i.e.
final public static  intEXPOSE_SAFE
     At this level of exposure, all methods and properties of the wrapped objects are exposed to the template except methods that are deemed not safe.
final static  ObjectGENERIC_GET_KEY
    

Constructor Summary
public  BeansWrapper()
     Creates a new instance of BeansWrapper.

Method Summary
public static  voidcoerceBigDecimals(AccessibleObject callable, Object[] args)
     Converts any BigDecimal s in the passed array to the type of the corresponding formal argument of the method.
protected  TemplateModelcreate(Object object, Object factory)
    
static  Class[]getArgTypes(Map classMap, AccessibleObject methodOrCtor)
    
 MapgetClassKeyMap(Class clazz)
    
protected  intgetDefaultDateType()
    
final public static  BeansWrappergetDefaultInstance()
     Returns the default instance of the wrapper.
public  TemplateHashModelgetEnumModels()
     Returns a hash model that represents the so-called class enum models. Every class' enum model is itself a hash through which you can access enum value declared by the specified class, assuming that class is an enumeration.
 intgetExposureLevel()
    
protected  TemplateModelgetInstance(Object object, ModelFactory factory)
    
public  ObjectWrappergetOuterIdentity()
     By default returns this.
public  TemplateHashModelgetStaticModels()
     Returns a hash model that represents the so-called class static models. Every class static model is itself a hash through which you can call static methods on the specified class.
 voidintrospectClass(Class clazz)
    
 TemplateModelinvokeMethod(Object object, Method method, Object[] args)
     Invokes the specified method, wrapping the return value.
public  booleanisExposeFields()
    
 booleanisMethodsShadowItems()
    
 booleanisSafeMethod(Method method)
    
public  booleanisSimpleMapWrapper()
    
public  booleanisStrict()
    
 intkeyCount(Class clazz)
     Returns the number of introspected methods/properties that should be available via the TemplateHashModel interface.
 SetkeySet(Class clazz)
     Returns the Set of names of introspected methods/properties that should be available via the TemplateHashModel interface.
public  ObjectnewInstance(Class clazz, List arguments)
    
public synchronized  voidsetDefaultDateType(int defaultDateType)
     Sets the default date type to use for date models that result from a plain java.util.Date instead of java.sql.Date or java.sql.Time or java.sql.Timestamp.
public  voidsetExposeFields(boolean exposeFields)
    
public  voidsetExposureLevel(int exposureLevel)
     Sets the method exposure level.
public synchronized  voidsetMethodsShadowItems(boolean methodsShadowItems)
     Sets whether methods shadow items in beans.
public  voidsetNullModel(TemplateModel nullModel)
     Sets the null model.
public  voidsetOuterIdentity(ObjectWrapper outerIdentity)
     When wrapping an object, the BeansWrapper commonly needs to wrap "sub-objects", for example each element in a wrapped collection. Normally it wraps these objects using itself.
public  voidsetSimpleMapWrapper(boolean simpleMapWrapper)
     By default the BeansWrapper wraps classes implementing java.util.Map using MapModel .
public  voidsetStrict(boolean strict)
     Specifies if an attempt to read a bean property that doesn't exist in the wrapped object should throw an InvalidPropertyException .

If this property is false (the default) then an attempt to read a missing bean property is the same as reading an existing bean property whose value is null.

public  voidsetUseCache(boolean useCache)
     Sets whether this wrapper caches model instances.
public  Objectunwrap(TemplateModel model)
     Attempts to unwrap a model into underlying object.
public  Objectunwrap(TemplateModel model, Class hint)
    
 Object[]unwrapArguments(List arguments, Class[] argTypes)
     Auxiliary method that unwraps arguments for a method or constructor call.
Parameters:
  arguments - the argument list of template models
Parameters:
  argTypes - the preferred types of the arguments Object[] the unwrapped arguments.
 Object[]unwrapArguments(List arguments)
    
public  TemplateModelwrap(Object object)
     Wraps the object with a template model that is most specific for the object's class.

Field Detail
EXPOSE_ALL
final public static int EXPOSE_ALL(Code)
At this level of exposure, all methods and properties of the wrapped objects are exposed to the template.



EXPOSE_NOTHING
final public static int EXPOSE_NOTHING(Code)
At this level of exposure, no bean properties and methods are exposed. Only map items, resource bundle items, and objects retrieved through the generic get method (on objects of classes that have a generic get method) can be retrieved through the hash interface. You might want to call BeansWrapper.setMethodsShadowItems(boolean) with false value to speed up map item retrieval.



EXPOSE_PROPERTIES_ONLY
final public static int EXPOSE_PROPERTIES_ONLY(Code)
At this level of exposure, only property getters are exposed. Additionally, property getters that map to unsafe methods are not exposed (i.e. Class.classLoader and Thread.contextClassLoader).



EXPOSE_SAFE
final public static int EXPOSE_SAFE(Code)
At this level of exposure, all methods and properties of the wrapped objects are exposed to the template except methods that are deemed not safe. The not safe methods are java.lang.Object methods wait() and notify(), java.lang.Class methods getClassLoader() and newInstance(), java.lang.reflect.Method and java.lang.reflect.Constructor invoke() and newInstance() methods, all java.lang.reflect.Field set methods, all java.lang.Thread and java.lang.ThreadGroup methods that can change its state, as well as the usual suspects in java.lang.System and java.lang.Runtime.



GENERIC_GET_KEY
final static Object GENERIC_GET_KEY(Code)




Constructor Detail
BeansWrapper
public BeansWrapper()(Code)
Creates a new instance of BeansWrapper. The newly created instance will use the null reference as its null object, it will use BeansWrapper.EXPOSE_SAFE method exposure level, and will not cache model instances.




Method Detail
coerceBigDecimals
public static void coerceBigDecimals(AccessibleObject callable, Object[] args)(Code)
Converts any BigDecimal s in the passed array to the type of the corresponding formal argument of the method.



create
protected TemplateModel create(Object object, Object factory)(Code)



getArgTypes
static Class[] getArgTypes(Map classMap, AccessibleObject methodOrCtor)(Code)



getClassKeyMap
Map getClassKeyMap(Class clazz)(Code)



getDefaultDateType
protected int getDefaultDateType()(Code)



getDefaultInstance
final public static BeansWrapper getDefaultInstance()(Code)
Returns the default instance of the wrapper. This instance is used when you construct various bean models without explicitly specifying a wrapper. It is also returned by freemarker.template.ObjectWrapper.BEANS_WRAPPER and this is the sole instance that is used by the JSP adapter. You can modify the properties of the default instance (caching, exposure level, null model) to affect its operation. By default, the default instance is not caching, uses the EXPOSE_SAFE exposure level, and uses null reference as the null model.



getEnumModels
public TemplateHashModel getEnumModels()(Code)
Returns a hash model that represents the so-called class enum models. Every class' enum model is itself a hash through which you can access enum value declared by the specified class, assuming that class is an enumeration. To obtain an enum model for a class, get the element of this hash with the fully qualified class name. For example, if you place this hash model inside the root data model under name "enums", you can use i.e. statics["java.math.RoundingMode"].UP to access the java.math.RoundingMode.UP value. a hash model whose keys are fully qualified class names, andthat returns hash models whose elements are the enum models of theclasses.
throws:
  UnsupportedOperationException - if this method is invoked on a pre-1.5 JRE, as Java enums aren't supported there.



getExposureLevel
int getExposureLevel()(Code)



getInstance
protected TemplateModel getInstance(Object object, ModelFactory factory)(Code)



getOuterIdentity
public ObjectWrapper getOuterIdentity()(Code)
By default returns this.
See Also:   BeansWrapper.setOuterIdentity(ObjectWrapper)



getStaticModels
public TemplateHashModel getStaticModels()(Code)
Returns a hash model that represents the so-called class static models. Every class static model is itself a hash through which you can call static methods on the specified class. To obtain a static model for a class, get the element of this hash with the fully qualified class name. For example, if you place this hash model inside the root data model under name "statics", you can use i.e. statics["java.lang. System"]. currentTimeMillis() to call the java.lang.System.currentTimeMillis method. a hash model whose keys are fully qualified class names, andthat returns hash models whose elements are the static models of theclasses.



introspectClass
void introspectClass(Class clazz)(Code)



invokeMethod
TemplateModel invokeMethod(Object object, Method method, Object[] args) throws InvocationTargetException, IllegalAccessException, TemplateModelException(Code)
Invokes the specified method, wrapping the return value. The specialty of this method is that if the return value is null, and the return type of the invoked method is void, TemplateModel.NOTHING is returned.
Parameters:
  object - the object to invoke the method on
Parameters:
  method - the method to invoke
Parameters:
  args - the arguments to the method the wrapped return value of the method.
throws:
  InvocationTargetException - if the invoked method threw an exception
throws:
  IllegalAccessException - if the method can't be invoked due to anaccess restriction.
throws:
  TemplateModelException - if the return value couldn't be wrapped(this can happen if the wrapper has an outer identity or is subclassed,and the outer identity or the subclass throws an exception. PlainBeansWrapper never throws TemplateModelException).



isExposeFields
public boolean isExposeFields()(Code)



isMethodsShadowItems
boolean isMethodsShadowItems()(Code)



isSafeMethod
boolean isSafeMethod(Method method)(Code)



isSimpleMapWrapper
public boolean isSimpleMapWrapper()(Code)



isStrict
public boolean isStrict()(Code)

See Also:   BeansWrapper.setStrict(boolean)



keyCount
int keyCount(Class clazz)(Code)
Returns the number of introspected methods/properties that should be available via the TemplateHashModel interface. Affected by the BeansWrapper.setMethodsShadowItems(boolean) and BeansWrapper.setExposureLevel(int) settings.



keySet
Set keySet(Class clazz)(Code)
Returns the Set of names of introspected methods/properties that should be available via the TemplateHashModel interface. Affected by the BeansWrapper.setMethodsShadowItems(boolean) and BeansWrapper.setExposureLevel(int) settings.



newInstance
public Object newInstance(Class clazz, List arguments) throws TemplateModelException(Code)



setDefaultDateType
public synchronized void setDefaultDateType(int defaultDateType)(Code)
Sets the default date type to use for date models that result from a plain java.util.Date instead of java.sql.Date or java.sql.Time or java.sql.Timestamp. Default value is TemplateDateModel.UNKNOWN .
Parameters:
  defaultDateType - the new default date type.



setExposeFields
public void setExposeFields(boolean exposeFields)(Code)



setExposureLevel
public void setExposureLevel(int exposureLevel)(Code)
Sets the method exposure level. By default, set to EXPOSE_SAFE.
Parameters:
  exposureLevel - can be any of the EXPOSE_xxxconstants.



setMethodsShadowItems
public synchronized void setMethodsShadowItems(boolean methodsShadowItems)(Code)
Sets whether methods shadow items in beans. When true (this is the default value), ${object.name} will first try to locate a bean method or property with the specified name on the object, and only if it doesn't find it will it try to call object.get(name), the so-called "generic get method" that is usually used to access items of a container (i.e. elements of a map). When set to false, the lookup order is reversed and generic get method is called first, and only if it returns null is method lookup attempted.



setNullModel
public void setNullModel(TemplateModel nullModel)(Code)
Sets the null model. This model is returned from the BeansWrapper.wrap(Object) method whenever the underlying object reference is null. It defaults to null reference, which is dealt with quite strictly on engine level, however you can substitute an arbitrary (perhaps more lenient) model, such as freemarker.template.TemplateScalarModel.EMPTY_STRING .



setOuterIdentity
public void setOuterIdentity(ObjectWrapper outerIdentity)(Code)
When wrapping an object, the BeansWrapper commonly needs to wrap "sub-objects", for example each element in a wrapped collection. Normally it wraps these objects using itself. However, this makes it difficult to delegate to a BeansWrapper as part of a custom aggregate ObjectWrapper. This method lets you set the ObjectWrapper which will be used to wrap the sub-objects.
Parameters:
  outerIdentity - the aggregate ObjectWrapper



setSimpleMapWrapper
public void setSimpleMapWrapper(boolean simpleMapWrapper)(Code)
By default the BeansWrapper wraps classes implementing java.util.Map using MapModel . Setting this flag will cause it to use a SimpleMapModel instead. The biggest difference is that when using a SimpleMapModel , the map will be visible as TemplateHashModelEx, and the subvariables will be the content of the map, without the other methods and properties of the map object.
Parameters:
  simpleMapWrapper - enable simple map wrapping



setStrict
public void setStrict(boolean strict)(Code)
Specifies if an attempt to read a bean property that doesn't exist in the wrapped object should throw an InvalidPropertyException .

If this property is false (the default) then an attempt to read a missing bean property is the same as reading an existing bean property whose value is null. The template can't tell the difference, and thus always can use ?default('something') and ?exists and similar built-ins to handle the situation.

If this property is true then an attempt to read a bean propertly in the template (like myBean.aProperty) that doesn't exist in the bean object (as opposed to just holding null value) will cause InvalidPropertyException , which can't be suppressed in the template (not even with myBean.noSuchProperty?default('something')). This way ?default('something') and ?exists and similar built-ins can be used to handle existing properties whose value is null, without the risk of hiding typos in the property names. Typos will always cause error. But mind you, it goes against the basic approach of FreeMarker, so use this feature only if you really know what are you doing.




setUseCache
public void setUseCache(boolean useCache)(Code)
Sets whether this wrapper caches model instances. Default is false. When set to true, calling BeansWrapper.wrap(Object) multiple times for the same object will likely return the same model (although there is no guarantee as the cache items can be cleared anytime).



unwrap
public Object unwrap(TemplateModel model) throws TemplateModelException(Code)
Attempts to unwrap a model into underlying object. Generally, this method is the inverse of the BeansWrapper.wrap(Object) method. In addition it will unwrap arbitrary TemplateNumberModel instances into a number, arbitrary TemplateDateModel instances into a date, TemplateScalarModel instances into a String, and TemplateBooleanModel instances into a Boolean. All other objects are returned unchanged.



unwrap
public Object unwrap(TemplateModel model, Class hint) throws TemplateModelException(Code)



unwrapArguments
Object[] unwrapArguments(List arguments, Class[] argTypes) throws TemplateModelException(Code)
Auxiliary method that unwraps arguments for a method or constructor call.
Parameters:
  arguments - the argument list of template models
Parameters:
  argTypes - the preferred types of the arguments Object[] the unwrapped arguments. null if the passed list wasnull.
throws:
  TemplateModelException - if unwrapping any argument throws one



unwrapArguments
Object[] unwrapArguments(List arguments) throws TemplateModelException(Code)



wrap
public TemplateModel wrap(Object object) throws TemplateModelException(Code)
Wraps the object with a template model that is most specific for the object's class. Specifically:



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.