root / trunk / libraries / libGeometries / src / org / gvsig / fmap / geometries / operation / GeometryOperationsRegistry.java @ 20497
History | View | Annotate | Download (4.96 KB)
1 |
package org.gvsig.fmap.geometries.operation; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Enumeration; |
5 |
import java.util.Map; |
6 |
|
7 |
|
8 |
import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable; |
9 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
10 |
*
|
11 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
12 |
*
|
13 |
* This program is free software; you can redistribute it and/or
|
14 |
* modify it under the terms of the GNU General Public License
|
15 |
* as published by the Free Software Foundation; either version 2
|
16 |
* of the License, or (at your option) any later version.
|
17 |
*
|
18 |
* This program is distributed in the hope that it will be useful,
|
19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
* GNU General Public License for more details.
|
22 |
*
|
23 |
* You should have received a copy of the GNU General Public License
|
24 |
* along with this program; if not, write to the Free Software
|
25 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
26 |
*
|
27 |
* For more information, contact:
|
28 |
*
|
29 |
* Generalitat Valenciana
|
30 |
* Conselleria d'Infraestructures i Transport
|
31 |
* Av. Blasco Ib??ez, 50
|
32 |
* 46010 VALENCIA
|
33 |
* SPAIN
|
34 |
*
|
35 |
* +34 963862235
|
36 |
* gvsig@gva.es
|
37 |
* www.gvsig.gva.es
|
38 |
*
|
39 |
* or
|
40 |
*
|
41 |
* IVER T.I. S.A
|
42 |
* Salamanca 50
|
43 |
* 46005 Valencia
|
44 |
* Spain
|
45 |
*
|
46 |
* +34 963163400
|
47 |
* dac@iver.es
|
48 |
*/
|
49 |
/* CVS MESSAGES:
|
50 |
*
|
51 |
* $Id: GeometryOperationsRegistry.java,v 1.1 2008/03/12 08:46:21 cvs Exp $
|
52 |
* $Log: GeometryOperationsRegistry.java,v $
|
53 |
* Revision 1.1 2008/03/12 08:46:21 cvs
|
54 |
* *** empty log message ***
|
55 |
*
|
56 |
*
|
57 |
*/
|
58 |
/**
|
59 |
* @author Jorge Piera Llodr? (jorge.piera@iver.es)
|
60 |
*/
|
61 |
public class GeometryOperationsRegistry { |
62 |
private static Hashtable geometryOperations = new Hashtable(); |
63 |
|
64 |
/**
|
65 |
* Register a new operation
|
66 |
* @param geometryType
|
67 |
* The geometry type. See the FShape class to see the types
|
68 |
* @param operationCode
|
69 |
* Operation code. See the GeometryOperation class to see the codes
|
70 |
* @param operation
|
71 |
* The operation to register.
|
72 |
*/
|
73 |
public static void registerOperation(int geometryType, int operationCode, GeometryOperation operation){ |
74 |
GeometryOperationsSet operationsSet = null;
|
75 |
Integer key = new Integer(geometryType); |
76 |
//If the operations set exists...
|
77 |
if (geometryOperations.containsKey(key)){
|
78 |
operationsSet = (GeometryOperationsSet)geometryOperations.get(key); |
79 |
}//If is the first time it is necessary to create a set of operations
|
80 |
else{
|
81 |
operationsSet = new GeometryOperationsSet(GeometryOperation.NUMBER_OF_OPERATIONS, geometryType);
|
82 |
geometryOperations.put(key, operationsSet); |
83 |
} |
84 |
operationsSet.addOperation(operationCode, operation); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Gets the set of operations defined for a concrete geometry type
|
89 |
* @param geometryType
|
90 |
* The geometry type. See the FShape class to see the types
|
91 |
* @return
|
92 |
* A set of operations
|
93 |
* @throws NotRegisteredOperationSetException
|
94 |
*/
|
95 |
public static GeometryOperationsSet getOperationSet(int geometryType) throws NotRegisteredOperationSetException{ |
96 |
Integer key = new Integer(geometryType); |
97 |
//If the operations set exists...
|
98 |
if (geometryOperations.containsKey(key)){
|
99 |
return (GeometryOperationsSet)geometryOperations.get(key);
|
100 |
} |
101 |
throw new NotRegisteredOperationSetException(geometryType); |
102 |
} |
103 |
|
104 |
/**
|
105 |
* Gets a concrete operation for a geometry type
|
106 |
* @param geometryType
|
107 |
* The geometry type code
|
108 |
* @param operationCode
|
109 |
* The operation code
|
110 |
* @return
|
111 |
* The GeometryOpration is exists
|
112 |
* @throws NotRegisteredOperationSetException
|
113 |
*/
|
114 |
public static GeometryOperation getOperation(int geometryType, int operationCode) throws NotRegisteredOperationSetException{ |
115 |
return getOperationSet(geometryType).getOperation(operationCode);
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* Sets the parameters for all the objects that implements the same
|
120 |
* operation
|
121 |
* @param parameters
|
122 |
* The parameters object
|
123 |
* @param operationCode
|
124 |
* The operation code
|
125 |
*/
|
126 |
public static void setParametersPropertiesForOperation(Map parameters, int operationCode){ |
127 |
Enumeration enumeration = geometryOperations.keys();
|
128 |
while (enumeration.hasMoreElements()){
|
129 |
GeometryOperationsSet operationsSet = |
130 |
(GeometryOperationsSet) geometryOperations.get(enumeration.nextElement()); |
131 |
GeometryOperation operation = operationsSet.getOperation(operationCode); |
132 |
if (operation != null){ |
133 |
operation.setParemeters(parameters); |
134 |
} |
135 |
} |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Gets a list of all the classes than implements a concrete
|
140 |
* operation
|
141 |
* @param operationCode
|
142 |
* The operation code
|
143 |
* @return
|
144 |
*/
|
145 |
public static ArrayList getOperationsByOperationCode(int operationCode){ |
146 |
ArrayList operations = new ArrayList(); |
147 |
Enumeration enumeration = geometryOperations.keys();
|
148 |
while (enumeration.hasMoreElements()){
|
149 |
GeometryOperationsSet operationsSet = |
150 |
(GeometryOperationsSet) geometryOperations.get(enumeration.nextElement()); |
151 |
GeometryOperation operation = operationsSet.getOperation(operationCode); |
152 |
if (operation != null){ |
153 |
operations.add(operation); |
154 |
} |
155 |
} |
156 |
return operations;
|
157 |
} |
158 |
} |