📄 damlsreader_0_7.java
字号:
"\n process " + processName2 +
"\n parameter " + paramName2 +
"\n data flow in " + process.getURI());
}
else {
param2 = p2.getParameter(Util.toURI(paramName2));
if(param2 == null) {
error("Cannot find the parameter data flow refers to " +
"\n process " + processName2 +
"\n parameter " + paramName2 +
"\n data flow in " + process.getURI());
}
}
if(param1 == null || param2 == null)
continue;
DataFlowElement dfe = OWLSFactory.createDataFlowElement();
dfe.add(param1);
dfe.add(param2);
dataFlow.add(dfe);
}
}
private void createProcessParams(Process process, Resource processInfo) {
StmtIterator i = processInfo.getModel().listStatements(null, RDFS.domain, processInfo);
while(i.hasNext()) {
Resource p = i.nextStatement().getSubject();
boolean isInput = p.hasProperty(RDFS.subPropertyOf, DAMLS_0_7.Process.input);
boolean isOutput = p.hasProperty(RDFS.subPropertyOf, DAMLS_0_7.Process.output);
boolean isEffect = p.hasProperty(RDFS.subPropertyOf, DAMLS_0_7.Process.effect);
boolean isPrecondition = p.hasProperty(RDFS.subPropertyOf, DAMLS_0_7.Process.precondition);
boolean isInvalid = !(isInput || isOutput || isEffect || isPrecondition);
if(isInvalid) {
System.err.println("WARNING: found a property of process" +
" which is neither an input nor an output\nparam " + p);
continue;
}
Parameter param = null;
if(isInput) {
param = OWLSFactory.createInput(p);
process.getInputs().add(param);
}
else {
param = OWLSFactory.createOutput(p);
process.getOutputs().add(param);
}
param.setProcess(process);
param.setType(OWLFactory.createOWLResource(p.getProperty(RDFS.range).getResource()));
StmtIterator j = processInfo.listProperties(RDFS.subClassOf);
while(j.hasNext()) {
Resource r = j.nextStatement().getResource();
if(r.hasProperty(DAML_OIL.onProperty, p) && r.hasProperty(DAML_OIL.hasValue)) {
Object value = null;
RDFNode node = r.getProperty(DAML_OIL.hasValue).getObject();
if(node instanceof Literal)
value = ((Literal) node).getValue();
else
value = ((Resource) node).getURI();
process.getDefaultValues().setValue(param, value);
break;
}
}
if(DEBUG) {
System.out.println(" Process " + process.getURI() + "\n" +
(isInput ? " Input ":" Output " ) +
param.getLabel() + "\n" +
" Type " + param.getType() + "\n");
}
}
}
public Profile createProfile(Service service, Resource profileInfo) {
Profile profile = OWLSFactory.createProfile(profileInfo);
Process process = service.getProcess();
createProfileParams(profile, process, true, profileInfo);
createProfileParams(profile, process, false, profileInfo);
profile.setType(Util.toURI(profileInfo.getProperty(RDF.type).getResource()));
copyPropertyValues(profileInfo, DAMLS_0_7.Profile.serviceName, RDFS.label);
profile.setService(service);
return profile;
}
private void createProfileParams(Profile profile, Process process, boolean isInput, Resource profileInfo) {
Property prop = isInput ? DAMLS_0_7.Profile.input : DAMLS_0_7.Profile.output;
StmtIterator i = profileInfo.getModel().listStatements(profileInfo, prop, (Resource)null);
while(i.hasNext()) {
Resource p = (Resource) i.nextStatement().getObject();
String paramURI = p.getURI();
String paramType = p.getProperty(DAMLS_0_7.Profile.restrictedTo).getObject().toString();
String paramLabel = p.getProperty(DAMLS_0_7.Profile.parameterName).getObject().toString();
URI refersURI = Util.toURI(p.getProperty(DAMLS_0_7.Profile.refersTo).getResource());
Parameter refersTo = isInput ?
process.getInputs().getParameter(refersURI):
process.getOutputs().getParameter(refersURI);
if(refersTo == null) {
error("Cannot find the target of refersTo for " +
"\n parameter " + paramURI +
"\n in profile " + profile.getURI() +
"\n referring " + refersURI);
continue;
}
if(!refersTo.getType().getURI().equals(Util.toURI(paramType))) {
error("The parameter type defined in profile and process does not match " +
"\n parameter " + paramURI +
"\n type " + paramType +
"\n in profile " + profile.getURI() +
"\n referring " + refersTo +
"\n type " + refersTo.getType());
continue;
}
//refersTo.setLabel(paramLabel);
copyPropertyValues(p, DAMLS_0_7.Profile.parameterName, refersTo.getJenaResource(), RDFS.label);
if(isInput)
profile.getInputs().add(refersTo);
else
profile.getOutputs().add(refersTo);
if(DEBUG) {
System.out.println(" Profile " + profile.getURI() + "\n" +
(isInput ? " Input ":" Output " ) +
paramURI + "\n" +
" Label " + refersTo.getLabel() + "\n" +
" Type " + paramType + "\n" +
" Refers to " + refersTo + "\n");
}
}
}
public Grounding createGrounding(Service service, Resource groundingInfo) {
Grounding grounding = OWLSFactory.createGrounding(groundingInfo);
StmtIterator i = groundingInfo.listProperties(DAMLS_0_7.Grounding.hasAtomicProcessGrounding);
while(i.hasNext()) {
Resource apGroundingInfo = i.nextStatement().getResource();
AtomicGrounding apGrounding = createAPGrounding(service, apGroundingInfo);
if(apGrounding != null)
grounding.addGrounding(apGrounding);
else
error("Invalid grounding " + apGroundingInfo);
}
i = groundingInfo.listProperties(FLAServiceOnt.hasUPnPAtomicProcessGrounding);
while(i.hasNext()) {
Resource apGroundingInfo = i.nextStatement().getResource();
AtomicGrounding apGrounding = createAPGrounding(service, apGroundingInfo);
if(apGrounding != null)
grounding.addGrounding(apGrounding);
else
error("Invalid grounding " + apGroundingInfo);
}
grounding.setService(service);
return grounding;
}
private AtomicGrounding createAPGrounding(Service service, Resource groundingInfo) {
AtomicGrounding grounding = null;
if(groundingInfo.hasProperty(RDF.type, DAMLS_0_7.Grounding.WsdlAtomicProcessGrounding))
grounding = createWSDLGrounding(service, groundingInfo);
if(groundingInfo.hasProperty(RDF.type, FLAServiceOnt.UPnPAtomicProcessGrounding))
grounding = createUPnPGrounding(service, groundingInfo);
if(grounding != null)
grounding.getProcess().setGrounding(grounding);
return grounding;
}
private AtomicGrounding createWSDLGrounding(Service service, Resource groundingInfo) {
URI processURI = Util.toURI(groundingInfo.getProperty(DAMLS_0_7.Grounding.damlsProcess).getResource());
String wsdlLoc = groundingInfo.getProperty(DAMLS_0_7.Grounding.wsdlDocument).getObject().toString();
String opName = groundingInfo.getProperty(DAMLS_0_7.Grounding.wsdlOperation).getObject().toString();
AtomicProcess process = (AtomicProcess) findProcess(service.getProcess(), processURI);
if(process == null) {
error("The process specified in the grounding cannot be found " +
"\n grounding " + groundingInfo +
"\n process " + processURI);
return null;
}
WSDLAtomicGrounding g = OWLSFactory.createWSDLAtomicGrounding(groundingInfo);
g.setProcess(process);
g.setWSDL(wsdlLoc);
g.setOperation(opName);
if(groundingInfo.hasProperty(DAMLS_0_7.Grounding.wsdlInputMessage))
g.setInputMessage(groundingInfo.getProperty(DAMLS_0_7.Grounding.wsdlInputMessage).getObject().toString());
if(groundingInfo.hasProperty(DAMLS_0_7.Grounding.wsdlOutputMessage))
g.setOutputMessage(groundingInfo.getProperty(DAMLS_0_7.Grounding.wsdlOutputMessage).getObject().toString());
createMessageMapList(g, groundingInfo, true);
createMessageMapList(g, groundingInfo, false);
if(DEBUG) {
System.out.println(" Process " + process.getURI() + "\n" +
" WSDL file " + wsdlLoc + "\n" +
" Operation " + opName + "\n");
}
return g;
}
private AtomicGrounding createUPnPGrounding(Service service, Resource groundingInfo) {
URI processURI = Util.toURI(groundingInfo.getProperty(DAMLS_0_7.Grounding.damlsProcess).getResource());
String upnpDevice = groundingInfo.getProperty(FLAServiceOnt.upnpDeviceURL).getObject().toString();
String upnpService = groundingInfo.getProperty(FLAServiceOnt.upnpServiceID).getObject().toString();
String upnpAction = groundingInfo.getProperty(FLAServiceOnt.upnpCommand).getObject().toString();
AtomicProcess process = (AtomicProcess) findProcess(service.getProcess(), processURI);
UPnPAtomicGrounding g = OWLSFactory.createUPnPAtomicGrounding(groundingInfo);
g.setProcess(process);
g.setUPnPDescription(upnpDevice);
g.setUPnPService(upnpService);
g.setUPnPAction(upnpAction);
createMessageMapList(g, groundingInfo, true);
createMessageMapList(g, groundingInfo, false);
if(DEBUG) {
System.out.println(" Process " + process.getURI() + "\n" +
" Device " + upnpDevice + "\n" +
" Service " + upnpService + "\n" +
" Action " + upnpAction + "\n");
}
return g;
}
private void createMessageMapList(AtomicGrounding g, Resource groundingInfo, boolean isInput) {
Process process = g.getProcess();
Property messageParts = null;
Property messagePart = null;
if(g instanceof UPnPAtomicGrounding) {
messageParts = isInput ?
FLAServiceOnt.UPnPInputMapping:
FLAServiceOnt.UPnPOutputMapping;
messagePart = FLAServiceOnt.upnpParameter;
}
else if(g instanceof WSDLAtomicGrounding) {
messageParts = isInput ?
DAMLS_0_7.Grounding.wsdlInputMessageParts:
DAMLS_0_7.Grounding.wsdlOutputMessageParts;
messagePart = DAMLS_0_7.Grounding.wsdlMessagePart;
}
if(!groundingInfo.hasProperty(messageParts))
return;
Resource messageMapInfo = (Resource) groundingInfo.getProperty(messageParts).getObject();
List messageMapList = Util.createList(messageMapInfo);
MessageMapList mapList = isInput ? g.getInputMap() : g.getOutputMap();
for(int i = 0; i < messageMapList.size(); i++) {
Resource messageMap = (Resource) messageMapList.get(i);
MessageMap map = OWLSFactory.createMessageMap(messageMap);
URI owlsParameterInfo = Util.toURI(messageMap.getProperty(DAMLS_0_7.Grounding.damlsParameter).getResource());
Parameter owlsParameter = isInput ?
process.getInputs().getParameter(owlsParameterInfo):
process.getOutputs().getParameter(owlsParameterInfo);
map.setOWLSParameter(owlsParameter);
String wsdlMessagePartInfo = messageMap.getProperty(messagePart).getObject().toString();
map.setGroundingParameter(wsdlMessagePartInfo);
String transformation = null;
if(messageMap.hasProperty(DAMLS_0_7.Grounding.xsltTranformation)) {
transformation = messageMap.getProperty(DAMLS_0_7.Grounding.xsltTranformation).getString();
map.setTransformation(transformation);
}
if(owlsParameter == null) {
error("Cannot find the target of message map for " +
"\n wsdl parameter " + wsdlMessagePartInfo +
"\n in process " + process.getURI() +
"\n mapped to " + owlsParameterInfo);
}
if(DEBUG) {
System.out.println(" Process " + process.getURI() + "\n" +
" Param " + owlsParameterInfo + "\n" +
" Grounding " + wsdlMessagePartInfo + "\n" +
" Transform " + transformation + "\n");
}
mapList.add(map);
}
}
private Process findProcess(ProcessComponent process, URI processURI) {
if(process == null)
return null;
else if(process.getURI() != null && process.getURI().equals(processURI)){
if(process instanceof Process) return (Process) process;
}
else if(process instanceof CompositeProcess) {
return findProcess(((CompositeProcess) process).getComposedOf(), processURI);
}
else if(process instanceof ControlConstruct) {
ProcessComponentList list = ((ControlConstruct)process).getComponents();
for(int i = 0; i < list.size(); i++) {
ProcessComponent pc = list.processComponentAt(i);
Process p = findProcess(pc, processURI);
if(p != null) return p;
}
}
return null;
}
private void copyPropertyValues(Resource subj, Property srcProp, Property targetProp) {
copyPropertyValues(subj, srcProp, subj, targetProp);
}
private void copyPropertyValues(Resource src, Property srcProp, Resource target, Property targetProp) {
List values = new ArrayList();
StmtIterator si = src.listProperties(srcProp);
while(si.hasNext())
values.add(si.nextStatement().getObject());
Iterator i = values.iterator();
while(i.hasNext())
target.addProperty(targetProp, (RDFNode) i.next());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -