net.sf.joost.instruction
Class FactoryBase

java.lang.Object
  extended by net.sf.joost.instruction.FactoryBase
All Implemented Interfaces:
Constants
Direct Known Subclasses:
AnalyzeTextFactory, AssignFactory, AttributeFactory, BufferFactory, CallProcedureFactory, CdataFactory, ChooseFactory, CommentFactory, CopyFactory, DoctypeFactory, ElementEndFactory, ElementFactory, ElementStartFactory, ElseFactory, ForEachFactory, GroupFactory, IfFactory, IncludeFactory, MatchFactory, MessageFactory, NoMatchFactory, NSAliasFactory, OtherwiseFactory, ParamFactory, PAttributesFactory, PBufferFactory, PChildrenFactory, PDocumentFactory, PIFactory, ProcedureFactory, PSelfFactory, PSiblingsFactory, ResultBufferFactory, ResultDocumentFactory, ScriptFactory, TemplateFactory, TextFactory, TransformFactory, ValueOfFactory, VariableFactory, WhenFactory, WhileFactory, WithParamFactory

public abstract class FactoryBase
extends Object
implements Constants

Abstract base class for all factory classes which produce nodes (NodeBase) for the tree representation of an STX transformation sheet.

Version:
$Revision: 2.11 $ $Date: 2007/12/19 10:39:37 $
Author:
Oliver Becker

Field Summary
private static int ATT_STATE
          state for the finite state machine implemented in parseAVT
private static int EXPR_STATE
          state for the finite state machine implemented in parseAVT
private static int LBRACE_STATE
          state for the finite state machine implemented in parseAVT
protected static int NO_VALUE
          Index in YESNO_VALUES
private static int RBRACE_STATE
          state for the finite state machine implemented in parseAVT
private static int STR_STATE
          state for the finite state machine implemented in parseAVT
protected static int YES_VALUE
          Index in YESNO_VALUES
protected static String[] YESNO_VALUES
          Attribute values "yes" and "no"
 
Fields inherited from interface net.sf.joost.Constants
DEBUG, DEFAULT_ENCODING, FEAT_NS, FEAT_NSPREFIX, FEATURE_URI_PREFIX, FUNC_NS, JOOST_EXT_NS, PR_ATTRIBUTES, PR_BUFFER, PR_CHILDREN, PR_CONTINUE, PR_ERROR, PR_SELF, PR_SIBLINGS, STX_NS
 
Constructor Summary
FactoryBase()
           
 
Method Summary
protected static void checkAttributes(String elementName, Attributes attrs, HashSet attNames, ParseContext context)
          Looks for extra attributes and throws an exception if present
abstract  NodeBase createNode(NodeBase parent, String qName, Attributes attrs, ParseContext context)
          The factory method.
protected static int getEnumAttValue(String name, Attributes attrs, String[] enumValues, ParseContext context)
          Looks for the attribute name in attrs and checks if the value is among the values of enumValues.
protected static String getExpandedName(String qName, ParseContext context)
          Parses a qualified name by extracting local name and namespace URI.
abstract  String getName()
           
protected static String getRequiredAttribute(String elementName, Attributes attrs, String name, ParseContext context)
          Looks for the required attribute name in attrs.
protected static Tree parseAVT(String string, ParseContext context)
          Parses an attribute value template (AVT) and creates a Tree (of AVT nodes) which works similar to the concat function.
static Tree parseExpr(String string, ParseContext context)
          Parses the string given in string as an expression
protected static Tree parsePattern(String string, ParseContext context)
          Parses the string given in string as a pattern.
protected static Tree parseRequiredAVT(String elName, Attributes attrs, String attName, ParseContext context)
           
protected static Tree parseRequiredExpr(String elName, Attributes attrs, String attName, ParseContext context)
           
protected static Tree parseRequiredPattern(String elName, Attributes attrs, String attName, ParseContext context)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

YESNO_VALUES

protected static final String[] YESNO_VALUES
Attribute values "yes" and "no"


YES_VALUE

protected static final int YES_VALUE
Index in YESNO_VALUES

See Also:
Constant Field Values

NO_VALUE

protected static final int NO_VALUE
Index in YESNO_VALUES

See Also:
Constant Field Values

ATT_STATE

private static final int ATT_STATE
state for the finite state machine implemented in parseAVT

See Also:
Constant Field Values

LBRACE_STATE

private static final int LBRACE_STATE
state for the finite state machine implemented in parseAVT

See Also:
Constant Field Values

RBRACE_STATE

private static final int RBRACE_STATE
state for the finite state machine implemented in parseAVT

See Also:
Constant Field Values

EXPR_STATE

private static final int EXPR_STATE
state for the finite state machine implemented in parseAVT

See Also:
Constant Field Values

STR_STATE

private static final int STR_STATE
state for the finite state machine implemented in parseAVT

See Also:
Constant Field Values
Constructor Detail

FactoryBase

public FactoryBase()
Method Detail

getName

public abstract String getName()
Returns:
the local name of this STX element

createNode

public abstract NodeBase createNode(NodeBase parent,
                                    String qName,
                                    Attributes attrs,
                                    ParseContext context)
                             throws SAXException
The factory method.

Parameters:
parent - the parent Node
qName - the full name of this node
attrs - the attribute set of this node
context - the parse context
Returns:
an Instance of the appropriate Node
Throws:
SAXParseException - for missing or wrong attributes, etc.
SAXException

getRequiredAttribute

protected static String getRequiredAttribute(String elementName,
                                             Attributes attrs,
                                             String name,
                                             ParseContext context)
                                      throws SAXParseException
Looks for the required attribute name in attrs.

Parameters:
elementName - the name of the parent element
attrs - the attribute set
name - the name of the attribute to look for
context - the parse context
Returns:
the attribute value as a String
Throws:
SAXParseException - if this attribute is not present

getEnumAttValue

protected static int getEnumAttValue(String name,
                                     Attributes attrs,
                                     String[] enumValues,
                                     ParseContext context)
                              throws SAXParseException
Looks for the attribute name in attrs and checks if the value is among the values of enumValues.

Parameters:
name - the name of the attribute to look for
attrs - the attribute set
enumValues - allowed attribute values
context - the parse context
Returns:
the index of the attribute value in enumValues, -1 if the attribute isn't present in attrs
Throws:
SAXParseException - if the attribute value isn't in enumValues

checkAttributes

protected static void checkAttributes(String elementName,
                                      Attributes attrs,
                                      HashSet attNames,
                                      ParseContext context)
                               throws SAXParseException
Looks for extra attributes and throws an exception if present

Parameters:
elementName - the name of the parent element
attrs - the attribute set
attNames - a set of allowed attribute names
context - the parse context
Throws:
SAXParseException - if an attribute was found that is not in attNames

getExpandedName

protected static String getExpandedName(String qName,
                                        ParseContext context)
                                 throws SAXParseException
Parses a qualified name by extracting local name and namespace URI. The result string has the form "{namespace-uri}local-name".

Parameters:
qName - string representing the qualified name
context - the parse context
Throws:
SAXParseException

parsePattern

protected static Tree parsePattern(String string,
                                   ParseContext context)
                            throws SAXParseException
Parses the string given in string as a pattern.

Parameters:
string - the string to be parsed
context - the parse context
Returns:
a Tree representation of the pattern
Throws:
SAXParseException - if a parse error occured

parseRequiredPattern

protected static Tree parseRequiredPattern(String elName,
                                           Attributes attrs,
                                           String attName,
                                           ParseContext context)
                                    throws SAXParseException
Throws:
SAXParseException
See Also:
getRequiredAttribute(String, Attributes, String, ParseContext), parsePattern(String, ParseContext)

parseExpr

public static Tree parseExpr(String string,
                             ParseContext context)
                      throws SAXParseException
Parses the string given in string as an expression

Parameters:
string - the string to be parsed
context - the parse context
Returns:
a Tree representation of the expression or null if string was null
Throws:
SAXParseException - if a parse error occured

parseRequiredExpr

protected static Tree parseRequiredExpr(String elName,
                                        Attributes attrs,
                                        String attName,
                                        ParseContext context)
                                 throws SAXParseException
Throws:
SAXParseException
See Also:
getRequiredAttribute(String, Attributes, String, ParseContext), parseExpr(String, ParseContext)

parseAVT

protected static Tree parseAVT(String string,
                               ParseContext context)
                        throws SAXParseException
Parses an attribute value template (AVT) and creates a Tree (of AVT nodes) which works similar to the concat function.

Parameters:
string - the string to be parsed
context - the parse context
Returns:
a Tree representation of the AVT or null if string was null
Throws:
SAXParseException - if a parse error occured

parseRequiredAVT

protected static Tree parseRequiredAVT(String elName,
                                       Attributes attrs,
                                       String attName,
                                       ParseContext context)
                                throws SAXParseException
Throws:
SAXParseException
See Also:
getRequiredAttribute(String, Attributes, String, ParseContext), parseAVT(String, ParseContext)