Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.ogc / org.gvsig.raster.wmts.ogc.impl / src / main / java / org / gvsig / raster / wmts / ogc / impl / struct / WMTSThemesImpl.java @ 1808

History | View | Annotate | Download (3.44 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.wmts.ogc.impl.struct;
23

    
24
import java.io.IOException;
25
import java.util.ArrayList;
26

    
27
import org.gvsig.raster.wmts.ogc.impl.base.WMTSServerDescription;
28
import org.gvsig.raster.wmts.ogc.struct.WMTSThemes;
29
import org.kxml2.io.KXmlParser;
30
import org.xmlpull.v1.XmlPullParserException;
31

    
32
/**
33
 * Layer hierarchy
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 */
36
public abstract class WMTSThemesImpl extends ArrayList implements WMTSThemes {
37
        private static final long serialVersionUID = 1L;
38
        
39
    /**
40
     * Parses this service ID
41
     * @param parser
42
     * @param content
43
     * @throws IOException
44
     * @throws XmlPullParserException
45
     */
46
    public abstract void parse(KXmlParser parser) throws IOException, XmlPullParserException; 
47
    
48
        /**
49
         * Assign the layer associated
50
         * @param layers
51
         */
52
        public void calculateLayers(ArrayList layers) {
53
                for (int i = 0; i < size(); i++) {
54
                        ((WMTSTheme)get(i)).calculateLayers(layers);
55
                }
56
        }
57
        
58
        /**
59
         * Loads this list of themes with the layer information
60
         * @param layers
61
         */
62
        public void loadThemesWithLayerInfo(ArrayList layers, WMTSServerDescription status) {
63
                if(size() == 0) {
64
                        for (int i = 0; i < layers.size(); i++) {
65
                                WMTSTheme theme = (WMTSTheme)status.createVersionObject("WMTSTheme");
66
                                WMTSLayerImpl layer = (WMTSLayerImpl)layers.get(i);
67
                                theme.setTitle(layer.getTitle());
68
                                theme.setLayer(layer);
69
                                theme.setAbstract(layer.getAbstract());
70
                                add(theme);
71
                        }
72
                }
73
        }
74
        
75
        /**
76
         * Gets a node by its name
77
         * @param name
78
         * @return
79
         */
80
        public WMTSTheme getNodeByName(String name) {
81
                WMTSTheme result = null;
82
                
83
                for (int i = 0; i < size(); i++) {
84
                        WMTSTheme theme = ((WMTSTheme)get(i));
85
                        String title = theme.getTitle();
86
                        if(title.compareTo(name) == 0)
87
                                result = ((WMTSTheme)get(i));
88
                        else 
89
                                result = theme.getNodeByName(name);
90
                        if(result != null)
91
                                return result;
92
                }
93
                return null;
94
        }
95
        
96
        /**
97
         * Gets the number of nodes
98
         * @param parent
99
         * @return
100
         */
101
        public int getChildCount() {
102
                /*int acum = 0;
103
                for (int i = 0; i < size(); i++) {
104
                        acum += 1 + ((WMTSTheme)get(i)).getChildCount();
105
                }
106
                return acum;
107
                */
108
                return size();
109
        }
110
        
111
        /**
112
         * Gets the children of the index position
113
         * @param index
114
         * @return
115
         */
116
        public WMTSTheme getChildren(int index) {
117
                return (WMTSTheme)get(index);        
118
        }
119
        
120
        /**
121
         * Gets the index of a children
122
         * @param parent
123
         * @param child
124
         * @return
125
         */
126
        public int getIndexOfChild(WMTSTheme child) {
127
                for (int i = 0; i < size(); i++)
128
                        if (child == getChildren(i)) 
129
                                return i;
130
                return -1;
131
        }
132
        
133
        public String toString() {
134
                return "Base";
135
        }
136
}