📄 owlswriter_1_0.java
字号:
addStatement(process, OWLS.Process.hasInput, param);
addStatement(param, RDF.type, OWLS.Process.Input);
}
else {
addStatement(process, OWLS.Process.hasOutput, param);
addStatement(param, RDF.type, OWLS.Process.Output);
}
if(process.getDefaultValues().hasValue(param)) {
Object value = process.getDefaultValues().getValue(param);
RDFNode node = null;
if(param.getType().getURI().toString().startsWith(XSD.ns))
node = model.createTypedLiteral(value);
else
node = model.createResource(value.toString());
Resource list = model.createResource();
Resource c = ResourceFactory.createResource();
addStatement(param, OWLS.Process.parameterType, c);
addStatement(c, RDF.type, OWL.Class);
addStatement(c, OWL.oneOf, list);
addStatement(list, RDF.type, RDF.List);
addStatement(list, RDF.first, node);
addStatement(list, RDF.rest, RDF.nil);
}
else
addStatement(param, OWLS.Process.parameterType, param.getType());
if(param.getLabel() != null)
addStatement(param, RDFS.label, param.getLabel());
}
}
private void writeCompositeProcess(CompositeProcess process) {
addStatement(process, RDF.type, OWLS.Process.CompositeProcess);
RDFNode cc = writeControlConstruct(process.getComposedOf());
addStatement(process, OWLS.Process.composedOf, 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 = writeList(construct, OWLS.Process.Sequence);
if(construct instanceof Split)
cc = writeList(construct, OWLS.Process.Split);
if(construct instanceof SplitJoin)
cc = writeList(construct, OWLS.Process.SplitJoin);
if(construct instanceof Choice)
cc = writeList(construct, OWLS.Process.Choice);
return cc;
}
private RDFNode writeList(ControlConstruct sequence, URI ccType) {
RDFNode components = writeComponents(sequence.getComponents());
addStatement(sequence, RDF.type, ccType);
addStatement(sequence, OWLS.Process.components, components);
return sequence.getJenaResource();
}
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);
}
return model.createList(elems);
}
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.Process.ValueOf);
addStatement(elems[j], OWLS.Process.theProperty, p);
if(p.getProcess() != null)
addStatement(elems[j], OWLS.Process.atClass, p.getProcess());
}
addStatement(process, OWLS.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.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.Grounding.hasAtomicProcessGrounding, ag);
writeWSDLGrounding((WSDLAtomicGrounding) ag);
}
else if(ag instanceof UPnPAtomicGrounding) {
addStatement(grounding, OWLS.Grounding.hasAtomicProcessGrounding, ag);
writeUPnPGrounding((UPnPAtomicGrounding) ag);
}
}
addStatement(grounding, OWLS.Service.supportedBy, grounding.getService());
if(isWSDL)
addStatement(grounding, RDF.type, OWLS.Grounding.WsdlGrounding);
else if(isUPnP)
addStatement(grounding, RDF.type, FLAServiceOnt.UPnPGrounding);
}
private void writeWSDLGrounding(WSDLAtomicGrounding grounding) {
addStatement(grounding, RDF.type, OWLS.Grounding.WsdlAtomicProcessGrounding);
addStatement(grounding, OWLS.Grounding.wsdlDocument, grounding.getWSDL());
addStatement(grounding, OWLS.Grounding.owlsProcess, grounding.getProcess());
try {
addStatement(grounding, OWLS.Grounding.wsdlInputMessage, grounding.getInputMessage());
addStatement(grounding, OWLS.Grounding.wsdlOutputMessage, grounding.getOutputMessage());
} catch (Exception e) {
}
Resource opDesc = ResourceFactory.createResource();
addStatement(grounding, OWLS.Grounding.wsdlOperation, opDesc);
addStatement(opDesc, RDF.type, OWLS.Grounding.WsdlOperationRef);
if(grounding.getPortType() != null)
addStatement(opDesc, OWLS.Grounding.portType, grounding.getPortType());
addStatement(opDesc, OWLS.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();
if(messageMapList.size() == 0)
return;
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.Grounding.wsdlMessageMap);
addStatement(r, OWLS.Grounding.owlsParameter, map.getOWLSParameter());
addStatement(r, OWLS.Grounding.wsdlMessagePart, map.getGroundingParameter());
if(map.getTransformation() != null)
addStatement(r, OWLS.Grounding.xsltTransformation, toRDF(map.getTransformation(), true));
elements[i] = r;
}
RDFList list = model.createList(elements);
if(writeInputs)
addStatement(grounding, OWLS.Grounding.wsdlInputMessageParts, list);
else
addStatement(grounding, OWLS.Grounding.wsdlOutputMessageParts, list);
}
private void writeUPnPGrounding(UPnPAtomicGrounding grounding) {
addStatement(grounding, RDF.type, FLAServiceOnt.UPnPAtomicProcessGrounding);
addStatement(grounding, OWLS.Grounding.owlsProcess, 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();
if(messageMapList.size() == 0)
return;
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.Grounding.owlsParameter, map.getOWLSParameter());
addStatement(r, FLAServiceOnt.upnpParameter, map.getGroundingParameter());
if(map.getTransformation() != null)
addStatement(r, OWLS.Grounding.xsltTransformation, toRDF(map.getTransformation(), true));
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 + -