Search in sources :

Example 41 with Schema

use of org.eclipse.persistence.internal.oxm.schema.model.Schema in project eclipselink by eclipse-ee4j.

the class WSDLGenerator method generateWSDL.

public Definition generateWSDL(boolean useSOAP12) throws WSDLException {
    WSDLFactory factory = WSDLFactory.newInstance();
    ExtensionRegistry registry = factory.newPopulatedExtensionRegistry();
    Definition def = factory.newDefinition();
    if (useSOAP12) {
        def.addNamespace(SOAP_12_NAMESPACE_PREFIX, SOAP_12_NAMESPACE_URI);
    } else {
        def.addNamespace(SOAP_11_NAMESPACE_PREFIX, SOAP_11_NAMESPACE_URI);
    }
    def.setTargetNamespace(serviceNameSpace);
    def.setQName(new QName(serviceNameSpace, serviceName));
    def.addNamespace(NS_TNS_PREFIX, serviceNameSpace);
    def.addNamespace(TARGET_NAMESPACE_PREFIX, importedSchemaNameSpace);
    def.addNamespace(NS_SCHEMA_PREFIX, W3C_XML_SCHEMA_NS_URI);
    Types types = def.createTypes();
    javax.wsdl.extensions.schema.Schema schema = (javax.wsdl.extensions.schema.Schema) registry.createExtension(Types.class, new QName(W3C_XML_SCHEMA_NS_URI, TAG_SCHEMA));
    schema.setElement(createInlineSchema());
    types.addExtensibilityElement(schema);
    def.setTypes(types);
    PortType portType = def.createPortType();
    portType.setUndefined(false);
    portType.setQName(new QName(serviceNameSpace, serviceName + PORT_SUFFIX));
    def.addPortType(portType);
    ExtensibilityElement soap = null;
    if (useSOAP12) {
        soap = registry.createExtension(Binding.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_BINDING));
        ((SOAP12Binding) soap).setStyle(SOAP_STYLE);
        ((SOAP12Binding) soap).setTransportURI(SOAP_HTTP_TRANSPORT);
    } else {
        soap = registry.createExtension(Binding.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_BINDING));
        ((SOAPBinding) soap).setStyle(SOAP_STYLE);
        ((SOAPBinding) soap).setTransportURI(SOAP_HTTP_TRANSPORT);
    }
    Binding binding = def.createBinding();
    binding.setUndefined(false);
    binding.setQName(new QName(serviceNameSpace, serviceName + BINDING_SUFFIX));
    binding.setPortType(portType);
    binding.addExtensibilityElement(soap);
    def.addBinding(binding);
    ExtensibilityElement sa = null;
    if (useSOAP12) {
        sa = registry.createExtension(Port.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_ADDRESS));
        ((SOAP12Address) sa).setLocationURI(wsdlLocationURI);
    } else {
        sa = registry.createExtension(Port.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_ADDRESS));
        ((SOAPAddress) sa).setLocationURI(wsdlLocationURI);
    }
    Service ws = def.createService();
    ws.setQName(new QName(serviceNameSpace, serviceName));
    Port port = def.createPort();
    port.setName(serviceName + "Port");
    port.setBinding(binding);
    port.addExtensibilityElement(sa);
    ws.addPort(port);
    def.addService(ws);
    boolean requireEmptyResponseMessages = false;
    for (Operation op : xrServiceModel.getOperationsList()) {
        if (!(op instanceof QueryOperation)) {
            requireEmptyResponseMessages = true;
            break;
        }
    }
    if (requireEmptyResponseMessages) {
        /*
             * Add in empty response message
             * <wsdl:message name="EmptyResponse">
             *   <wsdl:part name="emptyResponse" element="tns:EmptyResponse"></wsdl:part>
             * </wsdl:message>
             */
        Message emptyResponseMessage = def.createMessage();
        emptyResponseMessage.setUndefined(false);
        emptyResponseMessage.setQName(new QName(serviceNameSpace, EMPTY_RESPONSE));
        Part responsePart = def.createPart();
        responsePart.setName("emptyResponse");
        responsePart.setElementName(new QName(serviceNameSpace, EMPTY_RESPONSE));
        emptyResponseMessage.addPart(responsePart);
        def.addMessage(emptyResponseMessage);
        /*
             * Add in Fault message
             * <wsdl:message name="FaultType">
             *   <wsdl:part name="fault" element="tns:FaultType"></wsdl:part>
             * </wsdl:message>
             */
        Message faultMessage = def.createMessage();
        faultMessage.setUndefined(false);
        faultMessage.setQName(new QName(serviceNameSpace, FAULT_SUFFIX + TYPE_SUFFIX));
        Part faultPart = def.createPart();
        faultPart.setName("fault");
        faultPart.setElementName(new QName(serviceNameSpace, FAULT_SUFFIX + TYPE_SUFFIX));
        faultMessage.addPart(faultPart);
        def.addMessage(faultMessage);
    }
    for (Operation op : xrServiceModel.getOperationsList()) {
        createMethodDefinition(factory, registry, def, op, useSOAP12);
    }
    if (os != null) {
        WSDLWriter writer = factory.newWSDLWriter();
        writer.writeWSDL(def, os);
    }
    return def;
}
Also used : Types(javax.wsdl.Types) Message(javax.wsdl.Message) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) Port(javax.wsdl.Port) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) Operation(org.eclipse.persistence.internal.xr.Operation) BindingOperation(javax.wsdl.BindingOperation) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) WSDLWriter(javax.wsdl.xml.WSDLWriter) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) QueryOperation(org.eclipse.persistence.internal.xr.QueryOperation) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) Binding(javax.wsdl.Binding) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) Service(javax.wsdl.Service) WSDLFactory(javax.wsdl.factory.WSDLFactory) Part(javax.wsdl.Part) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) PortType(javax.wsdl.PortType)

Example 42 with Schema

use of org.eclipse.persistence.internal.oxm.schema.model.Schema in project eclipselink by eclipse-ee4j.

the class SchemaGeneratorTestCase method addTransformerToSchema.

@Test
public void addTransformerToSchema() {
    InputStream inputStream = ClassLoader.getSystemResourceAsStream(BINDINGS_DOC);
    HashMap<String, Source> metadataSourceMap = new HashMap<>();
    metadataSourceMap.put("org.eclipse.persistence.testing.jaxb.externalizedmetadata.mappings.xmltransformation", new StreamSource(inputStream));
    Map<String, Object> properties = new HashMap<>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataSourceMap);
    Map<String, XmlBindings> bindings = JAXBContextFactory.getXmlBindingsFromProperties(properties, Thread.currentThread().getContextClassLoader());
    JavaModelInputImpl jModelInput = new JavaModelInputImpl(DOMAIN_CLASSES, new JavaModelImpl(new JaxbClassLoader(Thread.currentThread().getContextClassLoader(), DOMAIN_CLASSES)));
    Helper helper = new Helper(jModelInput.getJavaModel());
    Generator generator = new Generator(jModelInput, bindings, Thread.currentThread().getContextClassLoader(), "", false);
    TypeInfo typeInfo = generator.getAnnotationsProcessor().getTypeInfos().get(EMPLOYEE_CLASS_NAME);
    Property normalHoursProperty = typeInfo.getProperties().get(XML_TRANSFORMATION_PROPERTY_NAME);
    ChildSchemaGenerator childSchemaGenerator = new ChildSchemaGenerator(helper);
    TransformerPropertyBuilder transformerPropertyBuilder = childSchemaGenerator.getTransformerPropertyBuilder(normalHoursProperty, typeInfo);
    java.util.List<Property> props = transformerPropertyBuilder.buildProperties();
    // Indirect call of org.eclipse.persistence.jaxb.compiler.SchemaGenerator.addTransformerToSchema(.....) method.
    List<Schema> schemas = (List) generator.generateSchema();
    XMLContext context = new XMLContext(new SchemaModelProject());
    XMLMarshaller marshaller = context.createMarshaller();
    final StringWriter stringWriter = new StringWriter();
    marshaller.marshal(schemas.get(0), stringWriter);
    String outputSchema = stringWriter.toString();
    // Verify that XML-Transformation property is added to XML schema
    for (Property property : props) {
        assertTrue(outputSchema.contains(property.getPropertyName()));
    }
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) HashMap(java.util.HashMap) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) ChildSchemaGenerator(org.eclipse.persistence.testing.moxy.unit.jaxb.compiler.builder.ChildSchemaGenerator) StringWriter(java.io.StringWriter) TransformerPropertyBuilder(org.eclipse.persistence.jaxb.compiler.builder.TransformerPropertyBuilder) List(java.util.List) Property(org.eclipse.persistence.jaxb.compiler.Property) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) XMLContext(org.eclipse.persistence.oxm.XMLContext) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) TypeInfo(org.eclipse.persistence.jaxb.compiler.TypeInfo) JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) Generator(org.eclipse.persistence.jaxb.compiler.Generator) ChildSchemaGenerator(org.eclipse.persistence.testing.moxy.unit.jaxb.compiler.builder.ChildSchemaGenerator) Test(org.junit.Test)

Example 43 with Schema

use of org.eclipse.persistence.internal.oxm.schema.model.Schema in project eclipselink by eclipse-ee4j.

the class SimpleTableWithNestedSQLTestSuite method validateElementRefType.

@Test
public void validateElementRefType() throws TransformerFactoryConfigurationError, TransformerException {
    StringWriter sw = new StringWriter();
    StreamSource wsdlStreamSource = new StreamSource(new StringReader(DBWS_WSDL_STREAM.toString()));
    Transformer t = TransformerFactory.newInstance().newTransformer(new StreamSource(new StringReader(MATCH_SCHEMA)));
    StreamResult streamResult = new StreamResult(sw);
    t.transform(wsdlStreamSource, streamResult);
    sw.toString();
    SchemaModelProject schemaProject = new SchemaModelProject();
    XMLContext xmlContext2 = new XMLContext(schemaProject);
    XMLUnmarshaller unmarshaller = xmlContext2.createUnmarshaller();
    Schema schema = (Schema) unmarshaller.unmarshal(new StringReader(sw.toString()));
    ComplexType findByNameResponseType = schema.getTopLevelComplexTypes().get(FINDBYNAME_RESPONSETYPE);
    Element result = findByNameResponseType.getSequence().getElements().get(0);
    Element unnamed = result.getComplexType().getSequence().getElements().get(0);
    assertTrue("wrong refType for " + FINDBYNAME_RESPONSETYPE, TABLE_ALIAS.equals(unnamed.getRef()));
}
Also used : Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) XMLContext(org.eclipse.persistence.oxm.XMLContext) StreamSource(javax.xml.transform.stream.StreamSource) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) StringReader(java.io.StringReader) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Test(org.junit.Test)

Example 44 with Schema

use of org.eclipse.persistence.internal.oxm.schema.model.Schema in project eclipselink by eclipse-ee4j.

the class BaseDBWSBuilderHelper method buildSchema.

/**
 * Build the schema
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void buildSchema(NamingConventionTransformer nct) {
    Project oxProject = dbwsBuilder.getOxProject();
    Schema schema = null;
    List<Descriptor> descriptorsToProcess = new ArrayList<Descriptor>();
    for (Descriptor desc : (List<Descriptor>) (List) oxProject.getOrderedDescriptors()) {
        String alias = desc.getAlias();
        if (!DEFAULT_SIMPLE_XML_FORMAT_TAG.equals(alias)) {
            descriptorsToProcess.add(desc);
        }
    }
    if (descriptorsToProcess.size() > 0) {
        // need a deep-copy clone of oxProject; simplest way is to marshall/unmarshall to a stream
        StringWriter sw = new StringWriter();
        XMLProjectWriter.write(oxProject, sw);
        XRDynamicClassLoader specialLoader = new XRDynamicClassLoader(this.getClass().getClassLoader());
        Project oxProjectClone = XMLProjectReader.read(new StringReader(sw.toString()), specialLoader);
        ProjectHelper.fixOROXAccessors(oxProjectClone, null);
        XMLLogin xmlLogin = new XMLLogin();
        DOMPlatform domPlatform = new DOMPlatform();
        domPlatform.getConversionManager().setLoader(specialLoader);
        xmlLogin.setPlatform(domPlatform);
        oxProjectClone.setLogin(xmlLogin);
        // initialize reference descriptors
        oxProjectClone.createDatabaseSession();
        SchemaModelGenerator schemaGenerator = new SchemaModelGenerator(XMLConversionManager.getDefaultXMLManager(), true);
        SchemaModelGeneratorProperties sgProperties = new SchemaModelGeneratorProperties();
        // set element form default to qualified for target namespace
        sgProperties.addProperty(dbwsBuilder.getTargetNamespace(), ELEMENT_FORM_QUALIFIED_KEY, true);
        Map<String, Schema> schemaMap = schemaGenerator.generateSchemas(descriptorsToProcess, sgProperties);
        Schema s = schemaMap.get(dbwsBuilder.getTargetNamespace());
        // check existing schema for any top-level ComplexTypes
        if (dbwsBuilder.getSchema() != null && s != null) {
            Map<String, ComplexType> topLevelComplexTypes = dbwsBuilder.getSchema().getTopLevelComplexTypes();
            for (Map.Entry<String, ComplexType> me : topLevelComplexTypes.entrySet()) {
                s.addTopLevelComplexTypes(me.getValue());
            }
            // add any additional namespaces
            NamespaceResolver snr = s.getNamespaceResolver();
            NamespaceResolver nr = dbwsBuilder.getSchema().getNamespaceResolver();
            // we only want to add prefix/uri pairs for prefixes that don't already exist
            for (String prefix : nr.getPrefixesToNamespaces().keySet()) {
                if (snr.resolveNamespacePrefix(prefix) == null) {
                    snr.put(prefix, nr.resolveNamespacePrefix(prefix));
                }
            }
            // switch
            schema = s;
            schema.setNamespaceResolver(snr);
        }
    } else {
        schema = new Schema();
        addSimpleXMLFormat(schema);
        schema.setTargetNamespace(dbwsBuilder.getTargetNamespace());
    }
    dbwsBuilder.setSchema(schema);
}
Also used : DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) ArrayList(java.util.ArrayList) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) Util.buildOXDescriptor(org.eclipse.persistence.tools.dbws.Util.buildOXDescriptor) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) Util.buildORDescriptor(org.eclipse.persistence.tools.dbws.Util.buildORDescriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) ArrayList(java.util.ArrayList) List(java.util.List) SchemaModelGenerator(org.eclipse.persistence.internal.oxm.schema.SchemaModelGenerator) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)44 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)18 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)17 Project (org.eclipse.persistence.sessions.Project)17 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)16 Element (org.eclipse.persistence.internal.oxm.schema.model.Element)15 ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)14 SchemaModelGeneratorProperties (org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties)13 XmlVirtualAccessMethodsSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema)12 XMLContext (org.eclipse.persistence.oxm.XMLContext)12 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)10 Document (org.w3c.dom.Document)10 QName (javax.xml.namespace.QName)7 StreamSource (javax.xml.transform.stream.StreamSource)7 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)7 Sequence (org.eclipse.persistence.internal.oxm.schema.model.Sequence)6 TypeDefParticle (org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle)6 IOException (java.io.IOException)5 StringWriter (java.io.StringWriter)5 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)5