root / org.gvsig.legend.aggregate / trunk / org.gvsig.legend.aggregate / org.gvsig.legend.aggregate.lib / org.gvsig.legend.aggregate.lib.impl / src / main / java / org / gvsig / legend / aggregate / lib / impl / OperationPersistenceFactory.java @ 1848
History | View | Annotate | Download (2.97 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.legend.aggregate.lib.impl; |
25 |
|
26 |
import org.gvsig.legend.aggregate.lib.api.AggregateLegendLocator; |
27 |
import org.gvsig.legend.aggregate.lib.api.AggregateLegendManager; |
28 |
import org.gvsig.legend.aggregate.lib.api.Operation; |
29 |
|
30 |
import org.gvsig.tools.dynobject.DynStruct; |
31 |
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory; |
32 |
import org.gvsig.tools.persistence.PersistentState; |
33 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
34 |
|
35 |
public class OperationPersistenceFactory extends AbstractSinglePersistenceFactory { |
36 |
|
37 |
static final String FIELD_NAME = "name"; |
38 |
static final String FIELD_ATTRIBUTE = "attribute"; |
39 |
static final String FIELD_VALUE = "value"; |
40 |
|
41 |
private static final String DYNCLASS_NAME = "AggregateLegendOperation"; |
42 |
private static final String DYNCLASS_DESCRIPTION = "Operation for aggregate legend"; |
43 |
|
44 |
public OperationPersistenceFactory() {
|
45 |
super(Operation.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null, null); |
46 |
|
47 |
DynStruct definition = this.getDefinition();
|
48 |
|
49 |
definition.addDynFieldString(FIELD_NAME).setMandatory(true);
|
50 |
definition.addDynFieldString(FIELD_ATTRIBUTE).setMandatory(false);
|
51 |
definition.addDynFieldString(FIELD_VALUE).setMandatory(false);
|
52 |
} |
53 |
|
54 |
@Override
|
55 |
public Object createFromState(PersistentState state) |
56 |
throws PersistenceException {
|
57 |
AggregateLegendManager manager = AggregateLegendLocator.getAggregateLegendManager(); |
58 |
|
59 |
String name = (String) state.get(FIELD_NAME); |
60 |
Operation operation = manager.createOperation(name);
|
61 |
operation.setAttributeName(state.getString(FIELD_ATTRIBUTE)); |
62 |
operation.setAditionalValue(state.getString(FIELD_VALUE)); |
63 |
|
64 |
return operation;
|
65 |
} |
66 |
|
67 |
@Override
|
68 |
public void saveToState(PersistentState state, Object obj) |
69 |
throws PersistenceException {
|
70 |
|
71 |
Operation op = (Operation) obj; |
72 |
state.set(FIELD_NAME, op.getName()); |
73 |
state.set(FIELD_ATTRIBUTE, op.getAttributeName()); |
74 |
state.set(FIELD_VALUE, op.getAditionalValue()); |
75 |
} |
76 |
} |