W3C home > Mailing lists > Public > www-jigsaw@w3.org > January to February 1997

Re: Global Information Store between resources

From: Anselm Baird_Smith <abaird@www43.inria.fr>
Date: Tue, 28 Jan 1997 09:25:27 +0100 (MET)
Message-Id: <199701280825.JAA13862@www43.inria.fr>
To: karenkay@sholink.com (Karen Cheng)
Cc: www-jigsaw@www10.w3.org
Karen Cheng writes:
 > Using getParent() within getSomeResource() means that this method
 > can't be made static, and so we'd have to create an instance of
 > MyResource before we can get the shared context resource, right?

Correct,

 > I have a GlobalResource class which registers a number of global 
 > attributes, and then I have the following ResourceManager class (which
 > is your MyResource class):
 > 
 > public class ResourceManager extends HTTPResource {
 >   static GlobalResource gr;
 > 
 >   public ResourceManager() {}
 > 
 >   public synchronized GlobalResource getGlobalResource() {
 >     if (gr == null) {
 >       // Get the container resource.
 >       Resource parent = getParent();
 >       // Lookup the global resource within that container.
 >       gr = (GlobalResource) ((DirectoryResource) parent).lookup("globalResource\
 > ");
 >     }
 >     return gr;
 >   }
 > }
 > 
 > However, when I tried to use it in the constructor of one of my other 
 > classes, I get a null pointer exception from getGlobalResource():
 > 
 >   public MyNewResource() {
 >     ResourceManager rm = new ResourceManager();
 >     GlobalResource gr = rm.getGlobalResource();
 > 
 >     String attr = gr.getAttr();
 > 	:	:	:
 >   }
 > 
 > Note that I've used Admin/Editor to create "globalResource" under the User
 > directory, which is where all my other resources were created.
 > 
 > Could you please tell me what's wrong?  Why didn't lookup() load the
 > global resource when it couldn't find it in the resource store?

It should have, can you provide the stack trace for the
NullPointerException ? I think either the globalResource doesn't
exist, or it hasn't been initialized properly; the stack trace will
help deteriming the precise cause of the problem.

Anselm.
Received on Tuesday, 28 January 1997 03:25:34 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:26 GMT