Ashwin Dinakar wrote:
>      Yes I know this is a no-no from the EJB specification but I am sure there is a 
>work around.
> I have a properties file for my system that I wish to read into a session bean. I am 
>using Sun's FSContext service provider to locate the file using JNDI and then I
>
> File file = (File)context.lookup("aaa.properties");
>
> This part works so far. However I am not sure whether this violates the EJB 
>specification. Can some one let me know ?
>
> Secondly I wish to make changes to this file and write it back to disk.
>
> Is the right way to do that is to have context invoke rebind() ?
>
> Finally I wish to read in my properties file as a properties file
>
> ala
>
> Properties p = new Properties();
>
> p.load(new FileInputStream(fileName));
>
> Can one do this using EJB ??

The answer to this is twofold. First of all, no your bean may not do
this. Specifically it's the new FileInputStream that you're not allowed
to do. From FileInputStream.java:
public FileInputStream(String name) throws FileNotFoundException {
SecurityManager security = System.getSecurityManager();
if (security != null) {
   security.checkRead(name);
}
fd = new FileDescriptor();
open(name);
}

And from SecurityManager.java:
public void checkRead(String file) {
        checkPermission(new FilePermission(file, "read"));
}

And according to EJB1.1PR2 you do not have that permission. So that wont
work.

If you really really want to read this file, I suggest that you check
the archives for the recent (a month ago or so) thread on restrictions
of I/O which provides information about how to get around this.

The second part of the answer is that there is a simpler way to do what
you want to do. Here ya go:
Properties prp = new Properties();
prp.load(getClass().getResourceAsStream("/aaa.properties"));

or (if you're into ResourceBundles, which work equally well in most
cases):
ResourceBundle prp = ResourceBundle.getBundle("aaa");

Use prp.getString(..) instead of prp.getProperty(..).

The current J2EE RI version has a bug which prevents this though. I have
reported this bug and it is being fixed.

/Rickard

--
Rickard �berg

@home: +46 13 177937
Email: [EMAIL PROTECTED]
Homepage: http://www-und.ida.liu.se/~ricob684

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to