/** * Check that child components are of types compatible with the collection item-type. This method * may call itself recursively to process the children of child components which do not themselves * set a type. * * @param vctx validation context * @param type collection item type * @param children list of child components to be checked */ private void checkCollectionChildren(ValidationContext vctx, IClass type, ArrayList children) { for (int i = 0; i < children.size(); i++) { ElementBase child = (ElementBase) children.get(i); if (!vctx.isSkipped(child)) { boolean expand = true; if (child instanceof IComponent) { IComponent comp = (IComponent) child; IClass ctype = comp.getType(); expand = false; if (comp instanceof ContainerElementBase) { ContainerElementBase contain = (ContainerElementBase) comp; if (contain.hasObject()) { ctype = contain.getObjectType(); } else { expand = true; } } if (!expand) { if (!ctype.isAssignable(type)) { vctx.addFatal( "References to collection items must " + "use compatible types: " + ctype.getName() + " cannot be used as " + type.getName(), child); } } } if (expand && child instanceof NestingElementBase) { checkCollectionChildren(vctx, type, ((NestingElementBase) child).children()); } } } }
/* (non-Javadoc) * @see org.jibx.binding.model.ElementBase#prevalidate(org.jibx.binding.model.ValidationContext) */ public void prevalidate(ValidationContext vctx) { m_nameAttrs.prevalidate(vctx); m_propertyAttrs.prevalidate(vctx); m_collectionItem = vctx.getParentContainer().type() == COLLECTION_ELEMENT; if (!vctx.isSkipped(this)) { super.prevalidate(vctx); } }
/* (non-Javadoc) * @see org.jibx.binding.model.ElementBase#validate(org.jibx.binding.model.ValidationContext) */ public void validate(ValidationContext vctx) { // validate the attribute groups m_nameAttrs.validate(vctx); m_propertyAttrs.validate(vctx); if (!vctx.isSkipped(this)) { // check for way of constructing object instance on input if (m_propertyAttrs.hasProperty() && children().size() > 0) { verifyConstruction(vctx, m_propertyAttrs.getType()); } // check use of text values in children of structure with name if (hasName()) { SequenceVisitor visitor = new SequenceVisitor(this, vctx); TreeContext tctx = vctx.getChildContext(); tctx.tourTree(this, visitor); } // finish with superclass validation super.validate(vctx); } }