01: // DummyResourceIndexer.java
02: // $Id: DummyResourceReference.java,v 1.4 2002/08/08 12:30:15 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1997.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.tools.resources;
07:
08: /**
09: * This class implements the ResourceReference interface. For external
10: * use only. The ResourceStoreManager has its own Reference class.
11: */
12:
13: public class DummyResourceReference implements ResourceReference {
14:
15: /**
16: * The lock count associated to the reference.
17: */
18: protected int lockCount = 0;
19:
20: private Resource resource = null;
21: private String identifier = null;
22:
23: /**
24: * update the cached context of that reference.
25: * @param ctxt the new ResourceContext.
26: */
27: public void updateContext(ResourceContext ctxt) {
28: }
29:
30: /**
31: * Lock the refered resource in memory.
32: * @return A real pointer to the resource.
33: * @exception InvalidResourceException is thrown if the resource is
34: * invalid (has been deleted or everything else).
35: */
36: public Resource lock() throws InvalidResourceException {
37: if (resource == null)
38: throw new InvalidResourceException(identifier,
39: "This reference has been invalidated");
40: lockCount++;
41: return resource;
42: }
43:
44: /**
45: * Lock the refered resource in memory.
46: * @return A real pointer to the resource.
47: * @exception InvalidResourceException is thrown if the resource is
48: * invalid (has been deleted or everything else).
49: */
50: public Resource unsafeLock() throws InvalidResourceException {
51: return lock();
52: }
53:
54: /**
55: * How many locks?
56: * @return an int.
57: */
58: public int nbLock() {
59: return lockCount;
60: }
61:
62: /**
63: * Unlock that resource from memory.
64: */
65: public void unlock() {
66: lockCount--;
67: }
68:
69: /**
70: * Is that resource reference locked ?
71: */
72: public boolean isLocked() {
73: return lockCount != 0;
74: }
75:
76: /**
77: * Set this reference as invalid.
78: */
79: public void invalidate() {
80: resource = null;
81: }
82:
83: /**
84: * @param resource The resource to reference.
85: */
86: public DummyResourceReference(Resource resource) {
87: this.resource = resource;
88: this.identifier = resource.getIdentifier();
89: }
90:
91: }
|