Java Doc for TypeConverter.java in  » IDE-Netbeans » visualweb.api.designer » com » sun » rave » web » ui » 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 » IDE Netbeans » visualweb.api.designer » com.sun.rave.web.ui.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.sun.rave.web.ui.util.TypeConverter

TypeConverter
public class TypeConverter extends Object (Code)
Provides an efficient and robust mechanism for converting an object to a different type. For example, one can convert a String to an Integer using the TypeConverter like this:
 Integer i = (Integer) TypeConverter.asType(Integer.class, "123");
 
or using the shortcut method:
 int i = TypeConverter.asInt("123");
 
The TypeConverter comes ready to convert all the primitive types, plus a few more like java.sql.Date and java.math.BigDecimal.

The conversion process has been optimized so that it is now a constant time operation (aside from the conversion itself, which may vary). Because of this optimization, it is possible to register classes that implement the new TypeConversion interface for conversion to a custom type. For example, this means that you can define a class to convert arbitrary objects to type Foo, and register it for use throughout the VM:

 TypeConversion fooConversion = new FooTypeConversion();
 TypeConverter.registerTypeConversion(Foo.class, fooConversion);
 ...
 Bar bar = new Bar();
 Foo foo = (Foo) TypeConverter.asType(Foo.class, bar);
 ...
 String s = "bar";
 Foo foo = (Foo) TypeConverter.asType(Foo.class, s);
 
The TypeConverter allows specification of an arbitrary type key in the registerTypeConversion() and asType() methods, so one can simultaneously register a conversion object under a Class object, a class name, and a logical type name. For example, the following are valid ways of converting a string to an int using TypeConverter:
 Integer i = (Integer) TypeConverter.asType(Integer.class, "123");
 Integer i = (Integer) TypeConverter.asType("java.lang.Integer", "123");
 Integer i = (Integer) TypeConverter.asType(TypeConverter.TYPE_INT, "123");
 Integer i = (Integer) TypeConverter.asType(TypeConverter.TYPE_INTEGER, "123");
 Integer i = (Integer) TypeConverter.asType("int", "123");
 Integer i = (Integer) TypeConverter.asType("integer", "123");
 int i = TypeConverter.asInt("123");
 
Default type conversions have been registered under the following keys:
 Classes:
 java.lang.Object
 java.lang.String
 java.lang.Integer
 java.lang.Integer.TYPE (int)
 java.lang.Double
 java.lang.Double.TYPE (double)
 java.lang.Boolean
 java.lang.Boolean.TYPE (boolean)
 java.lang.Long
 java.lang.Long.TYPE (long)
 java.lang.Float
 java.lang.Float.TYPE (float)
 java.lang.Short
 java.lang.Short.TYPE (short)
 java.lang.Byte
 java.lang.Byte.TYPE (byte)
 java.lang.Character
 java.lang.Character.TYPE (char)
 java.math.BigDecimal
 java.sql.Date
 java.sql.Time
 java.sql.Timestamp
 Class name strings:
 "java.lang.Object"
 "java.lang.String"
 "java.lang.Integer"
 "java.lang.Double"
 "java.lang.Boolean"
 "java.lang.Long"
 "java.lang.Float"
 "java.lang.Short"
 "java.lang.Byte"
 "java.lang.Character"
 "java.math.BigDecimal"
 "java.sql.Date"
 "java.sql.Time"
 "java.sql.Timestamp"
 Logical type name string constants:
 TypeConverter.TYPE_UNKNOWN ("null")
 TypeConverter.TYPE_OBJECT ("object")
 TypeConverter.TYPE_STRING ("string")
 TypeConverter.TYPE_INT ("int")
 TypeConverter.TYPE_INTEGER ("integer")
 TypeConverter.TYPE_DOUBLE ("double")
 TypeConverter.TYPE_BOOLEAN ("boolean")
 TypeConverter.TYPE_LONG ("long")
 TypeConverter.TYPE_FLOAT ("float")
 TypeConverter.TYPE_SHORT ("short")
 TypeConverter.TYPE_BYTE ("byte")
 TypeConverter.TYPE_CHAR ("char")
 TypeConverter.TYPE_CHARACTER ("character")
 TypeConverter.TYPE_BIG_DECIMAL ("bigdecimal")
 TypeConverter.TYPE_SQL_DATE ("sqldate")
 TypeConverter.TYPE_SQL_TIME ("sqltime")
 TypeConverter.TYPE_SQL_TIMESTAMP ("sqltimestamp")
 
The TypeConverter treats type keys of type Class slightly differently than other keys. If the provided value is already of the type specified by the type key class, it is returned without a conversion taking place. For example, a value of type MySub that extends the class MySuper would not be converted in the following situation because it is already of the necessary type:
 MySub o = (MySub) TypeConverter.asType(MySuper.class, mySub);
 
Be warned that although the type conversion infrastructure in this class is desgned to add only minimal overhead to the conversion process, conversion of an object to another type is a potentially expensive operation and should be used with discretion.
See Also:   TypeConversion
author:
   Todd Fast, todd.fast@sun.com
author:
   Mike Frisino, michael.frisino@sun.com
author:
   Ken Paulsen, ken.paulsen@sun.com (stripped down)

Inner Class :public static class UnknownTypeConversion implements TypeConversion
Inner Class :public static class StringTypeConversion implements TypeConversion
Inner Class :public static class IntegerTypeConversion implements TypeConversion
Inner Class :public static class DoubleTypeConversion implements TypeConversion
Inner Class :public static class BooleanTypeConversion implements TypeConversion
Inner Class :public static class LongTypeConversion implements TypeConversion
Inner Class :public static class FloatTypeConversion implements TypeConversion
Inner Class :public static class ShortTypeConversion implements TypeConversion
Inner Class :public static class BigDecimalTypeConversion implements TypeConversion
Inner Class :public static class ByteTypeConversion implements TypeConversion
Inner Class :public static class CharacterTypeConversion implements TypeConversion
Inner Class :public static class SqlDateTypeConversion implements TypeConversion
Inner Class :public static class SqlTimeTypeConversion implements TypeConversion
Inner Class :public static class SqlTimestampTypeConversion implements TypeConversion
Inner Class :public static class ObjectTypeConversion implements TypeConversion

Field Summary
final public static  TypeConversionBIG_DECIMAL_TYPE_CONVERSION
    
final public static  TypeConversionBOOLEAN_TYPE_CONVERSION
    
final public static  TypeConversionBYTE_TYPE_CONVERSION
    
final public static  TypeConversionCHARACTER_TYPE_CONVERSION
    
final public static  TypeConversionDOUBLE_TYPE_CONVERSION
    
final public static  TypeConversionFLOAT_TYPE_CONVERSION
    
final public static  TypeConversionINTEGER_TYPE_CONVERSION
    
final public static  TypeConversionLONG_TYPE_CONVERSION
    
final public static  TypeConversionOBJECT_TYPE_CONVERSION
    
final public static  TypeConversionSHORT_TYPE_CONVERSION
    
final public static  TypeConversionSQL_DATE_TYPE_CONVERSION
    
final public static  TypeConversionSQL_TIMESTAMP_TYPE_CONVERSION
    
final public static  TypeConversionSQL_TIME_TYPE_CONVERSION
    
final public static  TypeConversionSTRING_TYPE_CONVERSION
    
final public static  StringTYPE_BIG_DECIMAL
    
final public static  StringTYPE_BOOLEAN
    
final public static  StringTYPE_BYTE
    
final public static  StringTYPE_CHAR
    
final public static  StringTYPE_CHARACTER
    
final public static  StringTYPE_DOUBLE
    
final public static  StringTYPE_FLOAT
    
final public static  StringTYPE_INT
    
final public static  StringTYPE_INTEGER
    
final public static  StringTYPE_LONG
    
final public static  StringTYPE_OBJECT
    
final public static  StringTYPE_SHORT
    
final public static  StringTYPE_SQL_DATE
    
final public static  StringTYPE_SQL_TIME
    
final public static  StringTYPE_SQL_TIMESTAMP
    
final public static  StringTYPE_STRING
    
final public static  StringTYPE_UNKNOWN
    
final public static  TypeConversionUNKNOWN_TYPE_CONVERSION
    


Method Summary
public static  booleanasBoolean(Object value)
    
public static  booleanasBoolean(Object value, boolean defaultValue)
    
public static  byteasByte(Object value)
    
public static  byteasByte(Object value, byte defaultValue)
    
public static  charasChar(Object value)
    
public static  charasChar(Object value, char defaultValue)
    
public static  doubleasDouble(Object value)
    
public static  doubleasDouble(Object value, double defaultValue)
    
public static  floatasFloat(Object value)
    
public static  floatasFloat(Object value, float defaultValue)
    
public static  intasInt(Object value)
    
public static  intasInt(Object value, int defaultValue)
    
public static  longasLong(Object value)
    
public static  longasLong(Object value, long defaultValue)
    
public static  shortasShort(Object value)
    
public static  shortasShort(Object value, short defaultValue)
    
public static  StringasString(Object value)
    
public static  StringasString(Object value, String defaultValue)
    
public static  ObjectasType(Object typeKey, Object value)
    

Convert an object to the type specified by the provided type key. A type conversion object must have been previously registered under the provided key in order for the conversion to succeed (with one exception, see below).

Note, this method treats type keys of type Class differently than other type keys.

public static  MapgetTypeConversions()
     Return the map of type conversion objects.
public static  voidregisterTypeConversion(Object key, TypeConversion conversion)
     Register a type conversion object under the specified key.

Field Detail
BIG_DECIMAL_TYPE_CONVERSION
final public static TypeConversion BIG_DECIMAL_TYPE_CONVERSION(Code)



BOOLEAN_TYPE_CONVERSION
final public static TypeConversion BOOLEAN_TYPE_CONVERSION(Code)



BYTE_TYPE_CONVERSION
final public static TypeConversion BYTE_TYPE_CONVERSION(Code)



CHARACTER_TYPE_CONVERSION
final public static TypeConversion CHARACTER_TYPE_CONVERSION(Code)



DOUBLE_TYPE_CONVERSION
final public static TypeConversion DOUBLE_TYPE_CONVERSION(Code)



FLOAT_TYPE_CONVERSION
final public static TypeConversion FLOAT_TYPE_CONVERSION(Code)



INTEGER_TYPE_CONVERSION
final public static TypeConversion INTEGER_TYPE_CONVERSION(Code)



LONG_TYPE_CONVERSION
final public static TypeConversion LONG_TYPE_CONVERSION(Code)



OBJECT_TYPE_CONVERSION
final public static TypeConversion OBJECT_TYPE_CONVERSION(Code)



SHORT_TYPE_CONVERSION
final public static TypeConversion SHORT_TYPE_CONVERSION(Code)



SQL_DATE_TYPE_CONVERSION
final public static TypeConversion SQL_DATE_TYPE_CONVERSION(Code)



SQL_TIMESTAMP_TYPE_CONVERSION
final public static TypeConversion SQL_TIMESTAMP_TYPE_CONVERSION(Code)



SQL_TIME_TYPE_CONVERSION
final public static TypeConversion SQL_TIME_TYPE_CONVERSION(Code)



STRING_TYPE_CONVERSION
final public static TypeConversion STRING_TYPE_CONVERSION(Code)



TYPE_BIG_DECIMAL
final public static String TYPE_BIG_DECIMAL(Code)
Logical type name "bigdecimal"



TYPE_BOOLEAN
final public static String TYPE_BOOLEAN(Code)
Logical type name "boolean"



TYPE_BYTE
final public static String TYPE_BYTE(Code)
Logical type name "byte"



TYPE_CHAR
final public static String TYPE_CHAR(Code)
Logical type name "char"



TYPE_CHARACTER
final public static String TYPE_CHARACTER(Code)
Logical type name "character"



TYPE_DOUBLE
final public static String TYPE_DOUBLE(Code)
Logical type name "double"



TYPE_FLOAT
final public static String TYPE_FLOAT(Code)
Logical type name "float"



TYPE_INT
final public static String TYPE_INT(Code)
Logical type name "int"



TYPE_INTEGER
final public static String TYPE_INTEGER(Code)
Logical type name "integer"



TYPE_LONG
final public static String TYPE_LONG(Code)
Logical type name "long"



TYPE_OBJECT
final public static String TYPE_OBJECT(Code)
Logical type name "object"



TYPE_SHORT
final public static String TYPE_SHORT(Code)
Logical type name "short"



TYPE_SQL_DATE
final public static String TYPE_SQL_DATE(Code)
Logical type name "sqldate"



TYPE_SQL_TIME
final public static String TYPE_SQL_TIME(Code)
Logical type name "sqltime"



TYPE_SQL_TIMESTAMP
final public static String TYPE_SQL_TIMESTAMP(Code)
Logical type name "sqltimestamp"



TYPE_STRING
final public static String TYPE_STRING(Code)
Logical type name "string"



TYPE_UNKNOWN
final public static String TYPE_UNKNOWN(Code)
Logical type name "null"



UNKNOWN_TYPE_CONVERSION
final public static TypeConversion UNKNOWN_TYPE_CONVERSION(Code)





Method Detail
asBoolean
public static boolean asBoolean(Object value)(Code)



asBoolean
public static boolean asBoolean(Object value, boolean defaultValue)(Code)



asByte
public static byte asByte(Object value)(Code)



asByte
public static byte asByte(Object value, byte defaultValue)(Code)



asChar
public static char asChar(Object value)(Code)



asChar
public static char asChar(Object value, char defaultValue)(Code)



asDouble
public static double asDouble(Object value)(Code)



asDouble
public static double asDouble(Object value, double defaultValue)(Code)



asFloat
public static float asFloat(Object value)(Code)



asFloat
public static float asFloat(Object value, float defaultValue)(Code)



asInt
public static int asInt(Object value)(Code)



asInt
public static int asInt(Object value, int defaultValue)(Code)



asLong
public static long asLong(Object value)(Code)



asLong
public static long asLong(Object value, long defaultValue)(Code)



asShort
public static short asShort(Object value)(Code)



asShort
public static short asShort(Object value, short defaultValue)(Code)



asString
public static String asString(Object value)(Code)



asString
public static String asString(Object value, String defaultValue)(Code)



asType
public static Object asType(Object typeKey, Object value)(Code)

Convert an object to the type specified by the provided type key. A type conversion object must have been previously registered under the provided key in order for the conversion to succeed (with one exception, see below).

Note, this method treats type keys of type Class differently than other type keys. That is, this method will check if the provided value is the same as or a subclass of the specified class. If it is, this method returns the value object immediately without attempting to convert its type. One exception to this rule is if the provided type key is Object.class, in which case the conversion is attempted anyway. The reason for this deviation is that this key may have special meaning based on the type of the provided value. For example, if the provided value is a byte array, the ObjectTypeConversion class assumes it is a serialized object and attempts to deserialize it. Because all objects, including arrays, are of type Object, this conversion would never be attempted without this special handling. (Note that the default conversion for type key Object.class is to simply return the original object.)


Parameters:
  typeKey - The key under which the desired type conversion objecthas been previously registered. Most commonly, this keyshould be a Class object, a class namestring, or a logical type string represented by thevarious TYPE_* constants defined in thisclass.
Parameters:
  value - The value to convert to the specified target type The converted value object, or null if theoriginal value is null



getTypeConversions
public static Map getTypeConversions()(Code)
Return the map of type conversion objects. The keys for the values in this map may be arbitrary objects, but the values are of type TypeConversion.



registerTypeConversion
public static void registerTypeConversion(Object key, TypeConversion conversion)(Code)
Register a type conversion object under the specified key. This method can be used by developers to register custom type conversion objects.



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.