Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wms / trunk / org.gvsig.raster.wms / org.gvsig.raster.wms.io / src / main / java / org / gvsig / raster / wms / io / RemoteWMSStyle.java @ 883

History | View | Annotate | Download (5.91 KB)

1
package org.gvsig.raster.wms.io;
2

    
3
import java.lang.reflect.Field;
4

    
5
import org.gvsig.remoteclient.wms.WMSStyle;
6
import org.gvsig.tools.ToolsLocator;
7
import org.gvsig.tools.dynobject.DynStruct;
8
import org.gvsig.tools.persistence.PersistenceManager;
9
import org.gvsig.tools.persistence.Persistent;
10
import org.gvsig.tools.persistence.PersistentState;
11
import org.gvsig.tools.persistence.exception.PersistenceException;
12

    
13
/**
14
 * Just a C-struct-like class.
15
 * @author jaume
16
 *
17
 */
18
public class RemoteWMSStyle implements Persistent {
19
        /*
20
         * Please! ensure that the fields are double, int, or Object
21
         * or otherwise add the corresponding entry in the clone() method.
22
         */
23
    public String name;
24
    public String title;
25
    public String styleAbstract;
26
    public String format;
27
    public String type;
28
    public String href;
29
    public WMSLayerNode parent;
30
    public int legendHeight;
31
    public int legendWidth;
32
    
33
    /*
34
     * (non-Javadoc)
35
     * @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
36
     */
37
        public void loadFromState(PersistentState state) throws PersistenceException {
38
                this.name = state.getString("name");
39
                this.title = state.getString("title");
40
                this.styleAbstract = state.getString("styleAbstract");
41
                this.format = state.getString("format");
42
                this.type = state.getString("type");
43
                this.href = state.getString("href");
44
                this.parent = (WMSLayerNode)state.get("parent");
45
                this.legendHeight = state.getInt("legendHeight");
46
                this.legendWidth = state.getInt("legendWidth");
47
        }
48

    
49
        /*
50
         * (non-Javadoc)
51
         * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
52
         */
53
        public void saveToState(PersistentState state) throws PersistenceException {
54
                state.set("parent", parent);        
55
                state.set("name", name);        
56
                state.set("title", title);        
57
                state.set("styleAbstract", styleAbstract);        
58
                state.set("format", format);        
59
                state.set("type", type);        
60
                state.set("href", href);
61
                state.set("legendHeight", legendHeight);
62
                state.set("legendWidth", legendWidth);
63
        }        
64
    
65
    public static void registerPersistent() {
66
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
67
                DynStruct definition = manager.getDefinition("RemoteWMSStyle_Persistent");
68
                if( definition == null ) {
69
                        definition = manager.addDefinition(
70
                                        RemoteWMSStyle.class,
71
                                        "RemoteWMSStyle_Persistent",
72
                                        "RemoteWMSStyle Persistence",
73
                                        null, 
74
                                        null
75
                        );
76
                }
77

    
78
                definition.addDynFieldInt("legendHeight").setMandatory(false);
79
                definition.addDynFieldInt("legendWidth").setMandatory(false);
80
                definition.addDynFieldObject("parent").setClassOfValue(WMSLayerNode.class).setMandatory(false);
81
                definition.addDynFieldString("name").setMandatory(false);                
82
                definition.addDynFieldString("title").setMandatory(false);
83
                definition.addDynFieldString("styleAbstract").setMandatory(false);
84
                definition.addDynFieldString("format").setMandatory(false);
85
                definition.addDynFieldString("type").setMandatory(false);
86
                definition.addDynFieldString("href").setMandatory(false);
87
        }
88
    
89
    /*
90
         * Please! ensure that the fields are double, int, or Object
91
         * or otherwise add the corresponding entry in the clone() method.
92
         */
93

    
94
    /**
95
     * Creates a new instance of FMapWMSStyle
96
     * @param uri
97
     * @param title
98
     * @param styleAbstract
99
     * @param parent
100
     */
101
    public RemoteWMSStyle(WMSStyle style, WMSLayerNode parent){
102

    
103
        this.name = style.getName();
104
        this.title = style.getTitle();
105
        this.styleAbstract = style.getAbstract();
106
        this.legendWidth = style.getLegendURLWidth();
107
        this.legendHeight = style.getLegendURLHeight();
108
        this.format = style.getLegendURLFormat();
109
        this.href = style.getLegendURLOnlineResourceHRef();
110
        this.type = style.getLegendURLOnlineResourceType();
111
        this.parent = parent;
112
    }
113

    
114
    public RemoteWMSStyle() {
115
                // TODO Auto-generated constructor stub
116
        }
117

    
118
        public String toString(){
119
        return name;
120
    }
121

    
122
    public Object clone() throws CloneNotSupportedException {
123
            RemoteWMSStyle clone = new RemoteWMSStyle();
124
        Field[] fields = RemoteWMSStyle.class.getFields();
125
        for (int i = 0; i < fields.length; i++) {
126
                try {
127
                        Class<?> clazz = getClass();
128
                        String fieldName = fields[i].getName();
129
                        // int entry
130
                                if (fields[i].getType().equals(Integer.class)) {
131
                                        clazz.getField(fieldName).
132
                                        setInt(clone, clazz.getField(fieldName)
133
                                                                .getInt(this));
134
                                // double entry
135
                                } else if (fields[i].getType().equals(Double.class)) {
136
                                        clazz.getField(fieldName).
137
                                        setDouble(clone, clazz.getField(fieldName)
138
                                                        .getDouble(this));
139
                                // any object entry
140
                                } else {
141
                                        clazz.getField(fieldName).
142
                                        set(clone, clazz.getField(fieldName)
143
                                                        .get(this));
144
                                }
145
                        } catch (Exception e) {
146
                                throw new CloneNotSupportedException("Reflect error when cloning " +
147
                                                "'"+fields[i].getName()+"' field " +
148
                                                "(FMapWMSStyle)");
149
                        }
150
                }
151
        return clone;
152
    }
153

    
154
        public String getName() {
155
                return name;
156
        }
157

    
158
        public String getTitle() {
159
                return title;
160
        }
161

    
162
        public String getStyleAbstract() {
163
                return styleAbstract;
164
        }
165

    
166
        public String getFormat() {
167
                return format;
168
        }
169

    
170
        public String getType() {
171
                return type;
172
        }
173

    
174
        public String getHref() {
175
                return href;
176
        }
177

    
178
        public WMSLayerNode getParent() {
179
                return parent;
180
        }
181

    
182
        public int getLegendHeight() {
183
                return legendHeight;
184
        }
185

    
186
        public int getLegendWidth() {
187
                return legendWidth;
188
        }
189
        
190
        public void setParent(WMSLayerNode node) {
191
                this.parent = node;
192
        }
193
        
194
        public void setName(String name) {
195
                this.name = name;
196
        }
197

    
198
        public void setTitle(String title) {
199
                this.title = title;
200
        }
201

    
202
        public void setStyleAbstract(String sa) {
203
                this.styleAbstract = sa;
204
        }
205

    
206
        public void setType(String type) {
207
                this.type = type;
208
        }
209

    
210
        public void setHref(String href) {
211
                this.href = href;
212
        }
213

    
214
        public void setLegendHeight(int lHeight) {
215
                this.legendHeight = lHeight;
216
        }
217

    
218
        public void setLegendWidth(int lWidth) {
219
                this.legendWidth = lWidth;
220
        }
221
}