Thread: [CJ-dev] commonjava-projects/commonjava-opl/src/java/org/commonjava/opl NodeParser.java,1.13,1.14 OP
Brought to you by:
johnqueso
From: <joh...@co...> - 2004-02-18 06:21:30
|
Update of /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26618/src/java/org/commonjava/opl Modified Files: NodeParser.java OPLContext.java GenericNamespaceResolver.java OPLEngine.java OPLDriver.java SAXDriver.java DocumentDriver.java Log Message: updated documentation in project.xml files, and added functionality to: Console: - provide convenient way to prompt the user for more information Config: - Provide snap-in container stacking, or scoping - Provide a JBoss service implementation of a snap-in container Probably other things, but I don't honestly remember everything... Index: NodeParser.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/NodeParser.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- NodeParser.java 16 Jan 2004 01:37:33 -0000 1.13 +++ NodeParser.java 18 Feb 2004 06:12:10 -0000 1.14 @@ -422,7 +422,7 @@ mergedProperties = parent.getAccumulatedProperties(); } else{ - mergedProperties = new Properties(); + mergedProperties = new Properties(System.getProperties()); } if(this instanceof PropertiesContainer){ Index: OPLContext.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/OPLContext.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- OPLContext.java 9 Jan 2004 05:07:43 -0000 1.5 +++ OPLContext.java 18 Feb 2004 06:12:10 -0000 1.6 @@ -9,6 +9,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.commonjava.io.IOFactory; import org.commonjava.io.IOResource; import org.commonjava.opl.dynalib.DynaLibParsingLibrary; @@ -22,6 +24,8 @@ */ public class OPLContext { + private static final Log LOG = LogFactory.getLog(OPLContext.class); + private static final String DYNALIB_NS = "dynalib"; private static final Pattern OPL_DYNALIB_NS_PATTERN = Pattern.compile("opl:(.+)"); @@ -94,6 +98,10 @@ throws NoSuchLibraryException, LibraryConfigurationException, NoSuchParserException, ParserConfigurationException { + if (LOG.isTraceEnabled()) { + LOG.trace("Loading parser for node: \'" + nodeName + "\' in namespace: \'" + namespace + "\'"); + } + ParserLibrary library = null; synchronized(this){ @@ -187,9 +195,18 @@ private ParserLibrary loadLibrary(String namespace) throws NoSuchLibraryException, LibraryConfigurationException { + if (LOG.isTraceEnabled()) { + LOG.trace("loading library for namespace: \'" + namespace + "\'"); + } + Matcher matcher = OPL_DYNALIB_NS_PATTERN.matcher(namespace); - if(namespace.matches(DYNALIB_NS)){ + if(namespace == null){ + throw new NoSuchLibraryException( + "Null namespaces are not allowed. You may need to use a NamespaceResolver." + ); + } + else if(DYNALIB_NS.equals(namespace)){ synchronized(namespace.intern()){ if(dynalibParseLib == null){ dynalibParseLib = new DynaLibParsingLibrary(namespace); Index: GenericNamespaceResolver.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/GenericNamespaceResolver.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- GenericNamespaceResolver.java 9 Jan 2004 05:07:43 -0000 1.2 +++ GenericNamespaceResolver.java 18 Feb 2004 06:12:10 -0000 1.3 @@ -55,7 +55,6 @@ * @return the result of the [recursive] lookup */ private String _lookup(String namespace){ - System.out.println("looking up: " + namespace); if(namespace == null){return null;} String result = namespaceMappings.getProperty(namespace); Index: OPLEngine.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/OPLEngine.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- OPLEngine.java 10 Oct 2003 00:15:46 -0000 1.4 +++ OPLEngine.java 18 Feb 2004 06:12:10 -0000 1.5 @@ -6,6 +6,7 @@ import java.io.InputStream; import org.w3c.dom.Document; +import org.w3c.dom.Node; import org.xml.sax.InputSource; /** Engine which drives the parsing of some XML data into @@ -58,6 +59,14 @@ return driver.parse(new OPLContext(ignoreUnrecognized), document); } + public Object parse(Node node) throws ParseException{ + return driver.parse(new OPLContext(), node); + } + + public Object parse(Node node, boolean ignoreUnrecognized) throws ParseException{ + return driver.parse(new OPLContext(ignoreUnrecognized), node); + } + public Object parse(String uri) throws ParseException{ return driver.parse(new OPLContext(), uri); } Index: OPLDriver.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/OPLDriver.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- OPLDriver.java 16 Jan 2004 01:37:33 -0000 1.4 +++ OPLDriver.java 18 Feb 2004 06:12:10 -0000 1.5 @@ -7,6 +7,7 @@ import java.io.InputStream; import org.w3c.dom.Document; +import org.w3c.dom.Node; import org.xml.sax.InputSource; /** Driver used to fire OPL events to the current NodeParser, bind parsing @@ -39,4 +40,8 @@ public Object parse(OPLContext context, Document document) throws MissingAttributeException, ParseException; + // TODO Document + public Object parse(OPLContext context, Node node) + throws MissingAttributeException, ParseException; + } Index: SAXDriver.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/SAXDriver.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- SAXDriver.java 16 Jan 2004 01:37:33 -0000 1.8 +++ SAXDriver.java 18 Feb 2004 06:12:10 -0000 1.9 @@ -10,6 +10,8 @@ import java.util.Properties; import java.util.Stack; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -17,6 +19,7 @@ import org.commonjava.io.IOFactory; import org.commonjava.io.IOResource; import org.w3c.dom.Document; +import org.w3c.dom.Node; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -147,6 +150,39 @@ return parseInternal(new InputSource(bain)); } + /** Parse the XML content in the specified DOM node object, and return the + * resulting object. This is NOT efficient for this type of driver, it is + * merely provided for (a)consistency, and (b)those developers who find + * themselves painted into a corner as far as driver choice. + * + * @param context the parsing context + * @param node the DOM node to wrap in a document, serialize and then re-parse (ick!) + * @param ignoreUnrecognized whether to ignore unrecognized element types. + * @return the parsed object + * @throws ParseException + * @see org.commonjava.opl.OPLDriver#parse(org.commonjava.opl.OPLContext, org.w3c.dom.Document, boolean) + */ + public Object parse(OPLContext context, Node node) + throws MissingAttributeException, ParseException + { + this.context = context; + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + + DocumentBuilder builder = null; + try {builder = factory.newDocumentBuilder();} + catch (ParserConfigurationException e) { + throw new ParseException("Error creating document builder to wrap node.", e); + } + + Document document = builder.newDocument(); + document.appendChild(node); + ByteArrayInputStream bain = new ByteArrayInputStream( + document.toString().getBytes() + ); + + return parseInternal(new InputSource(bain)); + } + /** Parse the XML content on the specified SAX input source, and return the * resulting object. * @param in the input source Index: DocumentDriver.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/DocumentDriver.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- DocumentDriver.java 16 Jan 2004 01:37:33 -0000 1.10 +++ DocumentDriver.java 18 Feb 2004 06:12:10 -0000 1.11 @@ -31,6 +31,8 @@ */ public class DocumentDriver implements OPLDriver { + private static final Log LOG = LogFactory.getLog(DocumentDriver.class); + private static DocumentBuilderFactory FACTORY; private NodeParser parent; @@ -70,7 +72,7 @@ try { DocumentBuilder builder = FACTORY.newDocumentBuilder(); Document document = builder.parse(in); - return parseInternal(context, document); + return parseInternal(context, document.getDocumentElement()); } catch (ParserConfigurationException e) { throw new ParseException("Mis-configured JAXP.", e); @@ -106,7 +108,7 @@ Document document = builder.parse(resource.getInputStream()); resource.close(); - return parseInternal(context, document); + return parseInternal(context, document.getDocumentElement()); } catch (ParserConfigurationException e) { throw new ParseException("Mis-configured JAXP.", e); @@ -138,7 +140,7 @@ try { DocumentBuilder builder = FACTORY.newDocumentBuilder(); Document document = builder.parse(in); - return parseInternal(context, document); + return parseInternal(context, document.getDocumentElement()); } catch (ParserConfigurationException e) { throw new ParseException("Mis-configured JAXP.", e); @@ -164,7 +166,23 @@ public Object parse(OPLContext context, Document document) throws MissingAttributeException, ParseException { - return parseInternal(context, document); + return parseInternal(context, document.getDocumentElement()); + } + + /** Parse the XML content in the specified document object, and return the + * resulting object. + * + * @param context the parsing context + * @param document the DOM document to parse + * @param ignoreUnrecognized whether to ignore unrecognized element types. + * @return the parsed object + * @throws ParseException + * @see org.commonjava.opl.OPLDriver#parse(org.commonjava.opl.OPLContext, org.w3c.dom.Document, boolean) + */ + public Object parse(OPLContext context, Node node) + throws MissingAttributeException, ParseException + { + return parseInternal(context, node); } /** Traverse all elements in the specified document, building an object tree @@ -179,10 +197,26 @@ * @throws ParseException * @see org.commonjava.opl.OPLDriver#parse(java.io.InputStream, boolean) */ - private Object parseInternal(OPLContext context, Document document) + private Object parseInternal(OPLContext context, Node root) throws MissingAttributeException, ParseException { - Node root = document.getDocumentElement(); + if (LOG.isTraceEnabled()) { + LOG.trace("Root node is: " + root); + } + + if(root == null){ + throw new ParseException("Root configuration node is null. Parsing aborted."); + } + + if (LOG.isTraceEnabled()) { + LOG.trace( + "Root namespace is: \'" + root.getNamespaceURI() + "\'\n" + + "Root local name is: \'" + root.getLocalName() + "\'\n" + + "Root parent is: " + parent + "\n" + + "Root node name is: \'" + root.getNodeName() + "\'" + ); + } + NodeParser rootParser = null; if(parent != null) { rootParser = context.newParser( |