1 7 8 package com.sun.corba.se.impl.resolver ; 9 10 import org.omg.CORBA.ORBPackage.InvalidName ; 11 12 import com.sun.corba.se.spi.resolver.Resolver ; 13 14 import java.util.Enumeration ; 15 import java.util.Properties ; 16 import java.util.Set ; 17 import java.util.HashSet ; 18 19 import java.io.File ; 20 import java.io.FileInputStream ; 21 22 import com.sun.corba.se.spi.orb.ORB ; 23 24 import com.sun.corba.se.impl.orbutil.CorbaResourceUtil ; 25 26 public class FileResolverImpl implements Resolver 27 { 28 private ORB orb ; 29 private File file ; 30 private Properties savedProps ; 31 private long fileModified = 0 ; 32 33 public FileResolverImpl( ORB orb, File file ) 34 { 35 this.orb = orb ; 36 this.file = file ; 37 savedProps = new Properties () ; 38 } 39 40 public org.omg.CORBA.Object resolve( String name ) 41 { 42 check() ; 43 String stringifiedObject = savedProps.getProperty( name ) ; 44 if (stringifiedObject == null) { 45 return null; 46 } 47 return orb.string_to_object( stringifiedObject ) ; 48 } 49 50 public java.util.Set list() 51 { 52 check() ; 53 54 Set result = new HashSet () ; 55 56 Enumeration theKeys = savedProps.propertyNames(); 58 while (theKeys.hasMoreElements()) { 59 result.add( theKeys.nextElement() ) ; 60 } 61 62 return result ; 63 } 64 65 69 private void check() 70 { 71 if (file == null) 72 return; 73 74 long lastMod = file.lastModified(); 75 if (lastMod > fileModified) { 76 try { 77 FileInputStream fileIS = new FileInputStream (file); 78 savedProps.clear(); 79 savedProps.load(fileIS); 80 fileIS.close(); 81 fileModified = lastMod; 82 } catch (java.io.FileNotFoundException e) { 83 System.err.println( CorbaResourceUtil.getText( 84 "bootstrap.filenotfound", file.getAbsolutePath())); 85 } catch (java.io.IOException e) { 86 System.err.println( CorbaResourceUtil.getText( 87 "bootstrap.exception", 88 file.getAbsolutePath(), e.toString())); 89 } 90 } 91 } 92 } 93 | Popular Tags |