[CJ-dev] commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/dynalib DynamicLibraryParser
Brought to you by:
johnqueso
Update of /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/dynalib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2746/src/java/org/commonjava/opl/dynalib Modified Files: DynamicLibraryParser.java DynamicLibraryElements.java DynaLib.java DynamicParserParser.java DynaLibParsingLibrary.java Log Message: updated to 0.2, made method call parameter generation more robust. Index: DynamicLibraryParser.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/dynalib/DynamicLibraryParser.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- DynamicLibraryParser.java 16 Jan 2004 01:37:33 -0000 1.6 +++ DynamicLibraryParser.java 12 Mar 2004 19:46:55 -0000 1.7 @@ -8,69 +8,72 @@ import org.commonjava.opl.OPLContext; import org.commonjava.opl.OPLModelRoot; import org.commonjava.opl.ParseException; + import org.commonjava.util.Strings; -/** Parses a library xml file into a dynamically-instantiated + +/** Parses a library xml file into a dynamically-instantiated * ParserLibrary instance. - * + * * @author John Casey */ -public class DynamicLibraryParser extends NodeParser - implements OPLModelRoot +public class DynamicLibraryParser extends NodeParser implements OPLModelRoot { - private DynaLib library; /** Create a new DynamicLibraryParser. * @param context the parsing context * @param parent the parent parser */ - public DynamicLibraryParser(OPLContext context, NodeParser parent) { + public DynamicLibraryParser(OPLContext context, NodeParser parent) + { super(context, parent); } /** Create a new NodeParser, presumed to be at the root of a parse model. */ - public DynamicLibraryParser(OPLContext context) { + public DynamicLibraryParser(OPLContext context) + { super(context); } - + /** Return the new ParserLibrary. * NOTE: This method overrides getParsedObject * @return the parser library * @see org.commonjava.opl.OPLModelRoot#getParsedObject() */ - public Object getParsedObject() { + public Object getParsedObject() + { return library; } - + /** Register a new NodeParser type with the embedded library. * @param nodeName The name of the node for this parser * @param parserClass The class of parser to use for this node. */ - public void registerParser(String nodeName, Class parserClass){ - + public void registerParser(String nodeName, Class parserClass) + { library.register(nodeName, parserClass); } - + /** Just before we parse the children, determine if we should locally * ignore unrecognized elements in our new parser library, and setup * the library itself. - * + * * NOTE: This method overrides doBeforeChildren * @param node the current node. * @throws ParseException * @see org.commonjava.opl.NodeParser#doBeforeChildren(org.w3c.dom.Node) */ - protected void doBeforeChildren(ElementInfo info) throws ParseException { + protected void doBeforeChildren(ElementInfo info) throws ParseException + { library = new DynaLib(getParserLibrary().getNamespace()); - Boolean ignore = Strings.toBoolean(getAttribute( - DynamicLibraryElements.IGNORE_UNRECOGNIZED_ELEMENTS, info - )); - - if(ignore != null){ + + Boolean ignore = + Strings.toBoolean(getAttribute(DynamicLibraryElements.IGNORE_UNRECOGNIZED_ELEMENTS, info)); + + if(ignore != null) { library.setLocallyIgnoreUnrecognized(ignore.booleanValue()); } } - } Index: DynamicLibraryElements.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/dynalib/DynamicLibraryElements.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- DynamicLibraryElements.java 18 Sep 2003 04:57:09 -0000 1.1 +++ DynamicLibraryElements.java 12 Mar 2004 19:46:55 -0000 1.2 @@ -3,29 +3,32 @@ */ package org.commonjava.opl.dynalib; + /** Parser constants for xml-based parser libraries. - * + * * @author John Casey */ -public final class DynamicLibraryElements { - +public final class DynamicLibraryElements +{ /** A parser library root node. */ public static final String PARSER_LIBRARY = "parser-library"; + /** A parser definition. */ public static final String PARSER = "parser"; + /** A parser's associated node name. */ public static final String NODE_NAME = "node"; + /** The implementation class for the parser. */ public static final String CLASS = "class"; + /** Whether to ignore (pass-through) unrecognized elements. */ public static final String IGNORE_UNRECOGNIZED_ELEMENTS = "ignore-unrecognized"; - + /** The namespace which denotes a dynamic library in XML format. */ public static final String DYNALIB_NAMESPACE = "dynalib"; /** Deny creation */ - private DynamicLibraryElements() { - } - + private DynamicLibraryElements() {} } Index: DynaLib.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/dynalib/DynaLib.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- DynaLib.java 8 Jan 2004 20:35:11 -0000 1.1 +++ DynaLib.java 12 Mar 2004 19:46:55 -0000 1.2 @@ -3,14 +3,14 @@ import org.commonjava.opl.ParserLibrary; - /** Parser library which allows this NodeParser to register new - * parsers for the library. - * - * @author John Casey - */ + +/** Parser library which allows this NodeParser to register new + * parsers for the library. + * + * @author John Casey + */ public class DynaLib extends ParserLibrary { - /** Create a new dynamically-generated ParserLibrary instance * @param namespace The namespace of the library */ @@ -23,7 +23,8 @@ * @param node The node name * @param parserClass The NodeParser class. */ - void register(String node, Class parserClass){ + void register(String node, Class parserClass) + { registerParser(node, parserClass); } } Index: DynamicParserParser.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/dynalib/DynamicParserParser.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- DynamicParserParser.java 16 Jan 2004 01:37:33 -0000 1.6 +++ DynamicParserParser.java 12 Mar 2004 19:46:55 -0000 1.7 @@ -8,17 +8,19 @@ import org.commonjava.opl.OPLContext; import org.commonjava.opl.ParseException; + /** Parse a new NodeParser registration into a dynamically- * created parser library. - * + * * @author John Casey */ -public class DynamicParserParser extends NodeParser{ - +public class DynamicParserParser extends NodeParser +{ /** Create a new DynamicParserParser * @param context the context in which this parser acts. */ - public DynamicParserParser(OPLContext context) { + public DynamicParserParser(OPLContext context) + { super(context); addRequiredAttribute(DynamicLibraryElements.NODE_NAME); addRequiredAttribute(DynamicLibraryElements.CLASS); @@ -28,40 +30,41 @@ * @param context the context in which this parser acts. * @param parent The parent of this parser. */ - public DynamicParserParser(OPLContext context, NodeParser parent) { + public DynamicParserParser(OPLContext context, NodeParser parent) + { super(context, parent); addRequiredAttribute(DynamicLibraryElements.NODE_NAME); addRequiredAttribute(DynamicLibraryElements.CLASS); } - - /** Register the parser contained within this node with the + + /** Register the parser contained within this node with the * DynamicLibraryParser ancestor of this parser. * NOTE: This method overrides doAfterChildren * @param node The node to parse - * @throws ParseException in case of invalid data within the node or + * @throws ParseException in case of invalid data within the node or * parse-tree structure. * @see org.commonjava.opl.NodeParser#doAfterChildren(org.w3c.dom.Node) */ - protected void doAfterChildren(ElementInfo info, String body) throws ParseException { + protected void doAfterChildren(ElementInfo info, String body) + throws ParseException + { try { String nodeName = getAttribute(DynamicLibraryElements.NODE_NAME, info); String className = getAttribute(DynamicLibraryElements.CLASS, info); - + Class implCls = Class.forName(className); - - DynamicLibraryParser dynalib = (DynamicLibraryParser)findAncestorOfType( - DynamicLibraryParser.class - ); - - if(dynalib == null){ + + DynamicLibraryParser dynalib = + (DynamicLibraryParser)findAncestorOfType(DynamicLibraryParser.class); + + if(dynalib == null) { throw new ParseException("No DynamicLibraryParser ancestor found."); } - + dynalib.registerParser(nodeName, implCls); } - catch (ClassNotFoundException e) { + catch(ClassNotFoundException e) { throw new ParseException("Cannot load parser implementation class.", e); } } - } Index: DynaLibParsingLibrary.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/dynalib/DynaLibParsingLibrary.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- DynaLibParsingLibrary.java 18 Sep 2003 04:57:09 -0000 1.1 +++ DynaLibParsingLibrary.java 12 Mar 2004 19:46:55 -0000 1.2 @@ -5,35 +5,30 @@ import org.commonjava.opl.ParserLibrary; + /** ParserLibrary used to parse dynalib config xml files. * These files are used to dynamically build a parser library * from a set of parser classes (in the classpath), along with * an XML file in META-INF/parsers/<lib-namespace>.opl - * - * Specification for use of such a dynalib is a namespace which + * + * Specification for use of such a dynalib is a namespace which * matches the pattern "opl:<i>dynalib-parser-file</i>)". - * + * * @author John Casey */ -public class DynaLibParsingLibrary extends ParserLibrary { - +public class DynaLibParsingLibrary extends ParserLibrary +{ /** Create a new DynaLibParsingLibrary, for parsing dynalib * dynamic parser library xml configuration files. - * + * * @param namespace The namespace of this library. */ - public DynaLibParsingLibrary(String namespace) { + public DynaLibParsingLibrary(String namespace) + { super(namespace); - - registerParser( - DynamicLibraryElements.PARSER_LIBRARY, - DynamicLibraryParser.class - ); - - registerParser( - DynamicLibraryElements.PARSER, - DynamicParserParser.class - ); - } + registerParser(DynamicLibraryElements.PARSER_LIBRARY, DynamicLibraryParser.class); + + registerParser(DynamicLibraryElements.PARSER, DynamicParserParser.class); + } } |