/** * 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; }
/** * 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 createDefaultValue() { List out; out = new LinkedList(); for(int i=0;i<children.length;i++){ out.add(i, children[i].createDefaultValue()); } return out; }
public Object createDefaultValue() { List out; out = new LinkedList(); for(int i=0;i<children.length;i++){ out.add(i, children[i].createDefaultValue()); } return out; }
/** * This method is unstable ... and does not yet check validity well. * TODO make this method robust * * This method assumes the Objects are in the order of the attributes. * In the future, this should be implemented with a bubble sort type * algorithm for testing each object vs each child. Bubble sort is * recommended as the sample size is typically less than 25 elements, * and the operation takes O(n*n) time. */ public Object createDefaultValue() { Set out = new HashSet(children.length); for(int i=0;i<children.length;i++){ out.add( children[i].createDefaultValue()); } return out; }
/** * This method is unstable ... and does not yet check validity well. * TODO make this method robust * * This method assumes the Objects are in the order of the attributes. * In the future, this should be implemented with a bubble sort type * algorithm for testing each object vs each child. Bubble sort is * recommended as the sample size is typically less than 25 elements, * and the operation takes O(n*n) time. */ public Object createDefaultValue() { Set out = new HashSet(children.length); for(int i=0;i<children.length;i++){ out.add( children[i].createDefaultValue()); } return out; }
private void createDefault() { default_ = new Object[fType_.getAttributeCount()]; for (int i = default_.length - 1; i >= 0; i--) { default_[i] = fType_.getAttributeType(i).createDefaultValue(); } }
/** * 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; }
private Feature createFeature() { if (default_ == null) { default_ = new Object[fcmd_.getAttributeCount()]; for (int i = 0; i < default_.length; i++) { default_[i] = fcmd_.getAttributeType(i).createDefaultValue(); } } try { return fcmd_.create(default_); } catch (final IllegalAttributeException _evt) { FuLog.error(_evt); } return null; }
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(); }
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 ); }
/** * 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); } }