Revision 11159 trunk/libraries/libGPE-GML/src-test/org/gvsig/gpe/xml/XSOMSchemaParserTest.java
XSOMSchemaParserTest.java | ||
---|---|---|
4 | 4 |
import java.io.IOException; |
5 | 5 |
import java.util.Iterator; |
6 | 6 |
|
7 |
import org.xml.sax.ErrorHandler; |
|
7 | 8 |
import org.xml.sax.SAXException; |
8 | 9 |
|
9 | 10 |
import com.sun.xml.xsom.XSElementDecl; |
10 | 11 |
import com.sun.xml.xsom.XSSchema; |
11 | 12 |
import com.sun.xml.xsom.XSSchemaSet; |
12 | 13 |
import com.sun.xml.xsom.XSType; |
14 |
import com.sun.xml.xsom.parser.AnnotationParser; |
|
15 |
import com.sun.xml.xsom.parser.AnnotationParserFactory; |
|
13 | 16 |
import com.sun.xml.xsom.parser.XSOMParser; |
17 |
import com.sun.xml.xsom.util.DomAnnotationParserFactory; |
|
14 | 18 |
|
15 | 19 |
import junit.framework.TestCase; |
16 | 20 |
|
... | ... | |
58 | 62 |
* |
59 | 63 |
* $Id$ |
60 | 64 |
* $Log$ |
61 |
* Revision 1.1 2007-04-11 11:16:42 jorpiell |
|
65 |
* Revision 1.2 2007-04-12 10:24:12 jorpiell |
|
66 |
* Add the GML and schema tests |
|
67 |
* |
|
68 |
* Revision 1.1 2007/04/11 11:16:42 jorpiell |
|
62 | 69 |
* A?adido el test del XSOM |
63 | 70 |
* |
64 | 71 |
* |
... | ... | |
67 | 74 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
68 | 75 |
*/ |
69 | 76 |
public class XSOMSchemaParserTest extends TestCase { |
70 |
private XSOMParser parser = null; |
|
71 |
|
|
72 |
protected void setUp(){ |
|
73 |
parser = new XSOMParser(); |
|
77 |
protected void setUp() throws SAXException, IOException{ |
|
78 |
XSOMParser parser = new XSOMParser(); |
|
79 |
parser.parse(new File("testdata/schemas/2_1_2/feature.xsd")); |
|
74 | 80 |
} |
75 | 81 |
|
76 | 82 |
public void testParseLocalidadSchema() throws SAXException, IOException { |
83 |
long t1 = System.currentTimeMillis(); |
|
84 |
XSOMParser parser = new XSOMParser(); |
|
77 | 85 |
parser.parse(new File("testdata/schemas/localidad.xsd")); |
78 |
assertElement("Localidad","localidad_Type"); |
|
86 |
long t2 = System.currentTimeMillis(); |
|
87 |
System.out.println(t2-t1); |
|
88 |
print(parser); |
|
89 |
assertElement(parser,"Localidad","localidad_Type"); |
|
90 |
printElement(parser,"Localidad"); |
|
79 | 91 |
} |
80 | 92 |
|
81 |
// public void testParseCityGMLSchema() throws SAXException, IOException{ |
|
82 |
// parser.parse(new File("testdata/schemas/CityGML.xsd")); |
|
83 |
// assertElement("CityModel", "CityModelType"); |
|
84 |
// } |
|
93 |
public void testParseCitySchema() throws SAXException, IOException { |
|
94 |
long t1 = System.currentTimeMillis(); |
|
95 |
XSOMParser parser = new XSOMParser(); |
|
96 |
AnnotationParser anParser = new DomAnnotationParserFactory().create(); |
|
97 |
//parser.setAnnotationParser(.getClass()); |
|
98 |
//parser.setErrorHandler(ErrorHandler) |
|
99 |
parser.parse(new File("testdata/schemas/CityGML.xsd")); |
|
100 |
long t2 = System.currentTimeMillis(); |
|
101 |
System.out.println(t2-t1); |
|
102 |
} |
|
85 | 103 |
|
104 |
|
|
105 |
public void printElement(XSOMParser parser,String elementName) throws SAXException{ |
|
106 |
Iterator itr = parser.getResult().iterateSchema(); |
|
107 |
while( itr.hasNext() ) { |
|
108 |
XSSchema s = (XSSchema)itr.next(); |
|
109 |
XSElementDecl element = s.getElementDecl(elementName); |
|
110 |
if (element != null){ |
|
111 |
System.out.println(element.getName()); |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
public void print(XSOMParser parser) throws SAXException{ |
|
117 |
Iterator itr = parser.getResult().iterateSchema(); |
|
118 |
while( itr.hasNext() ) { |
|
119 |
XSSchema s = (XSSchema)itr.next(); |
|
120 |
System.out.println("Target namespace: "+s.getTargetNamespace()); |
|
121 |
|
|
122 |
Iterator jtr = s.iterateElementDecls(); |
|
123 |
while( jtr.hasNext() ) { |
|
124 |
XSElementDecl e = (XSElementDecl)jtr.next(); |
|
125 |
|
|
126 |
System.out.print("ELEMENT:" + e.getName() ); |
|
127 |
if (e.getAnnotation() != null){ |
|
128 |
System.out.print(" ANOTATION: " + e.getAnnotation().getAnnotation()); |
|
129 |
} |
|
130 |
XSType type = e.getType(); |
|
131 |
if (type.getAnnotation() != null){ |
|
132 |
System.out.print(" ANOTATION TYPE: " + type.getAnnotation().getLocator().toString()); |
|
133 |
} |
|
134 |
if( e.isAbstract() ){ |
|
135 |
System.out.print(" (abstract)"); |
|
136 |
} |
|
137 |
System.out.println(); |
|
138 |
} |
|
139 |
} parser.getResult().iterateSchema(); |
|
140 |
while( itr.hasNext() ) { |
|
141 |
XSSchema s = (XSSchema)itr.next(); |
|
142 |
System.out.println("Target namespace: "+s.getTargetNamespace()); |
|
143 |
|
|
144 |
Iterator jtr = s.iterateElementDecls(); |
|
145 |
while( jtr.hasNext() ) { |
|
146 |
XSElementDecl e = (XSElementDecl)jtr.next(); |
|
147 |
|
|
148 |
System.out.print( e.getName() ); |
|
149 |
if( e.isAbstract() ) |
|
150 |
System.out.print(" (abstract)"); |
|
151 |
System.out.println(); |
|
152 |
} |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
86 | 156 |
/** |
87 | 157 |
* Gets a XSElement and try its type |
88 | 158 |
* @param elementName |
... | ... | |
91 | 161 |
* XSElement type |
92 | 162 |
* @throws SAXException |
93 | 163 |
*/ |
94 |
private void assertElement(String elementName,String elementType) throws SAXException{ |
|
95 |
XSElementDecl element = getElement(elementName); |
|
164 |
private void assertElement(XSOMParser parser,String elementName,String elementType) throws SAXException{
|
|
165 |
XSElementDecl element = getElement(parser,elementName);
|
|
96 | 166 |
assertEquals(element == null,false); |
97 | 167 |
assertEquals(element.getType().getName(),elementType); |
98 | 168 |
} |
... | ... | |
104 | 174 |
* @return |
105 | 175 |
* @throws SAXException |
106 | 176 |
*/ |
107 |
private XSElementDecl getElement(String elementName) throws SAXException{ |
|
177 |
private XSElementDecl getElement(XSOMParser parser,String elementName) throws SAXException{
|
|
108 | 178 |
Iterator itr = parser.getResult().iterateSchema(); |
109 | 179 |
while( itr.hasNext() ) { |
110 | 180 |
XSSchema s = (XSSchema)itr.next(); |
... | ... | |
112 | 182 |
if (element != null){ |
113 | 183 |
return element; |
114 | 184 |
} |
115 |
} |
|
185 |
}
|
|
116 | 186 |
return null; |
117 | 187 |
} |
118 | 188 |
} |
Also available in: Unified diff