Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wfs / schema / XMLElementsFactory.java @ 33738

History | View | Annotate | Download (4.13 KB)

1
package org.gvsig.remoteclient.wfs.schema;
2

    
3
import java.io.IOException;
4
import java.util.Hashtable;
5
import java.util.Iterator;
6
import java.util.Map;
7
import java.util.Set;
8

    
9
import org.xmlpull.v1.XmlPullParserException;
10

    
11
import org.gvsig.remoteclient.wfs.schema.type.IXMLType;
12
import org.gvsig.remoteclient.wfs.schema.type.XMLComplexType;
13

    
14
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
15
 *
16
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
17
 *
18
 * This program is free software; you can redistribute it and/or
19
 * modify it under the terms of the GNU General Public License
20
 * as published by the Free Software Foundation; either version 2
21
 * of the License, or (at your option) any later version.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 * GNU General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU General Public License
29
 * along with this program; if not, write to the Free Software
30
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
31
 *
32
 * For more information, contact:
33
 *
34
 *  Generalitat Valenciana
35
 *   Conselleria d'Infraestructures i Transport
36
 *   Av. Blasco Ib??ez, 50
37
 *   46010 VALENCIA
38
 *   SPAIN
39
 *
40
 *      +34 963862235
41
 *   gvsig@gva.es
42
 *      www.gvsig.gva.es
43
 *
44
 *    or
45
 *
46
 *   IVER T.I. S.A
47
 *   Salamanca 50
48
 *   46005 Valencia
49
 *   Spain
50
 *
51
 *   +34 963163400
52
 *   dac@iver.es
53
 */
54
/* CVS MESSAGES:
55
 *
56
 * $Id: XMLElementsFactory.java 9451 2006-12-22 11:25:44Z csanchez $
57
 * $Log$
58
 * Revision 1.5  2006-12-22 11:25:44  csanchez
59
 * Nuevo parser GML 2.x para gml's sin esquema
60
 *
61
 * Revision 1.2  2006/10/10 12:52:28  jorpiell
62
 * Soporte para features complejas.
63
 *
64
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
65
 * Primer commit del driver de Gml
66
 *
67
 *
68
 */
69
/**
70
 * The XML "element" is an XML tag of a XSD schema and represent
71
 * a simple "element" or "object". One element has its name and 
72
 * the data type that contains (and the data)
73
 * 
74
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
75
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
76
 * 
77
 */
78
public class XMLElementsFactory {
79
        private static Hashtable elements = new Hashtable();
80
        
81
        public static XMLElement getElement(String name){
82
                if (name == null){
83
                        return null;
84
                }
85
                return (XMLElement)elements.get(name.toUpperCase());
86
        }
87
        
88
        /**
89
         * It parses the element and register it
90
         * @param schema
91
         * Schema parser that contains a "element"
92
         * @return
93
         */
94
        public static XMLElement addType(XMLSchemaParser schema){
95
                XMLElement element;
96
                try {
97
                        element = new XMLElement(schema);
98
                        if (element.getName() != null){
99
                                elements.put(element.getName().toUpperCase(),element);
100
                        }
101
                        return element;
102
                } catch (XmlPullParserException e) {
103
                        // TODO Auto-generated catch block
104
                        e.printStackTrace();
105
                } catch (IOException e) {
106
                        // TODO Auto-generated catch block
107
                        e.printStackTrace();
108
                }
109
                return null;
110
        }
111
        
112
        /**
113
         * Just for degug. It prints all the registred components.
114
         */
115
        public static void printEntities(){
116
                System.out.println("******* ELEMENTOS :");
117
                //metemos en un array los elementos de la tabla para mostrarlos
118
                Object[] keys = elements.keySet().toArray();
119
                for (int i=0 ; i<elements.size() ; i++){
120
                        XMLElement entity = (XMLElement)elements.get(keys[i]);
121
                        printEntity(entity,0);                        
122
                }
123
        }
124
        
125
        public static void printEntity(XMLElement entity,int level){
126
                String tab = "";
127
                for (int i=0 ; i<level ; i++){
128
                        tab = tab + "\t";
129
                }
130
                System.out.print(tab + "NAME: " + entity.getName());
131
                if (entity.getEntityType() != null){
132
                        System.out.print(" TYPE: " + entity.getEntityType().getName() + "\n");
133
                        if (entity.getEntityType().getType() == IXMLType.COMPLEX){
134
                                Map children = ((XMLComplexType)entity.getEntityType()).getSubtypes();
135
                                Set childrenKeys = children.keySet();
136
                                Iterator it = childrenKeys.iterator();
137
                                level++;
138
                                while(it.hasNext()){
139
                                        String child = (String)it.next();
140
                                        XMLElement eChild = (XMLElement)children.get(child);
141
                                        printEntity(eChild,level);        
142
                                }
143
                        }
144
                }else{
145
                        System.out.print(" TYPE: ERROR \n");
146
                }
147
                
148
        }
149
        
150
}