/** * Maps an AttributeType to a MapInfo field type. * * @param _at Attribute Type * @return the String description of the MapInfo Type */ private String getMapInfoAttrType(final AttributeType _at) { if (_at.getType() == String.class) { int l = AttributeTypes.getFieldLength(_at, MAX_STRING_LEN); if (l <= 0) { l = MAX_STRING_LEN; } return "Char(" + l + ")"; } else if (_at.getType() == Integer.class) { return "Integer"; } else if ((_at.getType() == Double.class) || (_at.getType() == Float.class)) { return "Float"; } else if (_at.getType() == Boolean.class) { return "Logical"; } else if (_at.getType() == Date.class) { return "Date"; } else { return "Char(" + MAX_STRING_LEN + ")"; // TODO Should it raise an exception here (UnsupportedSchema) ? } }
public String toString() { if ((expected == null) && (invalid == null)) { return super.toString(); } String message = "IllegalAttribute: " + ((expected == null) ? "null" : expected.getType().getName()); message += (" , but got " + ((invalid == null) ? "null" : invalid.getClass().getName())); return message; }
/** * Constructs an error message based on expected and invalid. * * @param expected the expected AttributeType. * @param invalid the attribute that does not validate against expected. * * @return an error message reporting the problem. */ static String errorMessage(AttributeType expected, Object invalid) { String message = "expected " + ((expected == null) ? "null" : expected.getType().getName()); message += (" , but got " + ((invalid == null) ? "null" : invalid.getClass().getName())); return message; } }
public static Class getBinding( AttributeType type ) { return type.getType().getBinding(); }
/** * Encode an AttributeType whose value type is a Date. * * @param attribute * * @throws SAXException */ protected void encodeDate(AttributeType attribute) throws SAXException { AttributesImpl atts = createStandardAttributes(attribute); if(java.sql.Date.class.isAssignableFrom(attribute.getType())) atts.addAttribute("", "type", "type", "", "xs:date"); else if(java.sql.Time.class.isAssignableFrom(attribute.getType())) 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"); }
public static GISAttributeInterface createAttributeFrom(final AttributeType _type) { final GISAttributeInterface known = GISAttributeConstants.getConstantAttribute(_type.getName()); if (known != null && known.getDataClass().equals(_type.getType())) { return known; } return createAttributeFrom(_type.getName(), _type.getType()); }
/** * Override of equals. * * @param other the object to be tested for equality. * * @return whether other is equal to this attribute Type. */ public boolean equals(Object other) { if (other == null) { return false; } if( !(other instanceof AttributeType) ){ return false; } AttributeType att = (AttributeType) other; if (name == null) { if (att.getName() != null) { return false; } } if (!name.equals(att.getName())) { return false; } if (!type.equals(att.getType())) { return false; } return true; }
/** * Encode an AttributeType. * * @param attribute * * @throws SAXException * @throws RuntimeException DOCUMENT ME! */ protected void encode(AttributeType attribute) throws SAXException { Class type = attribute.getType(); if (Number.class.isAssignableFrom(type)) { encodeNumber(attribute); } else if (Date.class.isAssignableFrom(type)) { encodeDate(attribute); } else if (type == String.class) { encodeString(attribute); } else if (Geometry.class.isAssignableFrom(type)) { encodeGeometry(attribute); } else if (type == Boolean.class) { encodeBoolean(attribute); /*} else if (FeatureType.class.isAssignableFrom(type)) { encodeFeature(attribute);*/ } else { throw new RuntimeException("Cannot encode " + type.getName()); } }
/** * Converts this GMLInputTemplate to a feature schema. */ public FeatureType toFeatureSchema() throws ParseException, SchemaException { if (featureType_ != null) { return featureType_; } if (!(loaded_)) { throw new ParseException("requested toFeatureSchema w/o loading the template"); } final int size = columnDefinitions_.size(); final AttributeType[] att = new AttributeType[1 + size]; att[0] = AttributeTypeFactory.newAttributeType(BasicFeatureTypes.GEOMETRY_ATTRIBUTE_NAME, Geometry.class); for (int i = 0; i < size; i++) { att[1 + i] = AttributeTypeFactory.newAttributeType(((ColumnDescription) columnDefinitions_.get(i)).columnName_, ((ColumnDescription) columnDefinitions_.get(i)).getType().getType()); } featureType_ = FeatureTypes.newFeatureType(att, "GML"); return featureType_; }
public SumVisitor(int attributeTypeIndex, FeatureType type) throws IllegalFilterException { FilterFactory factory = CommonFactoryFinder.getFilterFactory(null); AttributeType attributeType = type.getAttributeType(attributeTypeIndex); expr = factory.property(attributeType.getName()); createStrategy(attributeType.getType()); }
protected DefaultAttributeType(AttributeType copy) { this.name = copy.getName(); this.type = copy.getType(); this.nillable = copy.isNillable(); this.min = copy.getMinOccurs(); this.max = copy.getMaxOccurs(); this.defaultValue = copy.createDefaultValue(); }
public SumVisitor(String attrName, FeatureType type) throws IllegalFilterException { FilterFactory factory = CommonFactoryFinder.getFilterFactory(null); AttributeType attributeType = type.getAttributeType(attrName); expr = factory.property(attributeType.getName()); createStrategy(attributeType.getType()); }
public void testFixture() throws Exception { FeatureType type = DataUtilities.createType("namespace.typename", "name:String,id:0,geom:MultiLineString"); assertEquals("namespace", new URI("namespace"), type.getNamespace()); assertEquals("typename", "typename", type.getTypeName()); assertEquals("attributes", 3, type.getAttributeCount()); AttributeType[] a = type.getAttributeTypes(); assertEquals("a1", "name", a[0].getName()); assertEquals("a1", String.class, a[0].getType()); assertEquals("a2", "id", a[1].getName()); assertEquals("a2", Integer.class, a[1].getType()); assertEquals("a3", "geom", a[2].getName()); assertEquals("a3", MultiLineString.class, a[2].getType()); }
/** * Constructor class for the AverageVisitor using AttributeType Name * * @param attrName string respresenting the AttributeType * @param type FeatureType * * @throws IllegalFilterException */ public AverageVisitor(String attrName, FeatureType type) throws IllegalFilterException { FilterFactory factory = CommonFactoryFinder.getFilterFactory(null); AttributeType attributeType = type.getAttributeType(attrName); expr = factory.property(attributeType.getName()); createStrategy(attributeType.getType()); }
protected DefaultAttributeType(AttributeType copy) { super(copy.getType(),copy.getName(),copy.getMinOccurs(),copy.getMaxOccurs(),copy.isNillable(),copy.getDefaultValue()); }
/** * Constructor class for the AverageVisitor using AttributeType ID * * @param attributeTypeIndex integer representing the AttributeType * @param type FeatureType * * @throws IllegalFilterException */ public AverageVisitor(int attributeTypeIndex, FeatureType type) throws IllegalFilterException { FilterFactory factory = CommonFactoryFinder.getFilterFactory(null); AttributeType attributeType = type.getAttributeType(attributeTypeIndex); expr = factory.property(attributeType.getName()); createStrategy(attributeType.getType()); }
private AttributeType override(AttributeType type, AttributeType override ){ int max = override.getMaxOccurs(); if( max < 0 ) max = type.getMinOccurs(); int min = override.getMinOccurs(); if( min < 0 ) min = type.getMinOccurs(); String name = override.getName(); if( name == null ) name = type.getName(); Filter restriction = override( type.getRestriction(), override.getRestriction() ); Class javaType = override.getType(); if( javaType == null ) javaType = type.getType(); boolean isNilable = override.isNillable(); Object defaultValue = override.createDefaultValue(); if( defaultValue == null ) defaultValue = type.createDefaultValue(); // WARNING cannot copy metadata! return AttributeTypeFactory.newAttributeType( name, javaType, isNilable, restriction, defaultValue, null ); }
/** * Perform the visitation of an individual Feature. * * @param feature The Feature to explore. */ protected void walker(Feature feature) { final FeatureType schema = feature.getFeatureType(); final int cnt = schema.getAttributeCount(); handler.handleFeature(feature); for (int i = 0; i < cnt; i++) { AttributeType type = schema.getAttributeType(i); // recurse if attribute type is another collection if (FeatureCollection.class.isAssignableFrom(type.getType())) { walker((FeatureCollection) feature.getAttribute(i)); } else if (type instanceof FeatureType) { // recurse if attribute type is another feature walker((Feature) feature.getAttribute(i)); } else { // normal handling handler.handleAttribute(type, feature.getAttribute(i)); } } handler.endFeature(feature); }
public FeatureType getSchema() throws IOException { if (schema_ == null) { try { final AttributeType[] types = readAttributes(); FeatureType parent = null; final Class geomType = types[0].getType(); if ((geomType == Point.class) || (geomType == MultiPoint.class)) { parent = BasicFeatureTypes.POINT; } else if ((geomType == Polygon.class) || (geomType == MultiPolygon.class)) { parent = BasicFeatureTypes.POLYGON; } else if ((geomType == LineString.class) || (geomType == MultiLineString.class)) { parent = BasicFeatureTypes.LINE; } if (parent != null) { schema_ = FeatureTypes.newFeatureType(readAttributes(), createFeatureTypeName(), namespace_, false, new FeatureType[] { parent }); } else { if (namespace_ != null) { schema_ = FeatureTypes.newFeatureType(readAttributes(), createFeatureTypeName(), namespace_, false); } else { schema_ = FeatureTypes .newFeatureType(readAttributes(), createFeatureTypeName(), GMLSchema.NAMESPACE, false); } } } catch (final SchemaException se) { throw new DataSourceException("Error creating FeatureType", se); } } return schema_; }