📄 owlspresentationwriter.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.
/*
* Created on Dec 27, 2003
*
*/
package org.mindswap.utils;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.URI;
import org.mindswap.owls.io.OWLSWriter;
import org.mindswap.owls.process.InputList;
import org.mindswap.owls.process.Parameter;
import org.mindswap.owls.process.ParameterList;
import org.mindswap.owls.profile.Profile;
import org.mindswap.owls.service.Service;
/**
* @author Evren Sirin
*
*/
public class OWLSPresentationWriter implements OWLSWriter {
public static boolean DEBUG = false;
OutputFormatter formatter = null;
private URI base = null;
/**
*
*/
public OWLSPresentationWriter() {
}
public void write(Service service, OutputStream out) throws IOException {
write(service, new PrintWriter(out));
}
/* (non-Javadoc)
* @see org.mindswap.owls.io.OWLSWriter#write(org.mindswap.owls.service.Service, java.io.Writer)
*/
public void write(Service service, Writer out) {
write(service, new PrintWriter(out));
}
public void write(Service service, PrintWriter out) {
formatter = new OutputFormatter(out, true);
writeService(service);
}
private void writeService(Service service) {
formatter.printParagraph().println("Service {");
formatter.printTab().print("presents ").printLink("#profile", "Profile").println();
formatter.printTab().print("describedBy ").printLink("#processModel", "Process Model").println();
formatter.printTab().print("supports ").printLink("#grounding", "Grounding").println();
formatter.println("}");
writeProfile(service.getProfile());
// writeProcessModel(service.getProcessModel());
// writeGrounding(service.getGrounding());
formatter.flush();
}
private void writeProfile(Profile profile) {
formatter.printParagraph().println("Profile {");
formatter.printTab().print("type ").printLink(profile.getType().toString()).println();
formatter.printTab().print("label \"").printItalic(profile.toString()).println("\"");
if(profile.getTextDescription() != null)
formatter.printTab().print("description \"").printItalic(profile.getTextDescription()).println("\"");
writeProfileParams(profile, profile.getInputs());
writeProfileParams(profile, profile.getOutputs());
formatter.println("}");
}
private void writeProfileParams(Profile profile, ParameterList params) {
if(params instanceof InputList)
formatter.printParagraph().printTab().print("Inputs {");
else
formatter.printParagraph().printTab().print("Outputs {");
if(params.size() > 0) formatter.println();
for(int i = 0; i < params.size(); i++) {
Parameter param = params.parameterAt(i);
formatter.printTab().printTab().print((i+1) + ") Name: ");
formatter.printLink(param.getURI().toString(), param.toString());
formatter.print(" Type: ");
formatter.printLink(param.getType().getURI().toString(), param.getType().toString());
formatter.println();
}
formatter.printTab().println(" }");
}
// private void writeProcessModel(ProcessModel processModel) {
// addStatement(processModel, RDF.type, OWLS_0_9.Process.ProcessModel);
// addStatement(processModel, OWLS_0_9.Service.describes, OWLS_0_9.Process.AtomicProcess);
// addStatement(processModel, OWLS_0_9.Process.hasProcess, processModel.getProcess());
//
// writeProcess(processModel.getProcess());
// }
//
// private void writeProcess(Process process) {
// if(process instanceof AtomicProcess)
// writeAtomicProcess((AtomicProcess) process);
// else if(process instanceof CompositeProcess)
// writeCompositeProcess((CompositeProcess) process);
//
// writeProcessParams(process, process.getInputs());
// writeProcessParams(process, process.getOutputs());
//
//
// writeDefaultValues(process);
// writeDataFlow(process);
// }
//
// private void writeAtomicProcess(AtomicProcess process) {
// addStatement(process, RDF.type, OWL.Class);
// addStatement(process, RDFS.subClassOf, OWLS_0_9.Process.AtomicProcess);
//
// writeProcessParams(process, process.getInputs());
// writeProcessParams(process, process.getOutputs());
// }
//
// private void writeProcessParams(Process process, ParameterList params) {
// for(int i = 0; i < params.size(); i++) {
// Parameter paramDesc = params.parameterAt(i);
//
// Resource restr = ResourceFactory.createResource();
// addStatement(process, RDFS.subClassOf, restr);
// addStatement(restr, RDF.type, OWL.Restriction);
// addStatement(restr, OWL.onProperty, paramDesc);
// addStatement(restr, OWL.cardinality, "1");
//
// addStatement(paramDesc, RDF.type, RDF.Property);
// if(paramDesc instanceof Input)
// addStatement(paramDesc, RDFS.subPropertyOf, OWLS_0_9.Process.input);
// else
// addStatement(paramDesc, RDFS.subPropertyOf, OWLS_0_9.Process.output);
//
// addStatement(paramDesc, RDFS.domain, process);
// addStatement(paramDesc, RDFS.range, paramDesc.getType());
// }
// }
//
// private void writeCompositeProcess(CompositeProcess process) {
// addStatement(process, RDF.type, OWL.Class);
// addStatement(process, RDFS.subClassOf, OWLS_0_9.Process.CompositeProcess);
//
// RDFNode cc = writeControlConstruct(process.getComposedOf());
//
// Resource restr = ResourceFactory.createResource();
// addStatement(process, RDFS.subClassOf, restr);
// addStatement(restr, RDF.type, OWL.Restriction);
// addStatement(restr, OWL.onProperty, OWLS_0_9.Process.composedOf);
// addStatement(restr, OWL.allValuesFrom, cc);
// }
//
// private RDFNode writeProcessComponent(ProcessComponent c) {
// if(c instanceof Process) {
// writeProcess((Process) c);
// return c.getJenaResource();
// }
// else
// return writeControlConstruct((ControlConstruct) c);
// }
//
// private RDFNode writeControlConstruct(ControlConstruct construct) {
// RDFNode cc = null;
// if(construct instanceof Sequence)
// cc = writeSequence((Sequence) construct);
//
//// Resource restr = ResourceFactory.createResource();
//// addStatement(restr, RDF.type, OWL.Restriction);
//// addStatement(restr, OWL.onProperty, OWLS_0_9.Process.composedOf);
//// addStatement(restr, OWL.allValuesFrom, cc);
//
// return cc;
// }
//
// private RDFNode writeSequence(Sequence sequence) {
// RDFNode components = writeComponents(sequence.getComponents());
// Resource restr = ResourceFactory.createResource();
// addStatement(restr, RDF.type, OWL.Restriction);
// addStatement(restr, OWL.onProperty, OWLS_0_9.Process.components);
// addStatement(restr, OWL.allValuesFrom, components);
//
// RDFList list = model.createList(new RDFNode[] {Util.toResource(OWLS_0_9.Process.Sequence), restr});
//
// Resource c = ResourceFactory.createResource();
// addStatement(c, RDF.type, OWL.Class);
// addStatement(c, OWL.intersectionOf, list);
//
// return c;
// }
//
// private RDFNode writeComponents(ProcessComponentList list) {
// RDFNode[] elems = new RDFNode[list.size()];
// for(int i = 0; i < list.size(); i++) {
// ProcessComponent c = list.processComponentAt(i);
//
// elems[i] = writeProcessComponent(c);
// }
//
// Resource c = ResourceFactory.createResource();
// addStatement(c, RDF.type, OWL.Class);
// addStatement(c, OWLS_0_9.Process.listOfInstancesOf, model.createList(elems));
// return c;
// }
//
// private void writeDataFlow(Process process) {
// DataFlow df = process.getDataFlow();
// for(int i = 0; i < df.size(); i++) {
// DataFlowElement dfe = df.dfeAt(i);
//
// RDFNode[] elems = new RDFNode[dfe.size()];
// for(int j = 0; j < dfe.size(); j++) {
// Parameter p = dfe.parameterAt(j);
// elems[j] = ResourceFactory.createResource();
// addStatement(elems[j], RDF.type, OWLS_0_9.Process.ValueOf);
// addStatement(elems[j], OWLS_0_9.Process.theProperty, p);
// if(p.getProcess() != null)
// addStatement(elems[j], OWLS_0_9.Process.atClass, p.getProcess());
// }
// addStatement(process, OWLS_0_9.Process.sameValues, model.createList(elems));
// }
//
// }
//
// private void writeDefaultValues(Process process) {
// ValueMap values = process.getDefaultValues();
// Iterator i = values.entrySet().iterator();
// while(i.hasNext()) {
// Map.Entry entry = (Map.Entry) i.next();
// URI p = (URI) entry.getKey();
// String value = entry.getValue().toString();
//
// Resource restr = ResourceFactory.createResource();
// addStatement(restr, RDF.type, OWL.Restriction);
// addStatement(restr, OWL.onProperty, p);
// addStatement(restr, OWL.hasValue, value);
//
// addStatement(process, RDFS.subClassOf, restr);
// }
// }
//
// private void writeGrounding(Grounding grounding) {
// boolean isWSDL = false;
// boolean isUPnP = false;
//
// addStatement(grounding, OWLS_0_9.Service.supportedBy, grounding.getService());
//
// Iterator i = grounding.getAtomicGroundings().iterator();
// while(i.hasNext()) {
// Object n = i.next();
// AtomicGrounding ag = (AtomicGrounding) n;
// isWSDL = isWSDL || (ag instanceof WSDLAtomicGrounding);
// isUPnP = isUPnP && (ag instanceof UPnPAtomicGrounding);
//
// if(ag instanceof WSDLAtomicGrounding) {
// addStatement(grounding, OWLS_0_9.Grounding.hasAtomicProcessGrounding, ag);
// writeWSDLGrounding((WSDLAtomicGrounding) ag);
// }
// else if(ag instanceof UPnPAtomicGrounding) {
// addStatement(grounding, OWLS_0_9.Grounding.hasAtomicProcessGrounding, ag);
// writeUPnPGrounding((UPnPAtomicGrounding) ag);
// }
// }
//
// addStatement(grounding, OWLS_0_9.Service.supportedBy, grounding.getService());
// if(isWSDL)
// addStatement(grounding, RDF.type, OWLS_0_9.Grounding.WsdlGrounding);
// else if(isUPnP)
// addStatement(grounding, RDF.type, FLAServiceOnt.UPnPGrounding);
// }
//
// private void writeWSDLGrounding(WSDLAtomicGrounding grounding) {
// addStatement(grounding, RDF.type, OWLS_0_9.Grounding.WsdlAtomicProcessGrounding);
// addStatement(grounding, OWLS_0_9.Grounding.wsdlDocument, grounding.getWSDL());
// addStatement(grounding, OWLS_0_9.Grounding.damlsProcess, grounding.getProcess());
//
//
// try {
// addStatement(grounding, OWLS_0_9.Grounding.wsdlInputMessage, grounding.getInputMessage());
// addStatement(grounding, OWLS_0_9.Grounding.wsdlOutputMessage, grounding.getOutputMessage());
// } catch (Exception e) {
// }
//
// Resource opDesc = ResourceFactory.createResource();
// addStatement(grounding, OWLS_0_9.Grounding.wsdlOperation, opDesc);
// addStatement(opDesc, RDF.type, OWLS_0_9.Grounding.WsdlOperationRef);
// addStatement(opDesc, OWLS_0_9.Grounding.portType, grounding.getPortType());
// addStatement(opDesc, OWLS_0_9.Grounding.operation, grounding.getOperation());
//
// writeWSDLGroundingParams(grounding, true);
// writeWSDLGroundingParams(grounding, false);
// }
//
// private void writeWSDLGroundingParams(WSDLAtomicGrounding grounding, boolean writeInputs) {
// MessageMapList messageMapList;
// if(writeInputs)
// messageMapList = grounding.getInputMap();
// else
// messageMapList = grounding.getOutputMap();
//
// RDFNode[] elements = new RDFNode[messageMapList.size()];
// for(int i = 0; i < messageMapList.size(); i++) {
// MessageMap map = messageMapList.messageMapAt(i);
//
// Resource r = ResourceFactory.createResource();
// addStatement(r, RDF.type, OWLS_0_9.Grounding.wsdlMessageMap);
// addStatement(r, OWLS_0_9.Grounding.damlsParameter, map.getOWLSParameter());
// addStatement(r, OWLS_0_9.Grounding.wsdlMessagePart, map.getGroundingParameter());
// if(map.getTransformation() != null)
// addStatement(r, OWLS_0_9.Grounding.xsltTranformation, map.getTransformation());
// elements[i] = r;
// }
//
// RDFList list = model.createList(elements);
// if(writeInputs)
// addStatement(grounding, OWLS_0_9.Grounding.wsdlInputMessageParts, list);
// else
// addStatement(grounding, OWLS_0_9.Grounding.wsdlOutputMessageParts, list);
//
// }
//
// private void writeUPnPGrounding(UPnPAtomicGrounding grounding) {
// addStatement(grounding, RDF.type, FLAServiceOnt.UPnPAtomicProcessGrounding);
// addStatement(grounding, OWLS_0_9.Grounding.damlsProcess, grounding.getProcess());
//
// addStatement(grounding, FLAServiceOnt.upnpCommand, grounding.getUPnPAction());
// addStatement(grounding, FLAServiceOnt.upnpDeviceURL, grounding.getUPnPDescription());
// addStatement(grounding, FLAServiceOnt.upnpServiceID, grounding.getUPnPService());
//
// writeUPnPGroundingParams(grounding, true);
// writeUPnPGroundingParams(grounding, false);
// }
//
// private void writeUPnPGroundingParams(UPnPAtomicGrounding grounding, boolean writeInputs) {
// MessageMapList messageMapList;
// if(writeInputs)
// messageMapList = grounding.getInputMap();
// else
// messageMapList = grounding.getOutputMap();
//
// RDFNode[] elements = new RDFNode[messageMapList.size()];
// for(int i = 0; i < messageMapList.size(); i++) {
// MessageMap map = messageMapList.messageMapAt(i);
//
// Resource r = ResourceFactory.createResource();
// addStatement(r, RDF.type, FLAServiceOnt.UPnPMap);
// addStatement(r, OWLS_0_9.Grounding.damlsParameter, map.getOWLSParameter());
// addStatement(r, FLAServiceOnt.upnpParameter, map.getGroundingParameter());
// if(map.getTransformation() != null)
// addStatement(r, OWLS_0_9.Grounding.xsltTranformation, map.getTransformation());
// elements[i] = r;
// }
//
// RDFList list = model.createList(elements);
// if(writeInputs)
// addStatement(grounding, FLAServiceOnt.UPnPInputMapping, list);
// else
// addStatement(grounding, FLAServiceOnt.UPnPOutputMapping, list);
//
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -