Statistics
| Revision:

gvsig-educa / org.gvsig.educa.thematicmap / trunk / org.gvsig.educa.thematicmap / org.gvsig.educa.thematicmap.lib / org.gvsig.educa.thematicmap.lib.impl / src / main / java / org / gvsig / educa / thematicmap / impl / map / DefaultThematicMap.java @ 224

History | View | Annotate | Download (4.81 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.thematicmap.impl.map;
23

    
24
import java.io.File;
25
import java.io.IOException;
26

    
27
import org.gvsig.educa.thematicmap.ThematicMapLocator;
28
import org.gvsig.educa.thematicmap.ThematicMapManager;
29
import org.gvsig.educa.thematicmap.impl.MapResoucesManager;
30
import org.gvsig.educa.thematicmap.map.CantLoadContextException;
31
import org.gvsig.educa.thematicmap.map.InvalidThematicMapFormatException;
32
import org.gvsig.educa.thematicmap.map.ThematicMap;
33
import org.gvsig.educa.thematicmap.map.ThematicMapInformation;
34
import org.gvsig.educa.thematicmap.spi.ThematicMapProvider;
35
import org.gvsig.fmap.mapcontext.MapContext;
36
import org.gvsig.tools.ToolsLocator;
37
import org.gvsig.tools.dispose.DisposableManager;
38
import org.gvsig.tools.dynobject.DynObject;
39
import org.gvsig.tools.service.ServiceException;
40
import org.gvsig.tools.service.spi.ProviderManager;
41
import org.slf4j.Logger;
42
import org.slf4j.LoggerFactory;
43

    
44
/**
45
 * <p>
46
 * Default {@link ThematicMap} implementation
47
 * </p>
48
 * <p>
49
 * Delegates open/close operation on the {@link MapResoucesManager}
50
 * </p>
51
 *
52
 * @author gvSIG Team
53
 * @version $Id$
54
 *
55
 */
56
public class DefaultThematicMap implements ThematicMap {
57

    
58
    private static final Logger LOG = LoggerFactory
59
        .getLogger(DefaultThematicMap.class);
60

    
61
    private final DisposableManager disposableManager;
62
    private final File file;
63
    private final ThematicMapInformation info;
64
    private final MapResoucesManager resourceManager;
65
    private MapContext mapContext;
66

    
67
    public DefaultThematicMap(File file, ThematicMapInformation info,
68
        MapResoucesManager resourceManager) {
69
        this.file = file;
70
        this.info = info;
71
        this.resourceManager = resourceManager;
72
        disposableManager = ToolsLocator.getDisposableManager();
73
        disposableManager.bind(this);
74
        resourceManager.addResource(this);
75
    }
76

    
77
    /** {@inheridDoc} */
78
    public ThematicMapInformation getInformation() {
79
        return info;
80
    }
81

    
82
    /**
83
     * Returns source map file
84
     *
85
     * @return
86
     */
87
    public File getSourceFile() {
88
        return file;
89
    }
90

    
91
    /** {@inheridDoc} */
92
    public void open() throws IOException, InvalidThematicMapFormatException,
93
        CantLoadContextException {
94
        if (isOpen()) {
95
            throw new IllegalStateException("Map is already opened");
96
        }
97
        mapContext = resourceManager.openMap(this);
98
    }
99

    
100
    /** {@inheridDoc} */
101
    public boolean isOpen() {
102
        return resourceManager.isOpen(this);
103
    }
104

    
105
    /** {@inheridDoc} */
106
    public void close() throws IOException {
107
        if (!isOpen()) {
108
            // Nothing to do
109
            return;
110
        }
111
        resourceManager.closeMap(this);
112
        mapContext.dispose();
113
        mapContext = null;
114
    }
115

    
116
    /** {@inheridDoc} */
117
    public MapContext getMapContext() {
118
        if (!isOpen()) {
119
            throw new IllegalStateException("Map not open");
120
        }
121
        return mapContext;
122
    }
123

    
124
    /** {@inheridDoc} */
125
    public String getSourceFilePath() {
126
        return file.getAbsolutePath();
127
    }
128

    
129
    public void dispose() {
130
        disposableManager.release(this);
131
        try {
132
            close();
133
        } catch (IOException e) {
134
            LOG.warn("Problem dispossing ThematicMap", e);
135
        }
136

    
137
    }
138

    
139
        public void executeGame(DynObject pareameters) {
140
                ThematicMapManager manager = ThematicMapLocator.getManager();
141
                ProviderManager provMgr = manager.getProviderManager();
142
                try {
143
                        ThematicMapProvider game = (ThematicMapProvider) provMgr.createProvider(pareameters, null);
144
                } catch (ServiceException e) {
145
                        // TODO Auto-generated catch block
146
                        e.printStackTrace();
147
                }
148
                System.out.println("miau");
149
//                game.execute();
150
        }
151
        
152
//        public void executeGame(DynStruct pareameters) {
153
//                ThematicMapManager manager = ThematicMapLocator.getManager();
154
//                ProviderManager provMgr = manager.getProviderManager();
155
//                ThematicMapProvider game = (ThematicMapProvider) provMgr.createProvider(pareameters, null);
156
//                game.execute();
157
//        }
158

    
159
}