Changeset 2070


Ignore:
Timestamp:
2001-02-26T01:07:28+13:00 (23 years ago)
Author:
say1
Message:

checked in Brett"s getIorKey changes. i changed enough that any mistakes will be mine not his :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-client/org/nzdl/gsdl/SimpleClient.java

    r2067 r2070  
    2626
    2727// java libraries we're using
     28import java.io.BufferedReader;
    2829import java.io.File;
    2930import java.io.FileInputStream;
     
    3132import java.io.FileReader;
    3233import java.io.IOException;
     34import java.io.InputStreamReader;
    3335import java.io.LineNumberReader;
    3436import java.io.Serializable;
    35 import java.util.Vector;
     37import java.net.URL;
    3638import java.util.Enumeration;
    3739import java.util.Iterator;
     
    4143import java.util.Properties;
    4244import java.util.Set;
     45import java.util.Vector;
    4346
    4447// local libraries
     
    5659 * A class to test the workings of Corba interface from the client side.
    5760 *
     61 * @author stuart yeates ([email protected])
     62 * @author Brett Sheeran ([email protected])
    5863 * @author Dave Nichols ([email protected])
    5964 * @author Gordon Paynter ([email protected])
    60  * @author stuart yeates ([email protected])
    6165 * @version $Revision$
    62  * @see org.nzdl.service.NzdlCollectionInfo;
    63  * @see org.nzdl.service.NzdlQuery;
    64  * @see org.nzdl.service.NzdlRequest;
    65  * @see org.nzdl.service.NzdlResponse;
    66  * @see org.nzdl.service.NzdlResultSet;
    67  * @see org.nzdl.service.NzdlService;
    68  * @see org.nzdl.service.NzdlServiceImpl;
     66 * @see org.nzdl.service.NzdlCollectionInfo
     67 * @see org.nzdl.service.NzdlQuery
     68 * @see org.nzdl.service.NzdlRequest
     69 * @see org.nzdl.service.NzdlResponse
     70 * @see org.nzdl.service.NzdlResultSet
     71 * @see org.nzdl.service.NzdlService
     72 * @see org.nzdl.service.NzdlServiceImpl
    6973 * @see gnu.getopt.Getopt;
    7074 * @see gnu.getopt.LongOpt;
    7175 */
    7276
    73 public class SimpleClient implements Cloneable, Serializable{
     77public class SimpleClient implements Cloneable, Serializable {
    7478
    7579  /** The collection of CORBA IORs we know about */
     
    129133   
    130134    if (nzdl == null) {
    131       String IOR = getIorKey();
     135      String IOR = getIorKey(IORFileName);
    132136      System.err.println("ior = " + IOR);
    133137      System.err.println("after IOR");
     
    151155  }
    152156
    153   private String getIorKey() {
     157  /**
     158   * Pre:  Accept SourceOfID as either: URL or IOR string or Filename
     159   * Post: extract localcorba.objid from source of ID
     160   */
     161  private String getIorKey(String sourceOfID) {
    154162    String ior = null;
    155163    try  {
    156       LineNumberReader input
    157     = new LineNumberReader(new FileReader(IORFileName));
    158       ior = input.readLine();
    159     }
    160     catch (java.io.IOException e) {
     164      sourceOfID = sourceOfID.trim();
     165      System.err.println("Reading IOR from: " + sourceOfID);
     166
     167      String firstChars = sourceOfID.substring(0, Math.min(4,sourceOfID.length())).toUpperCase();
     168    // if sourceOfID is a URL ---------------------------------------
     169    if (sourceOfID.length() > 4 && firstChars.equalsIgnoreCase("HTTP")) {
     170      URL myUrl = new URL(sourceOfID);
     171      BufferedReader input =new
     172        BufferedReader(new InputStreamReader(myUrl.openStream()));
     173      ior = input.readLine();
     174    }
     175       
     176    // if sourceOfID is an IOR --------------------------------------
     177    else if (sourceOfID.length() > 4 && firstChars.equalsIgnoreCase("IOR:"))    {
     178      ior = sourceOfID;                 
     179    }
     180
     181    // else assume sourceOfID is a file name ------------------------
     182    else {
     183      BufferedReader input
     184        = new BufferedReader(new FileReader(sourceOfID));
     185      ior = input.readLine();               
     186    }
     187    }  //end of try
     188    catch (java.io.IOException e) {
    161189      System.err.println("Error reading IOR key:\n" + e);
    162190      System.err.println("Aborting service...");
     
    164192    }
    165193    return ior;
    166   }
     194  }   // end of getIorKey
     195
     196
    167197
    168198  private boolean attemptToInitialise(String [] _args,
     
    281311      Map metaData = nzdl.getMetaData( collName, docIDs, metaTag );
    282312     
    283     for (ListIterator i = docIDs.listIterator(); i.hasNext(); ) {
    284       String id = (String) i.next();
    285       Set meta = (Set) metaData.get( id );
    286       if (loadDocs) {
    287         if (verbosity > 3) {
    288           System.out.println(meta.toString());
    289           System.out.println("getting document contents ... ");
    290         }
    291         String documentContents = nzdl.getDocument(collName, id);
    292         if (verbosity > 3) {
    293           System.out.println("got document contents. ");
    294           System.out.println(" *************** START DOC " + id + " ***************");
    295           System.out.println(documentContents);
    296           System.out.println(" *************** END DOC " + id + " ***************");
    297         }
    298       } else {
    299         if (verbosity > 3)
    300           System.out.println(meta.toString());
     313      for (ListIterator i = docIDs.listIterator(); i.hasNext(); ) {
     314    String id = (String) i.next();
     315    Set meta = (Set) metaData.get( id );
     316    if (loadDocs) {
     317      if (verbosity > 3) {
     318        System.out.println(meta.toString());
     319        System.out.println("getting document contents ... ");
    301320      }
    302     }
     321      String documentContents = nzdl.getDocument(collName, id);
     322      if (verbosity > 3) {
     323        System.out.println("got document contents. ");
     324        System.out.println(" *************** START DOC " + id + " ***************");
     325        System.out.println(documentContents);
     326        System.out.println(" *************** END DOC " + id + " ***************");
     327      }
     328    } else {
     329      if (verbosity > 3)
     330        System.out.println(meta.toString());
     331    }
     332      }
    303333    }
    304334  }
Note: See TracChangeset for help on using the changeset viewer.