1 17 package org.apache.geronimo.axis.builder; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.util.Collection ; 22 import java.util.ArrayList ; 23 import java.util.Map ; 24 import java.util.Iterator ; 25 import java.net.URI ; 26 import java.net.URISyntaxException ; 27 28 import junit.framework.TestCase; 29 import org.apache.xmlbeans.XmlObject; 30 import org.apache.xmlbeans.XmlOptions; 31 import org.apache.xmlbeans.SchemaTypeSystem; 32 import org.apache.xmlbeans.XmlBeans; 33 import org.apache.xmlbeans.XmlException; 34 import org.apache.xmlbeans.SchemaTypeLoader; 35 import org.apache.geronimo.schema.SchemaConversionUtils; 36 import org.apache.geronimo.common.DeploymentException; 37 38 41 public class ParsingTest extends TestCase { 42 private static final File basedir = new File (System.getProperty("basedir", System.getProperty("user.dir"))); 43 private SchemaInfoBuilder schemaInfoBuilder; 44 45 public void testSchema1() throws Exception { 46 File schema1 = new File (basedir, "src/test-resources/schema/schema1.xsd"); 47 System.out.println("SCHEMA 1"); 48 Map map = parse(schema1); 49 assertEquals(13, map.size()); 50 } 51 52 public void testSchema2() throws Exception { 53 File schema1 = new File (basedir, "src/test-resources/schema/schema2.xsd"); 54 System.out.println("SCHEMA 2"); 55 Map map = parse(schema1); 56 assertEquals(4, map.size()); 57 } 58 59 public void testSchema3() throws Exception { 60 File schema1 = new File (basedir, "src/test-resources/schema/schema3.xsd"); 61 System.out.println("SCHEMA 3"); 62 Map map = parse(schema1); 63 assertEquals(3, map.size()); 64 } 65 66 private Map parse(File schema1) throws IOException , XmlException, DeploymentException, URISyntaxException { 67 XmlObject xmlObject = SchemaConversionUtils.parse(schema1.toURL()); 68 Collection errors = new ArrayList (); 69 XmlOptions xmlOptions = new XmlOptions(); 70 xmlOptions.setErrorListener(errors); 71 XmlObject[] schemas = new XmlObject[] {xmlObject}; 72 SchemaTypeLoader schemaTypeLoader = XmlBeans.loadXsd(new XmlObject[] {}); 73 SchemaTypeSystem schemaTypeSystem; 74 try { 75 schemaTypeSystem = XmlBeans.compileXsd(schemas, schemaTypeLoader, xmlOptions); 76 if (errors.size() > 0) { 77 throw new DeploymentException("Could not compile schema type system: errors: " + errors); 78 } 79 } catch (XmlException e) { 80 throw new DeploymentException("Could not compile schema type system", e); 81 } 82 schemaInfoBuilder = new SchemaInfoBuilder(null, new URI (""), schemaTypeSystem); 83 Map map = schemaInfoBuilder.getSchemaTypeKeyToSchemaTypeMap(); 84 for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { 85 Map.Entry entry = (Map.Entry ) iterator.next(); 86 System.out.println(entry.getKey() + " --> " + entry.getValue()); 87 } 88 return map; 89 } 90 91 public void testElementToTypeMapping() throws Exception { 92 File schema1 = new File (basedir, "src/test-resources/schema/schema4.xsd"); 93 System.out.println("SCHEMA 4"); 94 Map map = parse(schema1); 95 assertEquals(3, map.size()); 96 Map elements = schemaInfoBuilder.getElementToTypeMap(); 97 System.out.println("ELEMENT MAP"); 98 System.out.println(elements); 99 assertEquals(1, elements.size()); 100 } 101 102 } 103 | Popular Tags |