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

📄 wsdlatomicgroundingimpl.java

📁 开发owl的API,提供了W3C规定标准接口,是目前比较少的API.
💻 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 28, 2003
 *
 */
package org.mindswap.owls.grounding.impl;

import org.mindswap.owl.Util;
import org.mindswap.owls.OWLSFactory;
import org.mindswap.owls.grounding.MessageMap;
import org.mindswap.owls.grounding.WSDLAtomicGrounding;
import org.mindswap.owls.process.Parameter;
import org.mindswap.owls.process.ValueMap;
import org.mindswap.utils.Utils;
import org.mindswap.utils.XSLTEngine;
import org.mindswap.wsdl.WSDLOperation;
import org.mindswap.wsdl.WSDLParameter;
import org.mindswap.wsdl.WSDLService;

import com.hp.hpl.jena.rdf.model.Resource;

/**
 * @author Evren Sirin
 *
 */
public class WSDLAtomicGroundingImpl extends AtomicGroundingImpl implements WSDLAtomicGrounding {
	protected String wsdlLoc;
	protected String operation;
	protected String portType;
	
	protected String inputMessage;
	protected String outputMessage;	
	
	/**
	 * 
	 */
	public WSDLAtomicGroundingImpl(Resource resource) {
		super(resource);
	}

	/* (non-Javadoc)
	 * @see org.mindswap.owls.grounding.WSDLAtomicProcessGrounding#setWSDL(java.lang.String)
	 */
	public void setWSDL(String wsdlLoc) {
		this.wsdlLoc = wsdlLoc;
	}

	/* (non-Javadoc)
	 * @see org.mindswap.owls.grounding.WSDLAtomicProcessGrounding#getWSDL()
	 */
	public String getWSDL() {
		return wsdlLoc;
	}

	/* (non-Javadoc)
	 * @see org.mindswap.owls.grounding.WSDLAtomicProcessGrounding#setOperation(java.lang.String)
	 */
	public void setOperation(String operation) {		
		this.operation = operation;
	}

	/* (non-Javadoc)
	 * @see org.mindswap.owls.grounding.WSDLAtomicProcessGrounding#getOperation()
	 */
	public String getOperation() {
		return operation;
	}

	/* (non-Javadoc)
	 * @see org.mindswap.owls.grounding.WSDLAtomicProcessGrounding#setPortType(java.lang.String)
	 */
	public void setPortType(String port) {
		portType = port;		
	}

	/* (non-Javadoc)
	 * @see org.mindswap.owls.grounding.WSDLAtomicProcessGrounding#getPortType()
	 */
	public String getPortType() {
		return portType;
	}

	/* (non-Javadoc)
	 * @see org.mindswap.owls.grounding.AtomicProcessGrounding#invoke(org.mindswap.owls.process.ValueMap)
	 */
	public ValueMap invoke(ValueMap values) throws Exception {
		ValueMap results = OWLSFactory.createValueMap();
		
		WSDLService s = WSDLService.createService(wsdlLoc);
		WSDLOperation op = s.getOperation(operation);
		
		if(op == null) op = s.getOperation(Util.getLocalName(operation));
		
		if(op == null) throw new Exception("Operation " + operation + " cannot be found in the WSDL description");
		
		for(int i = 0; i < op.getInputs().size(); i++) {		
			WSDLParameter in = op.getInput(i);
			MessageMap mp = getInputMap().getMessageMap(in.getName());
			
			if(mp == null) continue;
			
			Parameter param = mp.getOWLSParameter();
					
			Object value = values.getValue(param);
			Object inputValue = value;
					
			if(mp.getTransformation() != null) {
				value = XSLTEngine.transform(value.toString(), mp.getTransformation());
				inputValue = Utils.getAsNode(value.toString());
				if(inputValue == null) inputValue = value.toString().trim();
			}				

			if(value == null) throw new Exception("Value of input parameter '" + param + "' is not set!");
			
			in.setValue(inputValue);
		}
									
		op.invoke();

		for(int i = 0; i < op.getOutputs().size(); i++) {		
			WSDLParameter out = op.getOutput(i);
			MessageMap mp = getOutputMap().getMessageMap(out.getName());
			Parameter param = mp.getOWLSParameter();

			Object outputValue = out.getValue();
			
			if(outputValue == null) 
				throw new Exception("Value of output parameter '" + out + "' is not set by the WSDL operation!");
			else if(mp.getTransformation() != null) 
				outputValue = XSLTEngine.transform(out.getTextValue(), mp.getTransformation());			
				
			if(outputValue == null) 
				throw new Exception("An error occurred when applying xsltTransformtion to output parameter '" + param + "'");
			
			results.setValue(param, outputValue);				
		}
		
		return results;
	}

	/* (non-Javadoc)
	 * @see org.mindswap.owls.grounding.AtomicProcessGrounding#getDescriptionURL()
	 */
	public String getDescriptionURL() {
		return getWSDL();
	}

	/**
	 * @return Returns the inputMessage.
	 */
	public String getInputMessage() {
		return inputMessage;
	}

	/**
	 * @param inputMessage The inputMessage to set.
	 */
	public void setInputMessage(String inputMessage) {
		this.inputMessage = inputMessage;
	}

	/**
	 * @return Returns the outputMessage.
	 */
	public String getOutputMessage() {
		return outputMessage;
	}

	/**
	 * @param outputMessage The outputMessage to set.
	 */
	public void setOutputMessage(String outputMessage) {
		this.outputMessage = outputMessage;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -