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

📄 soapclient.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*  OMM - Ontology Middleware Module *  Copyright (C) 2002 OntoText Lab, Sirma AI OOD * *  Contact: *	Sirma AI OOD, OntoText Lab. *	38A, Christo Botev Blvd. *  1000 Sofia, Bulgaria *	tel. +359(2)981 00 18 *	fax. +359(2)981 90 58 *	info@ontotext.com * * 	http://www.ontotext.com/ * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2.1 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with this library; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package org.openrdf.sesame.server.soap;import java.net.URL;import java.util.Map;import java.util.Vector;import org.apache.soap.Constants;import org.apache.soap.Fault;import org.apache.soap.SOAPException;import org.apache.soap.encoding.SOAPMappingRegistry;import org.apache.soap.rpc.Call;import org.apache.soap.rpc.Parameter;import org.apache.soap.rpc.Response;public class SoapClient {//  String SERVER_URL = "http://localhost:8080/soap/servlet/rpcrouter";  String SERVER_URL = "http://62.213.161.156:8888/soap/servlet/rpcrouter";  String SERVICE_NAME = "urn:SesameSoap";/** * The only constructor of the SOAP client. * @param ServerUrl the URL of the SOAP rpcrouter server * @param ServiceName the ID of the SOAP service to use */  public SoapClient(String ServerUrl, String ServiceName) throws java.net.MalformedURLException {    SERVER_URL = ServerUrl;    SERVICE_NAME = ServiceName;    url = new URL(SERVER_URL);    call.setEncodingStyleURI(encodingStyleURI);    call.setSOAPMappingRegistry(new SOAPMappingRegistry());    call.setTargetObjectURI(SERVICE_NAME);  }//----------------------------------------------------------------------// holds the used encoding style  private static final String encodingStyleURI = Constants.NS_URI_SOAP_ENC;// holds the url to the Soap server  private URL url;// holds the instance used to invoke the Remote interface via SOAP.// the server keep theck of the current session with the cliean during the// livetime of that instance (it keeps the cookies thet hold the reference to// the current session on the server  private Call call = new Call();/** * the Helper used to invoke the methods of REMOTE Sesame object via SOAP rpc */  private Object invoke(java.lang.reflect.Method method, String[] names, Object[] values)  {    // Build the call.    call.setMethodName(method.getName());    Vector params = new Vector();    Class[] paramTypes = method.getParameterTypes();    for (int i =0; i < names.length; i++)    {      Parameter p = new Parameter(names[i], paramTypes[i], SERVICE_NAME, null);      p.setValue(values[i]);      params.addElement(p);    }    call.setParams(params);    // Invoke the call.    Response resp;    try    {      resp = call.invoke(url, "");    }    catch (SOAPException e)    {      System.err.println("Caught SOAPException (" +                         e.getFaultCode() + "): " +                         e.getMessage()+"\n");      e.printStackTrace(System.err);      return null;    }    // Check the response.    if (!resp.generatedFault())    {      Parameter ret = resp.getReturnValue();			if (null!=ret) {				return ret.getValue();			} else {				return ret;			}    }    else    {      Fault fault = resp.getFault();      System.err.println("Generated fault: " + fault);    }    return null;  } // invoke()// the interface of the remote object/** * Retrieve a list of availibe repositories on the server * @return an array of repository ID's */  public String[] listRepositories() {    return (String[])invoke(listRepositories_0, new String[]{}, new Object[]{});  } //listRepositories()	public String getRepositoryTitle(String repositoryId) {		return (String)invoke(getRepositoryTitle_0, new String[]{"repositoryId"}, new Object[]{repositoryId});	}  /**   * Select a repository to work with   * @param repos repository ID.   * @return true if successful   */	public boolean selectRepository(String repos) {    Object o = invoke(selectRepository_0, new String[]{"repos"}, new Object[]{repos});    return ((Boolean)o).booleanValue();  }  /**   * Login to server.   * @param userID user ID   * @param pass user password   * @return true if successful   */	public boolean login(String userID, String pass) {    Object o = invoke(login_0, new String[]{"userID", "pass"}, new Object[]{userID, pass});    return ((Boolean)o).booleanValue();  }  /**   * Upload a RDF(S) data located on the NET using it's URI into the currently   * selected repository.   * @param dataUrl the URL to the RDF(S)data.   * @param baseURL URI that should be used as namespace for those resources, found in the   * data, that do not have an explicitly defined one. This parameter can be   * eiter null or empty string in ehich case the URL to the date will be   * used as base URL.   */  public int addDataFromUrl( String dataUrl, String baseURL) {    Object o = invoke(addDataFromUrl_0, new String[]{"dataUrl", "baseURL"}, new Object[]{dataUrl, baseURL});    return ((Integer)o).intValue();  }/** * Clear the contents of the current repository. * @return true if successfull */  public boolean clearRepository() {    Object o = invoke(clearRepository_0, new String[]{}, new Object[]{});    return ((Boolean)o).booleanValue();  }/** * Evaluate an RDQL query over the data held in the current repository * @param query the text of the query to evaluate * @return a Vector containing the distinct results of the query. * NOTE: Each element of that Vector is a String[] contating the URI's of particular * distinct result of the evaluated query. */  public Vector evalRdqlQuery(String query) {    return (Vector)invoke(evalRdqlQuery_0, new String[]{"query"}, new Object[]{query});  }/** * Evaluate an RQL query over the data held in the current repository * @param query the text of the query to evaluate * @return a Vector containing the distinct results of the query. * NOTE: Each element of that Vector is a String[] contating the URI's of particular * distinct result of the evaluated query. */  public Vector evalRqlQuery(String query) {    return (Vector)invoke(evalRqlQuery_0, new String[]{"query"}, new Object[]{query});  }/** * Etract the contents of the current repository as RDF. * @param ontology flag indicating to include the ontoloy in the result * @param instances flag indicating to include instances  in the result * @param explicit flag indicating to include only explicit statements in the result * @return a string containig the RDF data of the export */  public String extractRDF(boolean ontology, boolean instances, boolean explicit){    return (String)invoke(extractRDF_0, new String[]{"ontology", "instances", "explicit"}, new Object[]{Boolean.valueOf(ontology), Boolean.valueOf(instances), Boolean.valueOf(explicit)});  }/** * Retrive a list of the defined classes in the repository * @return Vector containig the URI's of the classes */  public Vector getClasses() {    return (Vector)invoke(getClasses_0, new String[]{}, new Object[]{});  }/** * Retrive a list of classes to which an Instance belongs * @param anInstance Instance to explore * @param mostSpecific flag indicating that only the most specific classes to be included in * the result * @return Vector containig the URI's of the classes */  public Vector getClassesOf(String anInstance, boolean mostSpecific) {    return (Vector)invoke(getClassesOf_0, new String[]{"anInstance", "mostSpecific"}, new Object[]{anInstance, Boolean.valueOf(mostSpecific)});  }/** * Retrive a list of URI's of an instances about specific class * @param aClass Class to explore * @param proper flag indicating thet only the proper instances to be included in * the result * @return Vector containig the URI's of the instances */  public Vector getInstancesOf(String aClass, boolean proper){    return (Vector)invoke(getInstancesOf_0, new String[]{"aClass", "proper"}, new Object[]{aClass, Boolean.valueOf(proper)});  }/** * Retrive a list of the defined properties in the repository * @return Vector containig the URI's of the properties */  public Vector getProperties() {    return (Vector)invoke(getProperties_0, new String[]{}, new Object[]{});  }/** * Retrive a list of the statemnets from the repository. All the * statements that match the provided pattern will be included into teh result * @param subj URI of the subject, The null means that the subject does not mather * and the statement will be included regarding on the match of its other * componets(predicate, object, or is it an explicit one) * @param pred URI of the predicate. Tha same rule for the null value is valid * @param obj URI of the object. Tha same rule for the null value is valid * @param explicitOnly flag indicating that only the explicit statements to be included in the result * @param objIsLiteral indicating the the URI of the object is actually an Literal not an * Resource URI. * @return Vector containig the String[] with URI's of the distinct componets * of each statement (subject, predicate and object) */  public Vector getStatements(String subj, String pred,	String obj, boolean explicitOnly, boolean objIsLiteral) {    return (Vector)invoke(getStatements_0, new String[]{"subj", "pred", "obj", "explicitOnly", "objIsLiteral"}, new Object[]{subj, pred, obj, Boolean.valueOf(explicitOnly), Boolean.valueOf(objIsLiteral)});  }  /**   * Query the repository for particular statement   * @param subj URI of Subject   * @param pred URI of Predicate   * @param obj URI of Object   * @param explicitOnly flag indicating the the statement is explicit   * @param objIsLiteral flag indicationg thet object's URI is actuallt a Literal   */	public boolean hasStatement(String subj, String pred, String obj, boolean explicitOnly, boolean objIsLiteral) {    Object o = invoke(hasStatement_0, new String[]{"subj", "pred", "obj", "explicitOnly", "objIsLiteral"}, new Object[]{subj, pred, obj, Boolean.valueOf(explicitOnly), Boolean.valueOf(objIsLiteral)});    return ((Boolean)o).booleanValue();  }  /**   * Retrieve a list of the subclasses of a class   * @param resource URI of the class   * @param direct flag indicating to include only its direct subclasses   * @return Vector containing the URI's of the subclasses   */  public Vector getSubClassesOf(String resource, boolean direct){    return (Vector)invoke(getSubClassesOf_0, new String[]{"resource", "direct"}, new Object[]{resource, Boolean.valueOf( direct)});  }  /**   * Retrieve a list of the subproperties of a property   * @param resource URI of the property   * @param direct flag indicating to include only its direct properties   * @return Vector containing the URI's of the subproperties   */  public Vector getSubPropertiesOf(String resource, boolean direct) {    return (Vector)invoke(getSubPropertiesOf_0, new String[]{"resource", "direct"}, new Object[]{resource, Boolean.valueOf(direct)});  }  /**   * Retrieve a list of the superclasses of a class   * @param resource URI of the class   * @param direct flag indicating to include only its direct superclasses   * @return Vector containing the URI's of the superclasses   */  public Vector getSuperClassesOf(String resource, boolean direct) {    return (Vector)invoke(getSuperClassesOf_0, new String[]{"resource", "direct"}, new Object[]{resource, Boolean.valueOf(direct)});  }  /**   * Retrieve a list of the superproperties of a property

⌨️ 快捷键说明

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