/** * static verison of {@link #calculateNillable(AttributeType[])} which can * be called from constructor. */ private static boolean calculateNillableStatic(AttributeType[] children) { for (int i = 0, ii = children.length; i < ii; i++) { if (children[i].isNillable()) { return true; } } //none of the children can take a null, so no nulls are allowed. return false; }
public boolean calculateNillable(AttributeType[] children) { for (int i = 0, ii = children.length; i < ii; i++) { if (children[i].isNillable()) { return true; } } //none of the children can take a null, so no nulls are allowed. return false; }
/** * Creates standard xml attributes present on all xs:element elements. * These are name, maxOccurs, minOccurs and nillable. * * @param attribute the attribute type from which the information is * retrieved * * @return an org.xml.sax.helpers.AttributesImpl object that contains * the standard attributes */ protected AttributesImpl createStandardAttributes( AttributeType attribute) { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "name", "name", "", attribute.getName()); if (attribute.isNillable() && attribute.getMinOccurs() == 0) { atts.addAttribute("", "minOccurs", "minOccurs", "", "0"); atts.addAttribute("", "nillable", "nillable", "", "true"); } else { atts.addAttribute("", "minOccurs", "minOccurs", "", "1"); atts.addAttribute("", "nillable", "nillable", "", "false"); } return atts; } }
/** * 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; }
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(); }
protected DefaultAttributeType(AttributeType copy) { super(copy.getType(),copy.getName(),copy.getMinOccurs(),copy.getMaxOccurs(),copy.isNillable(),copy.getDefaultValue()); }
/** * 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); } }
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 ); }