Ignore:
Timestamp:
2001-03-09T11:30:02+13:00 (23 years ago)
Author:
say1
Message:

moved init stuff to NzdlIORs. comments

File:
1 edited

Legend:

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

    r2136 r2140  
    9191  public static String IORFileName = "/tmp/localcorba.objid";
    9292
    93 
    94   /**
    95    *
     93  /** default places wit look for IORs ... */
     94  static String[] urlsCompiledIn =
     95  {
     96    "http://nikau.cs.waikato.ac.nz/~say1/gsdl/cgi-bin/getior",
     97    "http://www.nzdl.org/cgi-bin/getior"
     98  };
     99
     100
     101
     102  /**
     103   * Get the first known-good IOR
     104   * @see java.lang.String
     105   * @return the string containing the IOR
    96106   */
    97107  public static String getFirstValid()  {
     
    102112      while (e.hasMoreElements()) {
    103113    String IOR = (String) e.nextElement();
    104     if (attemptToInitialise(null, null, IOR)) {
     114    if (attemptToInitialise(null, null, IOR) != null) {
    105115      return IOR;
    106116    }
     
    111121
    112122  /**
    113    *
     123   * Check that the class has been correctly initialised
    114124   */
    115125  static protected void checkLoaded()  {
     
    149159
    150160  /**
    151    *
     161   * Save the IORs back to the underlying file
     162   * @see java.io.File
    152163   */
    153164  static protected void checkSave()  {
     
    165176    }
    166177  }
    167 
    168   /**
    169    *
    170    */
    171   public static void validate()  {
     178  /**
     179   * Find a valid IOR to initialise from.
     180   * @param _args the command line arguments
     181   * @param _URL a URL to look for an IOR in
     182   * @param _filename a local filename to look for an IOR in
     183   * @param _IOR a string to look for an IOR in
     184   * @see org.omg.CORBA.ORB
     185   */
     186  public static NzdlServiceClient findIOR(String [] _args,
     187                      String _URL,
     188                      String _filename,
     189                      String _IOR)  {
     190   
     191    // read our prevously seed IORs ...
     192    String IOR = null;
     193    NzdlServiceClient client = null;
     194     
     195    // try a URL from the command line
     196    if ( _URL != null) {
     197      IOR = NzdlIORs.getIORfromURL(_URL);
     198      client = attemptToInitialise(_args, null, IOR);
     199    }
     200   
     201    // try an IOR from the command line
     202    if (_IOR != null && client == null) {
     203      IOR = NzdlIORs.registerIOR(_IOR);
     204      client = attemptToInitialise(_args, null, IOR);
     205    }
     206   
     207    // try an IOR from a file (the filename may have been
     208    // given from teh commandline
     209    if (client == null) {
     210      IOR = NzdlIORs.getIORfromFile(_filename);
     211      client = attemptToInitialise(_args, null, IOR);
     212    }
     213   
     214    // try the compiled-in URLs
     215    if (client == null) {
     216      for (int i=0;( i<urlsCompiledIn.length && client == null );i++) {
     217    IOR = NzdlIORs.getIORfromURL(urlsCompiledIn[i]);
     218    client = attemptToInitialise(_args, null,IOR);
     219      }
     220    }
     221   
     222    // the knownIORs is the last resort
     223    if (client == null) {
     224      IOR = NzdlIORs.getFirstValid();
     225      client = attemptToInitialise(_args, null, IOR);
     226    }
     227    return client;
     228  }
     229
     230  /**
     231   * Connect to each of the ORB's described by the IORs and throw away
     232   * any that can't be connected to.
     233   * @see org.omg.CORBA.ORB
     234   */
     235 public static void validate()  {
    172236    checkLoaded();
    173237    synchronized (knownIORs) {
     
    181245      while (e.hasMoreElements()) {
    182246    String IOR = (String) e.nextElement();
    183     if (attemptToInitialise(null, null, IOR)) {
     247    if (attemptToInitialise(null, null, IOR) != null) {
    184248      valid.put(IOR,"");
    185249    }
     
    197261
    198262  /**
    199    *
    200    */
    201   public static String registerIOR(String str)
     263   * Register a given IOR
     264   * @see java.lang.String
     265   * @param str the IOR
     266   * @return the str
     267   */
     268 public static String registerIOR(String str)
    202269  {
    203270    checkLoaded();   
     
    211278 
    212279  /**
    213    *
     280   * Retrieve an IOR from a URL
     281   * @see java.net.URL
     282   * @param str the url to retrieve
     283   * @return the IOR
    214284   */
    215285  public static String getIORfromURL(String str)
     
    237307  }
    238308
    239   /**
    240    * Pre:  Accept SourceOfID as either: URL or IOR string or Filename
    241    * Post: extract localcorba.objid from source of ID
     309  /**
     310   * Retrieve an IOR from a file
     311   * @see java.io.File
     312   * @param str the file to open
     313   * @return the IOR
    242314   */
    243315  public static String getIORfromFile(String file) {
    244316    checkLoaded();
    245317    String ior = null;
    246       file = file.trim();
     318    if (file == null || file.equals(""))
     319      return "";
     320    file = file.trim();
    247321    try  {
    248322      BufferedReader input
     
    259333  }   // end of getIorKey
    260334
    261   /**
    262    * Pre:  Accept SourceOfID as either: URL or IOR string or Filename
    263    * Post: extract localcorba.objid from source of ID
     335  /**
     336   * Write all IORs to a flat file (for reading from c++ etc).
     337   *
     338   * Not used for the properties files.
     339   *
     340   * @see java.util.Properties
     341   * @param file the file to write to
    264342   */
    265343  public static void  writeToFile(String file) {
     
    284362
    285363
    286 
    287   static private boolean attemptToInitialise(String [] _args,
     364  /**
     365   * Attempt to connect to the object pointed to by an IOR
     366   * @see org.omg.CORBA.ORB
     367   * @param _args the command line arguments
     368   * @param _props the system properties
     369   * @param _IOR the IOR string
     370   * @return the newly created NzdlServiceClient
     371   */
     372  static public NzdlServiceClient attemptToInitialise(String [] _args,
    288373                      Properties _props,
    289374                      String _IOR) {
    290375    checkLoaded();
     376    NzdlServiceClient nzdl = null;
    291377    try {
    292       NzdlServiceClient nzdl = new NzdlServiceClient( _args, _props, _IOR);
     378      nzdl = new NzdlServiceClient( _args, _props, _IOR);
    293379    } catch (Throwable t) {
    294380      System.err.println ("failed to initialise using:");
    295381      System.err.println (_IOR);
    296       return false;
    297     }
    298     return true;
     382      return null;
     383    }
     384    return nzdl;
    299385  }
    300386 
     387  /**
     388   * Write the System properties to a file called "System.properties" in
     389   * the current directory.
     390   */
    301391  public static final void main( String [] args ) {
    302392 
Note: See TracChangeset for help on using the changeset viewer.