Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / tools / resources / DummyResourceReference.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/resources/DummyResourceReference.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/resources/DummyResourceReference.java
new file mode 100644 (file)
index 0000000..2970b26
--- /dev/null
@@ -0,0 +1,94 @@
+// DummyResourceIndexer.java\r
+// $Id: DummyResourceReference.java,v 1.1 2010/06/15 12:20:15 smhuang Exp $  \r
+// (c) COPYRIGHT MIT and INRIA, 1997.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.tools.resources;\r
+\r
+/**\r
+ * This class implements the ResourceReference interface. For external\r
+ * use only. The ResourceStoreManager has its own Reference class.\r
+ */\r
+\r
+public class DummyResourceReference implements ResourceReference {\r
+\r
+    /**\r
+     * The lock count associated to the reference.\r
+     */\r
+    protected int lockCount = 0;\r
+\r
+    private Resource resource = null;\r
+    private String identifier = null;\r
+\r
+    /**\r
+     * update the cached context of that reference.\r
+     * @param ctxt the new ResourceContext.\r
+     */\r
+    public void updateContext(ResourceContext ctxt) {\r
+    }\r
+\r
+    /**\r
+     * Lock the refered resource in memory.\r
+     * @return A real pointer to the resource.\r
+     * @exception InvalidResourceException is thrown if the resource is\r
+     * invalid (has been deleted or everything else).\r
+     */\r
+    public Resource lock()\r
+       throws InvalidResourceException\r
+    {\r
+       if (resource == null)\r
+           throw new InvalidResourceException(identifier,\r
+                                       "This reference has been invalidated");\r
+       lockCount++;\r
+       return resource;\r
+    }\r
+\r
+    /**\r
+     * Lock the refered resource in memory.\r
+     * @return A real pointer to the resource.\r
+     * @exception InvalidResourceException is thrown if the resource is\r
+     * invalid (has been deleted or everything else).\r
+     */\r
+    public Resource unsafeLock()\r
+       throws InvalidResourceException\r
+    {\r
+       return lock();\r
+    }\r
+    /**\r
+     * How many locks?\r
+     * @return an int.\r
+     */\r
+    public int nbLock() {\r
+       return lockCount;\r
+    }\r
+\r
+    /**\r
+     * Unlock that resource from memory.\r
+     */\r
+    public void unlock() {\r
+       lockCount--;\r
+    }\r
+\r
+    /**\r
+     * Is that resource reference locked ?\r
+     */\r
+    public boolean isLocked() {\r
+       return lockCount != 0;\r
+    }\r
+\r
+    /**\r
+     * Set this reference as invalid.\r
+     */\r
+    public void invalidate() {\r
+       resource = null;\r
+    }\r
+\r
+    /**\r
+     * @param resource The resource to reference.\r
+     */\r
+    public DummyResourceReference(Resource resource) {\r
+       this.resource = resource;\r
+       this.identifier = resource.getIdentifier();\r
+    }\r
+\r
+}\r