001: // ConfigResource.java
002: // $Id: ConfigResource.java,v 1.8 2000/08/16 21:37:40 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.http;
007:
008: import java.util.Enumeration;
009: import java.util.Hashtable;
010: import java.util.NoSuchElementException;
011:
012: import org.w3c.tools.resources.AbstractContainer;
013: import org.w3c.tools.resources.DummyResourceReference;
014: import org.w3c.tools.resources.Resource;
015: import org.w3c.tools.resources.ResourceReference;
016:
017: class ConfigResourceEnumeration implements Enumeration {
018:
019: private static final String ids[] = { ConfigResource.SPACE_NAME,
020: "properties", "indexers", "realms", "control" };
021: int idx = 0;
022:
023: public boolean hasMoreElements() {
024: return idx < ids.length;
025: }
026:
027: public Object nextElement() {
028: if (idx >= ids.length)
029: throw new NoSuchElementException(
030: "config resource enumeration");
031: return ids[idx++];
032: }
033:
034: ConfigResourceEnumeration() {
035: this .idx = 0;
036: }
037: }
038:
039: class PropertySetEnumeration implements Enumeration {
040: Enumeration e = null;
041:
042: public boolean hasMoreElements() {
043: return e.hasMoreElements();
044: }
045:
046: public Object nextElement() {
047: return ((Resource) e.nextElement()).getIdentifier();
048: }
049:
050: protected PropertySetEnumeration(Enumeration e) {
051: this .e = e;
052: }
053:
054: }
055:
056: class PropertiesConfig extends AbstractContainer {
057: httpd server = null;
058:
059: public void registerResource(String n, Resource c, Hashtable d) {
060: throw new RuntimeException("static container");
061: }
062:
063: public ResourceReference createDefaultResource(String name) {
064: throw new RuntimeException("static container");
065: }
066:
067: public void delete(String name) {
068: throw new RuntimeException("static container");
069: }
070:
071: public Enumeration enumerateResourceIdentifiers(boolean all) {
072: return new PropertySetEnumeration(server.enumeratePropertySet());
073: }
074:
075: public ResourceReference lookup(String name) {
076: return new DummyResourceReference(server.getPropertySet(name));
077: }
078:
079: protected PropertiesConfig(httpd server) {
080: this .server = server;
081: }
082:
083: }
084:
085: public class ConfigResource extends AbstractContainer {
086:
087: public final static String SPACE_NAME = "docs_space";
088:
089: protected httpd server = null;
090: protected ResourceReference propConfig = null;
091: protected ResourceReference realmConfig = null;
092: protected ResourceReference controlConfig = null;
093: protected ResourceReference indexers = null;
094:
095: public void registerResource(String n, Resource c, Hashtable d) {
096: throw new RuntimeException("static container");
097: }
098:
099: public ResourceReference createDefaultResource(String name) {
100: throw new RuntimeException("static container");
101: }
102:
103: public void delete(String name) {
104: throw new RuntimeException("static container");
105: }
106:
107: public Enumeration enumerateResourceIdentifiers(boolean all) {
108: return new ConfigResourceEnumeration();
109: }
110:
111: public ResourceReference lookup(String name) {
112: if (name.equals(SPACE_NAME)) {
113: return server.getEditRoot();
114: } else if (name.equals("properties")) {
115: return propConfig;
116: } else if (name.equals("indexers")) {
117: return indexers;
118: } else if (name.equals("realms")) {
119: return realmConfig;
120: } else if (name.equals("control")) {
121: return controlConfig;
122: }
123: return null;
124: }
125:
126: public ConfigResource(httpd server) {
127: this .server = server;
128: this .propConfig = new DummyResourceReference(
129: new PropertiesConfig(server));
130: this .realmConfig = new DummyResourceReference(server
131: .getRealmsCatalog());
132: this .controlConfig = new DummyResourceReference(
133: new ControlResource(server));
134: this .indexers = new DummyResourceReference(server
135: .getIndexersCatalog());
136: }
137:
138: }
|