use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.
the class XmlSchemaUtils method addImportIfNeeded.
/**
* Assist in managing the required <import namespace='uri'> for imports of peer schemas.
* @param schema
* @param namespaceUri
*/
public static void addImportIfNeeded(XmlSchema schema, String namespaceUri) {
// no need to import nothing or the XSD schema, or the schema we are fixing.
if ("".equals(namespaceUri) || Constants.URI_2001_SCHEMA_XSD.equals(namespaceUri) || schema.getTargetNamespace().equals(namespaceUri)) {
return;
}
List<XmlSchemaExternal> externals = schema.getExternals();
for (XmlSchemaExternal what : externals) {
if (what instanceof XmlSchemaImport) {
XmlSchemaImport imp = (XmlSchemaImport) what;
// already there.
if (namespaceUri.equals(imp.getNamespace())) {
return;
}
}
}
XmlSchemaImport imp = new XmlSchemaImport(schema);
imp.setNamespace(namespaceUri);
}
use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.
the class WSDLSchemaManager method attachSchemaToWSDL.
public void attachSchemaToWSDL(Definition definition, XmlSchema schema, boolean isSchemaGenerated) throws Exception {
Types types = definition.getTypes();
if (types == null) {
types = definition.createTypes();
definition.setTypes(types);
}
Schema wsdlSchema = (Schema) definition.getExtensionRegistry().createExtension(Types.class, new QName(Constants.URI_2001_SCHEMA_XSD, "schema"));
// See if a NamespaceMap has already been added to the schema (this can be the case with object
// references. If so, simply add the XSD URI to the map. Otherwise, create a new one.
NamespaceMap nsMap = null;
try {
nsMap = (NamespaceMap) schema.getNamespaceContext();
} catch (ClassCastException ex) {
// Consume. This will mean that the context has not been set.
}
if (nsMap == null) {
nsMap = new NamespaceMap();
nsMap.add("xs", Constants.URI_2001_SCHEMA_XSD);
schema.setNamespaceContext(nsMap);
} else {
nsMap.add("xs", Constants.URI_2001_SCHEMA_XSD);
}
if (isSchemaGenerated) {
nsMap.add("tns", schema.getTargetNamespace());
}
org.w3c.dom.Element el = schema.getAllSchemas()[0].getDocumentElement();
wsdlSchema.setElement(el);
for (XmlSchemaExternal ext : schema.getExternals()) {
if (ext instanceof XmlSchemaImport) {
XmlSchemaImport xmlSchemaImport = (XmlSchemaImport) ext;
SchemaImport schemaimport = wsdlSchema.createImport();
schemaimport.setNamespaceURI(xmlSchemaImport.getNamespace());
if (xmlSchemaImport.getSchemaLocation() != null && !ignoreImports) {
schemaimport.setSchemaLocationURI(xmlSchemaImport.getSchemaLocation());
}
wsdlSchema.addImport(schemaimport);
}
}
types.addExtensibilityElement(wsdlSchema);
}
use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.
the class WSDLToCorbaHelper method findTypeInSchema.
private XmlSchemaType findTypeInSchema(XmlSchema xmlSchema, QName typeName) {
XmlSchemaType schemaType = null;
if (xmlSchema.getElementByName(typeName) != null) {
XmlSchemaElement schemaElement = xmlSchema.getElementByName(typeName);
schemaType = schemaElement.getSchemaType();
} else if (xmlSchema.getTypeByName(typeName) != null) {
schemaType = xmlSchema.getTypeByName(typeName);
}
if (schemaType != null) {
return schemaType;
}
for (XmlSchemaExternal extSchema : xmlSchema.getExternals()) {
if (!(extSchema instanceof XmlSchemaImport)) {
schemaType = findTypeInSchema(extSchema.getSchema(), typeName);
if (schemaType != null) {
return schemaType;
}
}
}
return null;
}
use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.
the class WSDLSchemaManager method addXmlSchemaImport.
public void addXmlSchemaImport(XmlSchema rootSchema, XmlSchema schema, File file) {
// Make sure we haven't already imported the schema.
String importNamespace = schema.getTargetNamespace();
boolean included = false;
for (XmlSchemaExternal ext : rootSchema.getExternals()) {
if (ext instanceof XmlSchemaImport) {
XmlSchemaImport imp = (XmlSchemaImport) ext;
if (imp.getNamespace().equals(importNamespace)) {
included = true;
break;
}
}
}
if (!included) {
XmlSchemaImport importSchema = new XmlSchemaImport(rootSchema);
if (!ignoreImports) {
importSchema.setSchemaLocation(file.toURI().toString());
}
importSchema.setNamespace(schema.getTargetNamespace());
}
if (!importedSchemas.containsKey(file)) {
importedSchemas.put(file, schema);
}
}
use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.
the class WSDLParameter method findElement.
// Will check if the schema includes other schemas.
private static XmlSchemaElement findElement(XmlSchema xmlSchema, QName elName) {
XmlSchemaElement schemaElement = null;
schemaElement = xmlSchema.getElementByName(elName);
if (schemaElement == null) {
String prefix = definition.getPrefix(elName.getNamespaceURI());
QName name = new QName(elName.getNamespaceURI(), prefix + ":" + elName.getLocalPart(), prefix);
schemaElement = xmlSchema.getElementByName(name);
}
if (schemaElement != null) {
return schemaElement;
}
for (XmlSchemaExternal ext : xmlSchema.getExternals()) {
if (!(ext instanceof XmlSchemaImport)) {
schemaElement = findElement(ext.getSchema(), elName);
if (schemaElement != null) {
return schemaElement;
}
}
}
return schemaElement;
}
Aggregations