SmartFrog 3.10.000

org.smartfrog.sfcore.languages.sf
Class SFParser

java.lang.Object
  extended by org.smartfrog.sfcore.languages.sf.SFParser
All Implemented Interfaces:
StreamLanguageParser

public class SFParser
extends java.lang.Object
implements StreamLanguageParser

Implements the default Parser interface for SmartFrog parsers. This implementation uses DefaultParser (generated by sfparser.jj) to parse SmartFrog syntax. The getParser utility method will use the org.smartfrog.sfcore.parser.parserClass attribute to construct an instance of a Parser interface with as default this class. This allows different implementations of the parser. Note that a different implementation of the parser will also mean that the default include handler will need to be subclasses and changed since it uses the DefaultParser to parse include files


Field Summary
static java.lang.String defaultSFFactoryClass
          Default SF parser factory class
static java.lang.String defaultSFIncludeHandlerClass
          Default SF parser Include Handler class
protected static Factory factory
          Constructs a factory using the factoryClass (prepended by propBase) system property.
protected static java.lang.Class factoryClass
          Stores the class for the factory.
static java.lang.String factoryClassName
          Factory class name system property key.
protected static java.lang.Class includeHandlerClass
          Stores the class for the include handler.
static java.lang.String includeHandlerClassName
          include handler class name system property key.
 
Constructor Summary
SFParser()
          Constructor for getParser to be able to construct an instance of this parser.
 
Method Summary
static SFComponentDescription componentFactory(java.lang.String componentType)
          Generate a componentDescription node for the tree given the name of the type of the tree node.
static Factory getFactory()
          Gets the factory attribute of the SFParser class.
static IncludeHandler getIncludeHandler(java.lang.String codebase)
          Constructs an includehandler using the includeHandlerClass (prepended by propBase) system property.
 Phases sfParse(java.io.InputStream is)
          Parse an input stream.
 Phases sfParse(java.io.InputStream is, IncludeHandler handler)
          Parse an input stream.
 Phases sfParse(java.io.InputStream is, java.lang.String codebase)
          Parse an input stream.
 java.lang.Object sfParseAnyValue(java.io.InputStream is)
          Parses any value (ie as allowed in an attribute definition) from given string.
 java.lang.Object sfParsePrimitiveValue(java.io.InputStream is)
          Parses any primtiive value (ie no links, component descriptions) from given string.
 ReferencePhases sfParseReference(java.io.InputStream is)
          Parses a reference from given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultSFFactoryClass

public static final java.lang.String defaultSFFactoryClass
Default SF parser factory class

See Also:
Constant Field Values

defaultSFIncludeHandlerClass

public static final java.lang.String defaultSFIncludeHandlerClass
Default SF parser Include Handler class

See Also:
Constant Field Values

factoryClassName

public static java.lang.String factoryClassName
Factory class name system property key. This is the propBase + componentFactoryClass. This sets the parser to construct when getParser is called. Default is an instance of this class.


includeHandlerClassName

public static java.lang.String includeHandlerClassName
include handler class name system property key. This is the propBase + includeHandlerClass. This sets the include handler to construct when getIncludeHandler is called. Default is an instance of DefaultIncludeHandler class.


factoryClass

protected static java.lang.Class factoryClass
Stores the class for the factory.


includeHandlerClass

protected static java.lang.Class includeHandlerClass
Stores the class for the include handler.


factory

protected static Factory factory
Constructs a factory using the factoryClass (prepended by propBase) system property.

Constructor Detail

SFParser

public SFParser()
Constructor for getParser to be able to construct an instance of this parser.

Method Detail

getIncludeHandler

public static IncludeHandler getIncludeHandler(java.lang.String codebase)
                                        throws java.lang.Exception
Constructs an includehandler using the includeHandlerClass (prepended by propBase) system property.

Parameters:
codebase - an optional codebase where the include may be found. If null, use the default code base
Returns:
new include handler
Throws:
java.lang.Exception - failed to construct handler

getFactory

public static Factory getFactory()
                          throws ParseException
Gets the factory attribute of the SFParser class.

Returns:
The factory value
Throws:
ParseException - error creating factory class

componentFactory

public static SFComponentDescription componentFactory(java.lang.String componentType)
                                               throws ParseException
Generate a componentDescription node for the tree given the name of the type of the tree node.

Parameters:
componentType - type of the node component
Returns:
tree node
Throws:
ParseException - non existant component type

sfParse

public Phases sfParse(java.io.InputStream is,
                      IncludeHandler handler)
               throws SmartFrogParseException
Parse an input stream. Creates a DefaultParser and a root component description and uses the Attributes rule in the DefaultParser to fill in the root. Inlcudes are handled by the given include handler.

Parameters:
is - input stream to parse
handler - include handler
Returns:
root description with parsed attributes
Throws:
SmartFrogParseException - failure while parsing

sfParse

public Phases sfParse(java.io.InputStream is)
               throws SmartFrogParseException
Parse an input stream. Forwards to the expanded parse method with the result of getIncludeHandler.

Specified by:
sfParse in interface StreamLanguageParser
Parameters:
is - input stream to parse
Returns:
root description with parsed attributes
Throws:
SmartFrogParseException - failure while parsing

sfParse

public Phases sfParse(java.io.InputStream is,
                      java.lang.String codebase)
               throws SmartFrogParseException
Parse an input stream. Forwards to the expanded parse method with the result of getIncludeHandler.

Specified by:
sfParse in interface StreamLanguageParser
Parameters:
is - input stream to parse
codebase - an optional codebase where the include may be found. If null, use the default code base
Returns:
root description with parsed attributes
Throws:
SmartFrogParseException - failure while parsing

sfParseReference

public ReferencePhases sfParseReference(java.io.InputStream is)
                                 throws SmartFrogParseException
Parses a reference from given string. This is NOT a cheap method since a new DefaultParser will be constructed to create the reference.

Specified by:
sfParseReference in interface StreamLanguageParser
Parameters:
is - input stream to parse
Returns:
parsed reference
Throws:
SmartFrogParseException - failure while parsing reference

sfParseAnyValue

public java.lang.Object sfParseAnyValue(java.io.InputStream is)
                                 throws SmartFrogParseException
Parses any value (ie as allowed in an attribute definition) from given string. This is NOT a cheap method since a new DefaultParser will be constructed to create the reference.

Specified by:
sfParseAnyValue in interface StreamLanguageParser
Parameters:
is - input stream to parse
Returns:
parsed value
Throws:
SmartFrogParseException - failure while parsing value

sfParsePrimitiveValue

public java.lang.Object sfParsePrimitiveValue(java.io.InputStream is)
                                       throws SmartFrogParseException
Parses any primtiive value (ie no links, component descriptions) from given string. This is NOT a cheap method since a new DefaultParser will be constructed to create the reference.

Specified by:
sfParsePrimitiveValue in interface StreamLanguageParser
Parameters:
is - input stream to parse
Returns:
parsed value
Throws:
SmartFrogParseException - failure while parsing primitive value

SmartFrog CORE 3.10.000

(C) Copyright 1998-2006 Hewlett-Packard Development Company, LP