Changeset 2140 for trunk/java-client/org/nzdl/gsdl/util/NzdlIORs.java
- Timestamp:
- 2001-03-09T11:30:02+13:00 (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/java-client/org/nzdl/gsdl/util/NzdlIORs.java
r2136 r2140 91 91 public static String IORFileName = "/tmp/localcorba.objid"; 92 92 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 96 106 */ 97 107 public static String getFirstValid() { … … 102 112 while (e.hasMoreElements()) { 103 113 String IOR = (String) e.nextElement(); 104 if (attemptToInitialise(null, null, IOR) ) {114 if (attemptToInitialise(null, null, IOR) != null) { 105 115 return IOR; 106 116 } … … 111 121 112 122 /** 113 * 123 * Check that the class has been correctly initialised 114 124 */ 115 125 static protected void checkLoaded() { … … 149 159 150 160 /** 151 * 161 * Save the IORs back to the underlying file 162 * @see java.io.File 152 163 */ 153 164 static protected void checkSave() { … … 165 176 } 166 177 } 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() { 172 236 checkLoaded(); 173 237 synchronized (knownIORs) { … … 181 245 while (e.hasMoreElements()) { 182 246 String IOR = (String) e.nextElement(); 183 if (attemptToInitialise(null, null, IOR) ) {247 if (attemptToInitialise(null, null, IOR) != null) { 184 248 valid.put(IOR,""); 185 249 } … … 197 261 198 262 /** 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) 202 269 { 203 270 checkLoaded(); … … 211 278 212 279 /** 213 * 280 * Retrieve an IOR from a URL 281 * @see java.net.URL 282 * @param str the url to retrieve 283 * @return the IOR 214 284 */ 215 285 public static String getIORfromURL(String str) … … 237 307 } 238 308 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 242 314 */ 243 315 public static String getIORfromFile(String file) { 244 316 checkLoaded(); 245 317 String ior = null; 246 file = file.trim(); 318 if (file == null || file.equals("")) 319 return ""; 320 file = file.trim(); 247 321 try { 248 322 BufferedReader input … … 259 333 } // end of getIorKey 260 334 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 264 342 */ 265 343 public static void writeToFile(String file) { … … 284 362 285 363 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, 288 373 Properties _props, 289 374 String _IOR) { 290 375 checkLoaded(); 376 NzdlServiceClient nzdl = null; 291 377 try { 292 NzdlServiceClientnzdl = new NzdlServiceClient( _args, _props, _IOR);378 nzdl = new NzdlServiceClient( _args, _props, _IOR); 293 379 } catch (Throwable t) { 294 380 System.err.println ("failed to initialise using:"); 295 381 System.err.println (_IOR); 296 return false;297 } 298 return true;382 return null; 383 } 384 return nzdl; 299 385 } 300 386 387 /** 388 * Write the System properties to a file called "System.properties" in 389 * the current directory. 390 */ 301 391 public static final void main( String [] args ) { 302 392
Note:
See TracChangeset
for help on using the changeset viewer.