|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.taco.text.AbstractStringToObjectConverter
com.taco.text.StringToInstanceConverter
public class StringToInstanceConverter
An implementation of IStringToObjectConverter
that converts a
string, interpreted as a fully qualified class name, into a new instance of
the class denoted by s
by interpreting the string as a Java
literal or using reflection to create an instance of an object.
Field Summary | |
---|---|
protected java.lang.Class |
_returnType
The type returned objects must be instances of. |
static StringToInstanceConverter |
instance
The singleton instance of this class, which does not impose any type constraint. |
Constructor Summary | |
---|---|
protected |
StringToInstanceConverter()
Construct an instance that does not impose a type constraint on returned objects. |
|
StringToInstanceConverter(java.lang.Class returnType)
Construct an instance which checks that returned objects are instances of subclasses or implementations of the argument class or interface. |
Method Summary | |
---|---|
protected void |
_checkType(java.lang.Object obj)
Check that obj is an instance of each of the classes in
classArray . |
protected java.lang.Object |
_parseInstanceString(java.lang.String s)
Use s as a class name. |
protected java.lang.Object |
_parseJavaLiteral(java.lang.String s)
Parse s as a Java literal and return the
String or primitive wrapper that corresponds to it. |
protected java.lang.Object |
_toObject(java.lang.String s)
Convert s to an object as in toObject() ,
but don't do any type checking. |
java.lang.Object |
clone()
|
static void |
main(java.lang.String[] args)
A simple test program that gets and instance of the class denoted by the first command-line argument. |
java.lang.Object |
toObject(java.lang.String s)
|
Methods inherited from class com.taco.text.AbstractStringToObjectConverter |
---|
map |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final java.lang.Class _returnType
public static final StringToInstanceConverter instance
Constructor Detail |
---|
protected StringToInstanceConverter()
public StringToInstanceConverter(java.lang.Class returnType)
null
, do not perform any type checking.
Method Detail |
---|
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public java.lang.Object toObject(java.lang.String s) throws java.text.ParseException
toObject
in interface IStringToObjectConverter
java.text.ParseException
protected java.lang.Object _toObject(java.lang.String s) throws java.text.ParseException
Convert s
to an object as in toObject()
,
but don't do any type checking.
Try to parse s as a Java literal using
_parseJavaLiteral()
. Failing that, try to parse
s
as a instance string using
_parseInstanceString()
. If that fails, it throw a
ParseException
.
java.text.ParseException
protected java.lang.Object _parseJavaLiteral(java.lang.String s) throws java.text.ParseException
s
as a Java literal and return the
String
or primitive wrapper that corresponds to it. If
s
cannot be parsed as a Java literal, throw a
ParseException
java.text.ParseException
protected java.lang.Object _parseInstanceString(java.lang.String s) throws java.text.ParseException
s
as a class name. If the class has a static field
named "instance"
, return it. Otherwise, create a new
instance of the class using the default constructor.
java.text.ParseException
protected void _checkType(java.lang.Object obj) throws java.text.ParseException
obj
is an instance of each of the classes in
classArray
. If not, throw a ParseException
.
java.text.ParseException
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |