private AttributeDescriptor parseAttributeDescriptor(String line) { ArrayList<String> tokens = Lists.newArrayList(Splitter.on('\t').split(line)); Preconditions.checkArgument( tokens.size() == 5 || tokens.size() == 6, "Wrong attribute definition: %s", line); NameImpl name = new NameImpl(tokens.get(0)); Class<?> type; try { type = FieldType.valueOf(tokens.get(1)).getBinding(); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Wrong type: " + tokens.get(1)); } int min = Integer.parseInt(tokens.get(2)); int max = Integer.parseInt(tokens.get(3)); boolean nillable = Boolean.parseBoolean(tokens.get(4)); /* * Default values that are currently not encoded. */ boolean isIdentifiable = false; boolean isAbstract = false; List<Filter> restrictions = null; AttributeType superType = null; InternationalString description = null; Object defaultValue = null; AttributeType attributeType; AttributeDescriptor attributeDescriptor; if (Geometry.class.isAssignableFrom(type)) { String crsText = tokens.get(5); CoordinateReferenceSystem crs = CrsTextSerializer.deserialize(crsText); attributeType = typeFactory.createGeometryType( name, type, crs, isIdentifiable, isAbstract, restrictions, superType, description); attributeDescriptor = typeFactory.createGeometryDescriptor( (GeometryType) attributeType, name, min, max, nillable, defaultValue); } else { attributeType = typeFactory.createAttributeType( name, type, isIdentifiable, isAbstract, restrictions, superType, description); attributeDescriptor = typeFactory.createAttributeDescriptor( attributeType, name, min, max, nillable, defaultValue); } return attributeDescriptor; }
private Object parseAttribute(String line) { List<String> tokens = Lists.newArrayList(Splitter.on('\t').split(line)); Preconditions.checkArgument(tokens.size() == 2, "Wrong attribute definition: %s", line); String typeName = tokens.get(0); String value = tokens.get(1); FieldType type; try { type = FieldType.valueOf(typeName); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Wrong type name: " + typeName); } return TextValueSerializer.fromString(type, value); }