@Override public Converter createConverter(Class<?> source, Class<?> target, Hints hints) { final FieldType sourceBinding = FieldType.forBinding(source); final FieldType targetBinding = FieldType.forBinding(target); if (UNKNOWN == sourceBinding || UNKNOWN == targetBinding) { return null; } final boolean sourceIsArray = sourceBinding.getBinding().isArray(); final boolean targetIsArray = targetBinding.getBinding().isArray(); if (!sourceIsArray && !targetIsArray) { return null; } if (String.class.equals(sourceBinding.getBinding())) { return FROM_STRING; } if (String.class.equals(targetBinding.getBinding())) { return TO_STRING; } return null; }
@Override public Converter createConverter(Class<?> source, Class<?> target, Hints hints) { final FieldType sourceBinding = FieldType.forBinding(source); final FieldType targetBinding = FieldType.forBinding(target); if (UNKNOWN == sourceBinding || UNKNOWN == targetBinding) { return null; } final boolean sourceIsMap = Map.class.isAssignableFrom(sourceBinding.getBinding()); final boolean targetIsMap = Map.class.isAssignableFrom(targetBinding.getBinding()); if (!(sourceIsMap || targetIsMap)) { return null; } if (String.class.equals(sourceBinding.getBinding())) { return FROM_STRING; } if (String.class.equals(targetBinding.getBinding())) { return TO_STRING; } return null; }
@Override public Converter createConverter(Class<?> source, Class<?> target, Hints hints) { final FieldType sourceBinding = FieldType.forBinding(source); final FieldType targetBinding = FieldType.forBinding(target); if (UNKNOWN == sourceBinding || UNKNOWN == targetBinding) { return null; } final boolean sourceIsArray = sourceBinding.getBinding().isArray(); final boolean targetIsArray = targetBinding.getBinding().isArray(); if (!sourceIsArray && !targetIsArray) { return null; } if (String.class.equals(sourceBinding.getBinding())) { return FROM_STRING; } if (String.class.equals(targetBinding.getBinding())) { return TO_STRING; } return null; }
@Override public Converter createConverter(Class<?> source, Class<?> target, Hints hints) { final FieldType sourceBinding = FieldType.forBinding(source); final FieldType targetBinding = FieldType.forBinding(target); if (UNKNOWN == sourceBinding || UNKNOWN == targetBinding) { return null; } final boolean sourceIsMap = Map.class.isAssignableFrom(sourceBinding.getBinding()); final boolean targetIsMap = Map.class.isAssignableFrom(targetBinding.getBinding()); if (!(sourceIsMap || targetIsMap)) { return null; } if (String.class.equals(sourceBinding.getBinding())) { return FROM_STRING; } if (String.class.equals(targetBinding.getBinding())) { return TO_STRING; } return null; }
/** * @return the {@code FieldType} associated to the provided binding, or * {@link FieldType#UNKNOWN} if no {@code FieldType} relates to the argument attribute * type. */ public static FieldType forBinding(@Nullable Class<?> binding) { if (binding == null || Void.class.equals(binding)) { return NULL; } // try a hash lookup first FieldType fieldType = BINDING_MAPPING.get(binding); if (fieldType != null) { return fieldType; } // not in the map, lets check one by one anyways // beware for this to work properly FieldTypes for super classes must be defined _after_ // any subclass (i.e. Point before Geometry) for (FieldType t : values()) { if (t.getBinding() != null && t.getBinding().isAssignableFrom(binding)) { return t; } } return UNKNOWN; }
/** * @return the {@code FieldType} associated to the provided binding, or * {@link FieldType#UNKNOWN} if no {@code FieldType} relates to the argument attribute * type. */ public static FieldType forBinding(@Nullable Class<?> binding) { if (binding == null || Void.class.equals(binding)) { return NULL; } // try a hash lookup first FieldType fieldType = BINDING_MAPPING.get(binding); if (fieldType != null) { return fieldType; } // not in the map, lets check one by one anyways // beware for this to work properly FieldTypes for super classes must be defined _after_ // any subclass (i.e. Point before Geometry) for (FieldType t : values()) { Class<?> fieldTypeBinding = t.getBinding(); if (null != fieldTypeBinding && fieldTypeBinding.isAssignableFrom(binding)) { return t; } } return UNKNOWN; }
e); Class<?> valueBinding = valueFieldType.getBinding();
private static AttributeType readAttributeType(DataInput in, FeatureTypeFactory typeFactory) throws IOException { final Name name = readName(in); final byte typeTag = in.readByte(); final FieldType type = FieldType.valueOf(typeTag); if (Geometry.class.isAssignableFrom(type.getBinding())) { final boolean isCRSCode = in.readBoolean(); // as opposed to a raw WKT string final String crsText = in.readUTF(); final CoordinateReferenceSystem crs; try { if (isCRSCode) { if (RevObjects.NULL_CRS_IDENTIFIER.equals(crsText)) { crs = null; } else { boolean forceLongitudeFirst = crsText.startsWith("EPSG:"); crs = CRS.decode(crsText, forceLongitudeFirst); } } else { crs = CRS.parseWKT(crsText); } } catch (FactoryException e) { throw new RuntimeException(e); } return typeFactory.createGeometryType(name, type.getBinding(), crs, false, false, Collections.<Filter> emptyList(), null, null); } else { return typeFactory.createAttributeType(name, type.getBinding(), false, false, Collections.<Filter> emptyList(), null, null); } }
private static AttributeType readAttributeType(DataInput in, FeatureTypeFactory typeFactory) throws IOException { final Name name = readName(in); final byte typeTag = in.readByte(); final FieldType type = FieldType.valueOf(typeTag); if (Geometry.class.isAssignableFrom(type.getBinding())) { final boolean isCRSCode = in.readBoolean(); // as opposed to a raw WKT string final String crsText = in.readUTF(); final CoordinateReferenceSystem crs; try { if (isCRSCode) { if (RevObjects.NULL_CRS_IDENTIFIER.equals(crsText)) { crs = null; } else { boolean forceLongitudeFirst = crsText.startsWith("EPSG:"); crs = CRS.decode(crsText, forceLongitudeFirst); } } else { crs = CRS.parseWKT(crsText); } } catch (FactoryException e) { throw new RuntimeException(e); } return typeFactory.createGeometryType(name, type.getBinding(), crs, false, false, Collections.<Filter> emptyList(), null, null); } else { return typeFactory.createAttributeType(name, type.getBinding(), false, false, Collections.<Filter> emptyList(), null, null); } }
final byte typeTag = in.readByte(); final FieldType type = FieldType.valueOf(typeTag); if (Geometry.class.isAssignableFrom(type.getBinding())) { final boolean isCRSCode = in.readBoolean(); // as opposed to a raw throw new RuntimeException(e); return typeFactory.createGeometryType(name, type.getBinding(), crs, false, false, Collections.<Filter> emptyList(), null, null); } else { return typeFactory.createAttributeType(name, type.getBinding(), false, false, Collections.<Filter> emptyList(), null, null);
e); Class<?> valueBinding = valueFieldType.getBinding();
final byte typeTag = in.readByte(); final FieldType type = FieldType.valueOf(typeTag); if (Geometry.class.isAssignableFrom(type.getBinding())) { final boolean isCRSCode = in.readBoolean(); // as opposed to a raw throw new RuntimeException(e); return typeFactory.createGeometryType(name, type.getBinding(), crs, false, false, Collections.<Filter> emptyList(), null, null); } else { return typeFactory.createAttributeType(name, type.getBinding(), false, false, Collections.<Filter> emptyList(), null, null);
Class<?> type; try { type = FieldType.valueOf(tokens.get(1)).getBinding(); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Wrong type: " + tokens.get(1));
Preconditions.checkState(arrayType.getBinding().isArray());
Class<?> type; try { type = FieldType.valueOf(tokens.get(1)).getBinding(); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Wrong type: " + tokens.get(1));
@Test public void testFieldTypes() { assertEquals(Void.class, FieldType.NULL.getBinding()); assertEquals(Boolean.class, FieldType.BOOLEAN.getBinding()); assertEquals(Byte.class, FieldType.BYTE.getBinding()); assertEquals(Short.class, FieldType.SHORT.getBinding()); assertEquals(Integer.class, FieldType.INTEGER.getBinding()); assertEquals(Long.class, FieldType.LONG.getBinding()); assertEquals(Float.class, FieldType.FLOAT.getBinding()); assertEquals(Double.class, FieldType.DOUBLE.getBinding()); assertEquals(String.class, FieldType.STRING.getBinding()); assertEquals(boolean[].class, FieldType.BOOLEAN_ARRAY.getBinding()); assertEquals(byte[].class, FieldType.BYTE_ARRAY.getBinding()); assertEquals(short[].class, FieldType.SHORT_ARRAY.getBinding()); assertEquals(int[].class, FieldType.INTEGER_ARRAY.getBinding()); assertEquals(long[].class, FieldType.LONG_ARRAY.getBinding()); assertEquals(float[].class, FieldType.FLOAT_ARRAY.getBinding()); assertEquals(double[].class, FieldType.DOUBLE_ARRAY.getBinding()); assertEquals(String[].class, FieldType.STRING_ARRAY.getBinding()); assertEquals(Point.class, FieldType.POINT.getBinding()); assertEquals(LineString.class, FieldType.LINESTRING.getBinding()); assertEquals(Polygon.class, FieldType.POLYGON.getBinding()); assertEquals(MultiPoint.class, FieldType.MULTIPOINT.getBinding()); assertEquals(MultiLineString.class, FieldType.MULTILINESTRING.getBinding()); assertEquals(MultiPolygon.class, FieldType.MULTIPOLYGON.getBinding()); assertEquals(GeometryCollection.class, FieldType.GEOMETRYCOLLECTION.getBinding()); assertEquals(Geometry.class, FieldType.GEOMETRY.getBinding()); assertEquals(UUID.class, FieldType.UUID.getBinding()); assertEquals(BigInteger.class, FieldType.BIG_INTEGER.getBinding()); assertEquals(BigDecimal.class, FieldType.BIG_DECIMAL.getBinding());
for (String key : keys) { AttributeDefinition field = fields.get(key); Class<?> clazz = field.getType().getBinding(); if (Geometry.class.isAssignableFrom(clazz)) { Preconditions.checkArgument(geometryType == null,
public @Test final void createFeatureTypeAllSupportedAttributeTypes() { FieldType[] fieldTypes = FieldType.values(); StringBuilder typeSpec = new StringBuilder(); for (FieldType ft : fieldTypes) { if (typeSpec.length() > 0) { typeSpec.append(','); } if (ft != FieldType.NULL && ft != FieldType.UNKNOWN) { typeSpec.append(ft + "_type:").append(ft.getBinding().getName()); } } final String spec = typeSpec.toString(); final RevFeatureType revFType = testCreateFeatureType(id1, spec); for (FieldType ft : fieldTypes) { if (ft == FieldType.NULL || ft == FieldType.UNKNOWN) { continue; } String attName = ft + "_type"; PropertyDescriptor descriptor = revFType.type().getDescriptor(attName); assertNotNull(descriptor); assertEquals(attName, ft.getBinding(), descriptor.getType().getBinding()); } }
final int bindingOrdinal = type.binding() & 0xFF; final FieldType fieldType = FieldType.valueOf(bindingOrdinal); final Class<?> binding = fieldType.getBinding();
} else if (ft != FieldType.UNKNOWN) { attributeDescriptorSpecs .add(String.format("%s_type:%s", ft, ft.getBinding().getName())); attributeSampleValues.add(RevObjectTestUtil.sampleValue(ft));