use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.
the class ServiceWSDLBuilder method buildTypesWithSchemaImports.
/**
* @param schemas
* @param imports
* @param def
*/
protected void buildTypesWithSchemaImports(final Collection<SchemaInfo> schemas, final Map<String, SchemaInfo> imports, final Definition def) {
Types types = def.createTypes();
Map<String, Schema> namespaceToSchemaMap = new HashMap<>();
Map<String, SchemaInfo> namespaceToSchemaInfo = new HashMap<>();
for (SchemaInfo schemaInfo : schemas) {
Schema schema = getSchemaImplementation(def);
schema.setRequired(true);
schema.setElementType(WSDLConstants.QNAME_SCHEMA);
String name = baseFileName + "_schema" + (++xsdCount) + ".xsd";
schema.setDocumentBaseURI(name);
schema.setElement(schemaInfo.getElement());
namespaceToSchemaMap.put(schemaInfo.getNamespaceURI(), schema);
namespaceToSchemaInfo.put(schemaInfo.getNamespaceURI(), schemaInfo);
imports.put(name, schemaInfo);
}
for (Schema schema : namespaceToSchemaMap.values()) {
Element docElement = schema.getElement();
List<Element> elementList = DOMUtils.findAllElementsByTagNameNS(docElement, "http://www.w3.org/2001/XMLSchema", "import");
for (Element el : elementList) {
String sn = el.getAttribute("namespace");
Schema referencedSchema = namespaceToSchemaMap.get(sn);
if (referencedSchema != null) {
SchemaInfo schemaInfo = namespaceToSchemaInfo.get(sn);
el.setAttribute("schemaLocation", referencedSchema.getDocumentBaseURI());
addSchemaImport(schema, schemaInfo, referencedSchema);
}
}
}
Document doc = DOMUtils.createDocument();
Element nd = doc.createElementNS(WSDLConstants.NS_SCHEMA_XSD, "schema");
nd.setAttribute("xmlns", WSDLConstants.NS_SCHEMA_XSD);
doc.appendChild(nd);
Schema schema = getSchemaImplementation(def);
schema.setRequired(true);
schema.setElementType(WSDLConstants.QNAME_SCHEMA);
Collection<String> defNamespaces = CastUtils.cast(def.getNamespaces().values());
for (SchemaInfo schemaInfo : schemas) {
Schema referencedSchema = namespaceToSchemaMap.get(schemaInfo.getNamespaceURI());
// this ensures only the schemas directly referenced by the wsdl are included.
if (defNamespaces.contains(schemaInfo.getNamespaceURI())) {
Element impElement = doc.createElementNS(WSDLConstants.NS_SCHEMA_XSD, "import");
impElement.setAttribute("schemaLocation", referencedSchema.getDocumentBaseURI());
impElement.setAttribute("namespace", schemaInfo.getNamespaceURI());
nd.appendChild(impElement);
addSchemaImport(schema, schemaInfo, referencedSchema);
}
}
schema.setElement(nd);
types.addExtensibilityElement(schema);
def.setTypes(types);
}
use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.
the class WSDLServiceBuilderTest method testSchema.
@Test
public void testSchema() throws Exception {
setUpBasic();
SchemaCollection schemas = serviceInfo.getXmlSchemaCollection();
assertNotNull(schemas);
assertEquals(1, serviceInfo.getSchemas().size());
SchemaInfo schemaInfo = serviceInfo.getSchemas().iterator().next();
assertNotNull(schemaInfo);
assertEquals(schemaInfo.getNamespaceURI(), "http://apache.org/hello_world_soap_http/types");
assertEquals(schemas.read(schemaInfo.getElement()).getTargetNamespace(), "http://apache.org/hello_world_soap_http/types");
// add below code to test the creation of javax.xml.validation.Schema
// with schema in serviceInfo
Schema schema = EndpointReferenceUtils.getSchema(serviceInfo);
assertNotNull(schema);
control.verify();
}
use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.
the class ReflectionServiceFactoryBean method createWrappedSchema.
protected void createWrappedSchema(ServiceInfo serviceInfo, AbstractMessageContainer wrappedMessage, AbstractMessageContainer unwrappedMessage, QName wrapperBeanName) {
SchemaInfo schemaInfo = getOrCreateSchema(serviceInfo, wrapperBeanName.getNamespaceURI(), getQualifyWrapperSchema());
createWrappedMessageSchema(serviceInfo, wrappedMessage, unwrappedMessage, schemaInfo, wrapperBeanName);
}
use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.
the class WrapperClassGenerator method generatePackageInfo.
private void generatePackageInfo(String className, String ns, Class<?> clz) {
ClassWriter cw = createClassWriter();
String classFileName = periodToSlashes(className);
cw.visit(Opcodes.V1_5, Opcodes.ACC_ABSTRACT + Opcodes.ACC_INTERFACE, classFileName, null, "java/lang/Object", null);
boolean q = qualified;
SchemaInfo si = interfaceInfo.getService().getSchema(ns);
if (si != null) {
q = si.isElementFormQualified();
}
AnnotationVisitor av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/XmlSchema;", true);
av0.visit("namespace", ns);
av0.visitEnum("elementFormDefault", getClassCode(XmlNsForm.class), q ? "QUALIFIED" : "UNQUALIFIED");
av0.visitEnd();
if (clz.getPackage() != null && clz.getPackage().getAnnotations() != null) {
for (Annotation ann : clz.getPackage().getAnnotations()) {
if (ann instanceof XmlJavaTypeAdapters) {
av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapters;", true);
generateXmlJavaTypeAdapters(av0, (XmlJavaTypeAdapters) ann);
av0.visitEnd();
} else if (ann instanceof XmlJavaTypeAdapter) {
av0 = cw.visitAnnotation("Ljavax/xml/bind/annotation/adapters/XmlJavaTypeAdapter;", true);
generateXmlJavaTypeAdapter(av0, (XmlJavaTypeAdapter) ann);
av0.visitEnd();
}
}
}
cw.visitEnd();
loadClass(className, clz, cw.toByteArray());
}
use of org.apache.cxf.service.model.SchemaInfo in project cxf by apache.
the class CorbaUtils method isAttributeFormQualified.
// Change this method to access the XmlSchemaCollection.
public static boolean isAttributeFormQualified(ServiceInfo serviceInfo, String uri) {
if (uri != null) {
SchemaInfo schemaInfo = serviceInfo.getSchema(uri);
if (schemaInfo != null) {
return schemaInfo.isAttributeFormQualified();
}
Iterator<SchemaInfo> it = serviceInfo.getSchemas().iterator();
while (it.hasNext()) {
XmlSchema schema = it.next().getSchema();
return isAttributeFormQualified(schema, uri);
}
}
return false;
}
Aggregations