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 4 luisw
/*
2
 * Created on 12-may-2004
3
 */
4
5
package org.cresques.io;
6
7 6 luisw
import java.util.Hashtable;
8
9 4 luisw
/**
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 6 luisw
        private static Hashtable units = new Hashtable();
18 4 luisw
        String path = null;
19
        String name = null;
20
21
        public DataSource(String path, String name) {
22
                this.path = path;
23
                this.name = name;
24 6 luisw
                units.put(name, this);
25 4 luisw
        }
26
27 6 luisw
        public String getName() { return name; }
28
        public String getPath() { return path; }
29
30
        public static DataSource getDSFromName(String name) {
31 7 luisw
                if (name.indexOf("[") >= 0) name = name.substring(name.indexOf("[")+1);
32
                if (name.indexOf("]") >= 0) name = name.substring(0,name.indexOf("]"));
33 6 luisw
                DataSource ds = (DataSource) units.get(name);
34
                return ds;
35
        }
36
37 7 luisw
        /**
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 210 luisw
                        if (ds == null) return null;
47 7 luisw
                        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 4 luisw
        public String toString() {
55 6 luisw
                return "["+counter+"]";
56 4 luisw
        }
57
}