Package org.jibx.binding.model

Examples of org.jibx.binding.model.ValueElement


                        "(Ljava/lang/String;)");
                    if (dser == null || !tname.equals(dser.getTypeName())) {
                        throw new JiBXException("Deserializer method not " +
                            "found for enumeration class " + tname);
                    }
                    ValueElement value = new ValueElement();
                    value.setFieldName(fname);
                    value.setName(valueName(fname));
                    value.setUsageName("optional");
                    value.setStyleName("element");
                    value.setDeserializerName(mname);
                    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("[]")) {
                   
View Full Code Here


                       
                    }
                    if (simple) {
                       
                        // define a simple value
                        ValueElement value = new ValueElement();
                        value.setGetName(gname);
                        value.setSetName(sname);
                        value.setName(valueName(pname));
                        if (object) {
                            value.setUsageName("optional");
                        }
                        if (!attribute) {
                            value.setStyleName("element");
                        }
                        contain.addChild(value);
                       
                    } else if (m_enumerationNames.get(tname) != null) {
                       
                        // define a value using deserializer method
                        String mname = (String)m_enumerationNames.get(tname);
                        int split = mname.lastIndexOf('.');
                        ClassFile dcf = ClassCache.
                            requireClassFile(mname.substring(0, split));
                        ClassItem dser =
                            dcf.getStaticMethod(mname.substring(split+1),
                            "(Ljava/lang/String;)");
                        if (dser == null || !tname.equals(dser.getTypeName())) {
                            throw new JiBXException("Deserializer method not " +
                                "found for enumeration class " + tname);
                        }
                        ValueElement value = new ValueElement();
                        value.setGetName(gname);
                        value.setSetName(sname);
                        value.setName(valueName(pname));
                        value.setUsageName("optional");
                        value.setStyleName("element");
                        value.setDeserializerName(mname);
                        contain.addChild(value);
                       
                    } else if (m_mappedNames.get(tname) != null) {
                       
                        // use mapping definition for class
View Full Code Here

        assertEquals("specified type namespace", "http://www.jibx.org/test", qname.getUri());
        ArrayList mapchilds = mapping.children();
        assertEquals("mapped items", 3, mapchilds.size());
        child = mapchilds.get(0);
        assertTrue("child type", child instanceof ValueElement);
        ValueElement value = (ValueElement)child;
        assertEquals("get method", "getString", value.getGetName());
        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");
View Full Code Here

     */
    private ValueElement buildValueBinding(DataNode node, QName wrapname, String gname, String sname,
        BindingHolder holder) {
       
        // add <value> element to binding structure for simple (primitive or text) value
        ValueElement value = new ValueElement();
        if (gname == null) {
            value.setDeclaredType(node.getBindingType());
        } else {
            value.setGetName(gname);
            value.setSetName(sname);
        }
        setValueHandlingOptions(node.getItem(), value, holder);
       
        // set test method if needed to pick between alternatives
        ParentNode wrapper = node.getParent();
        if (wrapper.isSelectorNeeded()) {
            value.setTestName("if" + node.getSelectPropName());
            value.setUsage(PropertyAttributes.OPTIONAL_USAGE);
        } else if (node.isOptional()) {
            value.setUsage(PropertyAttributes.OPTIONAL_USAGE);
        }
       
        // get the schema component supplying an element or attribute name
        AnnotatedBase comp = node.getSchemaComponent();
        if (wrapname == null) {
           
            // scan up structure to find parent linked to a different schema component
            // TODO: find a better way to handle this in the node or item structures
            ParentNode parent = wrapper;
            while (parent != null && parent.getSchemaComponent() == comp) {
                parent = parent.getParent();
            }
           
            // set name from node and style from component type
            if (parent == null) {
               
                // all parents linked to same component, treat as special case with name already set
                value.setEffectiveStyle(ValueElement.TEXT_STYLE);
               
            } else {
               
                // name will have been passed down from containing element
                // (since attributes handled directly)
                if (comp.type() == SchemaBase.ELEMENT_TYPE) {
                   
                    // value is an element, set the name directly
                    value.setEffectiveStyle(NestingAttributes.ELEMENT_STYLE);
                    ElementElement elem = (ElementElement)comp;
                    if (SchemaUtils.isOptionalElement(elem)) {
                        // TODO: this is needed because the optional status doesn't inherit downward for embedded items,
                        // as when a simpleType is nested inside an optional attribute. should the code be changed to
                        // inherit instead?
                        value.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                    }
                   
                } else if (comp.type() == SchemaBase.ATTRIBUTE_TYPE) {
                   
                    // value is an attribute, set the name directly
                    value.setEffectiveStyle(NestingAttributes.ATTRIBUTE_STYLE);
                    AttributeElement attr = (AttributeElement)comp;
                    if (SchemaUtils.isOptionalAttribute(attr)) {
                        // TODO: this is needed because the optional status doesn't inherit downward for embedded items, as
                        // when a simpleType is nested inside an optional attribute. should the code be changed to
                        // inherit instead?
                        value.setUsage(PropertyAttributes.OPTIONAL_USAGE);
                    }
                   
                } else {
                    value.setEffectiveStyle(ValueElement.TEXT_STYLE);
                }
                setName(node.getQName(), holder, value);
            }
        } else {
            value.setEffectiveStyle(NestingAttributes.ELEMENT_STYLE);
            setName(wrapname, holder, value);
        }
        return value;
    }
View Full Code Here

                        // 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 {
                           
View Full Code Here

            coll.setItemTypeName(itype);
           
        } else if (Types.isSimpleValue(itype) || isValueClass(itype)) {
           
            // add <value> for simple type, or enum type with optional value method
            ValueElement value = new ValueElement();
            value.setName(iname);
            value.setDeclaredType(itype);
            coll.addChild(value);
            if (custom != null) {
                value.setDefaultText(custom.getEnumValueMethod());
            }
           
        } else {
           
            // embed structure definition within the collection
View Full Code Here

                // check whether value or structure
                String wtype = memb.getWorkingType();
                if (Types.isSimpleValue(wtype) || isValueClass(wtype)) {
                   
                    // add <value> for simple type or enum
                    ValueElement value = new ValueElement();
                    if (memb.getFieldName() == null) {
                        value.setGetName(gmeth);
                        value.setSetName(memb.getSetName());
                    } else {
                        value.setFieldName(memb.getFieldName());
                    }
                    value.setName(memb.getXmlName());
                    hold.addNamespaceUsage(hold.getNamespace());
                  
                    // pass on optional value method for enum
                    ClassCustom icust = m_global.getClassCustomization(wtype);
                    if (icust != null) {
                        value.setEnumValueName(icust.getEnumValueMethod());
                    }
                   
                    // check for optional value
                    if (!memb.isRequired()) {
                        value.setUsageName("optional");
                    }
                   
                    // configure added property values
                    int style = memb.getStyle();
                    if (style == NestingBase.ATTRIBUTE_VALUE_STYLE) {
                        value.setStyleName("attribute");
                    } else if (style == NestingBase.ELEMENT_VALUE_STYLE) {
                        value.setStyleName("element");
                    } else {
                        value.setStyleName("text");
                        value.setName(null);
                    }
                    if (memb.getActualType() != null) {
                        value.setDeclaredType(memb.getActualType());
                    }
                    parent.addChild(value);
                   
                } else {
                   
View Full Code Here

                }
                   
                case ElementBase.VALUE_ELEMENT:
                {
                    // get type information for value
                    ValueElement value = (ValueElement)child;
                    String tname = value.getType().getName();
                    String stype = (String)s_primitiveTypeMap.get(tname);
                    if (stype == null) {
                        stype = (String)s_objectTypeMap.get(tname);
                        if (stype == null) {
                            stype = "xsd:string";
                        }
                    }
                   
                    // build schema element or attribute for value
                    Element element;
                    int style = value.getStyle();
                    if (style == NestingAttributes.ATTRIBUTE_STYLE) {
                       
                        // append attribute as child of type
                        element = addChildElement(agroup, "attribute");
                        if (!value.isOptional()) {
                            element.setAttribute("use", "required");
                        }
                       
                    } else if (style == NestingAttributes.ELEMENT_STYLE) {
                       
                        // append simple element as child of grouping
                        element = addChildElement(egroup, "element");
                        if (mult) {
                            element.setAttribute("minOccurs", "0");
                            element.setAttribute("maxOccurs", "unbounded");
                        } else if (value.isOptional()) {
                            element.setAttribute("minOccurs", "0");
                        }
                       
                    } else {
                       
                        // other types are not currently handled
                        System.err.println("Error: value type " +
                            value.getEffectiveStyleName() + " not supported");
                        break;
                       
                    }
                   
                    // set common attributes on definition
                    element.setAttribute("name", value.getName());
                    element.setAttribute("type", stype);
                    break;
                }
            }
        }
View Full Code Here

    private static String itemType(MappingElement mappingElement, QName qName) {
        String localPart = qName.getLocalPart();
        for (Iterator childIterator = mappingElement.childIterator(); childIterator.hasNext();) {
            Object child = childIterator.next();
            if (child instanceof ValueElement) {
                ValueElement valueElement = (ValueElement)child;
                if (localPart.equals(valueElement.getName())) {
                    return valueElement.getDeclaredType();
                }
            }
            // TODO
            /*
             * else if (child instanceof ) { .. } else if () { .. }
View Full Code Here

    private static String itemType(MappingElement mappingElement, QName qName) {
        String localPart = qName.getLocalPart();
        for (Iterator childIterator = mappingElement.childIterator(); childIterator.hasNext();) {
            Object child = childIterator.next();
            if (child instanceof ValueElement) {
                ValueElement valueElement = (ValueElement)child;
                if (localPart.equals(valueElement.getName())) {
                    return valueElement.getDeclaredType();
                }
            }
            // TODO
            /*
             * else if (child instanceof ) { .. } else if () { .. }
View Full Code Here

TOP

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

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.