FileDocCategorySizeDatePackage
ParserFactory.javaAPI DocphoneME MR2 API (J2ME)4118Wed May 02 18:00:42 BST 2007gov.nist.javax.sdp.parser

ParserFactory

public class ParserFactory extends Object
Factory for creating parsers for the SDP stuff.
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
private static Hashtable
parserTable
Current parser table.
private static Class[]
constructorArgs
Parameters for instantiating the parser.
private static final String
packageName
the PArser classname.
Constructors Summary
Methods Summary
public static SDPParsercreateParser(java.lang.String field)
Factory method to create a parser engine.

param
field the name of the next field to parse
return
the handle to the SDP parsing engine

	constructorArgs = new Class[1];
	constructorArgs[0] = new String().getClass();
	parserTable = new Hashtable();
	parserTable.put("a", getParser("AttributeFieldParser"));
	parserTable.put("b", getParser("BandwidthFieldParser"));
	parserTable.put("c", getParser("ConnectionFieldParser"));
	parserTable.put("e", getParser("EmailFieldParser"));
	parserTable.put("i", getParser("InformationFieldParser"));
	parserTable.put("k", getParser("KeyFieldParser"));
	parserTable.put("m", getParser("MediaFieldParser"));
	parserTable.put("o", getParser("OriginFieldParser"));
	parserTable.put("p", getParser("PhoneFieldParser"));
	parserTable.put("v", getParser("ProtoVersionFieldParser"));
	parserTable.put("r", getParser("RepeatFieldParser"));
	parserTable.put("s", getParser("SessionNameFieldParser"));
	parserTable.put("t", getParser("TimeFieldParser"));
	parserTable.put("u", getParser("URIFieldParser"));
	parserTable.put("z", getParser("ZoneFieldParser"));
    
	String fieldName = Lexer.getFieldName(field);
	if (fieldName == null)
	    return null;
	Class parserClass = 
	    (Class) parserTable.get(fieldName.toLowerCase());
            
	if (parserClass != null) {
        Exception ex = null;
	    try {
    		SDPParser retval = (SDPParser) parserClass.newInstance();
    		retval.setField(field);
    		return retval;
        } catch (InstantiationException ie) {
            ex = ie;
        } catch (IllegalAccessException iae) {
            ex = iae;
        }
        if (ex != null) {
            // print system message and exit
            InternalErrorHandler.handleException(ex);
            return null;
        }
	} else
	    throw new ParseException
		("Could not find parser for " + fieldName, 0);
    
private static java.lang.ClassgetParser(java.lang.String parserClass)
Factory method to get the parser class.

param
parserClass the name of the parser class.
return
handle to parser engine


                             
         
	try {
	    return Class.forName(packageName + "." + parserClass);
	} catch (ClassNotFoundException ex) {
	    System.out.println("Could not find class");
	    ex.printStackTrace();
	    System.exit(0);
	    return null; // dummy
	}