root / org.gvsig.xmlschema / library / trunk / org.gvsig.xmlschema / org.gvsig.xmlschema.prov / org.gvsig.xmlschema.prov.kxml / src / main / java / org / gvsig / xmlschema / prov / kxml / model / XSExtension.java @ 250
History | View | Annotate | Download (5.95 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.xmlschema.prov.kxml.model; |
23 |
|
24 |
import java.io.IOException; |
25 |
import java.util.ArrayList; |
26 |
import java.util.Collection; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
|
30 |
|
31 |
import org.gvsig.xmlpull.lib.api.stream.IQName; |
32 |
import org.gvsig.xmlpull.lib.api.stream.IXmlStreamReader; |
33 |
import org.gvsig.xmlschema.lib.api.som.IXSComplexContent; |
34 |
import org.gvsig.xmlschema.lib.api.som.IXSElement; |
35 |
import org.gvsig.xmlschema.lib.api.som.IXSElementDeclaration; |
36 |
import org.gvsig.xmlschema.lib.api.som.IXSExtension; |
37 |
import org.gvsig.xmlschema.lib.api.som.IXSGroup; |
38 |
import org.gvsig.xmlschema.lib.api.som.IXSRestriction; |
39 |
import org.gvsig.xmlschema.lib.api.som.IXSSchema; |
40 |
import org.gvsig.xmlschema.lib.api.som.IXSSimpleContent; |
41 |
import org.gvsig.xmlschema.lib.api.som.IXSTypeDefinition; |
42 |
import org.gvsig.xmlschema.lib.api.som.IXSContentType; |
43 |
import org.gvsig.xmlschema.lib.api.som.IXSComplexTypeDefinition; |
44 |
import org.gvsig.xmlschema.lib.api.utils.SchemaTags; |
45 |
|
46 |
|
47 |
/**
|
48 |
* @author gvSIG Team
|
49 |
* @version $Id$
|
50 |
*
|
51 |
*/
|
52 |
public class XSExtension extends AbstractXSComponent implements IXSExtension{ |
53 |
private IXSGroup group = null; |
54 |
private String baseType = null; |
55 |
private boolean isExtended = false; |
56 |
|
57 |
public XSExtension(XSSchema schema, IXmlStreamReader xmlStreamReader) throws IOException { |
58 |
super(schema);
|
59 |
this.schema = schema;
|
60 |
parse(xmlStreamReader); |
61 |
} |
62 |
|
63 |
//Comprueba que las etiquetas extension se abren y se cierran
|
64 |
private void parse(IXmlStreamReader xmlStreamReader) throws IOException |
65 |
{ |
66 |
int currentTag;
|
67 |
boolean end = false; |
68 |
|
69 |
//require(KXmlParser.START_TAG, null, SchemaTags.EXTENSION);
|
70 |
for (int i=0 ; i<xmlStreamReader.getAttributeCount() ; i++){ |
71 |
String attName = xmlStreamReader.getAttributeName(i).getLocalPart();
|
72 |
String attValue = xmlStreamReader.getAttributeValue(i);
|
73 |
if (SchemaTags.BASE.equals(attName)){
|
74 |
setBaseType(attValue); |
75 |
} |
76 |
} |
77 |
|
78 |
currentTag = xmlStreamReader.next(); |
79 |
while (!end)
|
80 |
{ |
81 |
switch(currentTag)
|
82 |
{ |
83 |
case IXmlStreamReader.START_ELEMENT:
|
84 |
if (SchemaTags.SEQUENCE.equals(xmlStreamReader.getName().getLocalPart())){
|
85 |
group = new XSSequence(schema, xmlStreamReader);
|
86 |
} |
87 |
break;
|
88 |
case IXmlStreamReader.END_ELEMENT:
|
89 |
if (SchemaTags.EXTENSION.equals(xmlStreamReader.getName().getLocalPart())){
|
90 |
end = true;
|
91 |
} |
92 |
break;
|
93 |
case IXmlStreamReader.CHARACTERS:
|
94 |
break;
|
95 |
} |
96 |
if (!end){
|
97 |
currentTag = xmlStreamReader.next(); |
98 |
} |
99 |
} |
100 |
} |
101 |
|
102 |
public short getNodeType() { |
103 |
// TODO Auto-generated method stub
|
104 |
return 0; |
105 |
} |
106 |
|
107 |
public String getNodeValue() { |
108 |
// TODO Auto-generated method stub
|
109 |
return null; |
110 |
} |
111 |
|
112 |
/**
|
113 |
* @param baseType the baseType to set
|
114 |
*/
|
115 |
private void setBaseType(String baseType) { |
116 |
this.baseType = baseType;
|
117 |
} |
118 |
|
119 |
public IXSGroup getGroup() {
|
120 |
if (!isExtended){
|
121 |
//Add the types from the base type
|
122 |
if (baseType != null){ |
123 |
IXSTypeDefinition typeDefinition = schema.getTypeByName(null, baseType);
|
124 |
if (typeDefinition != null){ |
125 |
if (typeDefinition instanceof IXSComplexTypeDefinition){ |
126 |
IXSComplexTypeDefinition complexTypeDefinition = (IXSComplexTypeDefinition)typeDefinition; |
127 |
addGroup(((IXSComplexTypeDefinition)typeDefinition).getGroup()); |
128 |
|
129 |
IXSContentType contentType = complexTypeDefinition.getContentType(); |
130 |
if (contentType instanceof IXSSimpleContent){ |
131 |
|
132 |
}else if (contentType instanceof IXSComplexContent){ |
133 |
IXSRestriction restriction = contentType.getRestriction(); |
134 |
if (restriction != null){ |
135 |
addGroup(restriction.getGroup()); |
136 |
} |
137 |
IXSExtension extension = contentType.getExtension(); |
138 |
if (extension != null){ |
139 |
addGroup(extension.getGroup()); |
140 |
} |
141 |
}else if (contentType instanceof IXSGroup){ |
142 |
addGroup((IXSGroup)contentType); |
143 |
} |
144 |
} |
145 |
} |
146 |
} |
147 |
isExtended = true;
|
148 |
} |
149 |
return group;
|
150 |
} |
151 |
|
152 |
private void addGroup(IXSGroup group){ |
153 |
if (group != null){ |
154 |
Iterator it = group.getItems().iterator();
|
155 |
while (it.hasNext()){
|
156 |
Object item = it.next();
|
157 |
this.group.addChildElement((XSElement)item);
|
158 |
} |
159 |
} |
160 |
} |
161 |
} |