/** * 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; }
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(); }
/** * Sets the attribute at position to val. * * @param position the index of the attribute to set. * @param val the new value to give the attribute at position. * * @throws IllegalAttributeException if the passed in val does not validate * against the AttributeType at that position. */ public void setAttribute(int position, Object val) throws IllegalAttributeException { AttributeType type = schema.getAttributeType(position); try { if ((val == null) && !type.isNillable()) val = type.createDefaultValue(); Object parsed = type.parse(val); type.validate(parsed); setAttributeValue(position, parsed); } catch (IllegalArgumentException iae) { throw new IllegalAttributeException(type, val, iae); } }
protected DefaultAttributeType(AttributeType copy) { super(copy.getType(),copy.getName(),copy.getMinOccurs(),copy.getMaxOccurs(),copy.isNillable(),copy.getDefaultValue()); }
/** * Constructor with validator. * * @param validator Name of this attribute. */ public MultiAttributeType(AttributeType validator) { super(validator.getName(), List.class, false,1,1,null); this.validator = validator; }
Class colType = type.getType(); String colName = type.getName(); Filter f = type.getRestriction(); if (f != null && f != Filter.EXCLUDE
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; }
/** * @see org.geotools.data.FeatureReader#next() */ public Feature next() throws IOException, IllegalAttributeException, NoSuchElementException { if (reader == null) { throw new IOException("FeatureReader has been closed"); } Feature next = reader.next(); String id = next.getID(); Object[] attributes = new Object[types.length]; String xpath; for (int i = 0; i < types.length; i++) { xpath = types[i].getName(); if(clone) attributes[i] = types[i].duplicate(next.getAttribute(xpath)); else attributes[i] = next.getAttribute(xpath); } return featureType.create(attributes, id); }
private Filter restriction( FeatureType featureType, String name, Filter filter ){ FeatureType ancestors[] = featureType.getAncestors(); if( ancestors != null && ancestors.length != 0 ){ for( int i=0, length = ancestors.length; i<length; i++ ){ FeatureType superType = ancestors[i]; filter = restriction( superType, name, filter ); } } AttributeType attributes[] = featureType.getAttributeTypes(); if( attributes != null && attributes.length != 0 ){ for( int i=0, length = attributes.length; i<length; i++ ){ AttributeType type = attributes[i]; if( name.equals( type.getName() )){ filter = override( filter, type.getRestriction() ); } } } return filter; }
/** * Returns the default value for the first child which does not throw an * exception, null otherwise. * * @return The default value of the first choice that does not throw an * exception. */ public Object createDefaultValue() { for (int i = 0; i < children.length; i++) { try { return children[i].createDefaultValue(); } catch (IllegalArgumentException e) { // ignore ... try the next } } return null; }
public Object parse(Object value) throws IllegalArgumentException { if(value instanceof Object[]){ Object[] in, out; in = (Object[])value; out = new Object[in.length]; if(in.length == children.length){ for(int i=0;i<children.length;i++){ out[i] = children[i].parse(in[i]); } return out; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
/** * Provides a defautlValue for attributeType. * * <p> * Will return null if attributeType isNillable(), or attempt to use * Reflection, or attributeType.parse( null ) * </p> * * @param attributeType * * @return null for nillable attributeType, attempt at reflection * * @throws IllegalAttributeException If value cannot be constructed for * attribtueType */ public static Object defaultValue(AttributeType attributeType) throws IllegalAttributeException { Object value = attributeType.createDefaultValue(); if (value == null && !attributeType.isNillable()) { throw new IllegalAttributeException( "Got null default value for non-null type."); } return value; }
/** * Goes through the children, and searches for a duplicator that works. * This method searches in the order in which the children are specified * ... please keep this in mind when creating these objects if you care * about precedence. * * @param src The object to be duplicated. * * @return A deep copy of the original object. * * @throws IllegalAttributeException For any attribute errors. * @throws IllegalArgumentException If the object could not be duplicated. */ public Object duplicate(Object src) throws IllegalAttributeException { for (int i = 0; i < children.length; i++) { try { return children[i].duplicate(src); } catch (IllegalArgumentException e) { // ignore ... try the next } } throw new IllegalArgumentException("Could not be duplicated :("); }
int length = getFieldLengthFromFilter(_attr.getRestriction());
/** * Find the position of an AttributeType which matches the given String. * @param attName the name to look for * @return -1 if not found, zero-based index otherwise */ public int find(String attName) { int i=0; while(i<children.length && !attName.equals(children[i].getName()))i++; return i == children.length?-1:i; }
final AttributeType type = _featureType.getAttributeType(i); final Class colType = type.getType(); final String colName = type.getName(); final Filter f = type.getRestriction();
/** * 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) ? } }
/** * Creates duplicate of feature adjusted to the provided featureType. * * @param featureType FeatureType requested * @param feature Origional Feature from DataStore * * @return An instance of featureType based on feature * * @throws IllegalAttributeException If opperation could not be performed */ public static Feature reType(FeatureType featureType, Feature feature) throws IllegalAttributeException { FeatureType origional = feature.getFeatureType(); if (featureType.equals(origional)) { return featureType.duplicate(feature); } String id = feature.getID(); int numAtts = featureType.getAttributeCount(); Object[] attributes = new Object[numAtts]; String xpath; for (int i = 0; i < numAtts; i++) { AttributeType curAttType = featureType.getAttributeType(i); xpath = curAttType.getName(); attributes[i] = curAttType.duplicate(feature.getAttribute(xpath)); } return featureType.create(attributes, id); }
/** * Returns the default value for the first child which does not throw an * exception, null otherwise. * * @return The default value of the first choice that does not throw an * exception. */ public Object createDefaultValue() { for (int i = 0; i < children.length; i++) { try { return children[i].createDefaultValue(); } catch (IllegalArgumentException e) { // ignore ... try the next } } return null; }