root / trunk / libraries / libGPE / src / org / gvsig / xmlschema / som / impl / XSElementDeclarationImpl.java @ 12175
History | View | Annotate | Download (6.63 KB)
1 |
package org.gvsig.xmlschema.som.impl; |
---|---|
2 |
|
3 |
import java.util.Iterator; |
4 |
|
5 |
import org.gvsig.xmlschema.exceptions.TypeNotFoundException; |
6 |
import org.gvsig.xmlschema.som.IXSComplexTypeDefinition; |
7 |
import org.gvsig.xmlschema.som.IXSElementDeclaration; |
8 |
import org.gvsig.xmlschema.som.IXSSchema; |
9 |
import org.gvsig.xmlschema.som.IXSTypeDefinition; |
10 |
import org.gvsig.xmlschema.utils.SchemaCollection; |
11 |
import org.gvsig.xmlschema.utils.SchemaTags; |
12 |
import org.gvsig.xmlschema.utils.SchemaUtils; |
13 |
import org.w3c.dom.Element; |
14 |
import org.w3c.dom.Node; |
15 |
import org.w3c.dom.NodeList; |
16 |
|
17 |
|
18 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
19 |
*
|
20 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
21 |
*
|
22 |
* This program is free software; you can redistribute it and/or
|
23 |
* modify it under the terms of the GNU General Public License
|
24 |
* as published by the Free Software Foundation; either version 2
|
25 |
* of the License, or (at your option) any later version.
|
26 |
*
|
27 |
* This program is distributed in the hope that it will be useful,
|
28 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
29 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
30 |
* GNU General Public License for more details.
|
31 |
*
|
32 |
* You should have received a copy of the GNU General Public License
|
33 |
* along with this program; if not, write to the Free Software
|
34 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
35 |
*
|
36 |
* For more information, contact:
|
37 |
*
|
38 |
* Generalitat Valenciana
|
39 |
* Conselleria d'Infraestructures i Transport
|
40 |
* Av. Blasco Ib??ez, 50
|
41 |
* 46010 VALENCIA
|
42 |
* SPAIN
|
43 |
*
|
44 |
* +34 963862235
|
45 |
* gvsig@gva.es
|
46 |
* www.gvsig.gva.es
|
47 |
*
|
48 |
* or
|
49 |
*
|
50 |
* IVER T.I. S.A
|
51 |
* Salamanca 50
|
52 |
* 46005 Valencia
|
53 |
* Spain
|
54 |
*
|
55 |
* +34 963163400
|
56 |
* dac@iver.es
|
57 |
*/
|
58 |
/* CVS MESSAGES:
|
59 |
*
|
60 |
* $Id: XSElementDeclarationImpl.java 12175 2007-06-14 16:15:05Z jorpiell $
|
61 |
* $Log$
|
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 XSElementDeclarationImpl extends XSComponentImpl implements IXSElementDeclaration{ |
86 |
|
87 |
public XSElementDeclarationImpl(IXSSchema schema) {
|
88 |
super(schema);
|
89 |
} |
90 |
|
91 |
/**
|
92 |
* @return The element type
|
93 |
* @throws TypeNotFoundException
|
94 |
*/
|
95 |
public IXSTypeDefinition getTypeDefinition() throws TypeNotFoundException{ |
96 |
//If is defined in the same node
|
97 |
Iterator it = new SchemaCollection(getSchema(),getElement()).iterator(); |
98 |
it.hasNext(); |
99 |
Object type = it.next();
|
100 |
//If is defined in the same schema
|
101 |
if (type == null){ |
102 |
type = getSchema().getTypeByName(getQName().getNamespaceURI(), |
103 |
getElement().getAttribute(SchemaTags.TYPE)); |
104 |
} |
105 |
if (type != null){ |
106 |
return (IXSTypeDefinition)type;
|
107 |
} |
108 |
return null; |
109 |
} |
110 |
|
111 |
|
112 |
|
113 |
/*
|
114 |
* (non-Javadoc)
|
115 |
* @see org.gvsig.gpe.schema.som.IXSElementDeclaration#getTypeName()
|
116 |
*/
|
117 |
public String getTypeName() { |
118 |
return getElement().getAttribute(SchemaTags.TYPE);
|
119 |
} |
120 |
|
121 |
/*
|
122 |
* (non-Javadoc)
|
123 |
* @see org.gvsig.gpe.schema.som.IXSElementDeclaration#isNillable()
|
124 |
*/
|
125 |
public boolean isNillable() { |
126 |
String nillable = getElement().getAttribute(SchemaTags.NILLABLE);
|
127 |
if (nillable != null){ |
128 |
if (nillable.compareTo(SchemaTags.FALSE) == 0){ |
129 |
return false; |
130 |
} |
131 |
} |
132 |
return true; |
133 |
} |
134 |
|
135 |
/*
|
136 |
* (non-Javadoc)
|
137 |
* @see org.gvsig.gpe.schema.som.IXSElementDeclaration#getMaxOccurs()
|
138 |
*/
|
139 |
public int getMaxOccurs() { |
140 |
String maxOccurs = getElement().getAttribute(SchemaTags.MAX_OCCURS);
|
141 |
if (maxOccurs != null){ |
142 |
return Integer.parseInt(maxOccurs); |
143 |
} |
144 |
return 0; |
145 |
} |
146 |
|
147 |
/*
|
148 |
* (non-Javadoc)
|
149 |
* @see org.gvsig.gpe.schema.som.IXSElementDeclaration#getMinOccurs()
|
150 |
*/
|
151 |
public int getMinOccurs() { |
152 |
String minOccurs = getElement().getAttribute(SchemaTags.MIN_OCCURS);
|
153 |
if (minOccurs != null){ |
154 |
return Integer.parseInt(minOccurs); |
155 |
} |
156 |
return 0; |
157 |
} |
158 |
|
159 |
public IXSElementDeclaration getSubElementByName(String nodeName) { |
160 |
try {
|
161 |
if (getTypeDefinition() == null){ |
162 |
return null; |
163 |
} |
164 |
Element element = getTypeDefinition().getElement();
|
165 |
nodeName = nodeName.substring(nodeName.indexOf(":")+1,nodeName.length()); |
166 |
Element newElement = searchNode(element, nodeName);
|
167 |
if (newElement != null){ |
168 |
XSElementDeclarationImpl childElement = new XSElementDeclarationImpl(getSchema());
|
169 |
childElement.setElement(newElement); |
170 |
return childElement;
|
171 |
} |
172 |
} catch (TypeNotFoundException e) {
|
173 |
// TODO Auto-generated catch block
|
174 |
e.printStackTrace(); |
175 |
} |
176 |
return null; |
177 |
} |
178 |
|
179 |
private Element searchNode(Element element, String nodeName){ |
180 |
NodeList nodeList = element.getChildNodes(); |
181 |
for (int i=0 ; i<nodeList.getLength() ; i++){ |
182 |
Node node = nodeList.item(i); |
183 |
if(node.getNodeType() == Node.ELEMENT_NODE){
|
184 |
Element childElement = (Element)node; |
185 |
if (SchemaUtils.matches(node, SchemaTags.XS_NS, SchemaTags.COMPLEX_CONTENT)){
|
186 |
return searchNode(childElement, nodeName);
|
187 |
}else if (SchemaUtils.matches(node, SchemaTags.XS_NS, SchemaTags.EXTENSION)){ |
188 |
return searchNode(childElement, nodeName);
|
189 |
}else if (SchemaUtils.matches(node, SchemaTags.XS_NS, SchemaTags.RESTRICTION)){ |
190 |
return searchNode(childElement, nodeName);
|
191 |
}else if (SchemaUtils.matches(node, SchemaTags.XS_NS, SchemaTags.SEQUENCE)){ |
192 |
return searchNode(childElement, nodeName);
|
193 |
}else if (SchemaUtils.matches(node, SchemaTags.XS_NS, SchemaTags.ALL)){ |
194 |
return searchNode(childElement, nodeName);
|
195 |
}else if (SchemaUtils.matches(node, SchemaTags.XS_NS, SchemaTags.CHOICE)){ |
196 |
return searchNode(childElement, nodeName);
|
197 |
}else if (SchemaUtils.matches(node, SchemaTags.XS_NS, SchemaTags.GROUP)){ |
198 |
return searchNode(childElement, nodeName);
|
199 |
} |
200 |
if (childElement.getAttribute(SchemaTags.NAME).compareTo(nodeName) == 0){ |
201 |
return childElement;
|
202 |
} |
203 |
} |
204 |
} |
205 |
return null; |
206 |
} |
207 |
|
208 |
/*
|
209 |
* (non-Javadoc)
|
210 |
* @see org.gvsig.gpe.schema.som.IXSElementDeclaration#addComplexType(java.lang.String, java.lang.String, java.lang.String)
|
211 |
*/
|
212 |
public IXSComplexTypeDefinition addComplexType(String type, |
213 |
String contentType, String contentTypeRestriction) { |
214 |
Element eComplexType = getElementsFactory().createComplexType(
|
215 |
getSchema(), |
216 |
null,
|
217 |
type, |
218 |
contentType, |
219 |
contentTypeRestriction); |
220 |
addChildElement(eComplexType); |
221 |
XSComplexTypeDefinitionImpl complexType = new XSComplexTypeDefinitionImpl(getSchema());
|
222 |
complexType.setElement(eComplexType); |
223 |
return complexType;
|
224 |
} |
225 |
|
226 |
} |