public List<Filter> getRestrictions() { return getSubject().getRestrictions(); }
private List restriction(SimpleFeatureType featureType, String name, List filters) { List ancestors = FeatureTypes.getAncestors(featureType); if (ancestors != null && !ancestors.isEmpty()) { for (int i = 0, length = ancestors.size(); i < length; i++) { SimpleFeatureType superType = (SimpleFeatureType) ancestors.get(i); filters = restriction(superType, name, filters); } } List attributes = featureType.getAttributeDescriptors(); if (attributes != null && !attributes.isEmpty()) { for (int i = 0, length = attributes.size(); i < length; i++) { AttributeDescriptor type = (AttributeDescriptor) attributes.get(i); if (name.equals(type.getLocalName())) { filters = override(filters, type.getType().getRestrictions()); } } } return filters; }
int length = Integer.MAX_VALUE; for (Filter f : attribute.getType().getRestrictions()) { if (f == Filter.INCLUDE || f == Filter.EXCLUDE) continue;
if (type.getRestrictions() != null && type.getRestrictions().size() > 0) { for (Filter filter : type.getRestrictions()) { if (!filter.evaluate(value)) { throw new IllegalAttributeException(
/** * Searches the attribute descriptor restrictions in an attempt to determine the length of the * specified varchar column. */ private Integer findVarcharColumnLength(AttributeDescriptor att) { for (Filter r : att.getType().getRestrictions()) { if (r instanceof PropertyIsLessThanOrEqualTo) { PropertyIsLessThanOrEqualTo c = (PropertyIsLessThanOrEqualTo) r; if (c.getExpression1() instanceof Function && ((Function) c.getExpression1()) .getName() .toLowerCase() .endsWith("length")) { if (c.getExpression2() instanceof Literal) { Integer length = c.getExpression2().evaluate(null, Integer.class); if (length != null) { return length; } } } } } return dialect.getDefaultVarcharSize(); }
/** Initializes builder state from another attribute type. */ public AttributeTypeBuilder init(AttributeType type) { name = type.getName().getLocalPart(); separator = type.getName().getSeparator(); namespaceURI = type.getName().getNamespaceURI(); isAbstract = type.isAbstract(); if (type.getRestrictions() != null) { restrictions().addAll(type.getRestrictions()); } description = type.getDescription() != null ? type.getDescription().toString() : null; isIdentifiable = type.isIdentified(); binding = type.getBinding(); superType = type.getSuper(); if (type instanceof GeometryType) { crs = ((GeometryType) type).getCoordinateReferenceSystem(); } return this; }
if (type.getRestrictions() != null) { for (Filter f : type.getRestrictions()) { if (!f.evaluate(attribute)) { throw new IllegalAttributeException(
/** * Gets a new schema, built remapping attribute names via the attributeMappings map. * * @param schema * @return */ private SimpleFeatureType remapSchema(SimpleFeatureType schema) { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName(schema.getName()); for (AttributeDescriptor attDesc : schema.getAttributeDescriptors()) { if (attDesc instanceof GeometryDescriptor) { GeometryDescriptor geoDesc = (GeometryDescriptor) attDesc; builder.add( attributesMapping.get(attDesc.getLocalName()), attDesc.getType().getBinding(), geoDesc.getCoordinateReferenceSystem()); } else { List<Filter> filters = attDesc.getType().getRestrictions(); if (filters != null && !filters.isEmpty()) { builder.restrictions(filters); } builder.add( attributesMapping.get(attDesc.getLocalName()), attDesc.getType().getBinding()); } } return builder.buildFeatureType(); }
type.isIdentified(), type.isAbstract(), type.getRestrictions(), type.getSuper(), type.getDescription());
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); }
targetNodeType.isIdentified(), targetNodeType.isAbstract(), targetNodeType.getRestrictions(), targetNodeType.getSuper(), targetNodeType.getDescription());
public Filter getRestriction() { if ( !getType().getRestrictions().isEmpty() ) { return (Filter) getType().getRestrictions().iterator().next(); } return null; }
/** * Asserts the corresponding properties of <code>type</code> for equality with the provided * parameter values * * @param type * @param name * @param binding * @param restrictions * @param identified * @param _abstract * @param superType * @param nillable */ public static void checkType( AttributeType type, Name name, Class<?> binding, Set<Filter> restrictions, boolean identified, boolean _abstract, AttributeType superType) { assertNotNull(type); assertEquals(name, type.getName()); assertEquals(binding, type.getBinding()); assertNotNull(type.getRestrictions()); assertEquals(restrictions, type.getRestrictions()); assertEquals(identified, type.isIdentified()); assertEquals(_abstract, type.isAbstract()); assertEquals(superType, type.getSuper()); }
public List<Filter> getRestrictions() { return getSubject().getRestrictions(); }
public List<Filter> getRestrictions() { return getSubject().getRestrictions(); }
public static Filter getRestriction( AttributeType type ) { if ( type.getType() != null && type.getType().getRestrictions() != null && !type.getType().getRestrictions().isEmpty() ) { return (Filter) type.getType().getRestrictions().iterator().next(); } return null; } }
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())); } } } }
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(); }
tb.minOccurs(att.getMinOccurs()); tb.maxOccurs(att.getMaxOccurs()); tb.restrictions(att.getType().getRestrictions()); if (att instanceof GeometryDescriptor) { GeometryDescriptor gatt = (GeometryDescriptor) att;
public void testAttributeBuilder() { FilterFactory ff = CommonFactoryFinder.getFilterFactory(); AttributeTypeBuilder builder = new AttributeTypeBuilder(); builder.binding(Integer.class); builder.minOccurs(1).maxOccurs(1); builder.defaultValue(0); builder.name("percent").description("Percent between 0 and 100"); builder.restriction(ff.greaterOrEqual(ff.property("."), ff.literal(0))) .restriction(ff.lessOrEqual(ff.property("."), ff.literal(100))); final AttributeType PERCENT = builder.buildType(); builder.minOccurs(1).maxOccurs(1); builder.defaultValue(0); builder.name("percent").description("Percent between 0 and 100"); AttributeDescriptor a = builder.buildDescriptor("a", PERCENT); assertSame(a.getType(), PERCENT); assertEquals(a.getDefaultValue(), 0); Filter restrictions = ff.and(PERCENT.getRestrictions()); assertTrue(restrictions.evaluate(50)); assertFalse(restrictions.evaluate(150)); }