Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / tools / resources / PassDirectory.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/resources/PassDirectory.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/resources/PassDirectory.java
new file mode 100644 (file)
index 0000000..59f6995
--- /dev/null
@@ -0,0 +1,127 @@
+// PassDirectory.java\r
+// $Id: PassDirectory.java,v 1.2 2010/06/15 17:53:00 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 ;\r
+\r
+import java.io.File;\r
+\r
+/**\r
+ * A directory resource able to pass (jump) into some non-related directory.\r
+ * This resource provides something similar to the PASSS rule of the CERN\r
+ * server: it allows you to export a directory that is not strictly under \r
+ * the server physicall space (e.g. none of its parent directory is the server\r
+ * space directory).\r
+ * <p>Using this resource means that your exported space is no more\r
+ * restrained to the server space directory, which can be considered as \r
+ * a security problem.\r
+ */\r
+public class PassDirectory extends DirectoryResource {\r
+\r
+    /**\r
+     * Attribute index - The target physicall directory of this resource.\r
+     */\r
+    protected static int ATTR_PASSTARGET = -1 ;\r
+\r
+    static {\r
+       Attribute a   = null ;\r
+       Class     cls = null ;\r
+\r
+       // Get a pointer to our class.\r
+       try {\r
+           cls = Class.forName("org.w3c.tools.resources.PassDirectory") ;\r
+           //Added by Jeff Huang\r
+           //TODO: FIXIT\r
+       } catch (Exception ex) {\r
+           ex.printStackTrace() ;\r
+           System.exit(1) ;\r
+       }\r
+       // The directory attribute.\r
+       a = new FileAttribute("pass-target"\r
+                             , null\r
+                             , Attribute.EDITABLE);\r
+       ATTR_PASSTARGET = AttributeRegistry.registerAttribute(cls, a) ;\r
+    }\r
+\r
+    /**\r
+     * Catch side-effects on pass-target, to absolutize it.\r
+     * @param idx The attribute to set.\r
+     * @param value The new value.\r
+     */\r
+\r
+    public void setValue(int idx, Object value) {\r
+       if ( (idx == ATTR_IDENTIFIER) || (idx == ATTR_PASSTARGET)) {\r
+           try {\r
+               deleteChildren();\r
+           } catch (MultipleLockException ex) {\r
+               //nothing to do\r
+           }\r
+       }\r
+       super.setValue(idx, value);\r
+       if ( idx == ATTR_IDENTIFIER ) {\r
+           ResourceReference rr = getParent();\r
+           if (rr != null) {\r
+               try {\r
+                   Resource parent = rr.lock();\r
+                   if (parent.definesAttribute("directory")) {\r
+                       File pdir = (File) parent.getValue("directory", null);\r
+                       if ( pdir != null ) {\r
+                           // Compute and set our directory attribute:\r
+                           File dir = new File(pdir, getIdentifier()) ;\r
+                           super.setValue(ATTR_DIRECTORY, dir) ;\r
+                       }\r
+                   }\r
+               } catch (InvalidResourceException ex) {\r
+         \r
+               } finally {\r
+                   rr.unlock();\r
+               }\r
+           }\r
+           values[ATTR_PASSTARGET] = null;\r
+           values[ATTR_DIRSTAMP]   = new Long(-1);\r
+       } else if ( idx == ATTR_PASSTARGET ) {\r
+           File file = (File) value;\r
+           if ( ! file.isAbsolute() ) {\r
+               // Make it absolute, relative to the server space.\r
+               File abs = new File(getServer().getRootDirectory()\r
+                                   , file.toString());\r
+               values[ATTR_PASSTARGET] = abs;\r
+               values[ATTR_DIRECTORY]  = abs;\r
+           } else {\r
+               values[ATTR_PASSTARGET] = value;\r
+               values[ATTR_DIRECTORY]  = value;\r
+           }\r
+           values[ATTR_DIRSTAMP] = new Long(-1);\r
+       }\r
+    }\r
+\r
+    /**\r
+     * The getDirectory method now returns the pass-directory.\r
+     * @return The pass target location.\r
+     */\r
+\r
+    public File getDirectory() {\r
+       File dir = (File) getValue(ATTR_PASSTARGET, null) ;\r
+       if (dir == null)\r
+           dir = super.getDirectory();\r
+       return dir;\r
+    }\r
+\r
+    /**\r
+     * Make the directory attribute default to the target location.\r
+     * This is required for classes that rely on the directory attribute to\r
+     * compute their own attributes.\r
+     * @param values The values we should initialized from.\r
+     */\r
+\r
+    public void initialize(Object values[]) {\r
+       super.initialize(values);\r
+       disableEvent();\r
+       File target = getDirectory();\r
+       if ( target != null ) \r
+           setValue(ATTR_DIRECTORY, target);\r
+       enableEvent();\r
+    }\r
+\r
+}\r