Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / type / DefaultGeometryType.java @ 26866

History | View | Annotate | Download (4.59 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
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.fmap.geom.type;
29

    
30
import java.util.ArrayList;
31
import java.util.List;
32

    
33
import org.gvsig.fmap.geom.Geometry;
34
import org.gvsig.fmap.geom.GeometryManager;
35
import org.gvsig.fmap.geom.operation.GeometryOperation;
36

    
37
/**
38
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
39
 */
40
public class DefaultGeometryType implements GeometryType {
41
        /** 
42
         * The geometry identifier
43
         */
44
        private int id;
45
        
46
        /** 
47
         * Geometry type name
48
         */
49
        private String name;
50
                
51
        /** Class that implements this class type */
52
        private Class geometryClass;
53
        
54
        /**
55
         * The type of the geometry. The type is an abstract representation
56
         * of the object (Point, Curve...) but it is not a concrete 
57
         * representation (Point2D, Point3D...). To do that comparation
58
         * the id field is used.
59
         */
60
        private int type;
61
        
62
        /**
63
         * The subtype of the geometry. The subtype represents a set of 
64
         * geometries with a dimensional relationship (2D, 3D, 2DM...)
65
         */
66
        private int subType;
67
        
68
        
69
                
70
        /** Registered operations for a concrete geometry type */
71
        private List geometryOperations = new ArrayList();
72
        
73
        /**
74
         * This constructor is used by the {@link GeometryManager} when it
75
         * register a new GeometryType. It has not be used from other
76
         * parts.
77
         * @param geomClass
78
         * Geometry class (e.g: Point2D.class)
79
         * @param name
80
         * Symbolic Geometry name that is used to persist the geometry type. In some
81
         * cases, it is better to use this name because the id can change for different
82
         * application executions.                           
83
         * @param id
84
         * Geometry id        
85
         * @param typeName
86
         * The geometry type name
87
         * @param type
88
         * The geometry abstract type                        
89
         */
90
        public DefaultGeometryType(Class geomClass, String name, int id, int type, int subType) {
91
                this.geometryClass = geomClass;
92
                if (name == null) {
93
                        this.name = geomClass.getName();
94
                } else {
95
                        this.name = name;
96
                }
97
                this.id = id;                
98
                this.type = type;        
99
                this.subType = subType;
100
        }
101
        
102
        /**
103
         * This method creates a {@link Geometry} with the type specified 
104
         * by this GeometryType. The geometry has to have a constructor
105
         * without arguments.
106
         * 
107
         * @return A new geometry
108
         * @throws IllegalAccessException 
109
         * @throws InstantiationException 
110
         */
111
        public Geometry create() throws InstantiationException, IllegalAccessException{
112
                return (Geometry)geometryClass.newInstance();
113
        }
114
        
115
        /**
116
         * Guardamos una referencia a una instancia de la operación en el índice que se pasa como parámetro.
117
         * Si el índice ya está ocupado se sobrescribe.
118
         * 
119
         * @param index
120
         * @param geomOp
121
         */
122
        public void setGeometryOperation(int index, GeometryOperation geomOp) {
123
                
124
                while (index > geometryOperations.size()) {
125
                        geometryOperations.add(null);
126
                }
127
                
128
                if (index == geometryOperations.size()) {
129
                        geometryOperations.add(geomOp);
130
                } else {                                
131
                        geometryOperations.set(index, geomOp);
132
                }
133
        }
134
        
135
        public GeometryOperation getGeometryOperation(int index) {
136
                return (GeometryOperation) geometryOperations.get(index);
137
        }
138
        
139
        public Class getGeometryClass() {
140
                return geometryClass;
141
        }
142
        
143
        public String toString() {
144
                StringBuffer sb = new StringBuffer("[")
145
                .append(geometryClass.getName())
146
                .append(",[")
147
                .append(geometryOperations.toString())
148
                .append("]");
149
                
150
                return sb.toString();
151
        }
152

    
153
        /* (non-Javadoc)
154
         * @see org.gvsig.fmap.geom.type.GeometryType#getId()
155
         */
156
        public int getId() {
157
                return id;
158
        }
159

    
160
        /* (non-Javadoc)
161
         * @see org.gvsig.fmap.geom.type.GeometryType#getName()
162
         */
163
        public String getName() {
164
                return name;
165
        }
166

    
167
        /* (non-Javadoc)
168
         * @see org.gvsig.fmap.geom.type.GeometryType#getType()
169
         */
170
        public int getType() {
171
                return type;
172
        }
173

    
174
        /* (non-Javadoc)
175
         * @see org.gvsig.fmap.geom.type.GeometryType#getSubType()
176
         */
177
        public int getSubType() {
178
                return subType;
179
        }
180
}
181