Revision 3301

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLyrVect.java
70 70
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
71 71
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
72 72
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
73
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
73 74
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
74 75
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
75 76
import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable;
......
87 88
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
88 89
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
89 90
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
91
import com.iver.utiles.IPersistance;
90 92
import com.iver.utiles.PostProcessSupport;
91 93
import com.iver.utiles.XMLEntity;
92 94
import com.vividsolutions.jts.geom.Coordinate;
......
517 519
                throw new XMLException(e);
518 520
            }
519 521
            xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos metido la leyenda y el selection support
522
        } else if (source instanceof VectorialAdapter) { 
523
            // Se supone que hemos hecho algo gen?rico.
524
            xml.putProperty("type", "vectorial");
525
            
526
            VectorialDriver driver = (VectorialDriver) source.getDriver();
527
            
528
            // Guardamos el nombre del driver para poder recuperarlo
529
            // con el DriverManager de Fernando.
530
            xml.putProperty("other", driver.getName());            
531
            try {
532
                xml.putProperty("recordset-name", getRecordset().getName());
533
            } catch (DriverException e) {
534
                throw new XMLException(e);
535
            }
536
            if (driver instanceof IPersistance)
537
            {
538
                xml.putProperty("className", driver.getClass().getName());
539
                IPersistance persist = (IPersistance) driver;
540
                xml.addChild(persist.getXMLEntity()); // Tercer child. Antes hemos metido la leyenda y el selection support
541
            }
520 542
		} else if (source instanceof WFSAdapter) {
521 543
		}
522 544
		xml.putProperty("driverName", getSource().getDriver().getName());
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/VectorialDefaultAdapter.java
1
/*
2
 * Created on 10-nov-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 * 
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *  
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 * 
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *  
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 * 
34
 *    or
35
 * 
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 * 
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package com.iver.cit.gvsig.fmap.layers;
45

  
46
import java.awt.geom.Rectangle2D;
47
import java.io.IOException;
48

  
49
import com.hardcode.driverManager.DriverLoadException;
50
import com.hardcode.gdbms.engine.data.DataSource;
51
import com.hardcode.gdbms.engine.data.DataSourceFactory;
52
import com.hardcode.gdbms.engine.data.NoSuchTableException;
53
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
54
import com.iver.cit.gvsig.fmap.core.IGeometry;
55
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
56
import com.iver.cit.gvsig.fmap.drivers.IWFSdriver;
57

  
58
/**
59
 * @author fjp
60
 *
61
 */
62
public class VectorialDefaultAdapter extends VectorialAdapter {
63

  
64
    /* (non-Javadoc)
65
     * @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#getRecordset()
66
     */
67
    public DataSource getRecordset() throws DriverLoadException {
68
        if (getDriver() instanceof ObjectDriver)
69
        {
70
            String name = LayerFactory.getDataSourceFactory().addDataSource((ObjectDriver)getDriver());
71
            try {
72
                DataSource ds = LayerFactory.getDataSourceFactory().createRandomDataSource(name, DataSourceFactory.AUTOMATIC_OPENING);
73
                return ds;
74
            } catch (NoSuchTableException e) {
75
                throw new RuntimeException(e);
76
            } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
77
                throw new RuntimeException(e);
78
            }
79
        }
80
        return null;
81

  
82
    }
83

  
84
    /* (non-Javadoc)
85
     * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#start()
86
     */
87
    public void start() throws DriverIOException {
88
    }
89

  
90
    /* (non-Javadoc)
91
     * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#stop()
92
     */
93
    public void stop() throws DriverIOException {
94
    }
95

  
96
    /* (non-Javadoc)
97
     * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int)
98
     */
99
    public IGeometry getShape(int index) throws DriverIOException {
100
        try {
101
            return getDriver().getShape(index);
102
        } catch (IOException e) {
103
            throw new DriverIOException(e);
104
        }
105
    }
106

  
107
    /* (non-Javadoc)
108
     * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
109
     */
110
    public int getShapeCount() throws DriverIOException {
111
        try {
112
            return getDriver().getShapeCount();
113
        } catch (IOException e) {
114
            throw new DriverIOException(e);
115
        }
116
    }
117

  
118
    /* (non-Javadoc)
119
     * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
120
     */
121
    public Rectangle2D getFullExtent() throws DriverIOException {
122
        try {
123
            return getDriver().getFullExtent();
124
        } catch (IOException e) {
125
            throw new DriverIOException(e);
126
        }
127
    }
128

  
129
    /* (non-Javadoc)
130
     * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
131
     */
132
    public int getShapeType() throws DriverIOException {
133
        return getDriver().getShapeType();
134
    }
135

  
136
}
0 137

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/LayerFactory.java
189 189
		return capa;
190 190
	}
191 191

  
192
    public static FLayer createLayer(String layerName, VectorialDriver d,
193
            IProjection proj) throws DriverException {
194
            //TODO Comprobar si hay un adaptador ya
195
            VectorialDefaultAdapter adapter = new VectorialDefaultAdapter();
196
            adapter.setDriver((VectorialDriver) d);
197

  
198
            FLyrVect capa = new FLyrVect();
199
            capa.setName(layerName);
200

  
201
            capa.setSource(adapter);
202
            capa.setProjection(proj);
203

  
204
            try {
205
                
206
                // Le asignamos tambi?n una legenda por defecto acorde con
207
                // el tipo de shape que tenga. Tampoco s? si es aqu? el
208
                // sitio adecuado, pero en fin....
209
                if (d instanceof WithDefaultLegend) {
210
                    WithDefaultLegend aux = (WithDefaultLegend) d;
211
                    adapter.start();
212
                    capa.setLegend((VectorialLegend) aux.getDefaultLegend());
213
                    adapter.stop();
214
                } else {
215
                    capa.setLegend(LegendFactory.createSingleSymbolLegend(
216
                            capa.getShapeType()));
217
                }
218
            } catch (FieldNotFoundException e) {
219
                //Esta no puede saltar
220
            } catch (DriverIOException e) {
221
                throw new DriverException(e);
222
            }
223

  
224
            return capa;
225
        }
226
    
192 227
	/**
193 228
	 * Crea una capa WMS con el driver que se le pasa como par?metro y
194 229
	 * guard?ndose el nombre del fichero para realizar los accesos, la capa
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLayers.java
63 63
import com.iver.cit.gvsig.fmap.ViewPort;
64 64
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
65 65
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
66
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
66 67
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
67 68
import com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection;
68 69
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
......
70 71
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
71 72
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
72 73
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
74
import com.iver.utiles.IPersistance;
73 75
import com.iver.utiles.XMLEntity;
74 76

  
75 77
/**
......
672 674
                                e.printStackTrace();
673 675
                                throw new XMLException(e);
674 676
                            }                                                                                                                 
677
                        }
678
                        // Clases con algun driver gen?rico creado por otro
679
                        // programador
680
                        if (xml.getChild(i).contains("other")) {
681
                            
682
                            String driverName = xml.getChild(i).getStringProperty("other");
683
                            VectorialDriver driver = null;
684
                            try {                                
685
                                driver = (VectorialDriver) LayerFactory.getDM().getDriver(driverName);
686
                            } catch (DriverLoadException e) {
687
                                // Si no existe ese driver, no pasa nada.
688
                                // Puede que el desarrollador no quiera que
689
                                // aparezca en el cuadro de di?logo y ha metido
690
                                // el jar con sus clases en nuestro directorio lib.
691
                                // Intentamos cargar esa clase "a pelo".
692
                                if (xml.contains("className"))
693
                                {
694
                                    String className2 = xml.getChild(i).getStringProperty("className");
695
                                    try {
696
                                        driver = (VectorialDriver) Class.forName(className2).newInstance();
697
                                    } catch (Exception e1) {
698
                                        throw new XMLException(e1);
699
                                    }
700
                                }
701
                            }                                                                                                                                                 
702
                            if (driver instanceof IPersistance)
703
                            {
704
                                IPersistance persist = (IPersistance) driver;
705
                                persist.setXMLEntity(xml.getChild(i).getChild(2));
706
                            }
707
                            layer = LayerFactory.createLayer(s[i], driver, proj);
675 708
                        }                       
676 709
                        
710
                        
677 711
					} else if ("raster".equals(type)) {
678 712
/*						if (xml.getChild(i).contains("file")) {
679 713
							Driver d = LayerFactory.getDM().getDriver(xml.getChild(i).getStringProperty("driverName"));

Also available in: Unified diff