How can I read the initialization parameters for a bean, i.e. similar to what happens in servlets when we user the ServletConfig class and then use it's getInitParameter() function?

John Zukowski

The initial version of the JavaBeans API included no direct support for this. You would have had to program it in yourself. The simplest way to do this was to use a (java.util.)Properties file and load() / store() key-value pairs in it.

Use either the getResourceAsStream() or getSystemResourceAsStream() method of the ClassLoader to locate the file.

Java 1.2 introduced the BeanContext runtime containment and services protocol which essentially does this for you. You can learn more about it from the Sun tutorial at Lesson: Using the BeanContext API. Unfortunately, they don't describe how to provide intiialization parameters. Basically, the getResourceXXX() methods are now used off the BeanContext, instead of the ClassLoader.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact