Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / store / ParamImpl.java @ 1328

History | View | Annotate | Download (4.52 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
package org.gvsig.raster.impl.store;
23

    
24
import java.util.List;
25

    
26
import org.gvsig.fmap.dal.coverage.datastruct.Param;
27
import org.gvsig.raster.util.persistence.GenericPersistentObject;
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.dynobject.DynStruct;
30
import org.gvsig.tools.persistence.PersistenceManager;
31
import org.gvsig.tools.persistence.PersistentState;
32
import org.gvsig.tools.persistence.exception.PersistenceException;
33

    
34

    
35
/**
36
 * Generic parameter to store data for filters
37
 *
38
 * @version 17/04/2007
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 */
41
public class ParamImpl implements Param {
42
        private int      type         = -1;
43
        private String   id           = null;
44
        private Object   defaultValue = null;
45
        private String[] list         = null;
46

    
47
        /*
48
         * (non-Javadoc)
49
         * @see org.gvsig.fmap.dal.coverage.datastruct.Param#getType()
50
         */
51
        public int getType() {
52
                return type;
53
        }
54

    
55
        /*
56
         * (non-Javadoc)
57
         * @see org.gvsig.fmap.dal.coverage.datastruct.Param#setType(int)
58
         */
59
        public void setType(int type) {
60
                this.type = type;
61
        }
62

    
63
        /*
64
         * (non-Javadoc)
65
         * @see org.gvsig.fmap.dal.coverage.datastruct.Param#getId()
66
         */
67
        public String getId() {
68
                return id;
69
        }
70

    
71
        /*
72
         * (non-Javadoc)
73
         * @see org.gvsig.fmap.dal.coverage.datastruct.Param#setId(java.lang.String)
74
         */
75
        public void setId(String id) {
76
                this.id = id;
77
        }
78

    
79
        /*
80
         * (non-Javadoc)
81
         * @see org.gvsig.fmap.dal.coverage.datastruct.Param#getDefaultValue()
82
         */
83
        public Object getDefaultValue() {
84
                return defaultValue;
85
        }
86

    
87
        /*
88
         * (non-Javadoc)
89
         * @see org.gvsig.fmap.dal.coverage.datastruct.Param#setDefaultValue(java.lang.Object)
90
         */
91
        public void setDefaultValue(Object defaultValue) {
92
                this.defaultValue = defaultValue;
93
        }
94

    
95
        /*
96
         * (non-Javadoc)
97
         * @see org.gvsig.fmap.dal.coverage.datastruct.Param#getList()
98
         */
99
        public String[] getList() {
100
                return list;
101
        }
102

    
103
        /*
104
         * (non-Javadoc)
105
         * @see org.gvsig.fmap.dal.coverage.datastruct.Param#setList(java.lang.String[])
106
         */
107
        public void setList(String[] list) {
108
                this.list = list;
109
        }
110

    
111
        /*
112
         * (non-Javadoc)
113
         * @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
114
         */
115
        @SuppressWarnings("unchecked")
116
        public void loadFromState(PersistentState state)
117
        throws PersistenceException {
118

    
119
                this.type = state.getInt("type");
120
                this.id = state.getString("id");
121
                if(state.get("defaultValue") == null)
122
                        this.defaultValue = null;
123
                else
124
                        this.defaultValue = ((GenericPersistentObject)state.get("defaultValue")).getObject();
125
                List<String> list = state.getList("list");
126
                if(list != null) {
127
                        this.list = new String[list.size()];
128
                        for (int i = 0; i < list.size(); i++) {
129
                                this.list[i] = list.get(i);
130
                        }
131
                }
132
        }
133

    
134
        /*
135
         * (non-Javadoc)
136
         * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
137
         */
138
        public void saveToState(PersistentState state) throws PersistenceException {
139
                state.set("type", type);
140
                state.set("id", id);
141
                if(defaultValue != null)
142
                        state.set("defaultValue", GenericPersistentObject.create(defaultValue));
143
                else 
144
                        state.setNull("defaultValue");
145
                state.set("list", list);
146
        }        
147

    
148
        public static void registerPersistence() {
149
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
150

    
151
                DynStruct definition = manager.addDefinition(
152
                                ParamImpl.class,
153
                                "ParamImpl_Persistence",
154
                                "ParamImpl Persistence",
155
                                null, 
156
                                null
157
                );
158
                definition.addDynFieldInt("type").setMandatory(false);
159
                definition.addDynFieldString("id").setMandatory(false);
160
                definition.addDynFieldObject("defaultValue").setClassOfValue(GenericPersistentObject.class).setMandatory(false);
161
                definition.addDynFieldList("list").setClassOfItems(String.class).setMandatory(false);
162
        }
163
}