Hi,

1. why pass ServletContext, pass the String from
sc.getRealPath to a bean.

2. you can put your ini info in an xml and use a
program generation approach.

3. you can use a 'shell' class, that reads key/value
pairs into an 'ordered' hashtable (if order is
important), and have custom get( String key ) and set(
k, v) methods to change values in the ordered
hashtable.

just some thoughts.

ron

--- Rodrigo Gevaerd <[EMAIL PROTECTED]> wrote:
>    Thanks for your replies, Ron. But I think you did
> not quite understand
> the kind of problem here. The problem is how to do
> the functionallity of the
> code you wrote but without having to write another
> class like App1Constant
> or App2Constant when you add another application to
> the server. More than
> that... actually I want no change to code at all.
> This can be done, for
> example, this way:
>
>    Have this start up code to run before anything
> else in the application:
>
> getServletContext().setAttribute("Const", new
> Constant(getServletContext()));
>
>    And at Constant do:
>
> public Constant(ServletContext sc)
> {
>   String fileNameToReadValues =
> sc.getRealPath("/constant.ini");
>
>   // read values from 'fileNameToReadValues'
> }
>
>   This way, when adding another application, the
> same code may be used. Only
> the constant.ini file in the new application will be
> different (because it
> will contain the values the application will use).
> But there is a problem
> doing this way: all classes that want access to
> Constant must have access to
> ServletContext, because only that way they will
> obtain the right Constant
> instance (through the getAttribute method). This
> problem can be worked out
> by giving every class a reference to ServletContext.
> But I was asking if
> anyone have a better solution for this problem than
> doing all these.
>
>
>     Rodrigo.
>
>
> > -----Mensagem original-----
> > De: Ron Chan [mailto:[EMAIL PROTECTED]]
> > Enviada em: Segunda-feira, 9 de Abril de 2001
> 13:25
> > Para: [EMAIL PROTECTED]
> > Assunto: Re: Organizing Application Constants
> >
> >
> > hi,
> >
> > something like:
> >
> >
> >      1  import java.util.*;
> >
> >      2  public abstract class AbstractConstant
> >      3  {
> >      4      public final static int APP1 = 1;
> >      5      public final static int APP2 = 2;
> >      6      private final static String cdb =
> > "currentDB";
> >      7      private final static String DBURL =
> > "dbURL";
> >
> >      8      public static class App1Constant
> extends
> > AbstractConstant {
> >      9          public App1Constant() {
> >     10              super();
> >     11              setDBUrl( rb.getString( DBURL
> + currentDB
> > + APP1 ) );
> >     12          }
> >     13      }
> >     14      public static class App2Constant
> extends
> > AbstractConstant {
> >     15          public App2Constant() {
> >     16              super();
> >     17              setDBUrl( rb.getString( DBURL
> + currentDB
> > + APP2 ) );
> >     18          }
> >     19      }
> >
> >     20      private String dbURL = null;
> >     21      private String rbString = "ac";
> >     22      protected ResourceBundle rb = null;
> >     23      protected String currentDB = null;
> >
> >     24      public AbstractConstant() {
> >     25          rb = ResourceBundle.getBundle(
> rbString );
> >     26          currentDB = rb.getString( cdb );
> >     27      }
> >
> >     28      public void setDBUrl( String s ) {
> >     29          this.dbURL = s;
> >     30      }
> >     31      public String getDBUrl() {
> >     32          return this.dbURL;
> >     33      }
> >     34      public static AbstractConstant Create(
> int
> > i ) {
> >     35          AbstractConstant ap = null;
> >     36          if( APP1 == i ) {
> >     37              ap = new
> AbstractConstant.App1Constant();
> >     38          }
> >     39          else if( APP2 == i ) {
> >     40              ap = new
> AbstractConstant.App2Constant();
> >     41          }
> >     42          return ap;
> >     43      }
> >     44  }
> >
> >
> >     45  public class App1
> >     46  {
> >     47      private AbstractConstant abcon =
> > AbstractConstant.Create( AbstractConstant.APP1 );
> >     48      public App1() {
> >     49          System.out.println( "1 dburl: " +
> > abcon.getDBUrl() );
> >     50      }
> >     51      public static void main( String[] arg
> ) {
> >     52          App1 ap = new App1();
> >     53      }
> >     54  }
> >
> >
> >     55  public class App2
> >     56  {
> >     57      private AbstractConstant abcon =
> > AbstractConstant.Create( AbstractConstant.APP2 );
> >     58      public App2() {
> >     59          System.out.println( "2 dburl: " +
> > abcon.getDBUrl() );
> >     60      }
> >     61      public static void main( String[] arg
> ) {
> >     62          App2 ap = new App2();
> >     63      }
> >     64  }
> >
> >     65  currentDB=oracle
> >     66  dbURLpostgres1=something1
> >     67  dbURLpostgres2=something2
> >
> >     68  dbURLoracle1=somethingElse1
> >     69  dbURLoracle2=somethingElse2
> >
> > ron
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with
> body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body:
> "set JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to