Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / DataSource.java @ 1809

History | View | Annotate | Download (1.29 KB)

1
/*
2
 * Created on 12-may-2004
3
 */
4

    
5
package org.cresques.io;
6

    
7
import java.util.Hashtable;
8

    
9
/**
10
 * Origen de datos. Unidad, volumen de red, etc.
11
 * 
12
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
13
 */
14

    
15
public class DataSource {
16
        private static int counter = 0;
17
        private static Hashtable units = new Hashtable();
18
        String path = null;
19
        String name = null;
20

    
21
        public DataSource(String path, String name) {
22
                this.path = path;
23
                this.name = name;
24
                units.put(name, this);
25
        }
26
        
27
        public String getName() { return name; }
28
        public String getPath() { return path; }
29
        
30
        public static DataSource getDSFromName(String name) {
31
                if (name.indexOf("[") >= 0) name = name.substring(name.indexOf("[")+1);
32
                if (name.indexOf("]") >= 0) name = name.substring(0,name.indexOf("]"));
33
                DataSource ds = (DataSource) units.get(name);
34
                return ds;
35
        }
36
        
37
        /**
38
         * Sustituye en el path el nombre de la unidad por su path real.
39
         * 
40
         * @param path
41
         * @return
42
         */
43
        public static String normalize(String path) {
44
                if (path.indexOf("[") >= 0) {
45
                        DataSource ds = DataSource.getDSFromName(path);
46
                        if (ds == null) return null;
47
                        path = path.substring(0,path.indexOf("[")) + 
48
                                ds.getPath() + path.substring(path.indexOf("]")+1);
49
                        //System.out.println(path);
50
                }
51
                return path;
52
        }
53
        
54
        public String toString() {
55
                return "["+counter+"]";
56
        }
57
}