Java Doc for XWorkConverter.java in  » J2EE » webwork-2.2.6 » com » opensymphony » xwork » util » 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 » J2EE » webwork 2.2.6 » com.opensymphony.xwork.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


com.opensymphony.xwork.util.XWorkConverter

XWorkConverter
public class XWorkConverter extends DefaultTypeConverter (Code)
XWorkConverter is a singleton used by many of the WebWork's Ognl extention points, such as InstantiatingNullHandler, XWorkListPropertyAccessor etc to do object conversion. Type conversion is great for situations where you need to turn a String in to a more complex object. Because the web is type-agnostic (everything is a string in HTTP), WebWork's type conversion features are very useful. For instance, if you were prompting a user to enter in coordinates in the form of a string (such as "3, 22"), you could have WebWork do the conversion both from String to Point and from Point to String.

Using this "point" example, if your action (or another compound object in which you are setting properties on) has a corresponding ClassName-conversion.properties file, WebWork will use the configured type converters for conversion to and from strings. So turning "3, 22" in to new Point(3, 22) is done by merely adding the following entry to ClassName-conversion.properties (Note that the PointConverter should impl the ognl.TypeConverter interface):

point = com.acme.PointConverter

Your type converter should be sure to check what class type it is being requested to convert. Because it is used for both to and from strings, you will need to split the conversion method in to two parts: one that turns Strings in to Points, and one that turns Points in to Strings.

After this is done, you can now reference your point (using <ww:property value="post"/> in JSP or ${point} in FreeMarker) and it will be printed as "3, 22" again. As such, if you submit this back to an action, it will be converted back to a Point once again.

In some situations you may wish to apply a type converter globally. This can be done by editing the file xwork-conversion.properties in the root of your class path (typically WEB-INF/classes) and providing a property in the form of the class name of the object you wish to convert on the left hand side and the class name of the type converter on the right hand side. For example, providing a type converter for all Point objects would mean adding the following entry:

com.acme.Point = com.acme.PointConverter

Type conversion should not be used as a substitute for i18n. It is not recommended to use this feature to print out properly formatted dates. Rather, you should use the i18n features of WebWork (and consult the JavaDocs for JDK's MessageFormat object) to see how a properly formatted date should be displayed.

Any error that occurs during type conversion may or may not wish to be reported. For example, reporting that the input "abc" could not be converted to a number might be important. On the other hand, reporting that an empty string, "", cannot be converted to a number might not be important - especially in a web environment where it is hard to distinguish between a user not entering a value vs. entering a blank value.

By default, all conversion errors are reported using the generic i18n key xwork.default.invalid.fieldvalue, which you can override (the default text is Invalid field value for field "xxx", where xxx is the field name) in your global i18n resource bundle.

However, sometimes you may wish to override this message on a per-field basis. You can do this by adding an i18n key associated with just your action (Action.properties) using the pattern invalid.fieldvalue.xxx, where xxx is the field name.

It is important to know that none of these errors are actually reported directly. Rather, they are added to a map called conversionErrors in the ActionContext. There are several ways this map can then be accessed and the errors can be reported accordingly.
author:
   Pat Lightbody
author:
   Rainer Hermanns
author:
   Alexandru Popescu
See Also:   XWorkBasicConverter



Field Summary
final public static  StringCONVERSION_COLLECTION_PREFIX
    
final public static  StringCONVERSION_ERROR_PROPERTY_PREFIX
    
final public static  StringCONVERSION_PROPERTY_FULLNAME
    
final public static  StringLAST_BEAN_CLASS_ACCESSED
    
final public static  StringLAST_BEAN_PROPERTY_ACCESSED
    
final protected static  LogLOG
    
final public static  StringREPORT_CONVERSION_ERRORS
    
 HashMapdefaultMappings
    
 TypeConverterdefaultTypeConverter
    
 HashMapmappings
    
 HashSetnoMapping
    
 ObjectTypeDeterminerobjectTypeDeterminer
    
 HashSetunknownMappings
    

Constructor Summary
protected  XWorkConverter()
    

Method Summary
 voidaddConverterMapping(Map mapping, Class clazz)
     Looks for converter mappings for the specified class and adds it to an existing map.
public static  StringbuildConverterFilename(Class clazz)
    
public  ObjectconvertValue(Map map, Object o, Class aClass)
    
public  ObjectconvertValue(Map context, Object target, Member member, String property, Object value, Class toClass)
     Convert value from one form to another.
 TypeConvertercreateTypeConverter(String className)
    
public static  StringgetConversionErrorMessage(String propertyName, OgnlValueStack stack)
    
protected  ObjectgetConverter(Class clazz, String property)
    
public static  XWorkConvertergetInstance()
    
public  ObjectTypeDeterminergetObjectTypeDeterminer()
    
protected  voidhandleConversionException(Map context, String property, Object value, Object object)
    
public  voidloadConversionProperties(String propsName)
    
public  TypeConverterlookup(String className)
     Looks for a TypeConverter in the default mappings.
public  TypeConverterlookup(Class clazz)
     Looks for a TypeConverter in the default mappings.
 TypeConverterlookupSuper(Class clazz)
     Recurses through a class' interfaces and class hierarchy looking for a TypeConverter in the default mapping that can handle the specified class.
public synchronized  voidregisterConverter(String className, TypeConverter converter)
    
public synchronized  voidregisterConverterNotFound(String className)
    
public static  voidresetInstance()
    
public  voidsetDefaultConverter(TypeConverter defaultTypeConverter)
    
public static  voidsetInstance(XWorkConverter instance)
    
public  voidsetObjectTypeDeterminer(ObjectTypeDeterminer determiner)
    

Field Detail
CONVERSION_COLLECTION_PREFIX
final public static String CONVERSION_COLLECTION_PREFIX(Code)



CONVERSION_ERROR_PROPERTY_PREFIX
final public static String CONVERSION_ERROR_PROPERTY_PREFIX(Code)



CONVERSION_PROPERTY_FULLNAME
final public static String CONVERSION_PROPERTY_FULLNAME(Code)



LAST_BEAN_CLASS_ACCESSED
final public static String LAST_BEAN_CLASS_ACCESSED(Code)



LAST_BEAN_PROPERTY_ACCESSED
final public static String LAST_BEAN_PROPERTY_ACCESSED(Code)



LOG
final protected static Log LOG(Code)



REPORT_CONVERSION_ERRORS
final public static String REPORT_CONVERSION_ERRORS(Code)



defaultMappings
HashMap defaultMappings(Code)



defaultTypeConverter
TypeConverter defaultTypeConverter(Code)



mappings
HashMap mappings(Code)



noMapping
HashSet noMapping(Code)



objectTypeDeterminer
ObjectTypeDeterminer objectTypeDeterminer(Code)



unknownMappings
HashSet unknownMappings(Code)




Constructor Detail
XWorkConverter
protected XWorkConverter()(Code)




Method Detail
addConverterMapping
void addConverterMapping(Map mapping, Class clazz)(Code)
Looks for converter mappings for the specified class and adds it to an existing map. Only new converters are added. If a converter is defined on a key that already exists, the converter is ignored.
Parameters:
  mapping - an existing map to add new converter mappings to
Parameters:
  clazz - class to look for converter mappings for



buildConverterFilename
public static String buildConverterFilename(Class clazz)(Code)



convertValue
public Object convertValue(Map map, Object o, Class aClass)(Code)



convertValue
public Object convertValue(Map context, Object target, Member member, String property, Object value, Class toClass)(Code)
Convert value from one form to another. Minimum requirement of arguments:
  • supplying context, toClass and value
  • supplying context, target and value.

See Also:   ognl.TypeConverter.convertValue(java.util.Mapjava.lang.Objectjava.lang.reflect.Memberjava.lang.Stringjava.lang.Objectjava.lang.Class)



createTypeConverter
TypeConverter createTypeConverter(String className) throws Exception(Code)



getConversionErrorMessage
public static String getConversionErrorMessage(String propertyName, OgnlValueStack stack)(Code)



getConverter
protected Object getConverter(Class clazz, String property)(Code)



getInstance
public static XWorkConverter getInstance()(Code)



getObjectTypeDeterminer
public ObjectTypeDeterminer getObjectTypeDeterminer()(Code)



handleConversionException
protected void handleConversionException(Map context, String property, Object value, Object object)(Code)



loadConversionProperties
public void loadConversionProperties(String propsName) throws IOException(Code)



lookup
public TypeConverter lookup(String className)(Code)
Looks for a TypeConverter in the default mappings.
Parameters:
  className - name of the class the TypeConverter must handle a TypeConverter to handle the specified class or null if none can be found



lookup
public TypeConverter lookup(Class clazz)(Code)
Looks for a TypeConverter in the default mappings.
Parameters:
  clazz - the class the TypeConverter must handle a TypeConverter to handle the specified class or null if none can be found



lookupSuper
TypeConverter lookupSuper(Class clazz)(Code)
Recurses through a class' interfaces and class hierarchy looking for a TypeConverter in the default mapping that can handle the specified class.
Parameters:
  clazz - the class the TypeConverter must handle a TypeConverter to handle the specified class or null if none can be found



registerConverter
public synchronized void registerConverter(String className, TypeConverter converter)(Code)



registerConverterNotFound
public synchronized void registerConverterNotFound(String className)(Code)



resetInstance
public static void resetInstance()(Code)



setDefaultConverter
public void setDefaultConverter(TypeConverter defaultTypeConverter)(Code)



setInstance
public static void setInstance(XWorkConverter instance)(Code)



setObjectTypeDeterminer
public void setObjectTypeDeterminer(ObjectTypeDeterminer determiner)(Code)

Parameters:
  determiner -



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