📄 containerelementbase.java
字号:
/** * Get unmarshaller class name. * * @return unmarshaller class name (or <code>null</code> if none) */ public String getUnmarshallerName() { return m_objectAttrs.getUnmarshallerName(); } /** * Get unmarshaller class information. This call is only meaningful after * validation. * * @return class information for unmarshaller (or <code>null</code> if none) */ public IClass getUnmarshaller() { return m_objectAttrs.getUnmarshaller(); } /** * Set unmarshaller class name. * * @param name class name to be used for unmarshalling */ public void setUnmarshallerName(String name) { m_objectAttrs.setUnmarshallerName(name); } /** * Check if nillable object. * * @return nillable flag */ public boolean isNillable() { return m_objectAttrs.isNillable(); } /** * Set nillable flag. * * @param nillable flag */ public void setNillable(boolean nillable) { m_objectAttrs.setNillable(nillable); } /** * Get type to be used for creating new instance. * * @return class name for type to be created (or <code>null</code> if none) */ public String getCreateType() { return m_objectAttrs.getCreateType(); } /** * Get new instance creation class information. This method is only usable * after a call to {@link #validate}. * * @return class information for type to be created (or <code>null</code> if * none) */ public IClass getCreateClass() { return m_objectAttrs.getCreateClass(); } /** * Set new instance type class name. * * @param name class name to be used for creating new instance */ public void setCreateType(String name) { m_objectAttrs.setCreateType(name); } // // Structure attribute delegate methods /** * Get flexible flag. * * @return flexible flag */ public boolean isFlexible() { return m_structureAttrs.isFlexible(); } /** * Set flexible flag. * * @param flexible */ public void setFlexible(boolean flexible) { m_structureAttrs.setFlexible(flexible); } /** * Check if child components are ordered. * * @return <code>true</code> if ordered, <code>false</code> if not */ public boolean isOrdered() { return m_structureAttrs.isOrdered(); } /** * Set child components ordered flag. * * @param ordered <code>true</code> if ordered, <code>false</code> if not */ public void setOrdered(boolean ordered) { m_structureAttrs.setOrdered(ordered); } /** * Check if child components are a choice. * * @return <code>true</code> if choice, <code>false</code> if not */ public boolean isChoice() { return m_structureAttrs.isChoice(); } /** * Set child components choice flag. * * @param choice <code>true</code> if choice, <code>false</code> if not */ public void setChoice(boolean choice) { m_structureAttrs.setChoice(choice); } /** * Check if repeated child elements are allowed. * * @return <code>true</code> if repeats allowed, <code>false</code> if not */ public boolean isAllowRepeats() { return m_structureAttrs.isAllowRepeats(); } /** * Set repeated child elements allowed flag. * * @param ignore <code>true</code> if repeated child elements to be allowed, * <code>false</code> if not */ public void setAllowRepeats(boolean ignore) { m_structureAttrs.setAllowRepeats(ignore); } // // Validation methods. /** * Check that there's a way to construct an instance of an object class for * input bindings. This can be a factory method, an unmarshaller, a * no-argument constructor already defined in the class, or a modifiable * class with constructor generation enabled. If a create-type is specified, * this is used in place of the declared type. The call always succeeds if * the binding is output-only. * * @param vctx validation context * @param type constructed object type */ protected void verifyConstruction(ValidationContext vctx, IClass type) { if (vctx.isInBinding() && getFactory() == null && getUnmarshaller() == null) { IClass create = getCreateClass(); if (create != null) { if (create.isAssignable(type)) { type = create; } else { vctx.addError("Specified create-type '" + create.getName() + "' is not compatible with type '" + type.getName() + '\''); } } if (type.isAbstract()) { vctx.addError("factory-method needed for abstract type '" + type.getName() + '\''); } else if (!type.getName().endsWith("[]") && type.getInitializerMethod("()V") == null) { BindingElement binding = vctx.getBindingRoot(); if (binding.isAddConstructors()) { if (!type.isModifiable()) { vctx.addError("Need no-argument constructor or " + "factory method for unmodifiable class " + type.getName()); } else { IClass suptype = type; while ((suptype = suptype.getSuperClass()) != null) { IClassItem cons = suptype.getInitializerMethod("()V"); if ((cons == null || !type.isAccessible(cons)) && !suptype.isModifiable()) { vctx.addError("Need accessible no-argument constructor for unmodifiable class " + suptype.getName() + " (superclass of " + type.getName() + ')'); } } } } else { vctx.addError("Need no-argument constructor or " + "factory method for class " + type.getName()); } } } } /** * Check that child components are of types compatible with the container * object type. This method may call itself recursively to process the * children of child components which do not themselves set a type. It's not * used directly, but is here for use by subclasses. * * @param vctx validation context * @param type structure object type * @param children list of child components to be checked */ protected void checkCompatibleChildren(ValidationContext vctx, IClass type, ArrayList children) { for (int i = 0; i < children.size(); i++) { ElementBase child = (ElementBase)children.get(i); boolean expand = true; if (child instanceof IComponent && !vctx.isSkipped(child)) { IComponent comp = (IComponent)child; IClass ctype = comp.getType(); if (comp instanceof ContainerElementBase) { ContainerElementBase contain = (ContainerElementBase)comp; expand = !contain.hasObject(); } if (comp.isImplicit()) { if (!type.isAssignable(ctype)) { vctx.addFatal ("References to structure object must have " + "compatible types: " + type.getName() + " cannot be used as " + ctype.getName(), child); } } } if (expand && child instanceof NestingElementBase) { checkCompatibleChildren(vctx, type, ((NestingElementBase)child).children()); } } } /** * Check for child components classified. This is a convenience method for * subclasses to check if classification has already been done. * * @return <code>true</code> if classified, <code>false</code> if not */ protected boolean isClassified() { return m_attributeComponents != null; } /** * Classify child components as contributing attributes, content, or both. * This method is needed to handle on-demand classification during * validation. When a child component is another instance of this class, the * method calls itself on the child component prior to checking the child * component's contribution. * * @param vctx */ protected void classifyComponents(ValidationContext vctx) { if (m_attributeComponents == null && !m_inClassify) { ArrayList childs = children(); if (childs == null || childs.size() == 0) { // no children, so no components of either type m_attributeComponents = EmptyList.INSTANCE; m_contentComponents = EmptyList.INSTANCE; } else { // classify child components, setting flag to catch recursion m_inClassify = true; m_attributeComponents = new ArrayList(); m_contentComponents = new ArrayList(); for (int i = 0; i < childs.size(); i++) { Object child = childs.get(i); if (child instanceof ContainerElementBase) { ((ContainerElementBase)child).classifyComponents(vctx); } if (child instanceof IComponent) { IComponent comp = (IComponent)child; if (comp.hasAttribute()) { m_attributeComponents.add(child); } if (comp.hasContent()) { m_contentComponents.add(child); if (!comp.hasName() && isFlexible()) { vctx.addError("All child components must define element names for flexible='true'", comp); } } } } m_inClassify = false; } } } /** * Set child attribute and content components directly. This is provided for * use by subclasses requiring special handling, in particular the * <structure> element used as a mapping reference. * * @param attribs * @param contents */ protected void setComponents(ArrayList attribs, ArrayList contents) { m_attributeComponents = attribs; m_contentComponents = contents; } /* (non-Javadoc) * @see org.jibx.binding.model.ElementBase#prevalidate(org.jibx.binding.model.ValidationContext) */ public void prevalidate(ValidationContext vctx) { m_objectAttrs.prevalidate(vctx); m_structureAttrs.prevalidate(vctx); if (m_using != null && children().size() > 0) { vctx.addFatal("Child elements not allowed with using attribute"); } super.prevalidate(vctx); } /* (non-Javadoc) * @see org.jibx.binding.model.ElementBase#validate(org.jibx.binding.model.ValidationContext) */ public void validate(ValidationContext vctx) { super.validate(vctx); m_objectAttrs.validate(vctx); m_structureAttrs.validate(vctx); classifyComponents(vctx); if (isChoice() && m_attributeComponents.size() > 0) { vctx.addError("Attributes cannot be included in choice"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -