You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2010/10/17 04:26:29 UTC
svn commit: r1023403 - in /cxf/trunk/common/common/src:
main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java
Author: bimargulies
Date: Sun Oct 17 02:26:29 2010
New Revision: 1023403
URL: http://svn.apache.org/viewvc?rev=1023403&view=rev
Log:
Fix some but not all of the issues in testImportRepairs
Modified:
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
cxf/trunk/common/common/src/test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java
Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java?rev=1023403&r1=1023402&r2=1023403&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/xmlschema/SchemaCollection.java Sun Oct 17 02:26:29 2010
@@ -41,7 +41,6 @@ import org.apache.ws.commons.schema.XmlS
import org.apache.ws.commons.schema.XmlSchemaContent;
import org.apache.ws.commons.schema.XmlSchemaContentModel;
import org.apache.ws.commons.schema.XmlSchemaElement;
-import org.apache.ws.commons.schema.XmlSchemaObject;
import org.apache.ws.commons.schema.XmlSchemaParticle;
import org.apache.ws.commons.schema.XmlSchemaSequence;
import org.apache.ws.commons.schema.XmlSchemaSequenceMember;
@@ -53,7 +52,6 @@ import org.apache.ws.commons.schema.reso
import org.apache.ws.commons.schema.utils.NamespaceMap;
import org.apache.ws.commons.schema.utils.NamespacePrefixList;
-
/**
* Wrapper class for XmlSchemaCollection that deals with various quirks and bugs.
*/
@@ -63,7 +61,6 @@ public class SchemaCollection {
private Map<XmlSchema, Set<XmlSchemaType>> xmlTypesCheckedForCrossImportsPerSchema
= new HashMap<XmlSchema, Set<XmlSchemaType>>();
-
public SchemaCollection() {
this(new XmlSchemaCollection());
}
@@ -106,8 +103,7 @@ public class SchemaCollection {
}
public XmlSchemaType getTypeByQName(QName schemaTypeName) {
- XmlSchemaType xst = schemaCollection.getTypeByQName(schemaTypeName);
- return xst;
+ return schemaCollection.getTypeByQName(schemaTypeName);
}
public XmlSchema[] getXmlSchema(String systemId) {
@@ -242,18 +238,15 @@ public class SchemaCollection {
/*
* We need to visit all the top-level items.
*/
- for (XmlSchemaObject item : schema.getItems()) {
- if (item instanceof XmlSchemaElement) {
- addElementCrossImportsElement(schema, (XmlSchemaElement)item);
- } else if (item instanceof XmlSchemaAttribute) {
- XmlSchemaAttribute attr = (XmlSchemaAttribute)item;
- XmlSchemaUtils.addImportIfNeeded(schema, attr.getRef().getTargetQName());
- XmlSchemaUtils.addImportIfNeeded(schema, attr.getSchemaTypeName());
- /* Attributes have simple types and simple types don't have bases. */
- } else if (item instanceof XmlSchemaType) {
- XmlSchemaType type = (XmlSchemaType)item;
- addCrossImportsType(schema, type);
- }
+ for (XmlSchemaElement element : schema.getElements().values()) {
+ addElementCrossImportsElement(schema, element);
+ }
+ for (XmlSchemaAttribute attribute : schema.getAttributes().values()) {
+ XmlSchemaUtils.addImportIfNeeded(schema, attribute.getRef().getTargetQName());
+ XmlSchemaUtils.addImportIfNeeded(schema, attribute.getSchemaTypeName());
+ }
+ for (XmlSchemaType type : schema.getSchemaTypes().values()) {
+ addCrossImportsType(schema, type);
}
}
@@ -269,8 +262,8 @@ public class SchemaCollection {
}
/**
- * Determines whether the schema has already received (cross) imports for
- * the schemaType
+ * Determines whether the schema has already received (cross) imports for the schemaType
+ *
* @param schema
* @param schemaType
* @return false if cross imports for schemaType must still be added to schema
@@ -295,18 +288,15 @@ public class SchemaCollection {
}
private void addCrossImportsType(XmlSchema schema, XmlSchemaType schemaType) {
- if (schemaType != null) {
- // the base type might cross schemas.
-
- if (schemaType instanceof XmlSchemaComplexType) {
- XmlSchemaComplexType complexType = (XmlSchemaComplexType)schemaType;
- XmlSchemaUtils.addImportIfNeeded(schema, complexType.getBaseSchemaTypeName());
- addCrossImports(schema, complexType.getContentModel());
- addCrossImportsAttributeList(schema, complexType.getAttributes());
- // could it be a choice or something else?
- XmlSchemaSequence sequence = XmlSchemaUtils.getSequence(complexType);
- addCrossImportsSequence(schema, sequence);
- }
+ // the base type might cross schemas.
+ if (schemaType instanceof XmlSchemaComplexType) {
+ XmlSchemaComplexType complexType = (XmlSchemaComplexType)schemaType;
+ XmlSchemaUtils.addImportIfNeeded(schema, complexType.getBaseSchemaTypeName());
+ addCrossImports(schema, complexType.getContentModel());
+ addCrossImportsAttributeList(schema, complexType.getAttributes());
+ // could it be a choice or something else?
+ XmlSchemaSequence sequence = XmlSchemaUtils.getSequence(complexType);
+ addCrossImportsSequence(schema, sequence);
}
}
@@ -318,14 +308,13 @@ public class SchemaCollection {
}
}
- private void addCrossImportsAttributeList(XmlSchema schema,
- List<XmlSchemaAttributeOrGroupRef> list) {
+ private void addCrossImportsAttributeList(XmlSchema schema, List<XmlSchemaAttributeOrGroupRef> list) {
for (XmlSchemaAttributeOrGroupRef attr : list) {
QName ref = null;
if (attr instanceof XmlSchemaAttribute) {
ref = ((XmlSchemaAttribute)attr).getRef().getTargetQName();
} else {
- XmlSchemaAttributeGroupRef groupRef = (XmlSchemaAttributeGroupRef) attr;
+ XmlSchemaAttributeGroupRef groupRef = (XmlSchemaAttributeGroupRef)attr;
ref = groupRef.getRef().getTargetQName();
}
@@ -344,7 +333,7 @@ public class SchemaCollection {
return;
}
if (content instanceof XmlSchemaComplexContentExtension) {
- XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension) content;
+ XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content;
XmlSchemaUtils.addImportIfNeeded(schema, extension.getBaseTypeName());
addCrossImportsAttributeList(schema, extension.getAttributes());
XmlSchemaParticle particle = extension.getParticle();
@@ -352,18 +341,18 @@ public class SchemaCollection {
addCrossImportsSequence(schema, (XmlSchemaSequence)particle);
}
} else if (content instanceof XmlSchemaComplexContentRestriction) {
- XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction) content;
+ XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)content;
XmlSchemaUtils.addImportIfNeeded(schema, restriction.getBaseTypeName());
addCrossImportsAttributeList(schema, restriction.getAttributes());
} else if (content instanceof XmlSchemaSimpleContentExtension) {
- XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension) content;
+ XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension)content;
XmlSchemaUtils.addImportIfNeeded(schema, extension.getBaseTypeName());
addCrossImportsAttributeList(schema, extension.getAttributes());
} else if (content instanceof XmlSchemaSimpleContentRestriction) {
- XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) content;
+ XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction)content;
XmlSchemaUtils.addImportIfNeeded(schema, restriction.getBaseTypeName());
addCrossImportsAttributeList(schema, restriction.getAttributes());
}
}
-}
\ No newline at end of file
+}
Modified: cxf/trunk/common/common/src/test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java?rev=1023403&r1=1023402&r2=1023403&view=diff
==============================================================================
--- cxf/trunk/common/common/src/test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java (original)
+++ cxf/trunk/common/common/src/test/java/org/apache/cxf/common/xmlschema/ImportRepairTest.java Sun Oct 17 02:26:29 2010
@@ -27,7 +27,11 @@ import java.util.logging.Logger;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.DOMError;
import org.w3c.dom.DOMErrorHandler;
@@ -37,6 +41,7 @@ import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.XMLUtils;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaAttribute;
import org.apache.ws.commons.schema.XmlSchemaComplexContent;
@@ -131,6 +136,7 @@ public class ImportRepairTest extends As
createAttributeImportingType(importingSchema);
+
/*
* Notice that no imports have been added. In an ideal world, XmlSchema would do this for us.
*/
@@ -157,6 +163,7 @@ public class ImportRepairTest extends As
}
Document document = new XmlSchemaSerializer().serializeSchema(schema, false)[0];
DOMLSInput input = new DOMLSInput(document, schema.getTargetNamespace());
+ dumpSchema(document);
resolverMap.put(schema.getTargetNamespace(), input);
inputs.add(input);
}
@@ -172,7 +179,11 @@ public class ImportRepairTest extends As
schemaLoader.getConfig().setParameter("error-handler", new DOMErrorHandler() {
public boolean handleError(DOMError error) {
- LOG.info("Schema parsing error: " + error.getMessage());
+ LOG.info("Schema parsing error: " + error.getMessage()
+ + " " + error.getType()
+ + " " + error.getLocation().getUri()
+ + " " + error.getLocation().getLineNumber()
+ + ":" + error.getLocation().getColumnNumber());
throw new DOMErrorException(error);
}
});
@@ -187,6 +198,17 @@ public class ImportRepairTest extends As
schemaLoader.loadInputList(new ListLSInput(inputs));
}
+ private void dumpSchema(Document document) {
+ try {
+ Transformer t = XMLUtils.newTransformer(2);
+ t.setOutputProperty(OutputKeys.INDENT, "yes");
+ t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ t.transform(new DOMSource(document), new StreamResult(System.err));
+ } catch (Exception e) {
+ //
+ }
+ }
+
private void createTypeImportedByElement(XmlSchema elementTypeSchema) {
XmlSchemaComplexType elementImportedType = new XmlSchemaComplexType(elementTypeSchema, true);
elementImportedType.setName("importedElementType");