Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / resourcesstorage / ResourcesStorage.java @ 2142

History | View | Annotate | Download (2.67 KB)

1 1893 jjdelcerro
package org.gvsig.tools.resourcesstorage;
2 1881 jjdelcerro
3
import java.io.Closeable;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.OutputStream;
7 1993 jjdelcerro
import java.net.URI;
8 1881 jjdelcerro
import java.net.URL;
9 1888 jjdelcerro
import java.util.List;
10 1881 jjdelcerro
11
/**
12
 *
13
 * @author jjdelcerro
14
 */
15 1993 jjdelcerro
@SuppressWarnings("UseSpecificCatch")
16 1881 jjdelcerro
public interface ResourcesStorage {
17
18
    public interface Resource extends Closeable {
19 2107 jjdelcerro
20 1893 jjdelcerro
        /**
21 2107 jjdelcerro
         * Return the name of the resource.
22
         * With this name, can be rebuild the resource from the ResourcesStorage.
23
         *
24
         * @return name of the resource
25
         */
26
        public String getName();
27
28
        /**
29 1893 jjdelcerro
         * El recurso es de solo lectura, normalmente por que el tipo de recurso
30
         * no permite escribir sobre el.
31
         *
32
         * Podria devolver false, y a pesar de ello no poder escribir, normalmente
33
         * por carecer de permisos para ello.
34
         *
35
         * @return
36
         */
37
        public boolean isReadOnly();
38
39 1881 jjdelcerro
        public URL getURL();
40
41
        public boolean exists();
42
43
        public InputStream asInputStream() throws IOException;
44
45
        public OutputStream asOutputStream() throws IOException;
46
47
        @Override
48
        public void close();
49
    }
50
51 1991 jjdelcerro
    public static final ResourcesStorage EMPTY_RESOURCESSTORAGE = new EmptyResourcesStorage();
52
53
    public static ResourcesStorage createFilesResourcesStorage(String pathName) {
54
        return new FilesResourcesStorage(pathName);
55
    }
56
57
    public static MultiResourcesStorage createMultiResourcesStorage() {
58
        return new BaseMultiResourcesStorage();
59
    }
60
61 2107 jjdelcerro
    public static Resource createResource(String name, URL url) {
62 1993 jjdelcerro
        try {
63 2107 jjdelcerro
            return new URLResource(name, url);
64 1993 jjdelcerro
        } catch (Exception ex) {
65
            return null;
66
        }
67
    }
68
69 2107 jjdelcerro
    public static Resource createResource(String name, URI uri) {
70 1993 jjdelcerro
        try {
71 2107 jjdelcerro
            return new URLResource(name, uri.toURL());
72 1993 jjdelcerro
        } catch (Exception ex) {
73
            return null;
74
        }
75
    }
76
77 1991 jjdelcerro
    public String getSeparator();
78
79 1893 jjdelcerro
    public Resource getResource(String resourceName);
80 1881 jjdelcerro
81 1893 jjdelcerro
    public List<Resource> getResources(String resourceName);
82 1888 jjdelcerro
83 1947 jjdelcerro
    public Resource getLocalizedResource(String resourceName);
84
85
    public List<Resource> getLocalizedResources(String resourceName);
86
87 1893 jjdelcerro
    public boolean isEmpty();
88
89
    public boolean isReadOnly();
90
91
    public boolean exists(String resourceName);
92 2142 jjdelcerro
93
    /**
94
     * Return the resource names in this store.
95
     * If the storage don't have resources, return a empty list.
96
     *
97
     * @return list of resource names or empty list.
98
     */
99
    public List<String> getResourceNames();
100
101 1881 jjdelcerro
}