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
package org.gvsig.tools.resourcesstorage;
2

    
3
import java.io.Closeable;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.OutputStream;
7
import java.net.URI;
8
import java.net.URL;
9
import java.util.List;
10

    
11
/**
12
 *
13
 * @author jjdelcerro
14
 */
15
@SuppressWarnings("UseSpecificCatch")
16
public interface ResourcesStorage {
17

    
18
    public interface Resource extends Closeable {
19
      
20
        /**
21
         * 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
         * 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
        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
    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
    public static Resource createResource(String name, URL url) {
62
        try {
63
            return new URLResource(name, url);
64
        } catch (Exception ex) {
65
            return null;
66
        }
67
    }
68
    
69
    public static Resource createResource(String name, URI uri) {
70
        try {
71
            return new URLResource(name, uri.toURL());
72
        } catch (Exception ex) {
73
            return null;
74
        }
75
    }
76
    
77
    public String getSeparator();
78
    
79
    public Resource getResource(String resourceName);
80
    
81
    public List<Resource> getResources(String resourceName);
82

    
83
    public Resource getLocalizedResource(String resourceName);
84
    
85
    public List<Resource> getLocalizedResources(String resourceName);
86
    
87
    public boolean isEmpty();
88
    
89
    public boolean isReadOnly();
90
    
91
    public boolean exists(String resourceName);
92

    
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
}