Hi,

Maybe something like:


     1  public abstract class AbstractConstant
     2  {
     3      private final static int APP1 = 1;
     4      private final static int APP2 = 2;

     5      public static class App1Constant extends
AbstractConstant {
     6          public App1Constant() {
     7              setDBUrl( "some value for App1" );
     8          }
     9      }
    10      public static class App2Constant extends
AbstractConstant {
    11          public App2Constant() {
    12              setDBUrl( "some value for App2" );
    13          }
    14      }

    15      private String dbURL = null;
    16      public void setDBUrl( String s ) {
    17          this.dbURL = s;
    18      }
    19      public String getDBUrl() {
    20          return this.dbURL;
    21      }
    22      public static AbstractConstant Create( int
i ) {
    23          AbstractConstant ap = null;
    24          if( APP1 == i ) {
    25              ap = new AbstractConstant.App1Constant();
    26          }
    27          else if( APP2 == i ) {
    28              ap = new AbstractConstant.App2Constant();
    29          }
    30          return ap;
    31      }
    32  }


    33  public class App1
    34  {
    35      private AbstractConstant abcon =
AbstractConstant.Create( 1 );
    36      public App1() {
    37          System.out.println( "1 dburl: " +
abcon.getDBUrl() );
    38      }
    39      public static void main( String[] arg ) {
    40          App1 ap = new App1();
    41      }
    42  }


    43  public class App2
    44  {
    45      private AbstractConstant abcon =
AbstractConstant.Create( 2 );
    46      public App2() {
    47          System.out.println( "2 dburl: " +
abcon.getDBUrl() );
    48      }
    49      public static void main( String[] arg ) {
    50          App2 ap = new App2();
    51      }
    52  }


ron


--- Rodrigo Gevaerd <[EMAIL PROTECTED]> wrote:
>    That works fine when you got only one application
> using that class
> Constants. The problem appears in my case, where i
> got more than one
> application with the same classe Constants. It
> cannot be implemented as
> static because the values must be different for each
> application. My daught
> is what is the better way to organize the Constants
> instances, so that they
> may be easily accessible by all parts of the
> application and work with many
> applications on the same server using it. The best
> way I found until now is
> to on all classes' constructors receive the
> Constants instance as parameter
> and keep its reference on all classes so all may use
> it. Does anyone have
> any suggestion for this kind of problem?
>
>     Rodrigo.
>
>
> > -----Mensagem original-----
> > De: Rob L'Estrange [mailto:[EMAIL PROTECTED]]
> > Enviada em: Sábado, 7 de Abril de 2001 11:37
> > Para: [EMAIL PROTECTED]
> > Assunto: Re: Organizing Application Constants
> >
> >
> > I usually put my constants in a class called
> Constants. I
> > implement them as
> > final and static. I'd then deploy the class in my
> location
> > accessible to all
> > web applications running in my JSP/Servlet server.
> I think
> > this location
> > would be server specific (but I could be
> mistaken). From any
> > web app, I can
> > then access Constants.someConstant.
> >
> > Note that when you make any changes to your
> Constants class, you will
> > probably need to restart your JSP/Servlet server
> to force a
> > reload of the
> > class.
> >
> > Rob
> >
> >
> > ----- Original Message -----
> > From: "Rodrigo Gevaerd" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Friday, April 06, 2001 2:22 PM
> > Subject: Organizing Application Constants
> >
> >
> > >   I got an application that has several
> constants (for
> > example, database
> > > url). The application consists of several JSPs
> for presentation and
> > classes
> > > for the persistence. How can I keep the
> application
> > constants, so that 2
> > > applications of this type (with different
> constants values)
> > can co-exist
> > in
> > > the same JVM (possibly in different web
> applications)? It
> > was developed
> > > initially keeping the constants in a singleton
> class. But
> > with more than
> > one
> > > application it cannot be done like that. The
> constants
> > could be kept in
> > the
> > > ServletContext, but the classes would not have
> access to
> > them (unless each
> > > were given the SerlvetContext reference). Does
> anyone has
> > any idea for a
> > > solution for this situation?
> > >
> > >     []'s,
> > >     Rodrigo.
> > >
>
>
===========================================================================
> 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