ResourceServer Classes

Resource servers mainly do two things:
  1. Convert resource addresses to resource objects, and vice-versa.
  2. Act as interfaces to repositories (filesystems, the Collective, or CVS).
To do the first, resource servers implement toResource(String) and toAddress(Resource).

To do the second, resource servers implement getParentCategory(Category), getSubCategories(Category), and getResources(Category).

In addition, resource servers that interface to remote repositories must handle timeouts and connections and coordinate with the resource cache manager.

Interface
ResourceServer
+ getLabel() : String
+ isBrowsable() : boolean
+ supportsVersioning() : boolean
+ getRootCategory() : Category
+ getVersion(Resource) : String
+ toAddress(Resource) : String
+ toResource(String) : Resource
+ getInputStream(Resource) : InputStream
+ getParentCategory(Category) : Category
+ getResources(Category) : Resource[]
+ getResourceAllVersions(Resource) : Resource[]
+ getSubCategories(Category) : Category[]
ResourceServerBasics
# root : Category
+ getLabel() : String
+ isBrowsable() : boolean
+ supportsVersioning() : boolean
+ getRootCategory() : Category
LocalResourceServer
+ toAddress(Resource) : String
+ toResource(String) : Resource
+ getVersion(Resource) : String
+ getInputStream(Resource) : InputStream
+ getParentCategory(Category) : Category
+ getSubCategories(Category) : Category[]
+ getResources(Category) : Resource[]
UrlResourceServer
# cacheManager : ResourceCacheManager
# timeout : long
# existsURL(URL) : boolean
# extractHREFs(URL) : Iterator
# getName(URL) : String
# getParentDirectoryURL(URL) : URL
# hostFound(URL, long) : boolean
+ increaseTimeout()
+ toAddress(Resource) : String
+ toResource(String) : Resource
+ getVersion(Resource) : String
+ getInputStream(Resource) : InputStream
+ getParentCategory(Category) : Category
+ getSubCategories(Category) : Category[]
+ getResources(Category) : Resource[]
abstract class ResourceServerBasics
        implements ResourceServer, ResourceServerConstants {
    protected Category root = null;
    
    public String getLabel() {
        return label;
    }

    public boolean supportsVersioning() {
        return versioning;
    }

    public boolean isBrowsable() {
        return browsable;
    }

    public Category getRootCategory() {
        return root;
    }
}
public class LocalResourceServer extends ResourceServerBasics {

    public String toAddress(Resource resource) {
        File file = getFile(resource);
        return file.toString();
    }

    public Resource toResource(String address) 
                            throws BadResourceAddrException {
        File file = new File(address);
        return new LocalResource(this, file);
    }

    public Category getParentCategory(Category category) {
        File parentDirectory = getFile(category).getParentFile();
        return new LocalCategory(this, parentDirectory);
    }

    public Resource[] getResources(Category category) {
        File[] files = getFile(category).listFiles(resourceFilter);
        Resource[] resources = new Resource[files.length];
        for (int i = 0; i < resources.length; i++) {
            resources[i] = new LocalResource(this, files[i]);
        }
        return resources;
    }
}
public class UrlResourceServer extends ResourceServerBasics {

    public String toAddress(Resource resource) {
        URL url = getURL(resource);
        return url.toString();
    }

    public Resource toResource(String address) 
                    throws BadResourceAddrException {
        UrlResource resource = null;
        if (address.startsWith("http://")) {
            resource = new UrlResource(this, new URL(address));
        }
        return resource;
    }

    public Resource[] getResources(Category category) 
                    throws IOException {
        Iterator i = extractHREFs(getURL(category));
        List resources = new Vector();
        . . .
        return (Resource[]) resources.toArray(new Resource[0]);
    }

    protected synchronized Iterator extractHREFs(URL url) {
        . . .
        return refs.iterator();
    }
}