Changeset 2215


Ignore:
Timestamp:
2001-03-21T10:36:32+12:00 (23 years ago)
Author:
paynter
Message:

Updated handling of IOR keys.

File:
1 edited

Legend:

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

    r2203 r2215  
    5454import org.nzdl.gsdl.service.NzdlService;
    5555import org.nzdl.gsdl.service.NzdlServiceClient;
     56import org.nzdl.gsdl.util.NzdlServiceFactory;
    5657
    5758/**
     
    7172 * @see org.nzdl.gsdl.service.NzdlService
    7273 * @see org.nzdl.gsdl.service.NzdlServiceClient
     74 * @see org.nzdl.gsdl.util.NzdlServiceFactory
    7375 * @see gnu.getopt.Getopt
    7476 * @see gnu.getopt.LongOpt
     
    7779public class SearchAllCollections implements Cloneable, Serializable {
    7880
    79   /** The collection of CORBA IORs we know about */
    80   protected Properties knownIORs = null;
    8181  /** The underlying CORBA inferface */
    8282  NzdlService nzdl = null;
    8383
    84   /** The name of the properties file */
    85   String propertiesFileName = "knownIORs.properties";
    86   /** The name of the file we look for IOR's in */
    87   String IORFileName = "/tmp/localcorba.objid";
    8884  /** Look for an IOR in the file first */
    8985  boolean useFileFirst = false;
    9086  /** The IOR that was specified on the commandline */
    9187  String IORFromCommandLine = null;
     88  /** The URL that was specified on the commandline */
     89  String URLFromCommandLine = null;
     90  /** The name of the file we look for IOR's in */
     91  static String IORFileName = "/tmp/localcorba.objid";
    9292
    9393  /** The query to use */
     
    9898
    9999    SearchAllCollections() {
    100     init(null);
    101     }
    102    
     100    nzdl = NzdlServiceFactory.createNzdlService(null,
     101                            System.getProperties(),
     102                            URLFromCommandLine,
     103                            IORFileName,
     104                            IORFromCommandLine);
     105    if (nzdl == null)
     106        throw new Error("URK! unable to find an IOR...");
     107    }
     108   
     109
     110    /**
     111     * Normal constructor. the args are passed into the orb
     112     * initialisation code so they can extract obscure args ...
     113     */
    103114    SearchAllCollections(String [] args) {
    104     parseArgs(args);
    105     init(args);
    106     }
    107 
    108     void init(String [] args)  {
    109    
    110     // Load prevously seen IORs from property file
    111     knownIORs = new Properties();
    112    
    113     File file = new File(propertiesFileName);
    114     try {
    115         if (file.exists()) {
    116         knownIORs.load(new FileInputStream(file));
    117         }
    118     } catch (IOException i) {
    119         System.err.println("Error reading properties file:" + i);
    120     }
    121 
    122     // Attempt to initialise client with ORs from property file
    123     Enumeration e = knownIORs.keys();
    124     while (e.hasMoreElements() && nzdl == null) {
    125         String IOR = (String) e.nextElement();
    126         attemptToInitialise(args, null, IOR);
    127        
    128     }
    129    
    130     // Attempt to initialise client with IOR from file
    131     if (nzdl == null) {
    132         String IOR = getIorKey(IORFileName);
    133         attemptToInitialise(args, null, IOR);
    134         knownIORs.put(IOR,"");
    135     }
    136    
    137     }
    138    
     115    // parseArgs(args);
     116    nzdl = NzdlServiceFactory.createNzdlService(args,
     117                            System.getProperties(),
     118                            URLFromCommandLine,
     119                            IORFileName,
     120                            IORFromCommandLine);
     121    if (nzdl == null)
     122        throw new Error("Unable to find an IOR.");
     123    }
     124
    139125    public void finalize(){
    140     tidy();
    141     }
    142 
    143     void tidy() {
    144     try {
    145         File file = new File(propertiesFileName);
    146         knownIORs.store(new FileOutputStream(file),"These are CORBA IOR's that the SearchAllCollections client has seen and will check again...");
    147     } catch (IOException i) {
    148         System.err.println("Error writing properties file:" + i);
    149     }
     126
    150127    }
    151128
     
    190167   
    191168
    192     private boolean attemptToInitialise(String [] _args,
    193                     Properties _props,
    194                     String _IOR) {
    195     try {
    196         nzdl = new NzdlServiceClient( _args, _props, _IOR);
    197     } catch (Throwable t) {
    198         System.err.println ("Failed to initialise using:");
    199         System.err.println (_IOR);
    200         nzdl = null;
    201         return false;
    202     }
    203     return true;
    204     }
    205 
    206  
    207169    static String getHelpText() {
    208170    String s = "";
     
    345307   
    346308    SearchAllCollections client = new SearchAllCollections(args);
    347    
    348309    client.queryAllCollections();
    349     client.tidy();
    350 
     310 
    351311    } //main
    352312   
Note: See TracChangeset for help on using the changeset viewer.