clientcorbatransport.java

来自「数字图书馆的互操作接口」· Java 代码 · 共 179 行

JAVA
179
字号
package dli2fe.helpers;

/**
 * Title:        Digial Library Interoperable Interface Fudan Edition
 * Description:  This project contains all the classes required for DLI2FE interface. Developers use these classes to implement the wrapper and client side codes. The basic functions of DLI2FE is as follows:
 * Search: Search a digital library source site.
 * Metadata: Fetch metadata for a site.
 * ResultAccess: Get results for a given query.
 * DLI2FE uses Dublin Core as the basic attribute model, DAV/DASL as the general XML-based query language and CORBA as distributed object transportation mechanism.
 * Copyright:    Copyright (c) 2001
 * Company:      Fudan University
 * @author Carl Tao
 * @version 1.0
 */
import java.io.*;
import java.net.*;
import org.omg.CORBA.ORB;
import dli2fe.CORBA.*;
import dli2fe.DLI2FEException;

public class ClientCORBATransport extends ClientTransportModule {
  ORB orb;
  org.omg.CORBA.Object lsp;

  public ClientCORBATransport() {
  }

  public ClientCORBATransport(String uri) throws DLI2FEException{
    setLspURI(uri);
  }

  public void setLspURI(String uri) throws DLI2FEException{
    if (orb == null) {
      String args[] = new String[1];
      orb = org.omg.CORBA.ORB.init(args, null);
    }
    // Init lsp according to the supplied uri.
    // if uri is URL, get IOR
    // else directly create CORBA object from IOR
    if (uri.startsWith(dli2fe.DLI2FE.NameServerURISchema + ":")) {
      try {
        String url = uri.substring(dli2fe.DLI2FE.NameServerURISchema.length() + 1);
        BufferedReader din = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
        uri = din.readLine();
        din.close();
      } catch (IOException ex) {
        //throw new RuntimeException(ex.toString() + " can not resolve IOR: " + ex.getMessage());
        throw new DLI2FEException(DLI2FEException.SERVICE_UNAVAILABLE_EXC, " can not resolve IOR: " + ex.getMessage());
      }
    }

    lsp = orb.string_to_object(uri);
  }

  String toString(dli2fe.XMLObject obj) throws dli2fe.DLI2FEException {
    String res = obj == null ? "" : obj.getString();
    return res == null ? "" : res;
  }

  public void getSiteMetadata (dli2fe.XMLObject theSiteMetadata) throws dli2fe.DLI2FEException {
    org.omg.CORBA.StringHolder metadata = new org.omg.CORBA.StringHolder();
    try {
      DLI2FEIntfHelper.narrow(lsp).getSiteMetadata(metadata);
    } catch (Exception se) {
      if (se instanceof dli2fe.CORBA.DLI2FEException)
        throw new dli2fe.DLI2FEException((dli2fe.CORBA.DLI2FEException)se);
      else
        throw new dli2fe.DLI2FEException(dli2fe.DLI2FEException.SERVICE_UNAVAILABLE_EXC, String.valueOf(se));
    }
    theSiteMetadata.setString(metadata.value);
  }

  public void getAttributeInfo (String ctgrName,
                                dli2fe.XMLObject attributeInfo) throws dli2fe.DLI2FEException {
    org.omg.CORBA.StringHolder info = new org.omg.CORBA.StringHolder();
    try {
      DLI2FEIntfHelper.narrow(lsp).getAttributeInfo(ctgrName,
                                info);
    } catch (Exception se) {
      if (se instanceof dli2fe.CORBA.DLI2FEException)
        throw new dli2fe.DLI2FEException((dli2fe.CORBA.DLI2FEException)se);
      else
        throw new dli2fe.DLI2FEException(dli2fe.DLI2FEException.SERVICE_UNAVAILABLE_EXC, String.valueOf(se));
    }
    attributeInfo.setString(info.value);
  }

  public void search (int clientSID,
                      dli2fe.XMLObject subcols,
                      dli2fe.XMLObject query,
                      int numDocs,
                      dli2fe.XMLObject docPropList,
                      dli2fe.XMLObject queryOptions,
                      org.omg.CORBA.IntHolder expectedTotal,
                      org.omg.CORBA.IntHolder serverSID,
                      dli2fe.XMLObject result) throws dli2fe.DLI2FEException {
    org.omg.CORBA.StringHolder res = new org.omg.CORBA.StringHolder();
    expectedTotal.value = dli2fe.Searcher.UNKNOWABLE;

    try {
      DLI2FEIntfHelper.narrow(lsp).search(clientSID,
                      toString(subcols),
                      toString(query),
                      numDocs,
                      toString(docPropList),
                      toString(queryOptions),
                      expectedTotal,
                      serverSID,
                      res);
    } catch (Exception se) {
      se.printStackTrace();
      if (se instanceof dli2fe.CORBA.DLI2FEException)
        throw new dli2fe.DLI2FEException((dli2fe.CORBA.DLI2FEException)se);
      else
        throw new dli2fe.DLI2FEException(dli2fe.DLI2FEException.SERVICE_UNAVAILABLE_EXC, String.valueOf(se));
    }
    //System.out.println(res.value);
    result.setString(res.value);
  }

  public void getSessionInfo (int serverSID,
                              org.omg.CORBA.IntHolder expectedTotal,
                              org.omg.CORBA.IntHolder stateTimeout) throws dli2fe.DLI2FEException {
    try {
      DLI2FEIntfHelper.narrow(lsp).getSessionInfo(serverSID, expectedTotal, stateTimeout);
    } catch (Exception se) {
      if (se instanceof dli2fe.CORBA.DLI2FEException)
        throw new dli2fe.DLI2FEException((dli2fe.CORBA.DLI2FEException)se);
      else
        throw new dli2fe.DLI2FEException(dli2fe.DLI2FEException.SERVICE_UNAVAILABLE_EXC, String.valueOf(se));
    }
  }

  public void getDocs (int serverSID,
                       int reqID,
                       dli2fe.XMLObject docPropList,
                       String docsToGet,
                       dli2fe.XMLObject res) throws dli2fe.DLI2FEException {
    org.omg.CORBA.StringHolder result = new org.omg.CORBA.StringHolder();
    try {
      DLI2FEIntfHelper.narrow(lsp).getDocs(serverSID,
                        reqID,
                        toString(docPropList),
                        docsToGet == null ? "" : docsToGet,
                        result);
    } catch (Exception se) {
      if (se instanceof dli2fe.CORBA.DLI2FEException)
        throw new dli2fe.DLI2FEException((dli2fe.CORBA.DLI2FEException)se);
      else
        throw new dli2fe.DLI2FEException(dli2fe.DLI2FEException.SERVICE_UNAVAILABLE_EXC, String.valueOf(se));
    }
    res.setString(result.value);
  }

  public void extendStateTimeout (int serverSID,
                                  int secondsToExtend) throws dli2fe.DLI2FEException {
    try {
      DLI2FEIntfHelper.narrow(lsp).extendStateTimeout(serverSID, secondsToExtend);
    } catch (Exception se) {
      if (se instanceof dli2fe.CORBA.DLI2FEException)
        throw new dli2fe.DLI2FEException((dli2fe.CORBA.DLI2FEException)se);
      else
        throw new dli2fe.DLI2FEException(dli2fe.DLI2FEException.SERVICE_UNAVAILABLE_EXC, String.valueOf(se));
    }
  }

  public void cancelRequest (int serverSID,
                             int reqID) throws dli2fe.DLI2FEException {
    try {
      DLI2FEIntfHelper.narrow(lsp).cancelRequest(serverSID, reqID);
    } catch (Exception se) {
      if (se instanceof dli2fe.CORBA.DLI2FEException)
        throw new dli2fe.DLI2FEException((dli2fe.CORBA.DLI2FEException)se);
      else
        throw new dli2fe.DLI2FEException(dli2fe.DLI2FEException.SERVICE_UNAVAILABLE_EXC, String.valueOf(se));
    }
  }
}

⌨️ 快捷键说明

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