hi all,
is it possible to put one class in app server which should be accessed by all classes without creating again instance of that class.in my application i am handling all exception in beans through user defined exception.which will get error message from one common repository which will get all messages from back end put into hashtable.when user defined exception raised in bean the instance of exception is created by passing error code.this exception class will pass this error code to that common repository class which having hash table.it will get back the error message to exception class.this error message will thrown to front end.
so my problem is if it's possible to have one common class which hold my hash table and serve all my beans.this common class will be created once by login bean class when application starts.from then on wards it should serve my user defined exception class for getting error message from hash.
please,any suggestion is very much appriciatable.
regards
raju
rajireddy at hexaware dot co.in
-
is it possible all beans access one common class (11 messages)
- Posted by: chilkuri rajireddy
- Posted on: April 25 2001 09:09 EDT
Threaded Messages (11)
- is it possible all beans access one common class by Kapil Israni on April 25 2001 09:57 EDT
- is it possible all beans access one common class by chilkuri rajireddy on April 25 2001 10:21 EDT
-
is it possible all beans access one common class by Kapil Israni on April 25 2001 12:36 EDT
-
is it possible all beans access one common class by Andy . on April 25 2001 01:02 EDT
-
is it possible all beans access one common class by Kapil Israni on April 25 2001 02:16 EDT
-
is it possible all beans access one common class by Andy . on April 26 2001 04:17 EDT
-
is it possible all beans access one common class by chilkuri rajireddy on April 26 2001 08:06 EDT
-
is it possible all beans access one common class by Koshy Cherian on April 26 2001 09:39 EDT
- is it possible all beans access one common class by chilkuri rajireddy on April 26 2001 10:44 EDT
-
is it possible all beans access one common class by Kapil Israni on April 26 2001 02:29 EDT
- is it possible all beans access one common class by chilkuri rajireddy on April 26 2001 11:34 EDT
-
is it possible all beans access one common class by Koshy Cherian on April 26 2001 09:39 EDT
-
is it possible all beans access one common class by chilkuri rajireddy on April 26 2001 08:06 EDT
-
is it possible all beans access one common class by Andy . on April 26 2001 04:17 EDT
-
is it possible all beans access one common class by Kapil Israni on April 25 2001 02:16 EDT
-
is it possible all beans access one common class by Andy . on April 25 2001 01:02 EDT
-
is it possible all beans access one common class by Kapil Israni on April 25 2001 12:36 EDT
- is it possible all beans access one common class by chilkuri rajireddy on April 25 2001 10:21 EDT
-
is it possible all beans access one common class[ Go to top ]
- Posted by: Kapil Israni
- Posted on: April 25 2001 09:57 EDT
- in response to chilkuri rajireddy
u can do it using two ways. one way is to create a singleton class, thus making sure that only one instance of that class exists in one JVM.
the other way to do in ur case is define a static method getErrorCode() in ur class. read and populate the hashtable in the static block of that class. -
is it possible all beans access one common class[ Go to top ]
- Posted by: chilkuri rajireddy
- Posted on: April 25 2001 10:21 EDT
- in response to Kapil Israni
hi kapil,
same thing i am using static method wich gets all error messages from back end.where i have to place this class which has hashtable,which will be used by ueser difined exception class when i raise exception in my business method.please let me know.if you any code please send it accross it's very urgent for me. -
is it possible all beans access one common class[ Go to top ]
- Posted by: Kapil Israni
- Posted on: April 25 2001 12:36 EDT
- in response to chilkuri rajireddy
u have to place this class in a class path which is recognizable to ur app server.
for eg in weblogic u can put it in weblogic_root\your_server\classes
for websphere u can configure the classpath in one of the .cfg files. not sure. i think admin.cfg or startup.cfg.
just one more thing, this class has to be accessible to ur user defined exception which is bein thrown by ur EJB method, make sure if the exception is accessed by ur client then ur client shud also be aware of the error code class. if the client is part of ur app server like jsp or servlet then just point the class to app server class path. -
is it possible all beans access one common class[ Go to top ]
- Posted by: Andy .
- Posted on: April 25 2001 13:02 EDT
- in response to Kapil Israni
Hi,
I have a similar problem. I want to connect to a CORBA Object and I want to create the ORB only one time. So I thought to make the class static but this is not allowed by EJB. It is not allowed to have static variables.
So is it possible to have a EJB as a Singleton???
It would be very helpful if you could give me some hints.
Thanx, Andy -
is it possible all beans access one common class[ Go to top ]
- Posted by: Kapil Israni
- Posted on: April 25 2001 14:16 EDT
- in response to Andy .
well u can definitely make sure that only one instance of ur EJB is created, by restricting it in the deployment file, with number of instance as 1.
the ORB object can be defined as an object instance, which can be only be initialised once.
so u cud have a
ORBLookupBean implements SessionBean
{
ORBObject o = null;
public void ejbCreate(){
if (o == null){
//create object}
}
}
public ORBObject getORB(){
return o;}
} -
is it possible all beans access one common class[ Go to top ]
- Posted by: Andy .
- Posted on: April 26 2001 04:17 EDT
- in response to Kapil Israni
Thanx a lot for your help. That's a good solution and it should work in (hopefully) every Application Server.
Andy -
is it possible all beans access one common class[ Go to top ]
- Posted by: chilkuri rajireddy
- Posted on: April 26 2001 08:06 EDT
- in response to Andy .
hi kapil again,
singleton is good idea,but who should hold the handle for this singleton after created(say by my login bean when application starts).i have to get handle for this singleton class from different beans when i throw my user defined exception.please let me know how it will possible.
ragards
raju
-
is it possible all beans access one common class[ Go to top ]
- Posted by: Koshy Cherian
- Posted on: April 26 2001 09:39 EDT
- in response to chilkuri rajireddy
In a singleton class, there should be a getInstace(), which is a static method that will return the handle.
eg,
public class Singleton {
private Singleton() {
}
private static Singleton mySingleton= new Singleton();
public static Singleton getInstance() {
return mySingleton;
}
}
-
is it possible all beans access one common class[ Go to top ]
- Posted by: chilkuri rajireddy
- Posted on: April 26 2001 10:44 EDT
- in response to Koshy Cherian
hi koshy,
where i have to put this singleton class after creating.it should be accesseble by all of my beans in app server.
thanks
raju -
is it possible all beans access one common class[ Go to top ]
- Posted by: Kapil Israni
- Posted on: April 26 2001 14:29 EDT
- in response to chilkuri rajireddy
this single ton class will be normal java vanilla object and not bean, so theres no question of a handle.
about accessing it from other beans yes u can very well do it from anywhere within the same jvm.
as koshy has already mentioned the code.
wherever u wanna use it just call -
SingleTon o = SingleTon.getInstance();
and u will always get the same instance.
-
is it possible all beans access one common class[ Go to top ]
- Posted by: chilkuri rajireddy
- Posted on: April 26 2001 23:34 EDT
- in response to Kapil Israni
thanks kapil,for your reply.
raju