2ronwalf//The MIT License
2ronwalf//
2ronwalf// Copyright (c) 2004 Evren Sirin
2ronwalf//
2ronwalf// Permission is hereby granted, free of charge, to any person obtaining a copy
2ronwalf// of this software and associated documentation files (the "Software"), to
2ronwalf// deal in the Software without restriction, including without limitation the
2ronwalf// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2ronwalf// sell copies of the Software, and to permit persons to whom the Software is
2ronwalf// furnished to do so, subject to the following conditions:
2ronwalf//
2ronwalf// The above copyright notice and this permission notice shall be included in
2ronwalf// all copies or substantial portions of the Software.
2ronwalf//
2ronwalf// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2ronwalf// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2ronwalf// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2ronwalf// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2ronwalf// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2ronwalf// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2ronwalf// IN THE SOFTWARE.
2ronwalf
2ronwalfpackage org.mindswap.wsdl;
2ronwalf
2ronwalfimport java.io.OutputStream;
2ronwalfimport java.io.Writer;
2ronwalfimport java.net.URI;
2ronwalf
2ronwalfimport org.mindswap.owl.OWLFactory;
2ronwalfimport org.mindswap.owl.OWLKnowledgeBase;
2ronwalfimport org.mindswap.owl.OWLOntology;
2ronwalfimport org.mindswap.owl.OWLType;
2ronwalfimport org.mindswap.owls.grounding.AtomicGrounding;
2ronwalfimport org.mindswap.owls.grounding.Grounding;
2ronwalfimport org.mindswap.owls.grounding.WSDLAtomicGrounding;
2ronwalfimport org.mindswap.owls.process.AtomicProcess;
2ronwalfimport org.mindswap.owls.process.Input;
2ronwalfimport org.mindswap.owls.process.Output;
2ronwalfimport org.mindswap.owls.profile.Profile;
2ronwalfimport org.mindswap.owls.service.Service;
2ronwalfimport org.mindswap.utils.URIUtils;
2ronwalf
2ronwalfpublic class WSDLTranslator {
2ronwalf private Service service;
2ronwalf private OWLOntology ont;
2ronwalf URI baseURI;
2ronwalf
2ronwalf
2ronwalf public WSDLTranslator(WSDLOperation op, String serviceURI, String prefix) {
2ronwalf OWLKnowledgeBase kb = OWLFactory.createKB();
2ronwalf ont = kb.createOntology();
2ronwalf
2ronwalf baseURI = URIUtils.createURI(serviceURI);
2ronwalf
2ronwalf service = ont.createService(URIUtils.createURI(baseURI, prefix + "Service"));
2ronwalf
2ronwalf Profile profile = ont.createProfile(URIUtils.createURI(baseURI, prefix + "Profile"));
2ronwalf AtomicProcess process = ont.createAtomicProcess(URIUtils.createURI(baseURI, prefix + "Process"));
2ronwalf Grounding grounding = ont.createGrounding(URIUtils.createURI(baseURI, prefix + "Grounding"));
2ronwalf WSDLAtomicGrounding ag = ont.createWSDLAtomicGrounding(URIUtils.createURI(baseURI, prefix + "AtomicProcessGrounding"));
2ronwalf
2ronwalf process.setLabel(process.getURI().getFragment());
2ronwalf
2ronwalf // set the links between structures
2ronwalf service.setProfile(profile);
2ronwalf service.setProcess(process);
2ronwalf service.setGrounding(grounding);
2ronwalf
2ronwalf // add the WSDL details to the atomic grounding
2ronwalf ag.setProcess(process);
2ronwalf ag.setOperation(URI.create(op.getOperationName()));
2ronwalf ag.setWSDL(op.getService().getFileURI());
2ronwalf ag.setPortType(URI.create(op.getPortName()));
2ronwalf ag.setInputMessage(URI.create(op.getInputMessageName()));
2ronwalf ag.setOutputMessage(URI.create(op.getOutputMessageName()));
2ronwalf
2ronwalf // add the atomic process grounding to service grounding
2ronwalf grounding.addGrounding(ag);
2ronwalf }
2ronwalf
2ronwalf public void setServiceName(String serviceName) {
2ronwalf service.getProfile().setServiceName(serviceName);
2ronwalf }
2ronwalf
2ronwalf public void setTextDescription(String textDescription) {
2ronwalf service.getProfile().setTextDescription(textDescription);
2ronwalf System.out.println(service.getProfile().getTextDescription());
2ronwalf }
2ronwalf
2ronwalf public void addInput(WSDLParameter param, String paramName, URI paramType, String xsltTransformation) {
2ronwalf Profile profile = service.getProfile();
2ronwalf AtomicProcess process = (AtomicProcess) service.getProcess();
2ronwalf
2ronwalf // create process param
2ronwalf Input input = ont.createInput(URIUtils.createURI(baseURI, paramName));
2ronwalf input.setLabel(paramName);
2ronwalf
2ronwalf OWLType type = ont.getType(paramType);
2ronwalf input.setParamType(type == null ? ont.createClass(paramType) : type);
2ronwalf
2ronwalf // add the param to process and profile
2ronwalf process.addInput(input);
2ronwalf profile.addInput(input);
2ronwalf
2ronwalf AtomicGrounding grounding = process.getGrounding();
2ronwalf // create grounding message map
2ronwalf grounding.addMessageMap(input, param.getName(), xsltTransformation);
2ronwalf }
2ronwalf
2ronwalf public void addOutput(WSDLParameter param, String paramName, URI paramType, String xsltTransformation) {
2ronwalf Profile profile = service.getProfile();
2ronwalf AtomicProcess process = (AtomicProcess) service.getProcess();
2ronwalf
2ronwalf // create process param
2ronwalf Output output = ont.createOutput(URIUtils.createURI(baseURI, paramName));
2ronwalf output.setLabel(paramName);
2ronwalf
2ronwalf OWLType type = ont.getType(paramType);
2ronwalf output.setParamType(type == null ? ont.createClass(paramType) : type);
2ronwalf
2ronwalf // add the param to process and profile
2ronwalf process.addOutput(output);
2ronwalf profile.addOutput(output);
2ronwalf
2ronwalf AtomicGrounding grounding = process.getGrounding();
2ronwalf // create grounding message map
2ronwalf grounding.addMessageMap(output, param.getName(), xsltTransformation);
2ronwalf }
2ronwalf
2ronwalf public void writeOWLS(Writer out) {
2ronwalf ont.write(out, baseURI);
2ronwalf }
2ronwalf
2ronwalf public void writeOWLS(OutputStream out) {
2ronwalf ont.write(out, baseURI);
2ronwalf }
21daenzerorama
21daenzerorama public Service getService() {
21daenzerorama return service;
21daenzerorama }
2ronwalf}