Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / tools / resources / store / ResourceStore.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/resources/store/ResourceStore.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/resources/store/ResourceStore.java
new file mode 100644 (file)
index 0000000..3e6fc02
--- /dev/null
@@ -0,0 +1,177 @@
+// ResourceStore.java\r
+// $Id: ResourceStore.java,v 1.1 2010/06/15 12:25:24 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1996.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.tools.resources.store ;\r
+\r
+import org.w3c.tools.resources.InvalidResourceException;\r
+import org.w3c.tools.resources.Resource;\r
+\r
+import org.w3c.tools.resources.serialization.Serializer;\r
+\r
+import java.util.Enumeration;\r
+import java.util.Hashtable;\r
+\r
+import java.io.File;\r
+\r
+/**\r
+ * A resource store implements persistency for a set of resources.\r
+ * A resource store may implement a number of strategies along different\r
+ * axis, for example: \r
+ * <ul>\r
+ * <li>It may connect to some database to get the resource attributes. \r
+ * <li>It may restrict the classes of the resource it handles (for security\r
+ *      reasons), by using a specific class loader.\r
+ * <li>It may implement some caching scheme, to keep memory requirements low.\r
+ * <li>It may be distributed (eg using a ResourceStoreStub in the client, but\r
+ * providing access to a server-side resource store.).\r
+ * </ul>\r
+ */\r
+\r
+public interface ResourceStore {\r
+\r
+    /**\r
+     * Get the version of that resource store.\r
+     * Version numbers are used to distinguish between pickling format. \r
+     * A resource store implementator has the duty of bumping the returned\r
+     * number whenever it's archiving format changes.\r
+     * Resource stores that relies on some external archiving mechanisms\r
+     * (such as a database), may return a constant.\r
+     * @return An integer version number.\r
+     */\r
+\r
+    public int getVersion();\r
+\r
+    /**\r
+     * Get the identifier for that store.\r
+     * @return A uniq store identifier, as a String.\r
+     */\r
+\r
+    public String getIdentifier();\r
+\r
+     /**\r
+     * Restore the resource whose name is given.\r
+     * This method doesn't assume that the resource will actually be restored,\r
+     * it can be kept in a cache by the ResourceStore object, and the cached \r
+     * version of the resource may be returned.\r
+     * @param identifier The identifier of the resource to restore.\r
+     * @param defs Default attribute values. If the resource needs to be\r
+     *     restored from its pickled version, this Hashtable provides\r
+     *     a set of default values for some of the attributes.\r
+     * @return A Resource instance, or <strong>null</strong>.\r
+     * @exception InvalidResourceException If the resource could not\r
+     * be restored from the store.\r
+     */\r
+\r
+    public Resource loadResource(String identifier, Hashtable defs)\r
+       throws InvalidResourceException;\r
+\r
+    /**\r
+     * Get this resource, but only if already loaded.\r
+     * The resource store may (recommended) maintain a cache of the resource\r
+     * it loads from its store. If the resource having this identifier \r
+     * has already been loaded, return it, otherwise, return\r
+     * <strong>null</strong>.\r
+     * @param identifier The resource identifier.\r
+     * @return A Resource instance, or <strong>null</strong>.\r
+     */\r
+\r
+    public Resource lookupResource(String identifier) ;\r
+\r
+    /**\r
+     * Stabilize the given resource.\r
+     * @param resource The resource to save.\r
+     */\r
+\r
+    public void saveResource(Resource resource);\r
+\r
+    /**\r
+     * Add this resource to this resource store.\r
+     * @param resource The resource to be added.\r
+     */\r
+\r
+    public void addResource(Resource resource) ;\r
+\r
+    /**\r
+     * Remove this resource from the repository.\r
+     * @param identifier The identifier of the resource to be removed.\r
+     */\r
+\r
+    public void removeResource(String identifier) ;\r
+\r
+    /**\r
+     * Rename a given resource.\r
+     * @param oldid The olde resource identifier.\r
+     * @param newid The new resource identifier.\r
+     */\r
+\r
+    public void renameResource(String oldid, String newid);\r
+\r
+    /**\r
+     * Mark this resource as modified.\r
+     * @param resource The resource that has changed (and will have to be\r
+     * pickled some time latter).\r
+     */\r
+\r
+    public void markModified(Resource resource);\r
+\r
+    /**\r
+     * Can this resource store be unloaded now ?\r
+     * This method gets called by the ResourceStoreManager before calling\r
+     * the <code>shutdown</code> method, when possible. An implementation\r
+     * of that method is responsible for checking the <code>acceptUnload\r
+     * </code> method of all its loaded resource before returning \r
+     * <strong>true</strong>, meaning that the resource store can be unloaded.\r
+     * @return A boolean <strong>true</strong> if the resource store can be\r
+     * unloaded.\r
+     */\r
+\r
+    public abstract boolean acceptUnload();\r
+\r
+    /**\r
+     * Shutdown this store.\r
+     */\r
+\r
+    public void shutdown() ;\r
+\r
+    /**\r
+     * Save this store.\r
+     */\r
+\r
+    public void save() ;\r
+\r
+    /**\r
+     * Enumerate all the resources saved in this store.\r
+     * @return An enumeration of Strings, giving the identifier for all \r
+     *     the resources that this store knows about.\r
+     */\r
+\r
+    public Enumeration enumerateResourceIdentifiers() ;\r
+\r
+    /**\r
+     * Check for the existence of a resource in this store.\r
+     * @param identifier The identifier of the resource to check.\r
+     * @return A boolean <strong>true</strong> if the resource exists\r
+     *    in this store, <strong>false</strong> otherwise.\r
+     */\r
+\r
+    public boolean hasResource(String identifier) ;\r
+\r
+    /**\r
+     * This resource store is being built, initialize it with the given arg.\r
+     * @param manager The ResourceStoreManager instance that asks yourself\r
+     * to initialize.\r
+     * @param token The resource store manager key to that resource store, \r
+     * this token should be used when calling methods from the manager that\r
+     * are to act on yourself.\r
+     * @param repository A file, giving the location of the associated \r
+     *    repository.\r
+     */\r
+\r
+    public void initialize(ResourceStoreManager manager,\r
+                          Object token,\r
+                          File repository,\r
+                          Serializer serializer);\r
+\r
+}\r