use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.
the class WSDLParameter method findSchemaType.
// This willl search the current schemas and any included
// schemas for the schema type.
private static XmlSchemaType findSchemaType(XmlSchema xmlSchema, QName typeName) {
XmlSchemaType schemaType = xmlSchema.getTypeByName(typeName);
if (schemaType == null) {
for (XmlSchemaExternal ext : xmlSchema.getExternals()) {
if (ext instanceof XmlSchemaImport) {
XmlSchemaImport xmlImport = (XmlSchemaImport) ext;
if (xmlImport.getNamespace().equals(typeName.getNamespaceURI())) {
XmlSchema importSchema = xmlImport.getSchema();
schemaType = importSchema.getTypeByName(typeName);
} else {
schemaType = findSchemaType(ext.getSchema(), typeName);
if (schemaType != null) {
return schemaType;
}
}
}
}
if (schemaType != null) {
return schemaType;
}
}
return schemaType;
}
use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.
the class ObjectReferenceVisitor method addWSAddressingImport.
private void addWSAddressingImport(XmlSchema s) {
boolean alreadyImported = false;
for (XmlSchemaExternal ext : s.getExternals()) {
if (ext instanceof XmlSchemaImport) {
XmlSchemaImport schemaImport = (XmlSchemaImport) ext;
if (schemaImport.getNamespace().equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
alreadyImported = true;
break;
}
}
}
if (!alreadyImported) {
// We need to add an import statement to include the WS addressing types
XmlSchemaImport wsaImport = new XmlSchemaImport(s);
wsaImport.setNamespace(ReferenceConstants.WSADDRESSING_NAMESPACE);
wsaImport.setSchemaLocation(ReferenceConstants.WSADDRESSING_LOCATION);
}
// Add the addressing namespace to the WSDLs list of namespaces.
definition.addNamespace(ReferenceConstants.WSADDRESSING_PREFIX, ReferenceConstants.WSADDRESSING_NAMESPACE);
try {
// This is used to get the correct prefix in the schema section of
// the wsdl. If we don't have this, then this namespace gets an
// arbitrary prefix (e.g. ns5 instead of wsa).
NamespaceMap nsMap = (NamespaceMap) s.getNamespaceContext();
if (nsMap == null) {
nsMap = new NamespaceMap();
nsMap.add(ReferenceConstants.WSADDRESSING_PREFIX, ReferenceConstants.WSADDRESSING_NAMESPACE);
s.setNamespaceContext(nsMap);
} else {
nsMap.add(ReferenceConstants.WSADDRESSING_PREFIX, ReferenceConstants.WSADDRESSING_NAMESPACE);
}
} catch (ClassCastException ex) {
// Consume the exception. It is still OK with the default prefix,
// just not as clear.
}
}
use of org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.
the class ParamDeferredAction method execute.
public void execute(XmlSchemaType stype, CorbaTypeImpl ctype) {
if (param != null) {
param.setIdltype(ctype.getQName());
}
if (element != null) {
element.setSchemaTypeName(stype.getQName());
if (stype.getQName().equals(ReferenceConstants.WSADDRESSING_TYPE)) {
element.setNillable(true);
}
if (manager == null) {
return;
}
// Now we need to make sure we are importing any types we need
XmlSchema importedSchema = null;
if (stype.getQName().getNamespaceURI().equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
boolean alreadyImported = false;
for (XmlSchemaExternal ext : schema.getExternals()) {
if (ext instanceof XmlSchemaImport) {
XmlSchemaImport schemaImport = (XmlSchemaImport) ext;
if (schemaImport.getNamespace().equals(ReferenceConstants.WSADDRESSING_NAMESPACE)) {
alreadyImported = true;
break;
}
}
}
if (!alreadyImported) {
// We need to add an import statement to include the WS addressing types
XmlSchemaImport wsaImport = new XmlSchemaImport(schema);
wsaImport.setNamespace(ReferenceConstants.WSADDRESSING_NAMESPACE);
wsaImport.setSchemaLocation(ReferenceConstants.WSADDRESSING_LOCATION);
}
} else if (!stype.getQName().getNamespaceURI().equals(schema.getTargetNamespace())) {
importedSchema = manager.getXmlSchema(mapper.map(typeScope));
manager.addXmlSchemaImport(schema, importedSchema, typeScope.toString("_"));
}
}
}
use of org.apache.ws.commons.schema.XmlSchemaImport 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 org.apache.ws.commons.schema.XmlSchemaImport in project cxf by apache.
the class ReflectionServiceFactoryBean method addImport.
private void addImport(XmlSchema schema, String ns) {
if (!ns.equals(schema.getTargetNamespace()) && !ns.equals(WSDLConstants.NS_SCHEMA_XSD) && !isExistImport(schema, ns)) {
XmlSchemaImport is = new XmlSchemaImport(schema);
is.setNamespace(ns);
if (this.schemaLocationMapping.get(ns) != null) {
is.setSchemaLocation(this.schemaLocationMapping.get(ns));
}
if (!schema.getItems().contains(is)) {
schema.getItems().add(is);
}
}
}
Aggregations