KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > resolver > FileResolverImpl


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
8 package com.sun.corba.se.impl.resolver ;
9
10 import org.omg.CORBA.ORBPackage.InvalidName JavaDoc;
11
12 import com.sun.corba.se.spi.resolver.Resolver ;
13
14 import java.util.Enumeration JavaDoc;
15 import java.util.Properties JavaDoc;
16 import java.util.Set JavaDoc;
17 import java.util.HashSet JavaDoc;
18
19 import java.io.File JavaDoc;
20 import java.io.FileInputStream JavaDoc;
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 JavaDoc file ;
30     private Properties JavaDoc savedProps ;
31     private long fileModified = 0 ;
32
33     public FileResolverImpl( ORB orb, File JavaDoc file )
34     {
35     this.orb = orb ;
36     this.file = file ;
37     savedProps = new Properties JavaDoc() ;
38     }
39
40     public org.omg.CORBA.Object JavaDoc resolve( String JavaDoc name )
41     {
42     check() ;
43     String JavaDoc 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 JavaDoc list()
51     {
52     check() ;
53
54     Set JavaDoc result = new HashSet JavaDoc() ;
55
56     // Obtain all the keys from the property object
57
Enumeration JavaDoc theKeys = savedProps.propertyNames();
58     while (theKeys.hasMoreElements()) {
59         result.add( theKeys.nextElement() ) ;
60     }
61
62     return result ;
63     }
64
65     /**
66     * Checks the lastModified() timestamp of the file and optionally
67     * re-reads the Properties object from the file if newer.
68     */

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 JavaDoc fileIS = new FileInputStream JavaDoc(file);
78         savedProps.clear();
79         savedProps.load(fileIS);
80         fileIS.close();
81         fileModified = lastMod;
82         } catch (java.io.FileNotFoundException JavaDoc e) {
83         System.err.println( CorbaResourceUtil.getText(
84             "bootstrap.filenotfound", file.getAbsolutePath()));
85         } catch (java.io.IOException JavaDoc e) {
86         System.err.println( CorbaResourceUtil.getText(
87             "bootstrap.exception",
88             file.getAbsolutePath(), e.toString()));
89         }
90     }
91     }
92 }
93
Popular Tags