use of javax.wsdl.extensions.schema.SchemaImport in project cxf by apache.
the class SchemaUtil method addSchema.
private void addSchema(String docBaseURI, Schema schema) {
// String docBaseURI = schema.getDocumentBaseURI();
Element schemaEle = schema.getElement();
if (schemaList.get(docBaseURI) == null) {
schemaList.put(docBaseURI, schemaEle);
} else if (schemaList.get(docBaseURI) != null && schemaList.containsValue(schemaEle)) {
// do nothing
} else {
String tns = schema.getDocumentBaseURI() + "#" + schema.getElement().getAttribute("targetNamespace");
if (schemaList.get(tns) == null) {
schemaList.put(tns, schema.getElement());
}
}
Map<String, List<?>> imports = CastUtils.cast(schema.getImports());
if (imports != null && !imports.isEmpty()) {
for (Map.Entry<String, List<?>> entry : imports.entrySet()) {
String importNamespace = entry.getKey();
List<SchemaImport> schemaImports = CastUtils.cast(entry.getValue());
for (SchemaImport schemaImport : schemaImports) {
Schema tempImport = schemaImport.getReferencedSchema();
String key = schemaImport.getSchemaLocationURI();
if (importNamespace == null && tempImport != null) {
importNamespace = tempImport.getDocumentBaseURI();
}
if (tempImport != null && !catalogResolved.containsKey(key)) {
key = tempImport.getDocumentBaseURI();
}
if (tempImport != null && !isSchemaParsed(key, importNamespace) && !schemaList.containsValue(tempImport.getElement())) {
addSchema(key, tempImport);
}
}
}
}
}
use of javax.wsdl.extensions.schema.SchemaImport in project cxf by apache.
the class ServiceWSDLBuilder method buildTypes.
protected void buildTypes(final Collection<SchemaInfo> schemas, final Map<String, SchemaInfo> imports, final Definition def) {
Types types = def.createTypes();
for (SchemaInfo schemaInfo : schemas) {
Schema schemaImpl = getSchemaImplementation(def);
schemaImpl.setRequired(true);
schemaImpl.setElementType(WSDLConstants.QNAME_SCHEMA);
schemaImpl.setElement(schemaInfo.getElement());
for (XmlSchemaExternal ext : schemaInfo.getSchema().getExternals()) {
if (ext.getSchema() == null) {
continue;
}
if (ext instanceof XmlSchemaImport) {
SchemaImport imp = schemaImpl.createImport();
imp.setNamespaceURI(((XmlSchemaImport) ext).getNamespace());
imp.setSchemaLocationURI(((XmlSchemaImport) ext).getSchemaLocation());
Schema schemaImpl2 = getSchemaImplementation(def);
schemaImpl2.setRequired(true);
schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
try {
schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
} catch (XmlSchemaSerializerException e) {
// ignore
}
imp.setReferencedSchema(schemaImpl2);
schemaImpl.addImport(imp);
} else if (ext instanceof XmlSchemaInclude) {
SchemaReference imp = schemaImpl.createInclude();
imp.setSchemaLocationURI(((XmlSchemaInclude) ext).getSchemaLocation());
Schema schemaImpl2 = getSchemaImplementation(def);
schemaImpl2.setRequired(true);
schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
try {
schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
} catch (XmlSchemaSerializerException e) {
// ignore
}
imp.setReferencedSchema(schemaImpl2);
schemaImpl.addInclude(imp);
} else if (ext instanceof XmlSchemaRedefine) {
SchemaReference imp = schemaImpl.createRedefine();
imp.setSchemaLocationURI(((XmlSchemaRedefine) ext).getSchemaLocation());
Schema schemaImpl2 = getSchemaImplementation(def);
schemaImpl2.setRequired(true);
schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
try {
schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
} catch (XmlSchemaSerializerException e) {
// ignore
}
imp.setReferencedSchema(schemaImpl2);
schemaImpl.addRedefine(imp);
}
}
types.addExtensibilityElement(schemaImpl);
}
def.setTypes(types);
}
use of javax.wsdl.extensions.schema.SchemaImport in project cxf by apache.
the class ServiceWSDLBuilderTest method testXsdImportMultipleSchemas.
@Test
public void testXsdImportMultipleSchemas() throws Exception {
setupWSDL(WSDL_XSD_IMPORT_PATH, true);
Types types = newDef.getTypes();
assertNotNull(types);
Collection<ExtensibilityElement> schemas = CastUtils.cast(types.getExtensibilityElements(), ExtensibilityElement.class);
assertEquals(1, schemas.size());
Schema schema = (Schema) schemas.iterator().next();
assertEquals(1, schema.getImports().values().size());
SchemaImport serviceTypesSchemaImport = getImport(schema.getImports(), "http://apache.org/hello_world_soap_http/servicetypes");
Schema serviceTypesSchema = serviceTypesSchemaImport.getReferencedSchema();
assertEquals(1, serviceTypesSchema.getImports().values().size());
SchemaImport typesSchemaImport = getImport(serviceTypesSchema.getImports(), "http://apache.org/hello_world_soap_http/types");
Schema typesSchema = typesSchemaImport.getReferencedSchema();
Document doc = typesSchema.getElement().getOwnerDocument();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(outputStream, "utf-8");
StaxUtils.writeNode(doc, writer, true);
writer.close();
// this is a test to make sure any embedded namespaces are properly included
String savedSchema = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
assertTrue(savedSchema.contains("http://www.w3.org/2005/05/xmlmime"));
SchemaImport types2SchemaImport = getImport(typesSchema.getImports(), "http://apache.org/hello_world_soap_http/types2");
Schema types2Schema = types2SchemaImport.getReferencedSchema();
assertNotNull(types2Schema);
}
Aggregations