package org.w3c.tools.resources ;
import java.util.*;
import java.io.*;
public abstract class ExternalContainer extends ContainerResource {
protected boolean transientFlag = false;
protected File repository = null;
public ResourceReference createDefaultResource(String name) {
throw new RuntimeException("not extensible");
}
public void markModified() {
if (transientFlag) {
setValue(ATTR_LAST_MODIFIED, new Long(System.currentTimeMillis()));
} else {
super.markModified();
}
}
protected synchronized void acquireChildren() {
if (!acquired) {
ResourceSpace space = getSpace();
if (repository != null) {
space.acquireChildren( getChildrenSpaceEntry() ,
repository,
transientFlag );
} else {
space.acquireChildren( getChildrenSpaceEntry() );
}
acquired = true;
}
}
public synchronized void delete()
throws MultipleLockException
{
if (transientFlag) {
ResourceSpace space = getSpace();
if (space != null) {
acquireChildren();
Enumeration e = enumerateResourceIdentifiers();
ResourceReference rr = null;
Resource resource = null;
while (e.hasMoreElements()) {
rr = lookup((String) e.nextElement());
if (rr != null) {
try {
synchronized (rr) {
resource = rr.lock();
resource.delete();
}
} catch (InvalidResourceException ex) {
} finally {
rr.unlock();
}
}
}
space.deleteChildren(getChildrenSpaceEntry());
}
} else {
super.delete();
}
}
@param context@return
abstract public File getRepository(ResourceContext context);
public void initialize(Object values[]) {
super.initialize(values);
if (repository == null)
repository = getRepository(getContext());
}
@param id@param context@param transientFlag
public ExternalContainer (String id,
ResourceContext context,
boolean transientFlag)
{
Hashtable h = new Hashtable(3);
h.put("identifier", id);
h.put("context", context);
initialize(h);
this.acquired = false;
this.transientFlag = transientFlag;
if (transientFlag)
context.setResourceReference( new DummyResourceReference(this));
}
public ExternalContainer () {
super();
this.acquired = false;
this.transientFlag = false;
this.repository = null;
}
}