containerelementbase.java

来自「JiBX是一个为Java提供的XML数据绑定框架。它可以和现存的类一起运行」· Java 代码 · 共 622 行 · 第 1/2 页

JAVA
622
字号
    }        /**     * Get marshaller class name.     *      * @return marshaller class name (or <code>null</code> if none)     */    public String getMarshallerName() {        return m_objectAttrs.getMarshallerName();    }        /**     * Get marshaller class information. This call is only meaningful after     * validation.     *      * @return class information for marshaller (or <code>null</code> if none)     */    public IClass getMarshaller() {        return m_objectAttrs.getMarshaller();    }        /**     * Set marshaller class name.     *      * @param name class name to be used for marshalling     */    public void setMarshallerName(String name) {        m_objectAttrs.setMarshallerName(name);    }        /**     * 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 ordered <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.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 {                    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) {                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());            }        }    }        /* (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);        ArrayList childs = children();        if (childs == null || childs.size() == 0) {            m_attributeComponents = EmptyList.INSTANCE;            m_contentComponents = EmptyList.INSTANCE;        } else {            m_attributeComponents = new ArrayList();            m_contentComponents = new ArrayList();            for (int i = 0; i < childs.size(); i++) {                Object child = childs.get(i);                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);                        }                    }                }            }            if (isChoice() && m_attributeComponents.size() > 0) {                vctx.addError("Attributes cannot be included in choice");            }        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?