Package org.jibx.schema.elements

Examples of org.jibx.schema.elements.AnnotatedBase


     *
     * @return qname
     */
    public QName getQName() {
        if (m_qname == null) {
            AnnotatedBase comp = getSchemaComponent();
            QName qname = ((INamed)comp).getQName();
            if (qname == null && comp instanceof IReference) {
                qname = ((IReference)comp).getRef();
            }
            if (comp instanceof AttributeGroupElement) {
View Full Code Here


                    if (group.isInline()) {
                        if (group.getChildCount() > 0) {
                           
                            // create a new group for an inlined compositor only if it's <all> or <choice> or nested
                            ParentNode into = parent;
                            AnnotatedBase comp = item.getSchemaComponent();
                            if (comp instanceof CommonCompositorBase) {
                                if (comp.type() == SchemaBase.ALL_TYPE || comp.type() == SchemaBase.CHOICE_TYPE
                                    || comp.getParent() instanceof CommonCompositorBase) {
                                    into = new ParentNode(group, parent);
                                    into.setDocumentation(doctext);
                                    doctext = null;
                                }
                            } else {
View Full Code Here

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

            String fieldname = m_nameConverter.toFieldName(basename);
            parent.setSelectField(fieldname);
            builder.addIntField(fieldname, "-1").setPrivate();
           
            // build the basic description information
            AnnotatedBase comp = parent.getSchemaComponent();
            StringBuffer buff = new StringBuffer();
            if (parent.getQName() != null) {
                buff.append(parent.getQName().getName());
                buff.append(' ');
            }
            String descript;
            if (comp.type() == SchemaBase.UNION_TYPE) {
                descript = "form";
                buff.append("union");
            } else {
                descript = "choice";
                buff.append("choice");
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);
View Full Code Here

        }
        addFixedNames(m_dataRoot);
        fixFlexibleNames(m_dataRoot, false);
       
        // make class abstract if appropriate
        AnnotatedBase comp = m_dataRoot.getSchemaComponent();
        boolean abs = false;
        int type = comp.type();
        if (type == SchemaBase.ELEMENT_TYPE) {
            abs = ((ElementElement)comp).isAbstract();
        } else if (type == SchemaBase.COMPLEXTYPE_TYPE) {
            abs = ((ComplexTypeElement)comp).isAbstract();
        }
View Full Code Here

     *
     * @param item
     * @return name associated name, or <code>null</code> if none
     */
    private String checkDirectName(Item item) {
        AnnotatedBase comp = item.getSchemaComponent();
        if (comp instanceof INamed || comp instanceof IReference) {
           
            // check for an inlined global type definition
            boolean usename = true;
            if (comp.isGlobal()) {
                if ((comp.bit() & TYPE_DEFINE_MASK) != 0 && !(item instanceof DefinitionItem)) {
                    usename = false;
                }
            }
            if (usename) {
               
View Full Code Here

     * @return name (<code>null</code> if to use inherited name when <code>force == false</code>)
     */
    private String deriveName(Item item, boolean force) {
       
        // try alternatives, in decreasing preference order
        AnnotatedBase comp = item.getSchemaComponent();
        String text = null;
        if (force) {
           
            if (item instanceof ReferenceItem) {
                text = ((ReferenceItem)item).getDefinition().getName();
            } else if (item instanceof GroupItem && ((GroupItem)item).isEnumeration()) {
                text = "Enumeration";
            } else if ((TYPE_DERIVE_MASK & comp.bit()) != 0 && ((CommonTypeDerivation)comp).getBase() != null) {
                text = ((CommonTypeDerivation)comp).getBase().getName();
            } else if (item instanceof ValueItem) {
                text = ((ValueItem)item).getSchemaType().getName();
            } else {
                text = comp.name();
            }
           
        } else if (item instanceof ReferenceItem && (TYPE_DEFINE_MASK & comp.type()) == 0) {
           
            // use name from definition in the case of anything except a type definition
            text = ((ReferenceItem)item).getDefinition().getName();
        }
       
View Full Code Here

     */
    private void assignNames(String prefix, GroupItem group, boolean force) {
       
        // use existing name if set, otherwise derive from context if necessary
        String name = group.getName();
        AnnotatedBase comp = group.getSchemaComponent();
        int type = comp.type();
        boolean propagate = group.getChildCount() == 1 &&
            (type == SchemaBase.ELEMENT_TYPE || type == SchemaBase.ATTRIBUTE_TYPE);
        if (name == null) {
            name = checkDirectName(group);
            if (name == null && force) {
                propagate = false;
                name = deriveName(group, true);
            }
        }
       
        // set name needed for this structure (as either value or class)
        if (name != null) {
            if (group.getClassName() == null) {
                NameConverter conv = group.getComponentExtension().getGlobal().getNameConverter();
                group.setClassName(conv.toJavaClassName(name));
            }
            if (group.getName() == null) {
                group.setName(NameUtils.toNameLead(assembleName(prefix, name)));
            }
        }
       
        // set passed-down prefix to this name if inline group with element name and more than one child, or multiple
        //  nested children and no passed-in prefix
        if (group.isInline() && name != null) {
            if (comp.type() == SchemaBase.ELEMENT_TYPE && SchemaUtils.isNamed(comp)) {
                boolean passprefix = false;
                if (group.getChildCount() > 1) {
                    passprefix = true;
                } else if (prefix == null) {
                    passprefix = true;
View Full Code Here

        for (int i = 0; i < items.size(); i++) {
            DefinitionItem definition = (DefinitionItem)items.get(i);
            if (!definition.isPregenerated()) {
               
                // record all simple element definition items separately for next pass
                AnnotatedBase child = definition.getSchemaComponent();
                if (child.type() == SchemaBase.ELEMENT_TYPE && definition.getChildCount() == 1) {
                    Item item = definition.getFirstChild();
                    if (item instanceof ReferenceItem) {
                        DefinitionItem basedef = ((ReferenceItem)item).getDefinition();
                        if (!basedef.isPregenerated()) {
                            AnnotatedBase comp = basedef.getSchemaComponent();
                            if (comp.type() != SchemaBase.SIMPLETYPE_TYPE) {
                                checkitems.add(definition);
                            }
                        }
                    }
                }
            }
        }
       
        // build map from type definition used by element to flag for single vs. multiple usage
        Map usemap = new HashMap();
        for (int i = 0; i < checkitems.size(); i++) {
           
            // make sure the type definition is not using a pregenerated class (since can't be sure won't be reused)
            ReferenceItem reference = (ReferenceItem)((DefinitionItem)checkitems.get(i)).getFirstChild();
            DefinitionItem basedef = reference.getDefinition();
            if (!basedef.hasDirectGenerateClass()) {
                Boolean usedirect = (Boolean)usemap.get(basedef);
                if (usedirect == null) {
                   
                    // first time type was referenced, flag to use directly
                    usemap.put(basedef, Boolean.TRUE);
                   
                } else if (usedirect.booleanValue()) {
                   
                    // second time type was referenced, flag to use separate classes
                    usemap.put(basedef, Boolean.FALSE);
                   
                }
            }
        }
       
        // flag type-isomorphic elements as inlined, building map from type to isomorphic element definition
        HashMap typeinstmap = new HashMap();
        for (int i = 0; i < checkitems.size(); i++) {
            DefinitionItem elemdef = (DefinitionItem)checkitems.get(i);
            ReferenceItem reference = (ReferenceItem)elemdef.getFirstChild();
            DefinitionItem basedef = reference.getDefinition();
            if (!basedef.hasDirectGenerateClass() && ((Boolean)usemap.get(basedef)).booleanValue()) {
               
                // single element definition using type, make sure abstract state matches on element and type
                ElementElement element = (ElementElement)elemdef.getSchemaComponent();
                AnnotatedBase refcomp = basedef.getSchemaComponent();
                if (!(refcomp instanceof ComplexTypeElement) ||
                    ((ComplexTypeElement)refcomp).isAbstract() == element.isAbstract()) {
                   
                    // abstract state matches, force class for type but none for element
                    basedef.setInlineBlocked(true);
View Full Code Here

TOP

Related Classes of org.jibx.schema.elements.AnnotatedBase

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.