1. /*
  2. * @(#)FileResolverImpl.java 1.3 04/03/01
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.resolver ;
  8. import org.omg.CORBA.ORBPackage.InvalidName;
  9. import com.sun.corba.se.spi.resolver.Resolver ;
  10. import java.util.Enumeration;
  11. import java.util.Properties;
  12. import java.util.Set;
  13. import java.util.HashSet;
  14. import java.io.File;
  15. import java.io.FileInputStream;
  16. import com.sun.corba.se.spi.orb.ORB ;
  17. import com.sun.corba.se.impl.orbutil.CorbaResourceUtil ;
  18. public class FileResolverImpl implements Resolver
  19. {
  20. private ORB orb ;
  21. private File file ;
  22. private Properties savedProps ;
  23. private long fileModified = 0 ;
  24. public FileResolverImpl( ORB orb, File file )
  25. {
  26. this.orb = orb ;
  27. this.file = file ;
  28. savedProps = new Properties() ;
  29. }
  30. public org.omg.CORBA.Object resolve( String name )
  31. {
  32. check() ;
  33. String stringifiedObject = savedProps.getProperty( name ) ;
  34. if (stringifiedObject == null) {
  35. return null;
  36. }
  37. return orb.string_to_object( stringifiedObject ) ;
  38. }
  39. public java.util.Set list()
  40. {
  41. check() ;
  42. Set result = new HashSet() ;
  43. // Obtain all the keys from the property object
  44. Enumeration theKeys = savedProps.propertyNames();
  45. while (theKeys.hasMoreElements()) {
  46. result.add( theKeys.nextElement() ) ;
  47. }
  48. return result ;
  49. }
  50. /**
  51. * Checks the lastModified() timestamp of the file and optionally
  52. * re-reads the Properties object from the file if newer.
  53. */
  54. private void check()
  55. {
  56. if (file == null)
  57. return;
  58. long lastMod = file.lastModified();
  59. if (lastMod > fileModified) {
  60. try {
  61. FileInputStream fileIS = new FileInputStream(file);
  62. savedProps.clear();
  63. savedProps.load(fileIS);
  64. fileIS.close();
  65. fileModified = lastMod;
  66. } catch (java.io.FileNotFoundException e) {
  67. System.err.println( CorbaResourceUtil.getText(
  68. "bootstrap.filenotfound", file.getAbsolutePath()));
  69. } catch (java.io.IOException e) {
  70. System.err.println( CorbaResourceUtil.getText(
  71. "bootstrap.exception",
  72. file.getAbsolutePath(), e.toString()));
  73. }
  74. }
  75. }
  76. }