📄 wsdltranslator.java
字号:
// The MIT License
//
// Copyright (c) 2004 Evren Sirin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
package org.mindswap.wsdl;
import java.io.StringWriter;
import java.net.URI;
import org.mindswap.owl.OWLFactory;
import org.mindswap.owl.Util;
import org.mindswap.owls.OWLSFactory;
import org.mindswap.owls.grounding.Grounding;
import org.mindswap.owls.grounding.MessageMap;
import org.mindswap.owls.grounding.WSDLAtomicGrounding;
import org.mindswap.owls.io.OWLSWriter;
import org.mindswap.owls.process.AtomicProcess;
import org.mindswap.owls.process.Input;
import org.mindswap.owls.process.Output;
import org.mindswap.owls.process.ProcessModel;
import org.mindswap.owls.profile.Profile;
import org.mindswap.owls.service.Service;
public class WSDLTranslator
{
public WSDLTranslator() {
}
public String createOWLS(WSDLOperation op, String fileName,
String serviceName, String textDescription,
String[] inputNames, String[] inputTypes, String[] inputGroundings,
String[] outputNames, String[] outputTypes, String[] outputGroundings) {
try {
// use a dummy base URI
String baseURI = "";
Service service = OWLSFactory.createService(Util.toResource("#Service"));
//Service service = OWLSFactory.createService();
Profile profile = OWLSFactory.createProfile(Util.toResource("#Profile"));
ProcessModel processModel = OWLSFactory.createProcessModel(Util.toResource("#ProcessModel"));
AtomicProcess process = OWLSFactory.createAtomicProcess(Util.toResource("#Process"));
Grounding grounding = OWLSFactory.createGrounding(Util.toResource("#Grounding"));
WSDLAtomicGrounding ag = OWLSFactory.createWSDLAtomicGrounding(Util.toResource("#AtomicProcessGrounding"));
// output will be OWL-S version 1.0
service.setOWLSVersion("1.0");
// set the links between structures
service.setProfile(profile);
service.setProcessModel(processModel);
processModel.setProcess(process);
service.setGrounding(grounding);
// set human readable descriptions
profile.setLabel(serviceName);
profile.setTextDescription(textDescription);
// add the WSDL details to the atomic grounding
ag.setProcess(process);
ag.setOperation(op.getName());
ag.setWSDL(op.getService().getFileURI());
ag.setPortType(op.getPortName());
ag.setInputMessage(op.getInputMessageName());
ag.setOutputMessage(op.getOutputMessageName());
// add the atomic process grounding to service grounding
grounding.addGrounding(ag);
// create input params
for(int i = 0; i < inputNames.length; i++) {
WSDLParameter p = (WSDLParameter) op.getInputs().get(i);
// create process param
Input input = OWLSFactory.createInput(Util.toResource("#in" + i));
input.setLabel(inputNames[i]);
input.setType(OWLFactory.createOWLResource(new URI(inputTypes[i])));
// add the param to process and profile
process.getInputs().add(input);
profile.getInputs().add(input);
// create grounding message map
MessageMap map = OWLSFactory.createMessageMap();
map.setGroundingParameter(p.getName());
map.setOWLSParameter(input);
if(inputGroundings[i] != null && !inputGroundings[i].trim().equals(""))
map.setTransformation(inputGroundings[i]);
// add the message map to atomic process grounding
ag.getInputMap().add(map);
}
// create output params
for(int i = 0; i < outputNames.length; i++) {
WSDLParameter p = (WSDLParameter) op.getOutputs().get(i);
// create param
Output output = OWLSFactory.createOutput(Util.toResource("#out" + i));
output.setLabel(outputNames[i]);
output.setType(OWLFactory.createOWLResource(new URI(outputTypes[i])));
// add the param to process and profile
process.getInputs().add(output);
profile.getInputs().add(output);
// create grounding message map
MessageMap map = OWLSFactory.createMessageMap();
map.setGroundingParameter(p.getName());
map.setOWLSParameter(output);
if(outputGroundings[i] != null && !outputGroundings[i].trim().equals(""))
map.setTransformation(outputGroundings[i]);
// add the message map to atomic process grounding
ag.getOutputMap().add(map);
}
// use the generic OWL-S writer (writer will be used based)
OWLSWriter writer = OWLSFactory.createOWLSWriter();
// create a string buffer
StringWriter sw = new StringWriter(1024);
// write the service description to the string buffer
writer.write(service, sw);
return sw.toString();
} catch(Exception x) {
System.out.println(x);
x.printStackTrace();
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -