Statistics
| Revision:

root / branches / Mobile1.0 / org.gvsig.gpe / src / org / gvsig / xmlschema / som / impl / XSComplexTypeDefinitionImpl.java @ 79

History | View | Annotate | Download (5.22 KB)

1
package org.gvsig.xmlschema.som.impl;
2

    
3
import org.gvsig.xmlschema.som.IXSComplexTypeDefinition;
4
import org.gvsig.xmlschema.som.IXSContentType;
5
import org.gvsig.xmlschema.som.IXSElementDeclaration;
6
import org.gvsig.xmlschema.som.IXSGroup;
7
import org.gvsig.xmlschema.som.IXSNode;
8
import org.gvsig.xmlschema.som.IXSSchema;
9
import org.gvsig.xmlschema.utils.SchemaCollection;
10
import org.gvsig.xmlschema.utils.SchemaDefaults;
11
import org.gvsig.xmlschema.utils.SchemaObjectsMapping;
12
import org.gvsig.xmlschema.utils.SchemaTags;
13
import org.w3c.dom.Element;
14

    
15
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
16
 *
17
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
18
 *
19
 * This program is free software; you can redistribute it and/or
20
 * modify it under the terms of the GNU General Public License
21
 * as published by the Free Software Foundation; either version 2
22
 * of the License, or (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU General Public License
30
 * along with this program; if not, write to the Free Software
31
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
32
 *
33
 * For more information, contact:
34
 *
35
 *  Generalitat Valenciana
36
 *   Conselleria d'Infraestructures i Transport
37
 *   Av. Blasco Ib??ez, 50
38
 *   46010 VALENCIA
39
 *   SPAIN
40
 *
41
 *      +34 963862235
42
 *   gvsig@gva.es
43
 *      www.gvsig.gva.es
44
 *
45
 *    or
46
 *
47
 *   IVER T.I. S.A
48
 *   Salamanca 50
49
 *   46005 Valencia
50
 *   Spain
51
 *
52
 *   +34 963163400
53
 *   dac@iver.es
54
 */
55
/* CVS MESSAGES:
56
 *
57
 * $Id: XSComplexTypeDefinitionImpl.java 157 2007-06-22 12:22:53Z jorpiell $
58
 * $Log$
59
 * Revision 1.2  2007/06/22 12:20:48  jorpiell
60
 * The typeNotFoundException has been deleted. It never was thrown
61
 *
62
 * Revision 1.1  2007/06/14 16:15:03  jorpiell
63
 * builds to create the jars generated and add the schema code to the libGPEProject
64
 *
65
 * Revision 1.1  2007/06/14 13:50:07  jorpiell
66
 * The schema jar name has been changed
67
 *
68
 * Revision 1.4  2007/06/08 11:35:16  jorpiell
69
 * IXSSchema interface updated
70
 *
71
 * Revision 1.3  2007/06/07 14:54:13  jorpiell
72
 * Add the schema support
73
 *
74
 * Revision 1.2  2007/05/30 12:25:48  jorpiell
75
 * Add the element collection
76
 *
77
 * Revision 1.1  2007/05/25 11:55:00  jorpiell
78
 * First update
79
 *
80
 *
81
 */
82
/**
83
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
84
 */
85
public class XSComplexTypeDefinitionImpl extends XSTypeDefinitionImpl implements IXSComplexTypeDefinition {
86
                        
87
        public XSComplexTypeDefinitionImpl(IXSSchema schema) {
88
                super(schema);
89
        }
90
        /*
91
         * (non-Javadoc)
92
         * @see org.gvsig.gpe.schema.som.IXSComplexTypeDefinition#getContentType()
93
         */
94
        public IXSContentType getContentType(){
95
                IXSNode node = new SchemaCollection(getSchema(),getElement(),getContentMapping()).getFirstNode();
96
                if (node != null){
97
                        return (IXSContentType)node;
98
                }
99
                return null;
100
        }
101

    
102
        /**
103
         * @return The extension mapping
104
         * @throws TypeNotFoundException
105
         */
106
        private SchemaObjectsMapping getContentMapping(){
107
                SchemaObjectsMapping elementTm = new SchemaObjectsMapping(getSchema());
108
                elementTm.addType(SchemaTags.COMPLEX_CONTENT, XSComplexContentImpl.class);
109
                elementTm.addType(SchemaTags.SIMPLE_CONTENT, XSComplexContentImpl.class);
110
                return elementTm;
111
        }
112
        
113
        /*
114
         * (non-Javadoc)
115
         * @see org.gvsig.gpe.schema.som.IXSComplexTypeDefinition#getGroup()
116
         */
117
        public IXSGroup getGroup(){
118
                IXSNode node = new SchemaCollection(getSchema(),getElement(),getGroupMapping()).getFirstNode();
119
                if (node != null){
120
                        return (IXSGroup)node;
121
                }
122
                return null;
123
        }
124
        
125
        /**
126
         * @return The extension mapping
127
         * @throws TypeNotFoundException
128
         */
129
        private SchemaObjectsMapping getGroupMapping(){
130
                SchemaObjectsMapping elementTm = new SchemaObjectsMapping(getSchema());
131
                elementTm.addType(SchemaTags.SEQUENCE, XSSequenceImpl.class);
132
                elementTm.addType(SchemaTags.ALL, XSAllImpl.class);
133
                elementTm.addType(SchemaTags.GROUP, XSGroupImpl.class);
134
                elementTm.addType(SchemaTags.CHOICE, XSChoiceImpl.class);
135
                return elementTm;
136
        }
137
        
138
        /**
139
         * Adds a new element to the complex type
140
         */
141
        public IXSElementDeclaration addElement(String name, String typeName, boolean nillable, int minOccurs, int maxOccurs){
142
                Element eElement = getElementsFactory().createElement(getSchema(),
143
                                name,
144
                                typeName,
145
                                nillable,
146
                                minOccurs,
147
                                maxOccurs);
148
                getElementsFactory().addElementToComplexType(
149
                                getSchema(),
150
                                eElement, 
151
                                getElement());        
152
                XSElementDeclarationImpl elementDeclaration = new XSElementDeclarationImpl(getSchema());
153
                elementDeclaration.setElement(eElement);
154
                return elementDeclaration;
155
        }
156
        
157
        /*
158
         * (non-Javadoc)
159
         * @see org.gvsig.gpe.schema.som.IXSComplexTypeDefinition#addElement(java.lang.String, java.lang.String)
160
         */
161
        public IXSElementDeclaration addElement(String name, String typeName) {
162
                return addElement(name, typeName, SchemaDefaults.ELEMENT_NILLABLE,
163
                                SchemaDefaults.ELEMENT_MIN_OCCURS, SchemaDefaults.ELEMENT_MAX_OCCURS);
164
        }
165

    
166
        /*
167
         * (non-Javadoc)
168
         * @see org.gvsig.gpe.schema.som.IXSTypeDefinition#getTypeName()
169
         */
170
        public String getTypeName() {
171
                return getElement().getAttribute(SchemaTags.NAME);                
172
        }
173

    
174
}