Package org.jibx.binding.model

Examples of org.jibx.binding.model.StructureElement


                    contain.addChild(value);
                   
                } else if (m_mappedNames.get(tname) != null) {
                   
                    // use mapping definition for class
                    StructureElement structure = new StructureElement();
                    structure.setUsageName("optional");
                    structure.setFieldName(fname);
                    if (((String)m_mappedNames.get(tname)).length() == 0) {
                       
                        // add a name for reference to abstract mapping
                        structure.setName(elementName(tname));
                    }
                    contain.addChild(structure);
                    if (m_verbose) {
                        nestingIndent(System.out);
                        System.out.println("referenced existing binding for " +
                            tname);
                    }
                   
                } else if (simple) {
                   
                    // define a simple value
                    ValueElement value = new ValueElement();
                    value.setFieldName(fname);
                    value.setName(valueName(fname));
                    if (object) {
                        value.setUsageName("optional");
                    }
                    if (!attribute) {
                        value.setStyleName("element");
                    }
                    contain.addChild(value);
                   
                } else if (tname.endsWith("[]")) {
                   
                    // array, check if item type has a mapping
                    String bname = tname.substring(0, tname.length()-2);
                    if (m_mappedNames.get(bname) == null) {
                       
                        // no mapping, use collection with inline structure
                        // TODO: fill it in
                        throw new JiBXException("Base element type " + bname +
                            " 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
                        if ("java.util.List".equals(tname)) {
                            element.setFactoryName
                                ("org.jibx.runtime.Utility.arrayListFactory");
                        }
                       
                    } else if (pcf.isInterface() ||
                        m_ignoreNames.contains(tname)) {
                       
                        // create mapping reference with warning for interface
                        nestingIndent(System.err);
                        System.err.println("Warning: reference to interface " +
                            "or abstract class " + tname +
                            " requires mapped implementation");
                        element = new StructureElement();
                        element.setFieldName(fname);
                       
                    } else {
                       
                        // handle other types of structures directly
View Full Code Here


                        contain.addChild(value);
                       
                    } else if (m_mappedNames.get(tname) != null) {
                       
                        // use mapping definition for class
                        StructureElement structure = new StructureElement();
                        structure.setUsageName("optional");
                        structure.setGetName(gname);
                        structure.setSetName(sname);
                        if (((String)m_mappedNames.get(tname)).length() == 0) {
                           
                            // add a name for reference to abstract mapping
                            structure.setName(elementName(tname));
                        }
                        contain.addChild(structure);
                        if (m_verbose) {
                            nestingIndent(System.out);
                            System.out.println
                                ("referenced existing binding for " + tname);
                        }
                       
                    } else if (tname.endsWith("[]")) {
                       
                        // array, only supported for mapped base type
                        String bname = tname.substring(0, tname.length()-2);
                        if (m_mappedNames.get(bname) == null) {
                            throw new JiBXException("Base element type " +
                                bname + " must be mapped");
                        } else {
                            StructureElement structure = new StructureElement();
                            structure.setUsageName("optional");
                            structure.setGetName(gname);
                            structure.setSetName(sname);
                            structure.setMarshallerName
                                ("org.jibx.extras.TypedArrayMapper");
                            structure.setUnmarshallerName
                                ("org.jibx.extras.TypedArrayMapper");
                            contain.addChild(structure);
                        }
                       
                    } else {
                       
                        // no defined handling, check 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: 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);
                           
                            // specify factory method if just typed as interface
                            if ("java.util.List".equals(tname)) {
                                element.setFactoryName("org.jibx.runtime." +
                                    "Utility.arrayListFactory");
                            }
                           
                        } else if (pcf.isInterface() ||
                            m_ignoreNames.contains(tname)) {
                           
                            // mapping reference with warning for interface
                            nestingIndent(System.err);
                            System.err.println("Warning: reference to " +
                                "interface or abstract class " + tname +
                                " requires mapped implementation");
                            element = new StructureElement();
                            element.setGetName(gname);
                            element.setSetName(sname);
                           
                        } else {
                           
View Full Code Here

        ClassFile sf = cf.getSuperFile();
        String sname = sf.getName();
        if (!"java.lang.Object".equals(sname) &&
            !m_ignoreNames.contains(sname)) {
            if (m_mappedNames.get(sname) != null) {
                StructureElement structure = new StructureElement();
                structure.setMapAsName(sname);
                structure.setName(elementName(sname));
                contain.addChild(structure);
            } else if (m_beanNames.get(sname) != null) {
                defineProperties(sf, (ArrayList)m_beanNames.get(sname),
                    false, contain);
            } else if (sf.getRawClass().getFields().length > 0) {
View Full Code Here

                cname + "; consider adding to mapping list");
        } else {
            m_structureNames.add(cname);
        }
        m_structureStack.push(cname);
        StructureElement element = new StructureElement();
        element.setFieldName(fname);
        element.setName(valueName(fname));
        defineStructure(cf, element);
        if (element.children().isEmpty()) {
            throw new JiBXException("No content found for class " + cname);
        }
        m_structureStack.pop();
        if (m_verbose) {
            nestingIndent(System.out);
View Full Code Here

        assertEquals("mapped class", mapping.getClassName(), "org.jibx.binding.generator.DataClass1");
        assertEquals("default element name", "dataClass1", mapping.getName());
        assertEquals("mapped items", 1, mapping.children().size());
        child = mapping.children().get(0);
        assertTrue("child type", child instanceof StructureElement);
        StructureElement struct = (StructureElement)child;
        assertEquals("mapping reference structure content", 0, struct.children().size());
        qname = struct.getMapAsQName();
        assertNotNull("type name", qname);
        assertEquals("reference type name", "dataClass1", qname.getName());
        assertEquals("reference type namespace", "http://jibx.org/binding/generator", qname.getUri());
    }
View Full Code Here

        assertEquals("set method", "setString", value.getSetName());
        assertEquals("value style", "element", value.getStyleName());
        assertEquals("element name", "string", value.getName());
        child = mapchilds.get(1);
        assertTrue("child type", child instanceof StructureElement);
        StructureElement struct = (StructureElement)child;
        assertEquals("get method", "getLinked", struct.getGetName());
        assertEquals("set method", "setLinked", struct.getSetName());
        assertEquals("element name", "linked", struct.getName());
        child = mapchilds.get(2);
        assertTrue("child type", child instanceof ValueElement);
        value = (ValueElement)child;
        assertEquals("get method", "getInt", value.getGetName());
        assertEquals("set method", "setInt", value.getSetName());
        assertEquals("value style", "attribute", value.getStyleName());
        assertEquals("element name", "int", value.getName());
        child = childs.get(2);
        assertTrue("child type", child instanceof MappingElement);
        mapping = (MappingElementBase)child;
        assertFalse("expected concrete mapping second", mapping.isAbstract());
        assertEquals("mapped class", mapping.getClassName(), "org.jibx.binding.generator.DataClass1");
        assertEquals("specified element name", "class1", mapping.getName());
        assertEquals("mapped items", 1, mapping.children().size());
        child = mapping.children().get(0);
        assertTrue("child type", child instanceof StructureElement);
        struct = (StructureElement)child;
        assertEquals("mapping reference structure content", 0, struct.children().size());
        qname = struct.getMapAsQName();
        assertNotNull("type name", qname);
        assertEquals("reference type name", "class1", qname.getName());
        assertEquals("reference type namespace", "http://www.jibx.org/test", qname.getUri());
    }
View Full Code Here

                checkReferences(collect, null);
               
            } else if (child instanceof StructureElement) {
               
                // structure, check for nested definition
                StructureElement struct = (StructureElement)child;
                if (struct.children().size() > 0) {
                   
                    // just handle references from nested components
                    checkReferences(struct, null);
                   
                } else {
                   
                    // no nested definition, check for mapping reference
                    MappingElement ref = (MappingElement)struct.getEffectiveMapping();
                    if (ref == null) {
                        m_context.addError("No handling defined for empty structure with no mapping reference", struct);
                    } else {
                       
                        // get the referenced mapping information
                        MappingDetail detail = forceMappingDetail(ref);
                        if (struct.hasDirectName()) {
                            if (ref.isAbstract()) {
                               
                                // named element referencing the mapping implies it's a type definition
                                detail.setType(true);
                               
View Full Code Here

     */
    private MappingDetail addDetail(MappingElement map) {
       
        // check structure of mapping definition for schema type extension
        MappingElement base = null;
        StructureElement baseref = null;
        ArrayList contents = map.getContentComponents();
        if (contents.size() > 0) {
           
            // type extension requires reference as first content component
            Object content = contents.get(0);
            if (content instanceof StructureElement) {
                StructureElement struct = (StructureElement)content;
                if (isTypeDerivation(struct)) {
                    base = (MappingElement)struct.getEffectiveMapping();
                    baseref = struct;
                }
            }
        }
       
        // next search recursively for text and/or child element components this is done at this point (with loop
        //  recursion, if needed) so that the flags can be set when creating the detail instance
        boolean haschild = false;
        boolean hastext = false;
        ArrayList expands = new ArrayList();
        expands.add(map);
        for (int i = 0; i < expands.size(); i++) {
           
            // check for container with element name or text content
            ContainerElementBase contain = (ContainerElementBase)expands.get(i);
            contents = contain.getContentComponents();
            for (int j = 0; j < contents.size(); j++) {
                IComponent comp = (IComponent)contents.get(j);
                if (comp.hasName()) {
                   
                    // component with name means child element
                    haschild = true;
                   
                } else if (comp instanceof ValueElement) {
                   
                    // value with no name implies text content
                    hastext = true;
                   
                } else if (comp instanceof CollectionElement) {
                   
                    // collection implies child element (repeating)
                    haschild = true;
                   
                } else {
                   
                    // structure, check for mapping reference
                    StructureElement struct = (StructureElement)comp;
                    if (struct.children().size() > 0) {
                       
                        // add container structure to expansion list
                        expands.add(comp);
                       
                    } else {
                        MappingElementBase ref = (MappingElementBase)struct.getEffectiveMapping();
                        if (ref != null) {
                           
                            // mapping element reference, check if named
                            if (ref.getName() != null) {
                                haschild = true;
View Full Code Here

     */
    private StructureElement addReferenceStructure(LeafNode leaf, DefinitionItem def, boolean single,
        BindingHolder holder, ContainerElementBase bindcomp) {
       
        // first check if a new structure element is needed in the binding for the reference
        StructureElement struct = null;
        boolean keep = false;
        int type = leaf.getSchemaComponent().type();
        if (single && bindcomp instanceof StructureElement) {
            struct = (StructureElement)bindcomp;
            keep = struct.getGetName() == null && struct.getSetName() == null && struct.getFieldName() == null &&
                !struct.isChoice() && struct.getDeclaredType() == null && struct.getMapAsQName() == null &&
                (struct.getName() == null || (type != SchemaBase.ATTRIBUTE_TYPE && type != SchemaBase.ELEMENT_TYPE));
        }
        if (!keep) {
            struct = new StructureElement();
        }
        if (def.getSchemaComponent().type() == SchemaBase.ELEMENT_TYPE) {
           
            // element definition reference, invoke concrete mapping by class name
            struct.setDeclaredType(leaf.getBindingType());
           
        } else {
           
            // not an element reference, so map by abstract mapping 'type' name (which may or may not be a type)
            QName qname = def.getQName();
            String uri = qname.getUri();
            if (uri != null) {
                holder.addTypeNameReference(uri, def.getSchemaComponent().getSchema());
            }
            struct.setMapAsQName(qname);
           
        }
        return struct;
    }
View Full Code Here

            Item item = child.getItem();
            String propname = child.getPropName();
            if (child.isIgnored()) {
               
                // create structure for element to be ignored in unmarshalling
                StructureElement struct = new StructureElement();
                setName(child.getQName(), holder, struct);
                struct.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                bindcomp.addChild(struct);
               
            } else if (item.isImplicit()) {
               
                // implicit item uses superclass data, not a field, so just handle with map-as structure
                DefinitionItem def = ((ReferenceItem)item).getDefinition();
                QName qname = def.getQName();
                AnnotatedBase comp = def.getSchemaComponent();
                int type = comp.type();
                StructureElement struct = new StructureElement();
                if (type == SchemaBase.ELEMENT_TYPE) {
                   
                    // reference to global element definition, just set it directly as concrete mapping reference
                    struct.setMapAsName(getSuperClass().getBindingName());
                   
                } else {
                   
                    // set reference to abstract mapping without name, since this is an implicit reference
                    String uri = qname.getUri();
                    if (uri != null) {
                        holder.addTypeNameReference(uri, def.getSchemaComponent().getSchema());
                    }
                    struct.setMapAsQName(qname);
                   
                }
                bindcomp.addChild(struct);
               
            } else if (child instanceof ParentNode) {
               
                // set up for binding generation alternatives
                ParentNode subparent = (ParentNode)child;
                boolean empty = subparent.getChildren().size() == 0;
                boolean recurse = true;
                ContainerElementBase wrapcomp = bindcomp;
                StructureElementBase newcomp = null;
                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 {
                           
                            // handle list serialization and deserialization directly
                            ValueElement value = buildValueBinding(leaf, null, gname, sname, holder);
                            value.setSerializerName(getBindingName() + '.' + LIST_SERIALIZE_PREFIX + propname);
                            value.setDeserializerName(getBindingName() + '.' + LIST_DESERIALIZE_PREFIX + propname);
                            bindcomp.addChild(value);
                           
                        }
                       
                    } else {
                       
                        // add <structure> wrapper if name passed in with name on value
                        ContainerElementBase contain = bindcomp;
                        boolean consing = single && children.size() == 1;
                        if (wrapname != null && (leaf.isNamed() || leaf.isReference())) {
                            StructureElement struct = new StructureElement();
                            setName(wrapname, holder, struct);
                            String type = leaf.getBindingType();
                            if (gname == null) {
                                struct.setDeclaredType(type);
                            } else if (!Types.isSimpleValue(type)) {
                               
                                // apply access methods to wrapper only if this is a complex value
                                struct.setGetName(gname);
                                struct.setSetName(sname);
                                gname = sname = null;
                                if (getSchemaCustom().isForceTypes()) {
                                    struct.setDeclaredType(type);
                                }
                               
                            }
                            if (wrapopt) {
                                struct.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                            }
                            contain.addChild(struct);
                            contain = struct;
                            consing = true;
                            wrapname = null;
                            wrapopt = false;
                        }
                       
                        // build the appropriate binding representation
                        StructureElement struct = null;
                        if (item instanceof ReferenceItem) {
                           
                            // handle reference directly if a structure class, else just as value
                            DefinitionItem def = ((ReferenceItem)item).getDefinition();
                            TypeData defclas = def.getGenerateClass();
                            if (!defclas.isSimpleValue()) {
                                struct = addReferenceStructure(leaf, def, consing, holder, contain);
                            }
                           
                        } else if (item instanceof GroupItem) {
                           
                            // handle group directly if a structure class, else just as value
                            TypeData groupclas = ((GroupItem)item).getGenerateClass();
                            if (!groupclas.isSimpleValue()) {
                               
                                // create a new <structure> element for reference
                                struct = new StructureElement();
                                StructureClassHolder refclas = (StructureClassHolder)groupclas;
                                if (gname == null) {
                                    struct.setDeclaredType(refclas.getBindingName());
                                }
                               
                                // set the binding component to be filled in by inner class generation
                                refclas.setBinding(struct);
                               
                            }
                           
                        }
                        if (struct == null) {
                           
                            // add simple <value> binding for field
                            ValueElement value = buildValueBinding(leaf, wrapname, gname, sname, holder);
                            if (getSchemaCustom().isForceTypes()) {
                                value.setDeclaredType(leaf.getBindingType());
                            }
                            if (wrapopt) {
                                value.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                            }
                            contain.addChild(value);
                           
                        } else {
                           
                            // fill in structure attributes
                            struct.setGetName(gname);
                            struct.setSetName(sname);
                            if (getSchemaCustom().isForceTypes()) {
                                struct.setDeclaredType(leaf.getBindingType());
                            }
                           
                            // set the name and optional status from wrapper or item
                            setName(wrapname == null ? leaf.getQName() : wrapname, holder, struct);
                            setStructureOptional(leaf, wrapopt, struct);
                           
                            // common <choice> handling for structure
                            if (parent.isSelectorNeeded()) {
                                struct.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                                struct.setTestName("if" + leaf.getSelectPropName());
                            }
                           
                            // add to containing binding component
                            if (struct != contain) {
                                contain.addChild(struct);
View Full Code Here

TOP

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

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.