Package org.jibx.binding.model

Examples of org.jibx.binding.model.CollectionElement


                            " must be mapped");
                       
                    } else {
                       
                        // mapping for type, use simple collection
                        CollectionElement collection = new CollectionElement();
                        collection.setUsageName("optional");
                        collection.setFieldName(fname);
                        contain.addChild(collection);
                    }
                   
                } else {
                   
                    // no defined handling, check for collection vs. structure
                    ClassFile pcf = ClassCache.requireClassFile(tname);
                    StructureElementBase element;
                    if (pcf.isImplements("Ljava/util/List;")) {
                       
                        // create a collection for list subclass
                        System.err.println("Warning: field " + fname +
                            " requires mapped implementation of item classes");
                        element = new CollectionElement();
                        element.setComment(" add details of collection items " +
                            "to complete binding definition ");
                        element.setFieldName(fname);
                       
                        // specify factory method if just typed as interface
View Full Code Here


                           
                            // create a collection for list subclass
                            System.err.println("Warning: property " + pname +
                                " requires mapped implementation of item " +
                                "classes");
                            element = new CollectionElement();
                            element.setComment(" add details of collection " +
                                "items to complete binding definition ");
                            element.setGetName(gname);
                            element.setSetName(sname);
                           
View Full Code Here

                }
               
            } else if (child instanceof CollectionElement) {
               
                // check for collection item type
                CollectionElement collect = (CollectionElement)child;
                IClass itype = collect.getItemTypeClass();
                if (isEnumeration(itype)) {
                   
                    // collection items are enumeration type, count directly
                    countEnumUsage(itype.getName());
                   
                } else if (!isSimpleValue(itype)) {
                   
                    // find implied mapping, if one defined
                    String type = itype.getName();
                    TemplateElementBase ref = collect.getDefinitions().getSpecificTemplate(type);
                    if (ref instanceof MappingElement) {
                        MappingElement mapref = (MappingElement)ref;
                        MappingDetail detail = forceMappingDetail(mapref);
                        detail.setElement(true);
                    }
View Full Code Here

                mapping.setTypeQName(qname);
                bind.addTypeNameReference(uri, uri);
                typemap.put(ptype, qname);
               
                // add collection definition details
                CollectionElement coll = new CollectionElement();
                m_bindingGenerator.defineCollection(itype, value.getItemName(), coll, bind);
                mapping.addChild(coll);
               
                // add mapping to binding
                bind.addMapping(mapping);
View Full Code Here

     * @param holder binding definition tracking information
     * @param node data node associated with collection
     * @return collection element
     */
    private CollectionElement newCollection(QName wrapname, boolean wrapopt, BindingHolder holder, DataNode node) {
        CollectionElement collect = new CollectionElement();
        int reptype = getSchemaCustom().getRepeatType();
        boolean list = reptype == SchemaRootBase.REPEAT_LIST || reptype == SchemaRootBase.REPEAT_TYPED;
        if (list) {
            collect.setCreateType(m_listImplClass);
        }
        if (wrapname == null) {
            if (node.isOptional()) {
                collect.setUsage(PropertyAttributes.OPTIONAL_USAGE);
            }
        } else {
            setName(wrapname, holder, collect);
            if (wrapopt) {
                collect.setUsage(PropertyAttributes.OPTIONAL_USAGE);
            }
        }
        return collect;
    }
View Full Code Here

                QName newname = null;
                boolean newopt = false;
                if (subparent.isCollection() && !empty) {
                   
                    // always create a new <collection> element for the binding to match a collection parent node
                    CollectionElement collect = newCollection(wrapname, wrapopt, holder, subparent);
                    wrapcomp.addChild(collect);
                    newcomp = collect;
                    newname = subparent.getQName();
                   
                } else {
                   
                    // check for wrapper <structure> element needed (with nested name, or multiple values, or all)
                    boolean all = item.getSchemaComponent().type() == SchemaBase.ALL_TYPE;
                    boolean multi = subparent.getChildren().size() > 1;
                    if ((wrapname != null && (subparent.isNamed() || multi)) || (all && multi)) {
                        StructureElement struct = new StructureElement();
                        struct.setOrdered(!all);
                        setName(wrapname, holder, struct);
                        if (wrapopt) {
                            struct.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                        }
                        wrapcomp.addChild(struct);
                        wrapcomp = struct;
                        if (!empty && bindcomp.type() == ElementBase.COLLECTION_ELEMENT &&
                            getSchemaCustom().getRepeatType() != SchemaRootBase.REPEAT_ARRAY) {
                           
                            // dig into child node(s) to find the item type
                            DataNode nested = subparent;
                            String type = null;
                            while (((ParentNode)nested).getChildren().size() > 0) {
                                nested = (DataNode)((ParentNode)nested).getChildren().get(0);
                                if (nested.isCollection() || nested instanceof LeafNode) {
                                    type = nested.getBindingType();
                                    break;
                                }
                            }
                            struct.setDeclaredType(type);
                           
                        }
                    } else {
                        newname = wrapname;
                        newopt = wrapopt;
                    }
                   
                    // check for name associated with this node
                    if (subparent.isNamed()) {
                       
                        // check if this is an attribute
                        AnnotatedBase comp = item.getSchemaComponent();
                        if (comp.type() == SchemaBase.ATTRIBUTE_TYPE) {
                           
                            // handle attribute with embedded definition
                            ValueElement value = new ValueElement();
                            value.setEffectiveStyle(NestingAttributes.ATTRIBUTE_STYLE);
                            setName(subparent.getQName(), holder, value);
                            DataNode nested = subparent;
                            while ((nested = (DataNode)((ParentNode)nested).getChildren().get(0)).isInterior());
                            value.setGetName(((LeafNode)nested).getGetMethodName());
                            value.setSetName(((LeafNode)nested).getSetMethodName());
                            setValueHandlingOptions(item, value, holder);
                            wrapcomp.addChild(value);
                            if (SchemaUtils.isOptionalAttribute((AttributeElement)comp)) {
                                value.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                            }
                            if (nested.isList()) {
                                String nestname = nested.getPropName();
                                value.setSerializerName(getBindingName() + '.' + LIST_SERIALIZE_PREFIX + nestname);
                                value.setDeserializerName(getBindingName() + '.' + LIST_DESERIALIZE_PREFIX + nestname);
                            } else if (getSchemaCustom().isForceTypes()) {
                                value.setDeclaredType(nested.getBindingType());
                            }
                            recurse = false;
                           
                        } else if (subparent.getChildren().size() == 1) {
                           
                            // wrapper for an embedded structure or value, just pass name
                            newname = subparent.getQName();
                            newopt = subparent.isOptional();
                           
                        } else {
                           
                            // create a <structure> element, using the name supplied
                            StructureElement struct = new StructureElement();
                            setName(subparent.getQName(), holder, struct);
                            wrapcomp.addChild(struct);
                            newcomp = struct;
                            newname = null;
                            newopt = false;
                           
                        }
                    }
                }
               
                // set 'if' method and optional if inside a choice
                if (parent.isSelectorNeeded()) {
                    if (newcomp == null) {
                        newcomp = new StructureElement();
                        setName(newname, holder, newcomp);
                        newname = null;
                        wrapcomp.addChild(newcomp);
                    }
                    newcomp.setTestName("if" + child.getSelectPropName());
                    newcomp.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                    newopt = false;
                }
               
                // handle parent with no children as flag-only value
                if (empty) {
                   
                    // make sure there's a structure element
                    StructureElementBase struct = newcomp;
                    if (struct == null) {
                       
                        // create a <structure> element, using the wrapping name supplied
                        if (newname == null) {
                            throw new IllegalStateException("Internal error - no wrapping name for empty structure");
                        } else {
                            struct = new StructureElement();
                            setName(newname, holder, struct);
                            wrapcomp.addChild(struct);
                            newcomp = struct;
                        }
                    }
                   
                    // set flag and test methods on structure
                    struct.setFlagName(subparent.getFlagMethodName());
                    struct.setTestName(subparent.getTestMethodName());
                    setStructureOptional(subparent, newopt, struct);
                   
                } else {
                   
                    // add choice handling for this structure
                    if (subparent.isSelectorNeeded()) {
                        if (newcomp == null) {
                            newcomp = new StructureElement();
                            setStructureOptional(subparent, false, newcomp);
                            wrapcomp.addChild(newcomp);
                        }
                        newcomp.setChoice(true);
                        newcomp.setOrdered(false);
                    }
                   
                    // check for new binding component created for this node
                    if (recurse) {
                        if (newcomp == null) {
                            addToBinding(subparent, newname, newopt, single && children.size() == 1, wrapcomp, holder);
                        } else {
                            newcomp.setGetName(subparent.getGetMethodName());
                            newcomp.setSetName(subparent.getSetMethodName());
                            if (getSchemaCustom().isForceTypes()) {
                                newcomp.setDeclaredType(subparent.getBindingType());
                            }
                            addToBinding(subparent, newname, newopt, true, newcomp, holder);
                        }
                    }
                   
                }
               
            } else {
                LeafNode leaf = (LeafNode)child;
                String gname = leaf.getGetMethodName();
                String sname = leaf.getSetMethodName();
                if (leaf.isAny()) {
                   
                    // add structure binding with details determined by xs:any handling
                    int anytype = item.getComponentExtension().getAnyType();
                    StructureElementBase struct = (leaf.isCollection() && anytype != NestingCustomBase.ANY_DOM) ?
                        (StructureElementBase)new CollectionElement() : (StructureElementBase)new StructureElement();
                    String mapper;
                    switch (anytype) {
                       
                        case NestingCustomBase.ANY_DISCARD:
                           
                            // use discard mapper to skip past arbitrary element(s) when unmarshalling
                            mapper = leaf.isCollection() ? "org.jibx.extras.DiscardListMapper" :
                                "org.jibx.extras.DiscardElementMapper";
                            struct.setDeclaredType("java.lang.Object");
                            gname = sname = null;
                            break;
                           
                        case NestingCustomBase.ANY_DOM:
                           
                            // use DOM mapper to marshal/unmarshal arbitrary element(s)
                            mapper = leaf.isCollection() ? "org.jibx.extras.DomListMapper" :
                                "org.jibx.extras.DomElementMapper";
                            break;
                           
                        case NestingCustomBase.ANY_MAPPED:
                           
                            // create item <structure> child for case of list, otherwise just handle directly
                            mapper = null;
                            if (leaf.isCollection()) {
                                StructureElement itemstruct = new StructureElement();
                                itemstruct.setDeclaredType("java.lang.Object");
                                struct.addChild(itemstruct);
                                struct.setCreateType(m_listImplClass);
                            }
                            break;
                           
                        default:
                            throw new IllegalStateException("Internal error - unknown xs:any handling");
                       
                    }
                    if (leaf.isOptional()) {
                        struct.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                    }
                    struct.setGetName(gname);
                    struct.setSetName(sname);
                    struct.setMarshallerName(mapper);
                    struct.setUnmarshallerName(mapper);
                    bindcomp.addChild(struct);
                   
                } else {
                   
                    // set the names to be used for value
                    if (leaf.isCollection() || leaf.isList()) {
                       
                        // process list and collection differently for binding
                        if (leaf.isCollection()) {
                           
                            // create a new collection element
                            CollectionElement collect = newCollection(wrapname, wrapopt, holder, leaf);
                            bindcomp.addChild(collect);
                           
                            // fill in the collection details
                            collect.setGetName(gname);
                            collect.setSetName(sname);
                            if (parent.isSelectorNeeded()) {
                                collect.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                                collect.setTestName("if" + leaf.getSelectPropName());
                            }
                            int reptype = getSchemaCustom().getRepeatType();
                            if (reptype == SchemaRootBase.REPEAT_LIST || reptype == SchemaRootBase.REPEAT_TYPED) {
                                collect.setCreateType(m_listImplClass);
                                if (gname == null) {
                                    collect.setDeclaredType(COLLECTION_VARIABLE_TYPE);
                                }
                            }
                           
                            // check the content (if any) for <collection>
                            boolean usevalue = true;
                            String usetype = leaf.getType();
                            if (item instanceof ReferenceItem) {
                                DefinitionItem def = ((ReferenceItem)item).getDefinition();
                                TypeData defclas = def.getGenerateClass();
                                if (defclas.isSimpleValue()) {
                                    usetype = defclas.getBindingName();
                                } else {
                                   
                                    // reference to mapped class, configure <collection> to handle it properly
                                    usevalue = false;
                                    if (def.getSchemaComponent().type() == SchemaBase.ELEMENT_TYPE) {
                                       
                                        // must be a non-abstract <mapping>, so use it directly
                                        collect.setItemTypeName(defclas.getBindingName());
                                       
                                    } else {
                                       
                                        // abstract mapping reference, create child <structure> with map-as type
                                        StructureElement struct = new StructureElement();
                                        QName qname = def.getQName();
                                        String uri = qname.getUri();
                                        if (uri != null) {
                                            holder.addTypeNameReference(uri, def.getSchemaComponent().getSchema());
                                        }
                                        struct.setMapAsQName(qname);
                                        if (leaf.isNamed()) {
                                            setName(leaf.getQName(), holder, struct);
                                        }
                                        collect.addChild(struct);
                                       
                                    }
                                   
                                }
                               
                            } else if (item instanceof GroupItem) {
                               
                                // handle group directly if a structure class, else just as <value>
                                TypeData groupclas = ((GroupItem)item).getGenerateClass();
                                if (groupclas.isSimpleValue()) {
                                    usetype = groupclas.getBindingName();
                                } else {
                                   
                                    // add <structure> element to be filled in by inner class generation
                                    usevalue = false;
                                    StructureClassHolder classholder = ((StructureClassHolder)groupclas);
                                    StructureElement struct = new StructureElement();
                                    struct.setDeclaredType(classholder.getBindingName());
                                    setName(leaf.getQName(), holder, struct);
                                   
                                    // set component for dependent class generation
                                    classholder.setBinding(struct);
                                    collect.addChild(struct);
                                   
                                }
                               
                            }
                            if (usevalue) {
                               
                                // add <value> element to collection for simple (primitive or text) value
                                ValueElement value = new ValueElement();
                                value.setEffectiveStyle(NestingAttributes.ELEMENT_STYLE);
                                if (leaf.isNamed()) {
                                    setName(leaf.getQName(), holder, value);
                                }
                                setValueHandlingOptions(item, value, holder);
                                value.setDeclaredType(usetype);
                                collect.addChild(value);
                               
                            }
                           
                        } else {
                           
View Full Code Here

            } else {
                setElementType(qname, elem, hold);
            }
            addItemDocumentation((ValueElement)comp, elem);
        } else if (comp instanceof CollectionElement) {
            CollectionElement coll = (CollectionElement)comp;
            if (coll.children().size() > 0) {
               
                // collection with children, choice or sequence from order
                ComplexTypeElement type = new ComplexTypeElement();
                if (coll.isOrdered()) {
                   
                    // ordered children go to sequence element, repeating
                    SequenceElement seq = new SequenceElement();
                    type.setContentDefinition(seq);
                   
                } else {
                   
                    // unordered children go to repeated choice element
                    ChoiceElement choice = new ChoiceElement();
                    type.setContentDefinition(choice);
                   
                }
                type.setContentDefinition(buildCompositor(coll, 0, true, hold));
                elem.setTypeDefinition(type);
               
            } else {
               
                // empty collection, item-type must reference a concrete mapping
                String itype = coll.getItemTypeName();
                TemplateElementBase ref = coll.getDefinitions().getSpecificTemplate(itype);
                if (ref instanceof MappingElement) {
                   
                    // item type with concrete mapping, make it an element
                    MappingDetail detail = m_detailDirectory.getMappingDetail((MappingElementBase)ref);
                    ComplexTypeElement type = new ComplexTypeElement();
View Full Code Here

                    addCompositorPart(part, cdef);
                   
                } else if (iscoll) {
                   
                    // collection without a wrapper element
                    CollectionElement coll = (CollectionElement)comp;
                    String itype = coll.getItemTypeName();
                    TemplateElementBase ref = coll.getDefinitions().getSpecificTemplate(itype);
                    if (ref instanceof MappingElement) {
                       
                        // item type with concrete mapping, make it an element
                        MappingDetail detail = m_detailDirectory.getMappingDetail((MappingElementBase)ref);
                        ElementElement item = new ElementElement();
View Full Code Here

           
            // check for repeated item
            if (memb.isCollection()) {
               
                // create collection element for field or property
                CollectionElement coll = new CollectionElement();
                if (memb.getFieldName() == null) {
                    coll.setGetName(gmeth);
                    coll.setSetName(memb.getSetName());
                } else {
                    coll.setFieldName(memb.getFieldName());
                }
                setTypes(memb, coll);
               
                // set the element name, if defined
                String name = memb.getXmlName();
                if ((cust.isWrapCollections() || memb.isElementForced()) && name != null) {
                    coll.setName(name);
                    hold.addNamespaceUsage(hold.getNamespace());
                }
               
                // check for optional value
                if (!memb.isRequired()) {
                    coll.setUsageName("optional");
                }
               
                // check for type defined
                String itype = memb.getItemType();
                if (itype != null) {
                   
                    // set name to be used for items in collection
                    String iname = memb.getItemName();
                    if (iname == null) {
                       
                        // use name based on item type
                        String simple = itype;
                        int split = simple.lastIndexOf('.');
                        if (split >= 0) {
                            simple = simple.substring(0, split);
                        }
                        iname = cust.convertName(simple);
                       
                    }
                   
                    // define the collection details
                    defineCollection(itype, iname, coll, hold);
                   
                    // check for special case of two unwrapped collections with same item-type and no children
                    ArrayList siblings = parent.children();
                    if (siblings.size() > 0 && coll.children().size() == 0 && coll.getName() == null) {
                        ElementBase sibling = (ElementBase)siblings.get(siblings.size()-1);
                        if (sibling.type() == ElementBase.COLLECTION_ELEMENT) {
                            CollectionElement lastcoll = (CollectionElement)sibling;
                            if (lastcoll.children().size() == 0 && lastcoll.getName() == null &&
                                Utility.safeEquals(lastcoll.getItemTypeName(), coll.getItemTypeName())) {
                                throw new IllegalStateException("Need to use wrapper element for collection member '" +
                                    memb.getBaseName() + "' of class " + cust.getName());
                            }
                        }
                    }
View Full Code Here

            (NestingElementBase)m_structureStack.peek(0);
        boolean only = parent.children().size() == 1;
        if (comp.type() == ElementBase.COLLECTION_ELEMENT) {
           
            // collection may define type or not
            CollectionElement collection = (CollectionElement)comp;
            String itype = collection.getItemTypeClass().getName();
            DefinitionContext dctx = getDefinitions();
            TemplateElementBase templ = dctx.getSpecificTemplate(itype);
            Element element = null;
            if (! (templ instanceof MappingElement)) {
                if (only) {
View Full Code Here

TOP

Related Classes of org.jibx.binding.model.CollectionElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.