Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wms / branches / org.gvsig.raster.wms_dataaccess_refactoring / org.gvsig.raster.wms.io / src / main / java / org / gvsig / raster / wms / io / RemoteWMSStyle.java @ 2378

History | View | Annotate | Download (5.64 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
        public void loadFromState(PersistentState state) throws PersistenceException {
34
                this.name = state.getString("name");
35
                this.title = state.getString("title");
36
                this.styleAbstract = state.getString("styleAbstract");
37
                this.format = state.getString("format");
38
                this.type = state.getString("type");
39
                this.href = state.getString("href");
40
                this.parent = (WMSLayerNode)state.get("parent");
41
                this.legendHeight = state.getInt("legendHeight");
42
                this.legendWidth = state.getInt("legendWidth");
43
        }
44

    
45
        public void saveToState(PersistentState state) throws PersistenceException {
46
                state.set("parent", parent);        
47
                state.set("name", name);        
48
                state.set("title", title);        
49
                state.set("styleAbstract", styleAbstract);        
50
                state.set("format", format);        
51
                state.set("type", type);        
52
                state.set("href", href);
53
                state.set("legendHeight", legendHeight);
54
                state.set("legendWidth", legendWidth);
55
        }        
56
    
57
    public static void registerPersistent() {
58
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
59
                DynStruct definition = manager.getDefinition("RemoteWMSStyle_Persistent");
60
                if( definition == null ) {
61
                        definition = manager.addDefinition(
62
                                        RemoteWMSStyle.class,
63
                                        "RemoteWMSStyle_Persistent",
64
                                        "RemoteWMSStyle Persistence",
65
                                        null, 
66
                                        null
67
                        );
68
                }
69

    
70
                definition.addDynFieldInt("legendHeight").setMandatory(false);
71
                definition.addDynFieldInt("legendWidth").setMandatory(false);
72
                definition.addDynFieldObject("parent").setClassOfValue(WMSLayerNode.class).setMandatory(false);
73
                definition.addDynFieldString("name").setMandatory(false);                
74
                definition.addDynFieldString("title").setMandatory(false);
75
                definition.addDynFieldString("styleAbstract").setMandatory(false);
76
                definition.addDynFieldString("format").setMandatory(false);
77
                definition.addDynFieldString("type").setMandatory(false);
78
                definition.addDynFieldString("href").setMandatory(false);
79
        }
80
    
81
    /*
82
         * Please! ensure that the fields are double, int, or Object
83
         * or otherwise add the corresponding entry in the clone() method.
84
         */
85

    
86
    /**
87
     * Creates a new instance of FMapWMSStyle
88
     * @param uri
89
     * @param title
90
     * @param styleAbstract
91
     * @param parent
92
     */
93
    public RemoteWMSStyle(WMSStyle style, WMSLayerNode parent){
94

    
95
        this.name = style.getName();
96
        this.title = style.getTitle();
97
        this.styleAbstract = style.getAbstract();
98
        this.legendWidth = style.getLegendURLWidth();
99
        this.legendHeight = style.getLegendURLHeight();
100
        this.format = style.getLegendURLFormat();
101
        this.href = style.getLegendURLOnlineResourceHRef();
102
        this.type = style.getLegendURLOnlineResourceType();
103
        this.parent = parent;
104
    }
105

    
106
    public RemoteWMSStyle() {
107
                // TODO Auto-generated constructor stub
108
        }
109

    
110
        public String toString(){
111
        return name;
112
    }
113

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

    
146
        public String getName() {
147
                return name;
148
        }
149

    
150
        public String getTitle() {
151
                return title;
152
        }
153

    
154
        public String getStyleAbstract() {
155
                return styleAbstract;
156
        }
157

    
158
        public String getFormat() {
159
                return format;
160
        }
161

    
162
        public String getType() {
163
                return type;
164
        }
165

    
166
        public String getHref() {
167
                return href;
168
        }
169

    
170
        public WMSLayerNode getParent() {
171
                return parent;
172
        }
173

    
174
        public int getLegendHeight() {
175
                return legendHeight;
176
        }
177

    
178
        public int getLegendWidth() {
179
                return legendWidth;
180
        }
181
        
182
        public void setParent(WMSLayerNode node) {
183
                this.parent = node;
184
        }
185
        
186
        public void setName(String name) {
187
                this.name = name;
188
        }
189

    
190
        public void setTitle(String title) {
191
                this.title = title;
192
        }
193

    
194
        public void setStyleAbstract(String sa) {
195
                this.styleAbstract = sa;
196
        }
197

    
198
        public void setType(String type) {
199
                this.type = type;
200
        }
201

    
202
        public void setHref(String href) {
203
                this.href = href;
204
        }
205

    
206
        public void setLegendHeight(int lHeight) {
207
                this.legendHeight = lHeight;
208
        }
209

    
210
        public void setLegendWidth(int lWidth) {
211
                this.legendWidth = lWidth;
212
        }
213
}