private void encodeUndeclaredExtensions( IBaseResource theResource, XMLStreamWriter theWriter, List<? extends IBaseExtension<?>> theExtensions, String tagName, boolean theIncludedResource) throws XMLStreamException, DataFormatException { for (IBaseExtension<?> next : theExtensions) { if (next == null) { continue; } theWriter.writeStartElement(tagName); String url = next.getUrl(); theWriter.writeAttribute("url", url); if (next.getValue() != null) { IBaseDatatype value = next.getValue(); RuntimeChildUndeclaredExtensionDefinition extDef = myContext.getRuntimeChildUndeclaredExtensionDefinition(); String childName = extDef.getChildNameByDatatype(value.getClass()); BaseRuntimeElementDefinition<?> childDef; if (childName == null) { childDef = myContext.getElementDefinition(value.getClass()); if (childDef == null) { throw new ConfigurationException( "Unable to encode extension, unrecognized child element type: " + value.getClass().getCanonicalName()); } else { childName = RuntimeChildUndeclaredExtensionDefinition.createExtensionChildName(childDef); } } else { childDef = extDef.getChildElementDefinitionByDatatype(value.getClass()); } encodeChildElementToStreamWriter( theResource, theWriter, value, childName, childDef, null, theIncludedResource); } // child extensions encodeExtensionsIfPresent(theResource, theWriter, next, theIncludedResource); theWriter.writeEndElement(); } }