Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / MapContextLibrary.java @ 30011

History | View | Annotate | Download (3.17 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

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 IVER T.I. S.A.   {{Task}}
26
 */
27
package org.gvsig.fmap.mapcontext;
28

    
29
import org.gvsig.fmap.dal.DataTypes;
30
import org.gvsig.fmap.dal.feature.FeatureStore;
31
import org.gvsig.fmap.geom.GeometryLibrary;
32
import org.gvsig.fmap.mapcontext.impl.DefaultMapContextDrawer;
33
import org.gvsig.fmap.mapcontext.layers.FLayer;
34
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
35
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
36
import org.gvsig.tools.ToolsLibrary;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.dynobject.DynClass;
39
import org.gvsig.tools.dynobject.DynField;
40
import org.gvsig.tools.dynobject.DynObjectManager;
41
import org.gvsig.tools.locator.BaseLibrary;
42
import org.gvsig.tools.locator.LibraryException;
43
import org.gvsig.tools.locator.LocatorException;
44
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
45

    
46
/**
47
 * Library for the MapContext library API.
48
 * @author jmvivo
49
 */
50
public class MapContextLibrary extends BaseLibrary {
51

    
52
        private ToolsLibrary toolsLib;
53
        private GeometryLibrary geomLibrary;
54

    
55
        public void initialize() throws LocatorException {
56
                super.initialize();
57
                toolsLib = new ToolsLibrary();
58

    
59
                toolsLib.initialize();
60

    
61
                geomLibrary = new GeometryLibrary();
62

    
63
                geomLibrary.initialize();
64

    
65
                LayerFactory.getInstance().registerLayerToUseForStore(
66
                                FeatureStore.class, FLyrVect.class);
67

    
68
        }
69

    
70
        public void postInitialize() throws LocatorException {
71
                super.postInitialize();
72

    
73
                toolsLib.postInitialize();
74
                geomLibrary.postInitialize();
75

    
76
                DynObjectManager dynManager = ToolsLocator.getDynObjectManager();
77

    
78
                DynField field;
79
                DynClass fLayerDynClass = dynManager.get(FLayer.DYNCLASS_NAME);
80
                if (fLayerDynClass == null) {
81
                        fLayerDynClass = dynManager.add(FLayer.DYNCLASS_NAME);
82

    
83
                        field = fLayerDynClass.addDynField("name");
84
                        field.setType(DataTypes.STRING);
85

    
86
                        field = fLayerDynClass.addDynField("SRS");
87
                        field.setType(DataTypes.SRS);
88
                }
89

    
90
                MapContextManager manager = MapContextLocator.getMapContextManager();
91

    
92
                if (manager == null) {
93
                        throw new ReferenceNotRegisteredException(
94
                                        MapContextLocator.MAPCONTEXT_MANAGER_NAME,
95
                                        MapContextLocator.getInstance());
96
                }
97

    
98
                try {
99
                        manager.setDefaultMapContextDrawer(DefaultMapContextDrawer.class);
100
                } catch (MapContextException ex) {
101
                        throw new LibraryException(ex);
102
                }
103

    
104
        }
105

    
106
}