Statistics
| Revision:

root / trunk / libraries / libGPE / src / org / gvsig / xmlschema / utils / SchemaObjectsMapping.java @ 12175

History | View | Annotate | Download (3.28 KB)

1
package org.gvsig.xmlschema.utils;
2

    
3
import java.util.Hashtable;
4
import java.util.Map;
5
import java.util.Set;
6

    
7
import org.gvsig.xmlschema.exceptions.TypeNotFoundException;
8
import org.gvsig.xmlschema.som.IXSNode;
9
import org.gvsig.xmlschema.som.IXSSchema;
10
import org.w3c.dom.Element;
11

    
12
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
13
 *
14
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
 *
30
 * For more information, contact:
31
 *
32
 *  Generalitat Valenciana
33
 *   Conselleria d'Infraestructures i Transport
34
 *   Av. Blasco Ib??ez, 50
35
 *   46010 VALENCIA
36
 *   SPAIN
37
 *
38
 *      +34 963862235
39
 *   gvsig@gva.es
40
 *      www.gvsig.gva.es
41
 *
42
 *    or
43
 *
44
 *   IVER T.I. S.A
45
 *   Salamanca 50
46
 *   46005 Valencia
47
 *   Spain
48
 *
49
 *   +34 963163400
50
 *   dac@iver.es
51
 */
52
/* CVS MESSAGES:
53
 *
54
 * $Id: SchemaObjectsMapping.java 12175 2007-06-14 16:15:05Z jorpiell $
55
 * $Log$
56
 * Revision 1.1  2007-06-14 16:15:03  jorpiell
57
 * builds to create the jars generated and add the schema code to the libGPEProject
58
 *
59
 * Revision 1.1  2007/06/14 13:50:07  jorpiell
60
 * The schema jar name has been changed
61
 *
62
 * Revision 1.1  2007/06/07 14:54:13  jorpiell
63
 * Add the schema support
64
 *
65
 * Revision 1.1  2007/05/30 12:25:48  jorpiell
66
 * Add the element collection
67
 *
68
 *
69
 */
70
/**
71
 * A mapping between a xml node name and a class that
72
 * implements it.
73
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
74
 */
75
public class SchemaObjectsMapping {
76
        private Map types = null;
77
        private IXSSchema schema = null;
78
        
79
        public SchemaObjectsMapping(IXSSchema schema) {
80
                super();
81
                this.schema = schema;
82
                types = new Hashtable();                
83
        }        
84
        
85
        /**
86
         * @return the supported types
87
         */
88
        public Set getTypes(){
89
                return types.keySet();
90
        }
91
        
92
        /**
93
         * Add a new type and creates the object that will be used to 
94
         * envolve the element
95
         * @param type
96
         * Type name that will be found in the XML file
97
         * @param clazz
98
         * Class used to create the object that envolves the element
99
         * @throws TypeNotFoundException
100
         */
101
        public void addType(String type, Class clazz) throws TypeNotFoundException{
102
                Class[] parameterTypes = {IXSSchema.class};
103
                Object[] initargs = {schema};
104
                IXSNode node = null;
105
                try {
106
                         node = (IXSNode)clazz.getConstructor(parameterTypes).newInstance(initargs);
107
                } catch (Exception e){
108
                        e.printStackTrace();
109
                        throw new TypeNotFoundException(clazz,e);
110
                }
111
                types.put(type, node);
112
        }
113
        
114
        /**
115
         * Returns the node
116
         * @param type
117
         * Type name
118
         * @return
119
         * A node with a element inside 
120
         */
121
        public IXSNode getNode(String type, Element element){
122
                Object obj = types.get(type);
123
                if (obj != null){
124
                        IXSNode node = (IXSNode)obj;
125
                        node.setElement(element);
126
                        return node;
127
                }
128
                return null;
129
        }
130
}