Statistics
| Revision:

gvsig-oracle / org.gvsig.oracle / trunk / org.gvsig.oracle / org.gvsig.oracle.provider / src / main / java / org / gvsig / oracle / dal / OracleSRSSolver.java @ 294

History | View | Annotate | Download (2.27 KB)

1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.oracle.dal;
7

    
8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.sql.Connection;
11
import java.util.Objects;
12
import java.util.Properties;
13
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
14
import org.gvsig.fmap.dal.store.jdbc2.spi.SRSSolverBase;
15

    
16
/**
17
 *
18
 * @author fdiaz
19
 */
20
public class OracleSRSSolver extends SRSSolverBase{
21

    
22
    private static Properties translations;
23
    
24
    public OracleSRSSolver(JDBCHelper helper) {
25
        super(helper);
26
    }
27
    
28
    @Override
29
    protected Object searchDatabaseCode(Connection connection, String applicationAbbrev) {
30
        try {
31
            String[] s = applicationAbbrev.split(":");
32
            String code_s = s[1].trim();
33
            try {
34
                int code_i = Integer.parseInt(code_s);
35
                return code_i;
36
            } catch(NumberFormatException e) {
37
                
38
            }
39
            return 0;
40
        } catch (Throwable ex) {
41
            throw new RuntimeException("Problems searching database code from '"+applicationAbbrev+"'.",ex);
42
        }
43
    }
44

    
45
    @Override
46
    protected String searchApplicationAbbrev(Connection connection, Integer databaseCode) {
47
        try {
48
            String s = Objects.toString(databaseCode,"0");
49
            String trans = getTranslations().getProperty(s, null);
50
            if(trans == null){
51
                return null;
52
            }
53
            return "EPSG:" + trans;
54
        } catch (Throwable ex) {
55
            throw new RuntimeException("Problems searching application abbrev from '"+databaseCode+"'.",ex);
56
        }
57
    }    
58
    
59
    private Properties getTranslations() {
60
        if (translations == null) {
61
            InputStream inStream = this.getClass().getClassLoader().getResourceAsStream("/srids/oracle2epsg.properties");
62
            if (inStream != null) {
63
                translations = new Properties();
64
                try {
65
                    translations.load(inStream);
66
                } catch (IOException ex) {
67
                    logger.warn("Can't load srid translations", ex);
68
                }
69

    
70
            }
71
        }
72
        return translations;
73
    }
74

    
75
}