Refine search
if (Feature.class.isAssignableFrom(att.getType().getBinding()) && !query.getJoins().isEmpty()) { continue;
public void modifyFeatures(AttributeDescriptor[] type, Object[] values, Filter filter) throws IOException { SimpleFeatureType original = typeMap.getOriginalFeatureType(); // map back attribute types and values to the original values AttributeDescriptor[] originalTypes = new AttributeDescriptor[type.length]; Object[] originalValues = new Object[values.length]; for (int i = 0; i < values.length; i++) { originalTypes[i] = original.getDescriptor(type[i].getName()); if (values[i] != null) { Class<?> target = originalTypes[i].getType().getBinding(); originalValues[i] = Converters.convert(values[i], target); if (originalValues[i] == null) throw new IOException("Could not map back " + values[i] + " to type " + target); } } featureStore() .modifyFeatures(originalTypes, originalValues, store.retypeFilter(filter, typeMap)); }
private Class getTargetClassFromContext(Object context) { if (context instanceof Class) { return (Class) context; } else if (context instanceof AttributeDescriptor) { return ((AttributeDescriptor) context).getType().getBinding(); } return null; }
private static Class[] collectionChoices(List l) { Class[] choices = new Class[l.size()]; int i = 0; for (Iterator iter = l.iterator(); iter.hasNext(); i++) { AttributeDescriptor type = (AttributeDescriptor) iter.next(); choices[i] = type.getType().getBinding(); } return choices; }
@Override public void encodePostColumnCreateTable(AttributeDescriptor att, StringBuffer sql) { if (att instanceof GeometryDescriptor) { // try to narrow down the type with a comment Class binding = att.getType().getBinding(); if (isConcreteGeometry(binding)) { sql.append(" COMMENT '").append(binding.getSimpleName().toUpperCase()).append("'"); } } }
@Override public Object visit(PropertyName expression, Object extraData) { AttributeDescriptor ad = expression.evaluate(featureType, AttributeDescriptor.class); if (ad != null) { return ad.getType().getBinding(); } else { return Object.class; } } }
/** * Encode an AttributeType whose value type is a Date. * * @param attribute * @throws SAXException */ protected void encodeDate(AttributeDescriptor attribute) throws SAXException { AttributesImpl atts = createStandardAttributes(attribute); Class binding = attribute.getType().getBinding(); if (java.sql.Date.class.isAssignableFrom(binding)) atts.addAttribute("", "type", "type", "", "xs:date"); else if (java.sql.Time.class.isAssignableFrom(binding)) atts.addAttribute("", "type", "type", "", "xs:time"); else atts.addAttribute("", "type", "type", "", "xs:dateTime"); contentHandler.startElement(SCHEMA_NS, "element", "xs:element", atts); contentHandler.endElement(SCHEMA_NS, "element", "xs:element"); }
/** Returns true if the type is usable as a mosaic index */ public static boolean isValidMosaicSchema( SimpleFeatureType schema, String locationAttributeName) { // does it have a geometry? if (schema == null || schema.getGeometryDescriptor() == null) { return false; } // does it have the location property? AttributeDescriptor location = schema.getDescriptor(locationAttributeName); return location != null && CharSequence.class.isAssignableFrom(location.getType().getBinding()); }
@Override public Object visit(PropertyName expression, Object extraData) { AttributeDescriptor result = expression.evaluate(schema, AttributeDescriptor.class); if (result == null) { throw new IllegalArgumentException( "Original feature type does not have a property named " + expression.getPropertyName()); } if (result instanceof GeometryDescriptor) { this.crs = ((GeometryDescriptor) result).getCoordinateReferenceSystem(); } return result.getType().getBinding(); }
/** * Checks if the feature type specified is a GridCoverage2DReader wrapper * * @param featureType * @return */ public static boolean isWrappedCoverageReader(SimpleFeatureType featureType) { if (!"GridCoverage".equals(featureType.getName().getLocalPart())) return false; if (featureType.getAttributeCount() != 3) return false; AttributeDescriptor polyDescriptor = featureType.getDescriptor("geom"); if (polyDescriptor == null || !Polygon.class.equals(polyDescriptor.getType().getBinding())) return false; AttributeDescriptor gridDescriptor = featureType.getDescriptor("grid"); if (gridDescriptor == null || !GridCoverage2DReader.class.equals(gridDescriptor.getType().getBinding())) return false; AttributeDescriptor paramDescriptor = featureType.getDescriptor("params"); if (paramDescriptor == null || !GeneralParameterValue[].class.equals(paramDescriptor.getType().getBinding())) return false; return true; }
public FeatureTypeAttributeIO(SimpleFeatureType featureType) { for (AttributeDescriptor ad : featureType.getAttributeDescriptors()) { AttributeIO io = null; if (Date.class.isAssignableFrom(ad.getType().getBinding())) { io = new DateAttributeIO(); } else { io = new DefaultAttributeIO(); } ios.put(ad.getLocalName(), io); } }
/** * Checks if the feature type specified is a GridCoverage wrapper * * @param featureType * @return */ public static boolean isWrappedCoverage(SimpleFeatureType featureType) { if (!"GridCoverage".equals(featureType.getName().getLocalPart())) return false; if (featureType.getAttributeCount() != 2) return false; AttributeDescriptor polyDescriptor = featureType.getDescriptor("geom"); if (polyDescriptor == null || !Polygon.class.equals(polyDescriptor.getType().getBinding())) return false; AttributeDescriptor gridDescriptor = featureType.getDescriptor("grid"); if (gridDescriptor == null || !GridCoverage.class.equals(gridDescriptor.getType().getBinding())) return false; return true; }
private boolean isMatch(ElementValue[] value, SimpleFeatureType ft, int i, int k) { AttributeDescriptor AttributeDescriptor = ft.getDescriptor(k); String typeName = ft.getTypeName(); if (!AttributeDescriptor.getLocalName().equals(typeName)) return false; Class instanceClass = value[i].getValue().getClass(); if (AttributeDescriptor instanceof ChoiceAttributeType) { ChoiceAttributeType choiceAT = (ChoiceAttributeType) AttributeDescriptor; Class[] choices = choiceAT.getChoices(); for (int j = 0; j < choices.length; j++) { if (choices[j].isAssignableFrom(instanceClass)) return true; } } return AttributeDescriptor.getType().getBinding().isAssignableFrom(instanceClass); }
/** * Uses {@link Converters} to parse the provided text into the correct values to create a * feature. * * @param type FeatureType * @param fid Feature ID for new feature * @param text Text representation of values * @return newly created feature * @throws IllegalAttributeException */ public static SimpleFeature parse(SimpleFeatureType type, String fid, String[] text) throws IllegalAttributeException { Object[] attributes = new Object[text.length]; for (int i = 0; i < text.length; i++) { AttributeType attType = type.getDescriptor(i).getType(); attributes[i] = Converters.convert(text[i], attType.getBinding()); } return SimpleFeatureBuilder.build(type, attributes, fid); }
private Class<?> getValueType(Expression e) { Class<?> valueType = null; valueType = getJsonSelectType(e); if (valueType != null) { return valueType; } if (e instanceof PropertyName && featureType != null) { // we should get the value type from the correspondent attribute descriptor AttributeDescriptor attType = (AttributeDescriptor) e.evaluate(featureType); if (attType != null) { valueType = attType.getType().getBinding(); } } else if (e instanceof Function) { // get the value type from the function return type Class<?> ret = getFunctionReturnType((Function) e); if (ret != null) { valueType = ret; } } return valueType; }
public SumVisitor(String attrName, SimpleFeatureType type) throws IllegalFilterException { FilterFactory factory = CommonFactoryFinder.getFilterFactory(null); AttributeDescriptor attributeType = type.getDescriptor(attrName); expr = factory.property(attributeType.getLocalName()); createStrategy(attributeType.getType().getBinding()); }
public SumVisitor(int attributeTypeIndex, SimpleFeatureType type) throws IllegalFilterException { FilterFactory factory = CommonFactoryFinder.getFilterFactory(null); AttributeDescriptor attributeType = type.getDescriptor(attributeTypeIndex); expr = factory.property(attributeType.getLocalName()); createStrategy(attributeType.getType().getBinding()); }
public void setAttribute(int index, Object value) throws IndexOutOfBoundsException { // first do conversion Object converted = Converters.convert( value, getFeatureType().getDescriptor(index).getType().getBinding()); // if necessary, validation too if (validating) Types.validate(featureType.getDescriptor(index), converted); // finally set the value into the feature values[index] = converted; }
private Object convert(Object value, AttributeDescriptor descriptor) { if (value == null) { // if the content is null and the descriptor says isNillable is false, // then set the default value if (!descriptor.isNillable()) { value = descriptor.getDefaultValue(); if (value == null) { // no default value, try to generate one value = DataUtilities.defaultValue(descriptor.getType().getBinding()); } } } else { // make sure the type of the value and the binding of the type match up value = super.convert(value, descriptor); } return value; }
public static SimpleFeature feature(SimpleFeatureType fType, String fid, Node node) throws Exception { SimpleFeatureBuilder b = new SimpleFeatureBuilder(fType); int attributeCount = fType.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { AttributeDescriptor att = fType.getDescriptor(i); AttributeType attType = att.getType(); Object attValue = node.getChildValue(att.getLocalName()); if ((attValue != null) && !attType.getBinding().isAssignableFrom(attValue.getClass())) { // type mismatch, to try convert Object converted = Converters.convert(attValue, attType.getBinding()); if (converted != null) { attValue = converted; } } b.add(attValue); } // create the feature return b.buildFeature(fid); }