Revision 25361

View differences:

branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/DataParameters.java
27 27

  
28 28
package org.gvsig.fmap.dal;
29 29

  
30
import org.gvsig.tools.dynobject.DynObject;
30 31
import org.gvsig.tools.persistence.Persistent;
31 32

  
32 33
/**
33
 * This interface is a generic persistent parameter container. It is used in a variety 
34
 * of contexts in which a set of arbitrary parameters is needed.
34
 * This interface is a generic persistent parameter container. It is used in a
35
 * variety of contexts in which a set of arbitrary parameters is needed.
35 36
 */
36
public interface DataParameters extends Persistent {
37
public interface DataParameters extends Persistent, DynObject {
37 38

  
38 39
	/**
39
	 * Returns the value of an attribute given its name.
40
	 * 
41
	 * @param name 
42
	 * 			of the attribute
43
	 * @return value of the attribute
44
	 */
45
	public Object getAttribute(String name);
46

  
47
	/**
48
	 * Sets the value of an attribute
49
	 * 
50
	 * @param name of the attribute, if it exists it is overwritten, if it does not exist it 
51
	 * 			is added to the container.
52
	 * @param value attribute's value
53
	 * @return this
54
	 */
55
	public DataParameters setAttribute(String name, Object value);
56

  
57
	/**
58 40
	 * clears the parameter container.
59 41
	 */
60 42
	public void clear();
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/spi/AbstractDataParameters.java
1 1
package org.gvsig.fmap.dal.spi;
2 2

  
3
import java.util.HashMap;
4 3
import java.util.Iterator;
5
import java.util.Map;
6 4

  
7
import org.gvsig.fmap.dal.DataParameterDescriptor;
8 5
import org.gvsig.fmap.dal.DataParameters;
9 6
import org.gvsig.fmap.dal.exception.CopyParametersException;
7
import org.gvsig.tools.dynobject.DynClass;
8
import org.gvsig.tools.dynobject.DynField;
9
import org.gvsig.tools.dynobject.DynObject;
10 10
import org.gvsig.tools.persistence.AbstractPersistenceManager;
11 11
import org.gvsig.tools.persistence.PersistenceException;
12 12
import org.gvsig.tools.persistence.PersistenceValueNotFoundException;
......
48 48
 *
49 49
 */
50 50
public abstract class AbstractDataParameters implements DataParameters {
51
	private Map params;
52
	private Map alias;
51
	protected DynObject delegatedDynObjet;
53 52

  
54
	public class DefaultDataParameter implements DataParameterDescriptor {
55
		private int dataType;
56
		private String name;
57
		private Object defaultValue;
58

  
59
		private int availableValuesType;
60
		private Object[] availableValues;
61
		private Object minValue;
62
		private Object maxValue;
63
		Object value;
64
		private String description;
65

  
66
		DefaultDataParameter(String name, int dataType, String description,
67
				Object defaultValue) {
68
			this.name = name;
69
			this.description = description;
70
			this.dataType = dataType;
71
			this.defaultValue = defaultValue;
72
			this.availableValuesType = SINGLE;
73

  
74
			this.minValue = null;
75
			this.maxValue = null;
76
			this.availableValues = null;
77

  
78
			this.value = defaultValue;
79

  
80
		}
81

  
82
		DefaultDataParameter(String name, int dataType, String description,
83
				Object defaultValue, Object[] avaliableValues) {
84
			this.name = name;
85
			this.description = description;
86
			this.dataType = dataType;
87
			this.defaultValue = defaultValue;
88
			this.availableValuesType = CHOICE;
89
			this.availableValues = avaliableValues;
90
			this.minValue = null;
91
			this.maxValue = null;
92

  
93
			this.value = defaultValue;
94
		}
95

  
96
		DefaultDataParameter(String name, int dataType, String description,
97
				Object defaultValue, Object minValue, Object maxValue) {
98
			this.name = name;
99
			this.description = description;
100
			this.dataType = dataType;
101
			this.defaultValue = defaultValue;
102
			this.availableValuesType = RANGE;
103
			this.availableValues = null;
104
			this.minValue = minValue;
105
			this.maxValue = maxValue;
106

  
107
			this.value = defaultValue;
108
		}
109

  
110
		public Object[] getAvailableValues() {
111
			return this.availableValues;
112
		}
113

  
114
		public Object getDefaultValue() {
115
			return this.defaultValue;
116
		}
117

  
118
		public String getName() {
119
			return this.name;
120
		}
121

  
122
		public int getDataType() {
123
			return this.dataType;
124
		}
125

  
126
		void clear() {
127
			value = defaultValue;
128
		}
129

  
130
		Object getValue() {
131
			return value;
132
		}
133

  
134
		void setValue(Object value) {
135
			// FIXME: hacer comprobaciones de tipos.
136
			this.value = value;
137
		}
138

  
139
		public int getAvailableValuesType() {
140
			return this.availableValuesType;
141
		}
142

  
143
		public String getDescription() {
144
			return this.description;
145
		}
146

  
147
		public Object getMaxValue() {
148
			return this.maxValue;
149
		}
150

  
151
		public Object getMinValue() {
152
			return this.minValue;
153
		}
53
	public Object getDynValue(String name) {
54
		return this.delegatedDynObjet.getDynValue(name);
154 55
	}
155 56

  
156
	public AbstractDataParameters() {
157
		this.params = new HashMap();
158
		this.alias = new HashMap();
57
	public void setDynValue(String name, Object value) {
58
		this.delegatedDynObjet.setDynValue(name, value);
59
		// return this ???
159 60
	}
160 61

  
161
	protected DataParameterDescriptor addParameter(String name, int dataType,
162
			String description, Object defaultValue) {
163
		this.params.put(name.toLowerCase(), new DefaultDataParameter(name,
164
				dataType,
165
				description, defaultValue));
166
		return null;
167
	}
62
	public void clear() {
63
		// TODO Delegar en el DynObject cuando tenga este servicio
168 64

  
169
	protected DataParameterDescriptor addParameter(String name, int dataType,
170
			String description, Object defaultValue, Object[] avaliableValues) {
171
		this.params.put(name.toLowerCase(), new DefaultDataParameter(name,
172
				dataType,
173
				description,
174
				defaultValue, avaliableValues));
175
		return null;
176
	}
65
		DynField[] fields = delegatedDynObjet.getDynClass()
66
				.getDeclaredDynFields();
177 67

  
178
	protected DataParameterDescriptor addParameter(String name, int dataType,
179
			String description, Object defaultValue, Object minValue,
180
			Object maxValue) {
181
		this.params.put(name, new DefaultDataParameter(name, dataType,
182
				description, defaultValue, minValue, maxValue));
183
		return null;
184
	}
185

  
186
	public DataParameterDescriptor addAttributeAlias(String name, String alias) {
187
		Object param = this.params.get(name);
188
		if( param == null  ){
189
			return null ;
68
		for (int i = 0; i < fields.length; i++) {
69
			this.setDynValue(fields[i].getName(), fields[i].getDefaultValue());
190 70
		}
191
		this.alias.put(alias, param);
192
		return (DataParameterDescriptor) param;
193 71
	}
194 72

  
195
	public Object getAttribute(String name) {
196
		return ((DefaultDataParameter) this.params.get(name.toLowerCase()))
197
				.getValue();
198
	}
73
	protected void copyValuesTo(AbstractDataParameters target) {
74
		// TODO Delegar en el DynObject cuando tenga este servicio
75
		DynField[] fields = delegatedDynObjet.getDynClass()
76
				.getDeclaredDynFields();
199 77

  
200
	public DataParameters setAttribute(String name, Object value) {
201
		((DefaultDataParameter) this.params.get(name.toLowerCase()))
202
				.setValue(value);
203
		return this;
204
	}
205 78

  
206
	public void clear() {
207
		Iterator it = params.values().iterator();
208
		while (it.hasNext()) {
209
			((DefaultDataParameter) it.next()).clear();
79
		for (int i = 0; i < fields.length; i++) {
80
			target.setDynValue(fields[i].getName(), this.getDynValue(fields[i]
81
					.getName()));
210 82
		}
211 83
	}
212 84

  
213
	public Iterator getAttributes() {
214
		return params.values().iterator();
215
	}
216

  
217
	protected void copyValuesTo(AbstractDataParameters target) {
218
		Iterator it = params.values().iterator();
219
		while (it.hasNext()) {
220
			DefaultDataParameter p = ((DefaultDataParameter) it.next());
221
			target.setAttribute(p.getName(), p.getValue());
222
		}
223
	}
224

  
225 85
	public DataParameters getCopy() {
86
		// TODO Delegar en el DynObject cuando tenga este servicio
226 87
		AbstractDataParameters copy;
227 88
		try {
228 89
			copy = (AbstractDataParameters) this.getClass().newInstance();
......
240 101
	}
241 102

  
242 103
	public void loadState(PersistentState state) throws PersistenceException {
243
		Iterator it = params.values().iterator();
244
		while (it.hasNext()) {
245
			DefaultDataParameter p = ((DefaultDataParameter) it.next());
246
			state.set(p.getName(), p.getValue());
104
		DynField[] fields = delegatedDynObjet.getDynClass()
105
				.getDeclaredDynFields();
106

  
107
		for (int i = 0; i < fields.length; i++) {
108
			state.set(fields[i].getName(), this
109
					.getDynValue(fields[i].getName()));
247 110
		}
248 111
	}
249 112

  
......
252 115
		while (it.hasNext()) {
253 116
			String name = (String) it.next();
254 117
			try {
255
				this.setAttribute(name, state.get(name));
118
				this.setDynValue(name, state.get(name));
256 119
			} catch (PersistenceValueNotFoundException e) {
257 120
				// Ignore
258 121
			}
259 122
		}
260 123
	}
261 124

  
125
	public void delegate(DynObject[] dynObject) {
126
		this.delegatedDynObjet.delegate(dynObject);
127

  
128
	}
129

  
130
	public DynClass getDynClass() {
131
		return this.delegatedDynObjet.getDynClass();
132
	}
133

  
134
	public boolean hasDynValue(String name) {
135
		return this.delegatedDynObjet.hasDynValue(name);
136
	}
137

  
138
	public void implement(DynClass dynClass) {
139
		this.delegatedDynObjet.implement(dynClass);
140
	}
141

  
262 142
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStoreTransforms.java
120 120
	}
121 121

  
122 122
	public void setState(PersistentState state) throws PersistenceException {
123
		this.loadState(state);
123
		// TODO
124 124
	}
125 125

  
126 126
	public FeatureStore getFeatureStore() {

Also available in: Unified diff