⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 owlsreader_0_9.java

📁 开发owl的API,提供了W3C规定标准接口,是目前比较少的API.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			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, OWLS_0_9.Process.input);
			boolean isOutput = p.hasProperty(RDFS.subPropertyOf, OWLS_0_9.Process.output);
			boolean isEffect = p.hasProperty(RDFS.subPropertyOf, OWLS_0_9.Process.effect);
			boolean isPrecondition = p.hasProperty(RDFS.subPropertyOf, OWLS_0_9.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);	
			
			if(p.hasProperty(RDFS.range)) {					
				String type = p.getProperty(RDFS.range).getObject().toString();
				URI uri = URI.create(type);
				if(uri == null)
					error("Invalid parameter type for the process parameter (" + 
							"\n      process: " + process + ", " +
							"\n    parameter: " + param + ", " + 
							"\n         type: " + type + ")");		
				else if(!uri.isAbsolute())
					error("Parameter type for the process parameter is not absolute (" + 
							"\n      process: " + process + ", " +
							"\n    parameter: " + param + ", " + 
							"\n         type: " + type + ")");		
				else
					param.setType(OWLFactory.createOWLResource(uri));
			}		
			else
				error("Cannot find the type for the process parameter (" + 
						"\n      process: " + process + ", " +
						"\n    parameter: " + param + ")");				
			
			StmtIterator j = processInfo.listProperties(RDFS.subClassOf);
			while(j.hasNext()) {
				Resource r = j.nextStatement().getResource();
				if(r.hasProperty(OWL.onProperty, p) && r.hasProperty(OWL.hasValue)) {
					Object value = null;
					RDFNode node = r.getProperty(OWL.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, OWLS_0_9.Profile.serviceName, RDFS.label);

		profile.setService(service);
		
		return profile;
	}
	
	private void createProfileParams(Profile profile, Process process, boolean isInput, Resource profileInfo) {
		Property prop = isInput ? OWLS_0_9.Profile.input : OWLS_0_9.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(OWLS_0_9.Profile.restrictedTo).getObject().toString();
			String paramLabel = p.getProperty(OWLS_0_9.Profile.parameterName).getObject().toString();
			URI    refersURI  = Util.toURI(p.getProperty(OWLS_0_9.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, OWLS_0_9.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(OWLS_0_9.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);
		}	
		
		if(grounding.getAtomicGroundings().size() == 0)
			warning("The grounding of the service is empty (" + 
					"\n    service " + service.getURI() +
					"\n  grounding " + grounding.getURI() + ")");
		
		grounding.setService(service);			
		
		return grounding;
	}	
		
	private AtomicGrounding createAPGrounding(Service service, Resource groundingInfo) {
		AtomicGrounding grounding = null;
		
		if(groundingInfo.hasProperty(RDF.type, OWLS_0_9.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(OWLS_0_9.Grounding.damlsProcess).getResource());
		Resource operationInfo = groundingInfo.getProperty(OWLS_0_9.Grounding.wsdlOperation).getResource();
		String wsdlLoc = groundingInfo.getProperty(OWLS_0_9.Grounding.wsdlDocument).getObject().toString();
		String opName = operationInfo.getProperty(OWLS_0_9.Grounding.operation).getObject().toString();		
		String portType = operationInfo.getProperty(OWLS_0_9.Grounding.portType).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);
		g.setPortType(portType);

		if(groundingInfo.hasProperty(OWLS_0_9.Grounding.wsdlInputMessage))
			g.setInputMessage(groundingInfo.getProperty(OWLS_0_9.Grounding.wsdlInputMessage).getObject().toString());		

		if(groundingInfo.hasProperty(OWLS_0_9.Grounding.wsdlOutputMessage))
			g.setOutputMessage(groundingInfo.getProperty(OWLS_0_9.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(OWLS_0_9.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 ? 
				OWLS_0_9.Grounding.wsdlInputMessageParts: 
				OWLS_0_9.Grounding.wsdlOutputMessageParts;
			messagePart = OWLS_0_9.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(OWLS_0_9.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(OWLS_0_9.Grounding.xsltTranformation)) {
				transformation = messageMap.getProperty(OWLS_0_9.Grounding.xsltTranformation).getString();
				map.setTransformation(transformation);
			}
			
			if(owlsParameter == null) {
				error("Cannot find the target of message map for " + (isInput?"input":"output") + " parameter" +
					"\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 + -