001: // PassDirectory.java
002: // $Id: PassDirectory.java,v 1.9 2000/08/16 21:37:44 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigsaw.resources;
007:
008: import java.io.File;
009:
010: import org.w3c.tools.resources.Attribute;
011: import org.w3c.tools.resources.AttributeHolder;
012: import org.w3c.tools.resources.AttributeRegistry;
013: import org.w3c.tools.resources.ContainerResource;
014: import org.w3c.tools.resources.DirectoryResource;
015: import org.w3c.tools.resources.FileAttribute;
016: import org.w3c.tools.resources.InvalidResourceException;
017: import org.w3c.tools.resources.MultipleLockException;
018: import org.w3c.tools.resources.Resource;
019: import org.w3c.tools.resources.ResourceReference;
020: import org.w3c.tools.resources.ServerInterface;
021:
022: public class PassDirectory extends
023: org.w3c.jigsaw.resources.DirectoryResource {
024:
025: /**
026: * Attribute index - The target physicall directory of this resource.
027: */
028: protected static int ATTR_PASSTARGET = -1;
029:
030: static {
031: Attribute a = null;
032: Class cls = null;
033:
034: // Get a pointer to our class.
035: try {
036: cls = Class
037: .forName("org.w3c.jigsaw.resources.PassDirectory");
038: } catch (Exception ex) {
039: ex.printStackTrace();
040: System.exit(1);
041: }
042: // The directory attribute.
043: a = new FileAttribute("pass-target", null, Attribute.EDITABLE);
044: ATTR_PASSTARGET = AttributeRegistry.registerAttribute(cls, a);
045: }
046:
047: /**
048: * Catch side-effects on pass-target, to absolutize it.
049: * @param idx The attribute to set.
050: * @param value The new value.
051: */
052:
053: public void setValue(int idx, Object value) {
054: if ((idx == ATTR_IDENTIFIER) || (idx == ATTR_PASSTARGET)) {
055: try {
056: deleteChildren();
057: } catch (MultipleLockException ex) {
058: //nothing to do
059: }
060: }
061: super .setValue(idx, value);
062: if (idx == ATTR_IDENTIFIER) {
063: ResourceReference rr = getParent();
064: if (rr != null) {
065: try {
066: Resource parent = rr.lock();
067: if (parent.definesAttribute("directory")) {
068: File pdir = (File) parent.getValue("directory",
069: null);
070: if (pdir != null) {
071: // Compute and set our directory attribute:
072: File dir = new File(pdir, getIdentifier());
073: super .setValue(ATTR_DIRECTORY, dir);
074: }
075: }
076: } catch (InvalidResourceException ex) {
077:
078: } finally {
079: rr.unlock();
080: }
081: }
082: values[ATTR_PASSTARGET] = null;
083: values[ATTR_DIRSTAMP] = new Long(-1);
084: } else if (idx == ATTR_PASSTARGET) {
085: File file = (File) value;
086: if (!file.isAbsolute()) {
087: // Make it absolute, relative to the server space.
088: File abs = new File(getServer().getRootDirectory(),
089: file.toString());
090: values[ATTR_PASSTARGET] = abs;
091: values[ATTR_DIRECTORY] = abs;
092: } else {
093: values[ATTR_PASSTARGET] = value;
094: values[ATTR_DIRECTORY] = value;
095: }
096: values[ATTR_DIRSTAMP] = new Long(-1);
097: }
098: }
099:
100: /**
101: * The getDirectory method now returns the pass-directory.
102: * @return The pass target location.
103: */
104:
105: public File getDirectory() {
106: File dir = (File) getValue(ATTR_PASSTARGET, null);
107: if (dir == null)
108: dir = super .getDirectory();
109: return dir;
110: }
111:
112: /**
113: * Make the directory attribute default to the target location.
114: * This is required for classes that rely on the directory attribute to
115: * compute their own attributes.
116: * @param values The values we should initialized from.
117: */
118:
119: public void initialize(Object values[]) {
120: super .initialize(values);
121: File target = getDirectory();
122: if (target != null)
123: setValue(ATTR_DIRECTORY, target);
124: }
125:
126: }
|