- if (childSchema instanceof ContainerSchemaNode) {
- Preconditions.checkState(child instanceof CompositeNode,
- "Data representation of Container should be CompositeNode - " + child.getNodeType());
- writeContainer(writer, (CompositeNode) child, (ContainerSchemaNode) childSchema);
- } else if (childSchema instanceof ListSchemaNode) {
- if (!foundLists.contains(childSchema)) {
- Preconditions.checkState(child instanceof CompositeNode,
- "Data representation of List should be CompositeNode - " + child.getNodeType());
- foundLists.add((ListSchemaNode) childSchema);
- writeList(writer, parent, (CompositeNode) child, (ListSchemaNode) childSchema);
+ if (childSchema == null) {
+ // Node may not conform to schema or allows "anyxml" - we'll process it.
+
+ LOG.debug("No schema found for data node \"{}\"", child.getNodeType());
+
+ if( !foundLists.contains( child.getNodeType() ) ) {
+ handleNoSchemaFound( writer, child, parent );
+
+ // Since we don't have a schema, we don't know which nodes are supposed to be
+ // lists so treat every one as a potential list to avoid outputting duplicates.
+
+ foundLists.add( child.getNodeType() );
+ }
+ }
+ else if (childSchema instanceof ContainerSchemaNode) {
+ Preconditions.checkState(child instanceof CompositeNode,
+ "Data representation of Container should be CompositeNode - %s", child.getNodeType());
+ writeContainer(writer, (CompositeNode) child, (ContainerSchemaNode) childSchema);
+ } else if (childSchema instanceof ListSchemaNode) {
+ if (!foundLists.contains( child.getNodeType() ) ) {
+ Preconditions.checkState(child instanceof CompositeNode,
+ "Data representation of List should be CompositeNode - %s", child.getNodeType());
+ foundLists.add( child.getNodeType() );
+ writeList(writer, parent, (CompositeNode) child, (ListSchemaNode) childSchema);
+ }
+ } else if (childSchema instanceof LeafListSchemaNode) {
+ if (!foundLists.contains( child.getNodeType() ) ) {
+ Preconditions.checkState(child instanceof SimpleNode<?>,
+ "Data representation of LeafList should be SimpleNode - %s", child.getNodeType());
+ foundLists.add( child.getNodeType() );
+ writeLeafList(writer, parent, (SimpleNode<?>) child, (LeafListSchemaNode) childSchema);
+ }
+ } else if (childSchema instanceof LeafSchemaNode) {
+ Preconditions.checkState(child instanceof SimpleNode<?>,
+ "Data representation of LeafList should be SimpleNode - %s", child.getNodeType());
+ writeLeaf(writer, (SimpleNode<?>) child, (LeafSchemaNode) childSchema);
+ } else if (childSchema instanceof AnyXmlSchemaNode) {
+ if( child instanceof CompositeNode ) {
+ writeContainer(writer, (CompositeNode) child, null);
+ }
+ else {
+ handleNoSchemaFound( writer, child, parent );
+ }
+ } else {
+ throw new UnsupportedDataTypeException("Schema can be ContainerSchemaNode, ListSchemaNode, "
+ + "LeafListSchemaNode, or LeafSchemaNode. Other types are not supported yet.");
+ }