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;
}
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()));
}
}
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()));
}
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);
}
Aggregations