001: // ContainerInterfaceImpl.java
002: // $Id: AbstractContainer.java,v 1.8 2002/06/26 17:27:43 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.tools.resources;
007:
008: import java.util.Enumeration;
009: import java.util.Hashtable;
010: import org.w3c.tools.resources.event.AttributeChangedEvent;
011: import org.w3c.tools.resources.event.AttributeChangedListener;
012: import org.w3c.tools.resources.event.StructureChangedEvent;
013: import org.w3c.tools.resources.event.StructureChangedListener;
014:
015: /**
016: * The top level class for Resource Container.
017: */
018: public abstract class AbstractContainer extends FramedResource
019: implements ContainerInterface, StructureChangedListener,
020: AttributeChangedListener {
021:
022: public static String ur = "url".intern();
023:
024: /**
025: * This handles the <code>RESOURCE_MODIFIED</code> kind of events.
026: * @param evt The StructureChangeEvent.
027: */
028:
029: public void resourceModified(StructureChangedEvent evt) {
030: if (debugEvent)
031: displayEvent(this , evt);
032: }
033:
034: /**
035: * A new resource has been created in some space.
036: * This handles the <code>RESOURCE_CREATED</code> kind of events.
037: * @param evt The event describing the change.
038: */
039:
040: public void resourceCreated(StructureChangedEvent evt) {
041: if (debugEvent)
042: displayEvent(this , evt);
043: }
044:
045: /**
046: * A resource is about to be removed
047: * This handles the <code>RESOURCE_REMOVED</code> kind of events.
048: * @param evt The event describing the change.
049: */
050:
051: public void resourceRemoved(StructureChangedEvent evt) {
052: if (debugEvent)
053: displayEvent(this , evt);
054: }
055:
056: /**
057: * A resource is about to be unloaded
058: * This handles the <code>RESOURCE_UNLOADED</code> kind of events.
059: * @param evt The event describing the change.
060: */
061:
062: public void resourceUnloaded(StructureChangedEvent evt) {
063: // don't display event here, because the resource is about
064: // to be unloaded.
065: }
066:
067: /**
068: * Gets called when a property changes.
069: * @param evt The AttributeChangeEvent describing the change.
070: */
071:
072: public void attributeChanged(AttributeChangedEvent evt) {
073: if (debugEvent)
074: displayEvent(this , evt);
075: }
076:
077: /**
078: * Enumerate children resource identifiers.
079: * @param all Should all resources be enumerated ? Resources are often
080: * created on demand only, this flag allows the caller to tell the
081: * container about wether it is interested only in already created
082: * resources, or in all resources (even the one that have not yet been
083: * created).
084: * @return An String enumeration, one element per child.
085: */
086:
087: abstract public Enumeration enumerateResourceIdentifiers(boolean all);
088:
089: public Enumeration enumerateResourceIdentifiers() {
090: return enumerateResourceIdentifiers(true);
091: }
092:
093: /**
094: * Ask our frames to update default child attributes.
095: * @param attrs A hashtable.
096: */
097: protected ResourceContext updateDefaultChildAttributes(
098: Hashtable attrs) {
099: ResourceFrame frames[] = getFrames();
100: if (frames != null) {
101: for (int i = 0; i < frames.length; i++) {
102: if (frames[i] == null)
103: continue;
104: frames[i].updateDefaultChildAttributes(attrs);
105: }
106: }
107: return (ResourceContext) attrs.get(co);
108: }
109:
110: /**
111: * Lookup a children in the container.
112: * @param name The name of the children to lookup.
113: * the resource from its store.
114: */
115:
116: abstract public ResourceReference lookup(String name);
117:
118: /**
119: * Remove a child resource from that container.
120: * @param name The name of the child to remove.
121: * @exception MultipleLockException If someone else
122: * has locked the resource.
123: */
124:
125: abstract public void delete(String name)
126: throws MultipleLockException;
127:
128: /**
129: * Create a default child resource in that container.
130: * This method is called by the editor to add a default resource
131: * in the container under the given name. The meaning of <em>default</em>
132: * is left up to the container here.
133: * @param name The identifier for the new resource.
134: */
135: abstract public ResourceReference createDefaultResource(String name);
136:
137: /**
138: * Initialize and register the given resource within that container.
139: * @param name The identifier for the resource.
140: * @param resource An unitialized resource instance.
141: * @param defs A default set of init attribute values (may be
142: * <strong>null</strong>).
143: * @exception InvalidResourceException If an error occurs during the
144: * registration.
145: */
146:
147: abstract public void registerResource(String name,
148: Resource resource, Hashtable defs)
149: throws InvalidResourceException;
150: }
|