EmfAppSchemaReader extends EmfComplexFeatureReader { public static EmfAppSchemaReader newInstance() { return new EmfAppSchemaReader(); } private  EmfAppSchemaReader(); static EmfAppSchemaReader newInstance(); static Configuration findGmlConfiguration(AppSchemaConfiguration configuration);  }
@Test public void testParseSimpleFeatureType() throws Exception { String res = "/test-data/simpleFeature.xsd"; URL resource = getClass().getResource(res); SchemaIndex schemaIndex = EmfAppSchemaReader.newInstance().parse(resource); AppSchemaFeatureTypeRegistry parsedTypes = new AppSchemaFeatureTypeRegistry(); try { parsedTypes.addSchemas(schemaIndex); Name typeName = Types.typeName(NS_URI, "simpleFeatureType"); AttributeType type = parsedTypes.getAttributeType(typeName); Assert.assertNotNull(type); Assert.assertTrue(type.getClass().getName(), type instanceof ComplexType); Assert.assertTrue(type.getUserData().get(XSDTypeDefinition.class) instanceof XSDComplexTypeDefinition); ComplexType ft = (ComplexType) type; String local = ft.getName().getLocalPart(); String uri = ft.getName().getNamespaceURI(); Assert.assertEquals("simpleFeatureType", local); Assert.assertEquals(NS_URI, uri); List<PropertyDescriptor> attributes = Arrays.asList(((ComplexFeatureTypeImpl) ft) .getTypeDescriptors().toArray(new PropertyDescriptor[0])); Assert.assertEquals(8, attributes.size()); AttributeDescriptor descriptor; descriptor = (AttributeDescriptor) attributes.get(5); Name name = Types.typeName(NS_URI, "the_geom"); typeName = Types.typeName(GML.NAMESPACE, "GeometryPropertyType"); assertSimpleAttribute(descriptor, name, typeName, Geometry.class, 1, 1); descriptor = (AttributeDescriptor) attributes.get(6); name = Types.typeName(NS_URI, "stringAtt"); typeName = Types.typeName(XS.NAMESPACE, XS.STRING.getLocalPart()); assertSimpleAttribute(descriptor, name, typeName, String.class, 1, 1); descriptor = (AttributeDescriptor) attributes.get(7); name = Types.typeName(NS_URI, "intAtt"); typeName = Types.typeName(XS.NAMESPACE, XS.INT.getLocalPart()); assertSimpleAttribute(descriptor, name, typeName, Integer.class, 1, 1); } finally { parsedTypes.disposeSchemaIndexes(); } }
@Test public void testComplexFeatureType() throws Exception { String res = "/test-data/complexFeature.xsd"; URL resource = getClass().getResource(res); SchemaIndex schemaIndex = EmfAppSchemaReader.newInstance().parse(resource); AppSchemaFeatureTypeRegistry typeRegistry = new AppSchemaFeatureTypeRegistry(); try { typeRegistry.addSchemas(schemaIndex); Name typeName = Types.typeName(NS_URI, "wq_plus_Type"); AttributeType type = (AttributeType) typeRegistry.getAttributeType(typeName); Assert.assertTrue(type instanceof FeatureType); Assert.assertFalse(type instanceof SimpleFeatureType); Assert.assertEquals(typeName, type.getName()); Assert.assertTrue(type.getUserData().get(XSDTypeDefinition.class) instanceof XSDComplexTypeDefinition); FeatureType wq_plus_Type = (FeatureType) type; Assert.assertNotNull(wq_plus_Type.getSuper()); typeName = Types.typeName(GML.NAMESPACE, GML.AbstractFeatureType.getLocalPart()); Assert.assertEquals(typeName, wq_plus_Type.getSuper().getName()); Assert.assertNotNull(wq_plus_Type.getDescriptors()); Assert.assertEquals(8, ((ComplexFeatureTypeImpl) wq_plus_Type).getTypeDescriptors().size()); Name name = Types.typeName(NS_URI, "wq_plus"); AttributeDescriptor wqPlusDescriptor = typeRegistry.getDescriptor(name, null); Assert.assertNotNull(wqPlusDescriptor); Assert.assertEquals(name, wqPlusDescriptor.getName()); Assert.assertSame(wq_plus_Type, wqPlusDescriptor.getType()); Assert.assertTrue(wqPlusDescriptor.getUserData().get(XSDElementDeclaration.class) instanceof XSDElementDeclaration); typeName = Types.typeName(NS_URI, "measurementType"); type = typeRegistry.getAttributeType(typeName); Assert.assertTrue(type instanceof ComplexType); Assert.assertFalse(type instanceof FeatureType); Assert.assertTrue(type.getUserData().get(XSDTypeDefinition.class) instanceof XSDComplexTypeDefinition); ComplexType measurementType = (ComplexType) type; Assert.assertEquals(typeName, measurementType.getName()); Assert.assertTrue(measurementType.isIdentified()); Assert.assertFalse(measurementType.isAbstract()); Assert.assertEquals(2, measurementType.getDescriptors().size()); name = Types.typeName(NS_URI, "measurement"); AttributeDescriptor descriptor; descriptor = (AttributeDescriptor) Types.descriptor(wq_plus_Type, name); Assert.assertNotNull(descriptor); Assert.assertEquals(name, descriptor.getName()); Assert.assertNotNull(descriptor.getType()); Assert.assertSame(measurementType, descriptor.getType()); Assert.assertEquals(0, descriptor.getMinOccurs()); Assert.assertEquals(Integer.MAX_VALUE, descriptor.getMaxOccurs()); Assert.assertTrue(descriptor.getUserData().get(XSDElementDeclaration.class) instanceof XSDElementDeclaration); name = Types.typeName(NS_URI, "result"); descriptor = (AttributeDescriptor) Types.descriptor(measurementType, name); typeName = Types.typeName(XS.NAMESPACE, XS.FLOAT.getLocalPart()); assertSimpleAttribute(descriptor, name, typeName, Float.class, 1, 1); name = Types.typeName(NS_URI, "determinand_description"); descriptor = (AttributeDescriptor) Types.descriptor(measurementType, name); typeName = Types.typeName(XS.NAMESPACE, XS.STRING.getLocalPart()); assertSimpleAttribute(descriptor, name, typeName, String.class, 1, 1); name = Types.typeName(NS_URI, "the_geom"); descriptor = (AttributeDescriptor) Types.descriptor(wq_plus_Type, name); typeName = Types.typeName(GML.NAMESPACE, GML.PointPropertyType.getLocalPart()); assertSimpleAttribute(descriptor, name, typeName, Point.class, 1, 1); name = Types.typeName(NS_URI, "sitename"); descriptor = (AttributeDescriptor) Types.descriptor(wq_plus_Type, name); typeName = Types.typeName(XS.NAMESPACE, XS.STRING.getLocalPart()); assertSimpleAttribute(descriptor, name, typeName, String.class, 1, Integer.MAX_VALUE); } finally { typeRegistry.disposeSchemaIndexes(); } }
@Test public void testSimpleAttributeFromComplexDeclaration() throws Exception { String res = "/test-data/complexFeature.xsd"; URL resource = getClass().getResource(res); SchemaIndex schemaIndex = EmfAppSchemaReader.newInstance().parse(resource); AppSchemaFeatureTypeRegistry registry = new AppSchemaFeatureTypeRegistry(); try { registry.addSchemas(schemaIndex); Name tcl = Types.typeName(NS_URI, "TypedCategoryListType"); AttributeType typedCategoryListType = registry.getAttributeType(tcl); Assert.assertNotNull(typedCategoryListType); Assert.assertTrue(typedCategoryListType instanceof ComplexType); AttributeType superType = typedCategoryListType.getSuper(); Assert.assertNotNull(superType); Name superName = superType.getName(); Assert.assertEquals(XS.STRING.getNamespaceURI(), superName.getNamespaceURI()); Assert.assertEquals(XS.STRING.getLocalPart(), superName.getLocalPart()); Assert.assertNotNull(typedCategoryListType.getUserData().get(XSDTypeDefinition.class)); } finally { registry.disposeSchemaIndexes(); } }