Revision 11159

View differences:

trunk/libraries/libGPE-GML/src-test/org/gvsig/gpe/gml/readers/GMLReaderBaseTest.java
1
package org.gvsig.gpe.gml.readers;
2

  
3
import java.io.File;
4

  
5
import junit.framework.TestCase;
6

  
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
/* CVS MESSAGES:
48
 *
49
 * $Id$
50
 * $Log$
51
 * Revision 1.1  2007-04-12 10:24:12  jorpiell
52
 * Add the GML and schema tests
53
 *
54
 *
55
 */
56
/**
57
 * All the GML tests must inherit this class. 
58
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
59
 */
60
public abstract class GMLReaderBaseTest extends TestCase {
61

  
62
	public void testParseFile(){
63
		File file = new File(getFile());
64

  
65
	}
66
	
67
	/**
68
	 * Gets the GML file to open
69
	 * @return
70
	 */
71
	public abstract String getFile();
72
	
73
	/**
74
	 * Return the numbre of features
75
	 * @return
76
	 */
77
	public abstract int getNumFeatures();
78
		
79
	/**
80
	 * Return if the GML has a schema
81
	 * @return
82
	 */
83
	public abstract boolean hasSchema();
84
	
85
	/**
86
	 * Compare the feature number i
87
	 * @param i
88
	 */
89
	public abstract void compareFeature(int i);
90
}
0 91

  
trunk/libraries/libGPE-GML/src-test/org/gvsig/gpe/xml/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