Extension SDK 10.1.2

oracle.ide.marshal
Class ToStringManager

java.lang.Object
  extended byoracle.ide.marshal.ToStringManager

public final class ToStringManager
extends java.lang.Object

Class that helps manage the conversion of objects to and from a String representation. The mechanisms that are available to perform this conversion are attempted in the following order:

  1. Otherwise, check if the object type has been identified as having a direct String representation. If so, use toString() to go from Object to String and use the constructor that takes a single String parameter to go from String to Object.
  2. Otherwise, check if an explicit converter class has been registered with the ToStringManager. If one is found, use its toString() and fromString() methods for carrying out the conversion.
If none of these methods is available, then no interconversion with String is possible for the given object, and any attempt to perform the conversion will result in an UnsupportedOperationException being thrown.


Method Summary
static boolean converterAvailable(java.lang.Class type)
          Returns true if the given class type can be converted to and from String for the purposes of persistence.
static boolean converterAvailable(java.lang.Object object)
          Returns true if the value of the given object can be converted to and from a String representation.
static boolean converterAvailable(java.lang.String typeStr)
          Invokes Class.forName() on the typeStr and then calls converterAvailable(Class).
static java.lang.Object fromString(java.lang.String s, java.lang.Class targetClass)
          Converts the given String into the specified target class type, returning an instance that has been properly initialized according to the contents of the String.
static boolean registerCustomConverter(java.lang.Class converterClass)
          Registers a class type as being able to interconvert an object type to and from String.
static boolean registerStringConvertible(java.lang.Class clazz)
          Adds the specified class to the list of classes that have a direct String representation.
static java.lang.String toString(java.lang.Object obj)
          Converts the given object to a String representation from which the instance can later be restored by invoking fromString().
static java.lang.String toString(java.lang.Object obj, java.lang.Class objClass)
          Converts the given object to a String representation, forcing the format to be that of the class objClass.
static java.lang.Class wrapPrimitive(java.lang.Class primitive)
          If the primitive argument represents a primitive type, then the returned class is the corresponding object-wrapped type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

registerStringConvertible

public static boolean registerStringConvertible(java.lang.Class clazz)
Adds the specified class to the list of classes that have a direct String representation.

Returns:
true if the class type has not already been registered as a constructor supported converter; false otherwise.

registerCustomConverter

public static boolean registerCustomConverter(java.lang.Class converterClass)
Registers a class type as being able to interconvert an object type to and from String. The class type passed in through converterClass must be declared as public and must supply three static methods that conform to the following: If any of these methods are missing or are not of the proper format or type, then registration of the converter will fail, and registerCustomConverter() will return false. If registration succeeds, registerCustomConverter() returns true.

Generally, the name of the class should end with 2String, but this is not enforced by ToStringManager.


wrapPrimitive

public static java.lang.Class wrapPrimitive(java.lang.Class primitive)
If the primitive argument represents a primitive type, then the returned class is the corresponding object-wrapped type. Otherwise, the argument is returned as is.


converterAvailable

public static boolean converterAvailable(java.lang.Object object)
Returns true if the value of the given object can be converted to and from a String representation. If the object parameter is null, then this method returns false.


converterAvailable

public static boolean converterAvailable(java.lang.String typeStr)
Invokes Class.forName() on the typeStr and then calls converterAvailable(Class).


converterAvailable

public static boolean converterAvailable(java.lang.Class type)
Returns true if the given class type can be converted to and from String for the purposes of persistence. If the type parameter is null, then this method returns false.


toString

public static java.lang.String toString(java.lang.Object obj)
Converts the given object to a String representation from which the instance can later be restored by invoking fromString().


toString

public static java.lang.String toString(java.lang.Object obj,
                                        java.lang.Class objClass)
Converts the given object to a String representation, forcing the format to be that of the class objClass.


fromString

public static java.lang.Object fromString(java.lang.String s,
                                          java.lang.Class targetClass)
Converts the given String into the specified target class type, returning an instance that has been properly initialized according to the contents of the String. The fromString() method should restore the object instance to its exact state at the time that the ToStringManager.toString() method was used to persist it.


Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.