Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1008 / libraries / libCq CMS for java.old / src / org / cresques / io / DataSource.java @ 12520

History | View | Annotate | Download (2.41 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.io;
25

    
26
import java.util.Hashtable;
27

    
28

    
29
/**
30
 * Origen de datos. Unidad, volumen de red, etc.
31
 *
32
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
33
 */
34
public class DataSource {
35
    private static int counter = 0;
36
    private static Hashtable units = new Hashtable();
37
    String path = null;
38
    String name = null;
39

    
40
    public DataSource(String path, String name) {
41
        this.path = path;
42
        this.name = name;
43
        units.put(name, this);
44
    }
45

    
46
    public String getName() {
47
        return name;
48
    }
49

    
50
    public String getPath() {
51
        return path;
52
    }
53

    
54
    public static DataSource getDSFromName(String name) {
55
        if (name.indexOf("[") >= 0) {
56
            name = name.substring(name.indexOf("[") + 1);
57
        }
58

    
59
        if (name.indexOf("]") >= 0) {
60
            name = name.substring(0, name.indexOf("]"));
61
        }
62

    
63
        DataSource ds = (DataSource) units.get(name);
64

    
65
        return ds;
66
    }
67

    
68
    /**
69
     * Sustituye en el path el nombre de la unidad por su path real.
70
     *
71
     * @param path
72
     * @return
73
     */
74
    public static String normalize(String path) {
75
        if (path.indexOf("[") >= 0) {
76
            DataSource ds = DataSource.getDSFromName(path);
77

    
78
            if (ds == null) {
79
                return null;
80
            }
81

    
82
            path = path.substring(0, path.indexOf("[")) + ds.getPath() +
83
                   path.substring(path.indexOf("]") + 1);
84

    
85
            //System.out.println(path);
86
        }
87

    
88
        return path;
89
    }
90

    
91
    public String toString() {
92
        return "[" + counter + "]";
93
    }
94
}