/** * Goes through the children, and searches for a validator 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 obj The object to validate. * * @throws IllegalArgumentException If none of the children can validate. */ public void validate(Object obj) throws IllegalArgumentException { for (int i = 0; i < children.length; i++) { try { children[i].validate(obj); return; // validates } catch (IllegalArgumentException e) { // ignore ... try the next } } throw new IllegalArgumentException("Could not be validated :("); }
/** * Goes through the children, and searches for a validator 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 obj The object to validate. * * @throws IllegalArgumentException If none of the children can validate. */ public void validate(Object obj) throws IllegalArgumentException { for (int i = 0; i < children.length; i++) { try { children[i].validate(obj); return; // validates } catch (IllegalArgumentException e) { // ignore ... try the next } } throw new IllegalArgumentException("Could not be validated :("); }
public void validate(Object obj) throws IllegalArgumentException { if(obj instanceof List){ List in; in = (List)obj; if(in.size() == children.length){ for(int i=0;i<children.length;i++){ children[i].validate(in.get(i)); } return; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.size()+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
public void validate(Object obj) throws IllegalArgumentException { if(obj instanceof List){ List in; in = (List)obj; if(in.size() == children.length){ for(int i=0;i<children.length;i++){ children[i].validate(in.get(i)); } return; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.size()+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
/** * 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. * * Note that on the Attribute side of the fence ... this is acutally * an unordered List (a Set of elements, where each element has multiplicity ...) */ public void validate(Object obj) throws IllegalArgumentException { if(obj instanceof Set){ Object[] in; in = ((Set)obj).toArray(); if(in.length == children.length){ for(int i=0;i<children.length;i++){ children[i].validate(in[i]); } return; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
/** * 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. * * Note that on the Attribute side of the fence ... this is acutally * an unordered List (a Set of elements, where each element has multiplicity ...) */ public void validate(Object obj) throws IllegalArgumentException { if(obj instanceof Set){ Object[] in; in = ((Set)obj).toArray(); if(in.length == children.length){ for(int i=0;i<children.length;i++){ children[i].validate(in[i]); } return; } throw new IllegalArgumentException("Expected "+children.length+" Objects, got "+in.length+" Objects"); } throw new IllegalArgumentException("Not an Object []"); }
validator.validate(iter.next());
validator.validate(iter.next());
/** * 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); } }
type.validate(parsed); setAttributeValue(index, wrapInList(parsed)); } catch (IllegalArgumentException iae) {
type.validate(parsed); super.setAttribute(index, wrapInList(parsed)); } catch (IllegalArgumentException iae) {