net.sf.jga.parser
Class GenericParser

java.lang.Object
  extended by net.sf.jga.parser.GenericParser
All Implemented Interfaces:
FunctorParser

public class GenericParser
extends java.lang.Object
implements FunctorParser

FunctorParser wrapper that adds runtime type-safe entry points to the non-generified base parser. This class maps between the inherently typeunsafe baseclass and the generic functors that are returned: if the returned functor does not return the correct type, then a ClassCastException will be thrown by the entry point.

Copyright © 2004-2005 David A. Hall

Author:
David A. Hall

Constructor Summary
GenericParser()
           
GenericParser(FunctorParser delegate)
           
 
Method Summary
static GenericParser getInstance()
          Returns a globally accessible default instance of a GenericParser.
 java.lang.Class<?> getReturnType()
          Returns the type of object returned by the last functor parsed.
static
<R> Generator<R>
parse(java.lang.String str, java.lang.Class<R> returnType)
          Parses the string to create a Generator.
static
<T,R> UnaryFunctor<T,R>
parse(java.lang.String str, java.lang.Class<T> argType, java.lang.Class<R> returnType)
          Parses the string to create a UnaryFunctor that takes an argument of the given type.
static
<T1,T2,R> BinaryFunctor<T1,T2,R>
parse(java.lang.String str, java.lang.Class<T1> arg1Type, java.lang.Class<T2> arg2Type, java.lang.Class<R> returnType)
          Parses the string to create a BinaryFunctor that takes arguments of the given types.
<T1,T2> BinaryFunctor<T1,T2,?>
parseBinary(java.lang.String str, java.lang.Class<T1> arg1Type, java.lang.Class<T2> arg2Type)
          Parses the string to create a BinaryFunctor that takes arguments of the given types.
<T1,T2,R> BinaryFunctor<T1,T2,R>
parseBinary(java.lang.String str, java.lang.Class<T1> arg1Type, java.lang.Class<T2> arg2Type, java.lang.Class<R> returnType)
          Parses the string to create a BinaryFunctor that takes arguments of the given types.
<R> Functor<R>
parseFunctor(java.lang.String str, java.lang.Class<R> returnType, java.lang.Class<?>... argTypes)
          Parses the string to create a Functor.
 Generator<?> parseGenerator(java.lang.String str)
          Parses the string to create a Generator.
<R> Generator<R>
parseGenerator(java.lang.String str, java.lang.Class<R> returnType)
          Parses the string to create a Generator.
<T> UnaryFunctor<T,?>
parseUnary(java.lang.String str, java.lang.Class<T> argType)
          Parses the string to create a UnaryFunctor that takes an argument of the given type.
<T,R> UnaryFunctor<T,R>
parseUnary(java.lang.String str, java.lang.Class<T> argType, java.lang.Class<R> returnType)
          Parses the string to create a UnaryFunctor that takes an argument of the given type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericParser

public GenericParser()

GenericParser

public GenericParser(FunctorParser delegate)
Method Detail

getInstance

public static GenericParser getInstance()
Returns a globally accessible default instance of a GenericParser.


parseFunctor

public <R> Functor<R> parseFunctor(java.lang.String str,
                                   java.lang.Class<R> returnType,
                                   java.lang.Class<?>... argTypes)
                        throws java.lang.ClassCastException,
                               ParseException
Parses the string to create a Functor.

Throws:
java.lang.ClassCastException
ParseException

parseGenerator

public <R> Generator<R> parseGenerator(java.lang.String str,
                                       java.lang.Class<R> returnType)
                            throws java.lang.ClassCastException,
                                   ParseException
Parses the string to create a Generator.

Throws:
java.lang.ClassCastException
ParseException

parseUnary

public <T,R> UnaryFunctor<T,R> parseUnary(java.lang.String str,
                                          java.lang.Class<T> argType,
                                          java.lang.Class<R> returnType)
                             throws java.lang.ClassCastException,
                                    ParseException
Parses the string to create a UnaryFunctor that takes an argument of the given type.

Throws:
java.lang.ClassCastException
ParseException

parseBinary

public <T1,T2,R> BinaryFunctor<T1,T2,R> parseBinary(java.lang.String str,
                                                    java.lang.Class<T1> arg1Type,
                                                    java.lang.Class<T2> arg2Type,
                                                    java.lang.Class<R> returnType)
                                   throws java.lang.ClassCastException,
                                          ParseException
Parses the string to create a BinaryFunctor that takes arguments of the given types.

Throws:
java.lang.ClassCastException
ParseException

parseGenerator

public Generator<?> parseGenerator(java.lang.String str)
                            throws ParseException
Parses the string to create a Generator.

Specified by:
parseGenerator in interface FunctorParser
Throws:
ParseException

parseUnary

public <T> UnaryFunctor<T,?> parseUnary(java.lang.String str,
                                        java.lang.Class<T> argType)
                             throws ParseException
Parses the string to create a UnaryFunctor that takes an argument of the given type.

Specified by:
parseUnary in interface FunctorParser
Throws:
ParseException

parseBinary

public <T1,T2> BinaryFunctor<T1,T2,?> parseBinary(java.lang.String str,
                                                  java.lang.Class<T1> arg1Type,
                                                  java.lang.Class<T2> arg2Type)
                                   throws ParseException
Parses the string to create a BinaryFunctor that takes arguments of the given types.

Specified by:
parseBinary in interface FunctorParser
Throws:
ParseException

getReturnType

public java.lang.Class<?> getReturnType()
Returns the type of object returned by the last functor parsed.

Specified by:
getReturnType in interface FunctorParser
Throws:
java.lang.IllegalStateException - if the parser has not been used or if parsing the last functor resulted in an exception being thrown.

parse

public static <R> Generator<R> parse(java.lang.String str,
                                     java.lang.Class<R> returnType)
                          throws UncheckedParseException,
                                 java.lang.ClassCastException
Parses the string to create a Generator.

Throws:
UncheckedParseException
java.lang.ClassCastException

parse

public static <T,R> UnaryFunctor<T,R> parse(java.lang.String str,
                                            java.lang.Class<T> argType,
                                            java.lang.Class<R> returnType)
                               throws UncheckedParseException,
                                      java.lang.ClassCastException
Parses the string to create a UnaryFunctor that takes an argument of the given type.

Throws:
UncheckedParseException
java.lang.ClassCastException

parse

public static <T1,T2,R> BinaryFunctor<T1,T2,R> parse(java.lang.String str,
                                                     java.lang.Class<T1> arg1Type,
                                                     java.lang.Class<T2> arg2Type,
                                                     java.lang.Class<R> returnType)
                                    throws UncheckedParseException,
                                           java.lang.ClassCastException
Parses the string to create a BinaryFunctor that takes arguments of the given types.

Throws:
UncheckedParseException
java.lang.ClassCastException


Copyright © 2002-2006 David A. Hall. All Rights Reserved.