Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / LayerFactory.java @ 21659

History | View | Annotate | Download (3.36 KB)

1
package org.gvsig.fmap.mapcontext.layers;
2

    
3
import org.apache.log4j.Logger;
4
import org.cresques.cts.IProjection;
5
import org.gvsig.data.DataManager;
6
import org.gvsig.data.DataStore;
7
import org.gvsig.data.DataStoreParameters;
8
import org.gvsig.data.InitializeException;
9
import org.gvsig.data.ReadException;
10
import org.gvsig.data.operation.DataStoreOperationException;
11
import org.gvsig.data.operation.DataStoreOperationNotSupportedException;
12
import org.gvsig.data.vectorial.FeatureStore;
13
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
14
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
15
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
16
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
17
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory;
18
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy;
19

    
20

    
21
/**
22
 * Crea un adaptador del driver que se le pasa como par?metro en los m?todos
23
 * createLayer. Si hay memoria suficiente se crea un FLyrMemory que pasa todas
24
 * las features del driver a memoria
25
 */
26
public class LayerFactory {
27
        private static Logger logger = Logger.getLogger(LayerFactory.class
28
                        .getName());
29

    
30
        /*
31
         * Crea un RandomVectorialFile con el driver que se le pasa como par?metro y
32
         * guard?ndose el nombre del fichero para realizar los accesos, la capa
33
         * tendr? asociada la proyecci?n que se pasa como parametro tambi?n
34
         *
35
         * @param layerName Nombre de la capa. @param driverName Nombre del driver.
36
         * @param f fichero. @param proj Proyecci?n.
37
         *
38
         * @return FLayer. @throws DriverException
39
         *
40
         * @throws DriverException @throws DriverIOException
41
         */
42
        public static FLayer createLayer(String layerName, DataStoreParameters storeParameters,
43
                        IProjection proj) throws LoadLayerException  {
44
                // Se obtiene el driver que lee
45
                try{
46
                        DataManager dataManager=DataManager.getManager();
47
                        DataStore dataStore=dataManager.createDataStore(storeParameters);
48
                        if (dataStore instanceof FeatureStore){
49
                                FLyrVect layer=new FLyrVect();
50
                                layer.setDataStore(dataStore);
51
                                layer.setProjection(proj);
52
                                layer.setName(layerName);
53
                                ILegend legend = null;
54
                                try{
55
                                        legend = (ILegend) dataStore.invokeOperation("defaultLegend", null);
56
                                } catch (DataStoreOperationNotSupportedException e) {
57
                                        // Not suported
58
                                } catch (DataStoreOperationException e) {
59
                                        throw new LoadLayerException(layerName,e);
60
                                }
61

    
62
                                if (legend !=null) {
63
                                        layer.setLegend((IVectorLegend) legend);
64

    
65
                                        ILabelingStrategy labeler=null;
66
                                        try{
67
                                                labeler=(ILabelingStrategy) dataStore.invokeOperation("defaultLabelingStrategy", null);
68
                                        } catch (DataStoreOperationNotSupportedException e) {
69
                                                // Not suported
70
                                        } catch (DataStoreOperationException e) {
71
                                                throw new LoadLayerException(layerName,e);
72
                                        }
73

    
74

    
75
                                        if (labeler != null) {
76
                                                labeler.setLayer(layer);
77
                                                layer.setLabelingStrategy(labeler);
78
                                                layer.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? etiquetes?????
79
                                        }
80
                                } else {
81
                                        layer.setLegend(LegendFactory.createSingleSymbolLegend(layer
82
                                                        .getShapeType()));
83
                                }
84

    
85

    
86
                        }else{
87
                                //Raster
88
                        }
89
                } catch (InitializeException e1) {
90
                        throw new LoadLayerException(layerName,e1);
91
                } catch (ReadException e) {
92
                        throw new LoadLayerException(layerName,e);
93
                }
94
                return null;
95
        }
96

    
97

    
98
}