private List<String> getRequiredAttributes(SimpleFeatureType schema) { List<String> result = new ArrayList<String>(); for (AttributeDescriptor ad : schema.getAttributeDescriptors()) { if (ad.getMinOccurs() > 0) { result.add(ad.getLocalName()); } } return result; }
/** * Creates standard xml attributes present on all xs:element elements. These are name, * maxOccurs, minOccurs and nillable. * * @param attribute the attribute type from which the information is retrieved * @return an org.xml.sax.helpers.AttributesImpl object that contains the standard * attributes */ protected AttributesImpl createStandardAttributes(AttributeDescriptor attribute) { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "name", "name", "", attribute.getLocalName()); if (attribute.isNillable() && attribute.getMinOccurs() == 0) { atts.addAttribute("", "minOccurs", "minOccurs", "", "0"); atts.addAttribute("", "nillable", "nillable", "", "true"); } else { atts.addAttribute("", "minOccurs", "minOccurs", "", "1"); atts.addAttribute("", "nillable", "nillable", "", "false"); } return atts; } }
/** * Determines if a collection of attribute descriptors is "simple". * * @param schema Collection of attribute descriptors. * @return True if schema is simple, otherwise false. */ public static boolean isSimple(Collection /* <AttributeDescriptor> */ schema) { for (Iterator itr = schema.iterator(); itr.hasNext(); ) { AttributeDescriptor d = (AttributeDescriptor) itr.next(); if (d.getMinOccurs() != 1 || d.getMaxOccurs() != 1) { return false; } if (d.getType() instanceof ComplexType) { return false; } } return true; } }
/** Initializes builder state from another attribute descriptor. */ public void init(AttributeDescriptor descriptor) { init(descriptor.getType()); minOccurs = descriptor.getMinOccurs(); maxOccurs = descriptor.getMaxOccurs(); isNillable = descriptor.isNillable(); userData = descriptor.getUserData(); }
/** * Create a complex attribute for XS.AnyType, since it's defined as a simple type. We need a * complex attribute so we can set xlink:href in it. * * @param value * @param descriptor * @param id * @return */ public Attribute addComplexAnyTypeAttribute( Object value, AttributeDescriptor descriptor, String id) { // need to create a complex attribute for any type, so we can have client properties // for xlink:href and so we chain features etc. Map<Object, Object> userData = descriptor.getUserData(); descriptor = new AttributeDescriptorImpl( ANYTYPE_TYPE, descriptor.getName(), descriptor.getMinOccurs(), descriptor.getMaxOccurs(), descriptor.isNillable(), descriptor.getDefaultValue()); descriptor.getUserData().putAll(userData); return createComplexAttribute(value, ANYTYPE_TYPE, descriptor, id); }
private AttributeDescriptor reprojectAttribute(AttributeDescriptor descr) { if (reprojection != null && descr.getType() instanceof FeatureType) { AttributeDescriptor ad = ftf.createAttributeDescriptor( reprojectType((FeatureType) descr.getType()), descr.getName(), descr.getMinOccurs(), descr.getMaxOccurs(), descr.isNillable(), descr.getDefaultValue()); ad.getUserData().putAll(descr.getUserData()); return ad; } else { return descr; } }
public NonFeatureTypeProxy( final AttributeType type, final FeatureTypeMapping mapping, Collection<PropertyDescriptor> schema) { super(type.getName(), null); subject = type; AttributeDescriptor originalTarget = mapping.getTargetFeature(); int maxOccurs = originalTarget.getMaxOccurs(); int minOccurs = originalTarget.getMinOccurs(); boolean nillable = originalTarget.isNillable(); Object defaultValue = originalTarget.getDefaultValue(); Name name = originalTarget.getName(); // create a new descriptor with the wrapped type and set it to the mapping ComplexFeatureTypeFactoryImpl typeFactory = new ComplexFeatureTypeFactoryImpl(); AttributeDescriptor descriptor = typeFactory.createAttributeDescriptor( this, name, minOccurs, maxOccurs, nillable, defaultValue); descriptor.getUserData().putAll(originalTarget.getUserData()); mapping.setTargetFeature(descriptor); // smuggle FEATURE_LINK descriptor schema.add(ComplexFeatureConstants.FEATURE_CHAINING_LINK); this.descriptors = schema; }
private AttributeDescriptor override(AttributeDescriptor type, AttributeDescriptor override) { int max = override.getMaxOccurs(); if (max < 0) max = type.getMinOccurs(); int min = override.getMinOccurs(); if (min < 0) min = type.getMinOccurs(); String name = override.getLocalName(); if (name == null) name = type.getLocalName(); List restrictions = override(type.getType().getRestrictions(), override.getType().getRestrictions()); Class javaType = override.getType().getBinding(); if (javaType == null) javaType = type.getType().getBinding(); boolean isNilable = override.isNillable(); Object defaultValue = override.getDefaultValue(); if (defaultValue == null) defaultValue = type.getDefaultValue(); // WARNING cannot copy metadata! return new AttributeDescriptorImpl( new AttributeTypeImpl( new NameImpl(name), javaType, false, false, restrictions, null, null), new NameImpl(name), min, max, isNilable, defaultValue); }
nillable[i] = attributeType.getMinOccurs() <= 0 || attributeType.isNillable();
int minOccurs = originalTarget.getMinOccurs(); boolean nillable = originalTarget.isNillable(); Object defaultValue = originalTarget.getDefaultValue();
/** * Sets all the attribute specific state from a single descriptor. * * <p>This method is convenience for: <code> * builder.minOccurs( descriptor.getMinOccurs() ).maxOccurs( descriptor.getMaxOccurs() ) * .nillable( descriptor.isNillable() )... * </code> */ public SimpleFeatureTypeBuilder descriptor(AttributeDescriptor descriptor) { minOccurs(descriptor.getMinOccurs()); maxOccurs(descriptor.getMaxOccurs()); nillable(descriptor.isNillable()); // namespaceURI( descriptor.getName().getNamespaceURI() ); defaultValue(descriptor.getDefaultValue()); if (descriptor instanceof GeometryDescriptor) { crs(((GeometryDescriptor) descriptor).getCoordinateReferenceSystem()); } return this; }
/** * Checkes the two feature types are equal, taking into consideration the eventual modification * the datastore had to perform in order to actually manage the type (change in names case, for * example) */ protected void assertAttributesEqual(AttributeDescriptor expected, AttributeDescriptor actual) { assertEquals(aname(expected.getName()), actual.getName()); assertEquals(expected.getMinOccurs(), actual.getMinOccurs()); assertEquals(expected.getMaxOccurs(), actual.getMaxOccurs()); assertEquals(expected.isNillable(), actual.isNillable()); assertEquals(expected.getDefaultValue(), actual.getDefaultValue()); AttributeType texpected = expected.getType(); AttributeType tactual = actual.getType(); if (Number.class.isAssignableFrom(texpected.getBinding())) { assertTrue(Number.class.isAssignableFrom(tactual.getBinding())); } else if (Geometry.class.isAssignableFrom(texpected.getBinding())) { assertTrue(Geometry.class.isAssignableFrom(tactual.getBinding())); } else { assertTrue(texpected.getBinding().isAssignableFrom(tactual.getBinding())); } }
@Override protected SimpleFeatureType buildTargetFeatureType() { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); for (AttributeDescriptor ad : delegate.getSchema().getAttributeDescriptors()) { if (ad instanceof GeometryDescriptor) { GeometryDescriptor gd = (GeometryDescriptor) ad; Class<?> binding = ad.getType().getBinding(); if (Point.class.isAssignableFrom(binding)) { tb.add(ad); } else { tb.minOccurs(ad.getMinOccurs()); tb.maxOccurs(ad.getMaxOccurs()); tb.nillable(ad.isNillable()); tb.add(ad.getLocalName(), Point.class, gd.getCoordinateReferenceSystem()); } } else { tb.add(ad); } } tb.setName(delegate.getSchema().getName()); return tb.buildFeatureType(); }
builder.setNillable(descriptor.isNillable()); builder.setBinding(descriptor.getType().getBinding()); builder.setMinOccurs(descriptor.getMinOccurs()); builder.setMaxOccurs(descriptor.getMaxOccurs()); builder.setDefaultValue(descriptor.getDefaultValue());
/** * Checkes the two feature types are equal, taking into consideration the eventual modification * the datastore had to perform in order to actually manage the type (change in names case, for * example) */ protected void assertFeatureTypesEqual(SimpleFeatureType expected, SimpleFeatureType actual) { for (int i = 0; i < expected.getAttributeCount(); i++) { AttributeDescriptor expectedAttribute = expected.getDescriptor(i); AttributeDescriptor actualAttribute = actual.getDescriptor(i); assertAttributesEqual(expectedAttribute, actualAttribute); } // make sure the geometry is nillable and has minOccurrs to 0 if (expected.getGeometryDescriptor() != null) { AttributeDescriptor dg = actual.getGeometryDescriptor(); assertTrue(dg.isNillable()); assertEquals(0, dg.getMinOccurs()); } }
void assertEqualsLax(SimpleFeatureType e, SimpleFeatureType a) { if (e.equals(a)) { return; } // do a lax check assertEquals(e.getAttributeCount(), a.getAttributeCount()); for (int i = 0; i < e.getAttributeCount(); i++) { AttributeDescriptor att1 = e.getDescriptor(i); AttributeDescriptor att2 = a.getDescriptor(i); assertEquals(att1.getName(), att2.getName()); assertEquals(att1.getMinOccurs(), att2.getMinOccurs()); assertEquals(att1.getMaxOccurs(), att2.getMaxOccurs()); assertEquals(att1.isNillable(), att2.isNillable()); assertEquals(att1.getDefaultValue(), att2.getDefaultValue()); AttributeType t1 = att1.getType(); AttributeType t2 = att2.getType(); assertEquals(t1.getName(), t2.getName()); assertEquals(t1.getDescription(), t2.getDescription()); assertEquals(t1.getRestrictions(), t2.getRestrictions()); // be a bit lax on type mappings if (!t1.getBinding().equals(t2.getBinding())) { if (Number.class.isAssignableFrom(t1.getBinding())) { assertTrue(Number.class.isAssignableFrom(t2.getBinding())); } if (Date.class.isAssignableFrom(t2.getBinding())) { assertTrue(Date.class.isAssignableFrom(t2.getBinding())); } } } }
private void assertSimpleAttribute( AttributeDescriptor descriptor, Name name, Name typeName, Class<?> binding, int minOccurs, int maxOccurs) { AttributeType type; Assert.assertEquals(name, descriptor.getName()); Assert.assertEquals(minOccurs, descriptor.getMinOccurs()); Assert.assertEquals(maxOccurs, descriptor.getMaxOccurs()); Assert.assertTrue( descriptor.getUserData().get(XSDElementDeclaration.class) instanceof XSDElementDeclaration); type = (AttributeType) descriptor.getType(); Assert.assertNotNull(type); Assert.assertFalse(type instanceof ComplexType); Assert.assertEquals(typeName, type.getName()); Assert.assertEquals(binding, type.getBinding()); // they're prebuilt types, does not contains the emf information // assertTrue(type.getUserData(EmfComplexFeatureReader.EMF_USERDATA_KEY) // instanceof XSDTypeDefinition); }
public void testGetDescriptor() { assertNotNull(feature.getDescriptor()); assertSame(feature.getType(), feature.getDescriptor().getType()); assertTrue(feature.getDescriptor().isNillable()); assertEquals(0, feature.getDescriptor().getMinOccurs()); assertEquals(Integer.MAX_VALUE, feature.getDescriptor().getMaxOccurs()); }
public ZonalStatisticsCollection( SimpleFeatureCollection data, String dataAttribute, SimpleFeatureCollection zones) { super(zones); this.dataAttribute = dataAttribute; this.data = data; SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); for (AttributeDescriptor att : zones.getSchema().getAttributeDescriptors()) { tb.minOccurs(att.getMinOccurs()); tb.maxOccurs(att.getMaxOccurs()); tb.restrictions(att.getType().getRestrictions()); if (att instanceof GeometryDescriptor) { GeometryDescriptor gatt = (GeometryDescriptor) att; tb.crs(gatt.getCoordinateReferenceSystem()); } tb.add("z_" + att.getLocalName(), att.getType().getBinding()); } tb.add("count", Long.class); tb.add("min", Double.class); tb.add("max", Double.class); tb.add("sum", Double.class); tb.add("avg", Double.class); tb.add("stddev", Double.class); tb.setName(zones.getSchema().getName()); targetSchema = tb.buildFeatureType(); }
public void testGetSchemaRoad() throws IOException { SimpleFeatureType expected = td.roadType; SimpleFeatureType actual = dataStore.getSchema(tname("road")); assertEquals("name", aname(expected.getName()), actual.getName()); // assertEquals( "compare", 0, DataUtilities.compare( expected, actual )); assertEquals("attributeCount", expected.getAttributeCount(), actual.getAttributeCount()); for (int i = 0; i < expected.getAttributeCount(); i++) { AttributeDescriptor expectedAttribute = expected.getDescriptor(i); AttributeDescriptor actualAttribute = actual.getDescriptor(i); assertAttributesEqual(expectedAttribute, actualAttribute); } // make sure the geometry is nillable and has minOccurrs to 0 AttributeDescriptor dg = actual.getGeometryDescriptor(); assertTrue(dg.isNillable()); assertEquals(0, dg.getMinOccurs()); // assertEquals(expected, actual); }