[Practicalxml-commits] SF.net SVN: practicalxml:[63] trunk/src
Brought to you by:
kdgregory
|
From: Auto-Generated S. C. M. <pra...@li...> - 2008-12-29 00:35:20
|
Revision: 63
http://practicalxml.svn.sourceforge.net/practicalxml/?rev=63&view=rev
Author: kdgregory
Date: 2008-12-29 00:35:16 +0000 (Mon, 29 Dec 2008)
Log Message:
-----------
SchemaUtil: combineSchema() renamed, now returns Document[] not Schema
Modified Paths:
--------------
trunk/src/main/java/net/sf/practicalxml/SchemaUtil.java
trunk/src/test/java/net/sf/practicalxml/TestSchemaUtil.java
Modified: trunk/src/main/java/net/sf/practicalxml/SchemaUtil.java
===================================================================
--- trunk/src/main/java/net/sf/practicalxml/SchemaUtil.java 2008-12-28 15:56:10 UTC (rev 62)
+++ trunk/src/main/java/net/sf/practicalxml/SchemaUtil.java 2008-12-29 00:35:16 UTC (rev 63)
@@ -94,12 +94,33 @@
*/
public static Schema newSchema(SchemaFactory factory, InputSource... sources)
{
- Document[] parsed = parseSources(sources);
+ return newSchema(factory, parseSources(sources));
+ }
+
+
+ /**
+ * Compiles one or more DOM documents to produce a <code>Schema</code>
+ * object from the passed factory. This call is synchronized on the
+ * factory, which the JDK 1.5 docs describe as not threadsafe.
+ * <p>
+ * The caller is responsible for ordering the documents so that imported
+ * schemas appear first. This method is unable to combine sources from
+ * the same target namespace; see {@link #combineSchema combineSchema()}
+ * for explanation.
+ *
+ * @param factory Used to create the schema object.
+ * @param sources The source schema documents.
+ *
+ * @throws IllegalArgumentException if invoked without any sources.
+ * @throws XmlException if unable to compile the schema.
+ */
+ public static Schema newSchema(SchemaFactory factory, Document... sources)
+ {
try
{
synchronized (factory)
{
- return factory.newSchema(toDOMSources(parsed));
+ return factory.newSchema(toDOMSources(sources));
}
}
catch (SAXException e)
@@ -110,13 +131,14 @@
/**
- * Parses one or more input sources to produce a <code>Schema</code>
- * object. Unlike {@link #newSchema newSchema()}, this method will
- * combine source documents with the same target namespace (a workaround
- * for <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6198705">
- * JDK 1.5 bug 6198705</a>), order the source documents according to their
- * dependencies, and also remove external location references from <code>
- * <xsd:import></code> elements that reference provided sources.
+ * Parses and combines one or more input sources to produce an array
+ * of DOM documents containing schema components. Will properly order
+ * the output documents based on dependencies, remove any location
+ * references from imports that are satisfied by the sources, and
+ * provides a workaround for the
+ * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6198705">
+ * JDK 1.5 bug</a> that prevents combination of source documents with
+ * the same namespace.
* <p>
* When combining schema documents with the same namespace, all top-level
* attributes (eg, <code>elementFormDefault</code>) come from the first
@@ -129,9 +151,6 @@
* target namespace, any <code>schemaLocation</code> specification will
* be ignored.
*
- * @param factory Used to create the schema object. This factory's
- * <code>ErrorHandler</code> is also used to report
- * errors when parsing the source documents.
* @param sources The source schema documents. Note that these are
* <code>org.xml.sax.InputSource</code> objects for
* consistency with other classes in this library;
@@ -141,23 +160,12 @@
* @throws IllegalArgumentException if invoked without any sources, or if
* a source does not appear to be an XML Schema document (current
* checking is minimal, but that may change).
- * @throws XmlException on any failure that is not handled by the factory's
- * <code>ErrorHandler</code> (including parse errors).
+ * @throws XmlException on any parse error, or if the sources do not
+ * appear to be valid XSD documents.
*/
- public static Schema combineSchema(SchemaFactory factory, InputSource... sources)
+ public static Document[] combineSchemas(InputSource... sources)
{
- SchemaManager manager = new SchemaManager(parseSources(sources));
- try
- {
- synchronized (factory)
- {
- return factory.newSchema(manager.toDOMSources());
- }
- }
- catch (SAXException e)
- {
- throw new XmlException("unable to generate schema", e);
- }
+ return new SchemaManager(parseSources(sources)).buildOutput();
}
@@ -245,7 +253,7 @@
/**
* Returns the ordered set of sources for this manager.
*/
- public DOMSource[] toDOMSources()
+ public Document[] buildOutput()
{
TreeSet<Document> ordered = new TreeSet<Document>(new SchemaComparator());
for (Document doc : _documents.values())
@@ -253,7 +261,7 @@
ordered.add(rebuildImports(doc));
}
- return SchemaUtil.toDOMSources(ordered.toArray(new Document[ordered.size()]));
+ return ordered.toArray(new Document[ordered.size()]);
}
/**
Modified: trunk/src/test/java/net/sf/practicalxml/TestSchemaUtil.java
===================================================================
--- trunk/src/test/java/net/sf/practicalxml/TestSchemaUtil.java 2008-12-28 15:56:10 UTC (rev 62)
+++ trunk/src/test/java/net/sf/practicalxml/TestSchemaUtil.java 2008-12-29 00:35:16 UTC (rev 63)
@@ -208,11 +208,12 @@
+ "<bargle>test</bargle>"
+ "</foo>";
- Schema schema = SchemaUtil.combineSchema(
+ Schema schema = SchemaUtil.newSchema(
SchemaUtil.newFactory(new ExceptionErrorHandler()),
- new InputSource(new StringReader(xsd1)),
- new InputSource(new StringReader(xsd2)),
- new InputSource(new StringReader(xsd3)));
+ SchemaUtil.combineSchemas(
+ new InputSource(new StringReader(xsd1)),
+ new InputSource(new StringReader(xsd2)),
+ new InputSource(new StringReader(xsd3))));
assertNotNull(schema);
ParseUtil.validatingParse(new InputSource(new StringReader(xml)),
@@ -245,10 +246,12 @@
+ "<argle>12</argle>"
+ "</foo>";
- Schema schema = SchemaUtil.combineSchema(
+
+ Schema schema = SchemaUtil.newSchema(
SchemaUtil.newFactory(new ExceptionErrorHandler()),
- new InputSource(new StringReader(xsd1)),
- new InputSource(new StringReader(xsd2)));
+ SchemaUtil.combineSchemas(
+ new InputSource(new StringReader(xsd1)),
+ new InputSource(new StringReader(xsd2))));
assertNotNull(schema);
ParseUtil.validatingParse(new InputSource(new StringReader(xml)),
@@ -296,11 +299,13 @@
+ "</foo>";
// note: these sources are intentionally out-of-order
- Schema schema = SchemaUtil.combineSchema(
+
+ Schema schema = SchemaUtil.newSchema(
SchemaUtil.newFactory(new ExceptionErrorHandler()),
- new InputSource(new StringReader(xsd1)),
- new InputSource(new StringReader(xsd2)),
- new InputSource(new StringReader(xsd3)));
+ SchemaUtil.combineSchemas(
+ new InputSource(new StringReader(xsd1)),
+ new InputSource(new StringReader(xsd2)),
+ new InputSource(new StringReader(xsd3))));
assertNotNull(schema);
ParseUtil.validatingParse(new InputSource(new StringReader(xml)),
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|