Package org.jibx.runtime

Examples of org.jibx.runtime.QName


                } else {
                    AttributeElement attr = ((AttributeElement)component);
                    if (m_overrideType != null) {
                        attr.setType(m_overrideType);
                    }
                    QName type = attr.getType();
                    if (type == null) {
                        AttributeElement ref = attr.getReference();
                        if (ref != null) {
                            delete = !checkReference(ref);
                        } else if (!attr.isInlineType()) {
                            attr.setType(SchemaTypes.ANY_SIMPLE_TYPE.getQName());
                        }
                    } else {
                        QName repl = replaceAndReference(type, vctx);
                        if (repl == null) {
                            // TODO optionally make sure the attribute is optional?
                            delete = true;
                        } else if (repl != type) {
                            attr.setType(repl);
                        }
                    }
                }
                break;
            }
           
            case SchemaBase.ATTRIBUTEGROUP_TYPE:
            {
                if (component instanceof AttributeGroupRefElement) {
                    delete = !checkReference(((AttributeGroupRefElement)component).getReference());
                }
                break;
            }
           
            case SchemaBase.ELEMENT_TYPE:
            {
                ElementElement elem = ((ElementElement)component);
                if (isIgnored()) {
                   
                    // reference or definition determines handling
                    QName ref = elem.getRef();
                    if (ref == null) {
                       
                        // definition, just delete all content
                        for (int i = 0; i < elem.getChildCount(); i++) {
                            elem.detachChild(i);
                        }
                        elem.compactChildren();
                       
                    } else {
                       
                        // reference may be to other namespace, so convert to qualified name string
                        StringBuffer buff = new StringBuffer();
                        buff.append('{');
                        if (ref.getUri() != null) {
                            buff.append(ref.getUri());
                        }
                        buff.append('}');
                        buff.append(ref.getName());
                        elem.setName(buff.toString());
                        elem.setRef(null);
                       
                    }
                    elem.setType(SchemaTypes.ANY_TYPE.getQName());
                   
                } else {
                    if (m_overrideType != null) {
                        elem.setType(m_overrideType);
                    }
                    QName type = elem.getType();
                    if (type == null) {
                        delete = !checkReference(elem.getReference());
                    } else {
                        QName repl = replaceAndReference(type, vctx);
                        if (repl == null) {
                            // TODO optionally make sure the element is optional?
                            delete = true;
                        } else if (repl != type) {
                            elem.setType(repl);
                        }
                    }
                }
                break;
            }
           
            case SchemaBase.EXTENSION_TYPE:
            case SchemaBase.RESTRICTION_TYPE:
            {
                CommonTypeDerivation deriv = (CommonTypeDerivation)component;
                QName type = deriv.getBase();
                if (type != null) {
                    QName repl = replaceAndReference(type, vctx);
                    if (repl == null) {
                        delete = true;
                    } else if (repl != type) {
                        deriv.setBase(repl);
                    }
                }
                break;
            }
           
            case SchemaBase.GROUP_TYPE:
            {
                if (component instanceof GroupRefElement) {
                    delete = !checkReference(((GroupRefElement)component).getReference());
                }
                break;
            }
               
            case SchemaBase.LIST_TYPE:
            {
                ListElement list = ((ListElement)component);
/*                    // not currently supported - is it needed?
                    if (m_overrideType != null) {
                        list.setItemType(m_overrideType);
                    }   */
                QName type = list.getItemType();
                if (type != null) {
                    QName repl = replaceAndReference(type, vctx);
                    if (repl == null) {
                        delete = true;
                    } else if (repl != type) {
                        list.setItemType(repl);
                    }
                }
                break;
            }
           
            case SchemaBase.UNION_TYPE:
            {
                UnionElement union = ((UnionElement)component);
                QName[] types = union.getMemberTypes();
                if (types != null) {
                    ArrayList repls = new ArrayList();
                    boolean changed = false;
                    for (int i = 0; i < types.length; i++) {
                        QName type = types[i];
                        QName repl = replaceAndReference(type, vctx);
                        changed = changed || repl != type;
                        if (repl != null) {
                            repls.add(repl);
                        }
                    }
View Full Code Here


                        if (childcomp instanceof SimpleRestrictionElement) {
                           
                            // replace simple type restriction with base type unless it has facets
                            SimpleRestrictionElement restrict = (SimpleRestrictionElement)childcomp;
                            if (restrict.getFacetsList().size() == 0 && restrict.getBase() != null) {
                                QName base = restrict.getBase();
                                if (base == null) {
                                   
                                    // derivation using inline base type, just eliminate the restriction
                                   
                                } else {
                                    modified = substituteTypeDerivation(lead, topcomp, childcomp, restrict);
                                }
                            }
                           
                        } else {
                           
                            // always replace complex type restriction with base type
                            ComplexRestrictionElement restrict = (ComplexRestrictionElement)child;
                            modified = substituteTypeDerivation(lead, topcomp, childcomp, restrict);
                           
                        }
                        break;
                    }
                }
               
                // delete child component if flagged for removal
                if (childext.isRemoved()) {
                    removeChild(i);
                    compact = true;
                }
            }
        }
        if (compact) {
            topcomp.compactChildren();
            modified = true;
        }
       
        // handle union normalization after all children have been normalized
        if (topcomp.type() == SchemaBase.UNION_TYPE) {
           
            // start by checking duplicates in the member types
            compact = false;
            UnionElement union = (UnionElement)topcomp;
            Set typeset = new HashSet();
            ArrayList keeptypes = new ArrayList();
            QName[] membertypes = union.getMemberTypes();
            if (membertypes != null) {
                for (int i = 0; i < membertypes.length; i++) {
                    QName type = membertypes[i];
                    if (typeset.contains(type)) {
                        if (s_logger.isDebugEnabled()) {
                            s_logger.debug(lead + "removed redundant member type " + type + " from " + path);
                        }
                    } else {
                        typeset.add(type);
                        keeptypes.add(type);
                    }
                }
            }
           
            // then check inline types for duplicates, simplifying where possible
            count = union.getChildCount();
            for (int i = 0; i < count; i++) {
                SchemaBase child = topcomp.getChild(i);
                if (child instanceof OpenAttrBase) {
                   
                    // child schema component must be an inline simple type definition
                    SimpleTypeElement simple = (SimpleTypeElement)child;
                    boolean keeper = false;
                    SchemaBase derivation = simple.getDerivation();
                    QName repltype = null;
                    if (derivation != null) {
                       
                        // keep the inline definition by default, but check for replacement cases
                        keeper = true;
                        if (derivation.type() == SchemaBase.RESTRICTION_TYPE) {
View Full Code Here

       
        // check for missing items
        if (m_name == null) {
            vctx.addError("Missing required 'name' attribute", this);
        } else {
            m_qname = new QName(vctx.getCurrentSchema().getEffectiveNamespace(),
                getName());
        }
        if (m_anyAttributeList.size() > 1) {
            vctx.addError("Only one <anyAttribute> child allowed", this);
        }
View Full Code Here

     * Set type name.
     *
     * @param name type name
     */
    public void setTypeName(String name) {
        m_typeQName = new QName(name);
    }
View Full Code Here

            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);
           
View Full Code Here

     */
    private void setValueHandlingOptions(Item item, ValueElement value, BindingHolder holder) {
        if (item instanceof ReferenceItem) {
            ReferenceItem refitem = (ReferenceItem)item;
            DefinitionItem defitem = refitem.getDefinition();
            QName qname = defitem.getQName();
            if (qname != null) {
                value.setFormatQName(qname);
                String uri = qname.getUri();
                if (uri != null) {
                    holder.addTypeNameReference(uri, defitem.getSchemaComponent().getSchema());
                }
            }
        } else if (item instanceof ValueItem) {
View Full Code Here

               
            } 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()) {
View Full Code Here

        Object child = childs.get(1);
        assertTrue("child type", child instanceof MappingElement);
        MappingElementBase mapping = (MappingElementBase)child;
        assertTrue("expected abstract mapping first", mapping.isAbstract());
        assertEquals("mapped class", mapping.getClassName(), "org.jibx.binding.generator.DataClass1");
        QName qname = mapping.getTypeQName();
        assertNotNull("type name", qname);
        assertEquals("default type name", "dataClass1", qname.getName());
        assertEquals("default type namespace", "http://jibx.org/binding/generator", qname.getUri());
        assertEquals("mapped items", 4, mapping.children().size());
        // order of child values inside mapping not specified for class, so don't check
        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("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

        Object child = childs.get(1);
        assertTrue("child type", child instanceof MappingElement);
        MappingElementBase mapping = (MappingElementBase)child;
        assertTrue("expected abstract mapping first", mapping.isAbstract());
        assertEquals("mapped class", mapping.getClassName(), "org.jibx.binding.generator.DataClass1");
        QName qname = mapping.getTypeQName();
        assertNotNull("type name", qname);
        assertEquals("specified type name", "class1", qname.getName());
        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");
        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

     */
    public static String serializeList(QName[] qnames, IMarshallingContext ictx)
        throws JiBXException {
        StringBuffer buff = new StringBuffer();
        for (int i = 0; i < qnames.length; i++) {
            QName qname = qnames[i];
            if (qname != null) {
                if (buff.length() > 0) {
                    buff.append(' ');
                }
                buff.append(serialize(qname, ictx));
View Full Code Here

TOP

Related Classes of org.jibx.runtime.QName

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.