Package org.jibx.schema.elements

Examples of org.jibx.schema.elements.ElementElement


     * @return constructed element
     */
    private ElementElement buildValueElement(ValueCustom parm, Map typemap, Map namemap, SchemaHolder hold) {
       
        // create the basic element definition
        ElementElement elem = new ElementElement();
        if (!parm.isRequired()) {
            elem.setMinOccurs(Count.COUNT_ZERO);
        }
        String type = parm.getWorkingType();
        boolean repeat = false;
       
        // check type or reference for element
        boolean isref = false;
        String ptype = parm.getBoundType();
        QName tname = (QName)typemap.get(ptype);
        if (tname == null) {
           
            // no mapped handling, so check first for object type parameter with corresponding schema type (byte[])
            tname = Types.schemaType(type);
            if (tname == null && (tname = Types.schemaType(ptype)) == null) {
               
                // must be either an array collection, or a reference
                repeat = parm.isCollection();
                String usetype = ptype.endsWith(">") ? type : ptype;
                BindingMappingDetail detail = m_bindingGenerator.getMappingDetail(usetype);
                if (detail == null) {
                    throw new IllegalStateException("No mapping found for type " + usetype);
                } else if (detail.isExtended()) {
                    elem.setRef(detail.getElementQName());
                    isref = true;
                } else {
                    MappingElement mapping = detail.getAbstractMapping();
                    tname = mapping.getTypeQName();
                    if (tname == null) {
                        tname = getMappingQName(usetype, mapping);
                    }
                }
               
            }
        }
        if (isref) {
            addSchemaReference(elem.getRef(), namemap, hold);
        } else {
           
            // set element type and name
            m_schemaGenerator.setElementType(tname, elem, hold);
            String ename = parm.getXmlName();
            if (ename == null) {
                ename = tname.getName();
            }
            elem.setName(ename);
            addSchemaReference(tname, namemap, hold);
        }
       
        // handle repeated value
        if (repeat) {
            elem.setMaxOccurs(Count.COUNT_UNBOUNDED);
        }
       
        // add documentation if available
        List nodes = parm.getDocumentation();
        if (nodes != null) {
            AnnotationElement anno = new AnnotationElement();
            DocumentationElement doc = new DocumentationElement();
            for (Iterator iter = nodes.iterator(); iter.hasNext();) {
                Node node = (Node)iter.next();
                doc.addContent(node);
            }
            anno.getItemsList().add(doc);
            elem.setAnnotation(anno);
        }
        return elem;
    }
View Full Code Here


     *
     * @param qname name
     * @return definition, or <code>null</code> if not registered
     */
    public ElementElement findElement(QName qname) {
        ElementElement elem = (ElementElement)m_globalElementMap.get(qname);
        if (elem == null && m_importedElementMap != null) {
            elem = (ElementElement)m_importedElementMap.get(qname);
        }
        return elem;
    }
View Full Code Here

                    ValueCustom parm = (ValueCustom)parms.get(0);
                    rqelem = (QName)classelems.get(parm.getWorkingType());
                    if (rqelem == null) {
                       
                        // create new element for parameter
                        ElementElement pelem = buildValueElement(parm, ptypemap, typeschemas, holder);
                        schema.getTopLevelChildren().add(pelem);
                        rqelem = pelem.getQName();
                       
                    } else {
                       
                        // import and use existing element definition
                        imports.add(elemschemas.get(rqelem));
                        addSchemaReference(rqelem, elemschemas, holder);
                       
                    }
                }
               
            } else {
               
                // construct a sequence for wrapped method parameters
                SequenceElement seq = new SequenceElement();
                ArrayList parms = odef.getParameters();
                for (int j = 0; j < parms.size(); j++) {
                    ValueCustom parm = (ValueCustom)parms.get(j);
                    String type = parm.getWorkingType();
                    ElementElement pelem;
                    if (!typemap.containsKey(type)) {
                       
                        // add predefined mapping type to known types and require schema import
                        QName tname = (QName)classtypes.get(type);
                        if (tname != null) {
                            typemap.put(type, tname);
                            imports.add(typeschemas.get(tname));
                        }
                       
                    }
                    pelem = buildValueElement(parm, ptypemap, typeschemas, holder);
                    seq.getParticleList().add(pelem);
                }
               
                // add corresponding schema definition to schema
                ComplexTypeElement tdef = new ComplexTypeElement();
                tdef.setContentDefinition(seq);
                ElementElement elem = new ElementElement();
                String wname = odef.getRequestWrapperName();
                elem.setName(wname);
                elem.setTypeDefinition(tdef);
                schema.getTopLevelChildren().add(elem);
                rqelem = new QName(sns, wname);
               
            }
           
            // add part definition to message (if present)
            if (rqelem != null) {
                MessagePart part = new MessagePart("part", rqelem);
                rqmsg.getParts().add(part);
                def.addNamespace(rqelem.getUri());
            }
           
            // generate output message information
            Message rsmsg = new Message(odef.getResponseMessageName(), wns);
            op.addOutputMessage(rsmsg);
            def.addMessage(rsmsg);
            ValueCustom rtrn = odef.getReturn();
            QName rselem = null;
            if (m_generationParameters.isDocLit()) {
               
                // check if return value defined for method
                if (!"void".equals(rtrn.getWorkingType())) {
                   
                    // check for existing element definition matching the return type
                    rselem = (QName)classelems.get(rtrn.getWorkingType());
                    if (rselem == null) {
                       
                        // create new element for return
                        ElementElement relem = buildValueElement(rtrn, ptypemap, typeschemas, holder);
                        schema.getTopLevelChildren().add(relem);
                        rselem = relem.getQName();
                       
                    } else {
                       
                        // import and use existing element definition
                        imports.add(elemschemas.get(rselem));
                        addSchemaReference(rqelem, elemschemas, holder);
                       
                    }
                }
               
            } else {
               
                // add corresponding schema definition to schema
                SequenceElement seq = new SequenceElement();
                if (!"void".equals(rtrn.getWorkingType())) {
                    ElementElement relem = buildValueElement(rtrn, ptypemap, typeschemas, holder);
                    seq.getParticleList().add(relem);
                }
                ComplexTypeElement tdef = new ComplexTypeElement();
                tdef.setContentDefinition(seq);
                ElementElement elem = new ElementElement();
                String wname = odef.getResponseWrapperName();
                elem.setName(wname);
                elem.setTypeDefinition(tdef);
                schema.getTopLevelChildren().add(elem);
                rselem = new QName(sns, wname);
               
            }
           
View Full Code Here

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

     */
    public boolean visit(ElementElement node) {
        if (!SchemaUtils.isProhibited(node)) {
           
            // check if direct definition
            ElementElement refelem = node.getReference();
            if (refelem == null) {
                if (node.getType() == null || node.getType().equals(SchemaTypes.ANY_TYPE.getQName())) {
                   
                    // create a group for the embedded definition
                    buildStructure(false, node);
View Full Code Here

                }
               
                case SchemaBase.ELEMENT_TYPE:
                {
                    // set the element type to the restriction base
                    ElementElement elem = (ElementElement)parent;
                    elem.setTypeDefinition(derive.getBaseType());
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug(lead + "replaced element " + SchemaUtils.componentPath(elem) +
                            " type with base type from derivation " + SchemaUtils.componentPath(childcomp));
                    }
                    return true;
View Full Code Here

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

     *
     * @param qname name
     * @param def element definition
     */
    public void registerElement(QName qname, ElementElement def) {
        ElementElement dupl = m_nameRegister.registerElement(qname, def);
        if (dupl != null) {
            addError("Duplicate name " + qname, def);
        }
    }
View Full Code Here

     * @return element
     */
    private ElementElement buildElement(IComponent comp, boolean repeat, SchemaHolder hold) {
       
        // create the basic element structure
        ElementElement elem = new ElementElement();
        if (repeat) {
            elem.setMinOccurs(Count.COUNT_ZERO);
            elem.setMaxOccurs(Count.COUNT_UNBOUNDED);
        } else if (comp.isOptional()) {
            elem.setMinOccurs(Count.COUNT_ZERO);
        }
       
        // set or create the element type definition
        boolean isref = false;
        if (comp instanceof ValueElement) {
            QName qname = getSimpleTypeQName(comp);
            if (qname == null) {
                elem.setTypeDefinition(buildSimpleType(comp));
            } else {
                setElementType(qname, elem, hold);
            }
            addItemDocumentation((ValueElement)comp, elem);
        } else if (comp instanceof CollectionElement) {
            CollectionElement coll = (CollectionElement)comp;
            if (coll.children().size() > 0) {
               
                // collection with children, choice or sequence from order
                ComplexTypeElement type = new ComplexTypeElement();
                if (coll.isOrdered()) {
                   
                    // ordered children go to sequence element, repeating
                    SequenceElement seq = new SequenceElement();
                    type.setContentDefinition(seq);
                   
                } else {
                   
                    // unordered children go to repeated choice element
                    ChoiceElement choice = new ChoiceElement();
                    type.setContentDefinition(choice);
                   
                }
                type.setContentDefinition(buildCompositor(coll, 0, true, hold));
                elem.setTypeDefinition(type);
               
            } else {
               
                // empty collection, item-type must reference a concrete mapping
                String itype = coll.getItemTypeName();
                TemplateElementBase ref = coll.getDefinitions().getSpecificTemplate(itype);
                if (ref instanceof MappingElement) {
                   
                    // item type with concrete mapping, make it an element
                    MappingDetail detail = m_detailDirectory.getMappingDetail((MappingElementBase)ref);
                    ComplexTypeElement type = new ComplexTypeElement();
                    SequenceElement seq = new SequenceElement();
                    type.setContentDefinition(seq);
                    ElementElement item = new ElementElement();
                    setElementRef(detail.getOtherName(), item, hold);
                    item.setMinOccurs(Count.COUNT_ZERO);
                    item.setMaxOccurs(Count.COUNT_UNBOUNDED);
                    seq.getParticleList().add(item);
                    elem.setTypeDefinition(type);
                    addItemDocumentation(coll, item);
                   
                } else {
View Full Code Here

        for (int i = offset; i < comps.size(); i++) {
            IComponent comp = (IComponent)comps.get(i);
            if (comp.hasName()) {
               
                // create element for named content component
                ElementElement element = buildElement(comp, repeat, hold);
                if (comp instanceof StructureElementBase) {
                    addItemDocumentation((StructureElementBase)comp, element);
                }
                cdef.getParticleList().add(element);
               
            } else if (comp instanceof ContainerElementBase) {
                ContainerElementBase contain = (ContainerElementBase)comp;
                boolean iscoll = comp instanceof CollectionElement;
                if (contain.children().size() > 0) {
                   
                    // no element name, but children; handle with recursive call
                    CommonCompositorDefinition part = buildCompositor(contain, 0, iscoll, hold);
                    addCompositorPart(part, cdef);
                   
                } else if (iscoll) {
                   
                    // collection without a wrapper element
                    CollectionElement coll = (CollectionElement)comp;
                    String itype = coll.getItemTypeName();
                    TemplateElementBase ref = coll.getDefinitions().getSpecificTemplate(itype);
                    if (ref instanceof MappingElement) {
                       
                        // item type with concrete mapping, make it an element
                        MappingDetail detail = m_detailDirectory.getMappingDetail((MappingElementBase)ref);
                        ElementElement item = new ElementElement();
                        QName oname = detail.getOtherName();
                        setElementRef(oname, item, hold);
                        item.setMinOccurs(Count.COUNT_ZERO);
                        item.setMaxOccurs(Count.COUNT_UNBOUNDED);
                        addItemDocumentation(coll, item);
                        cdef.getParticleList().add(item);
                       
                    } else {
                       
                        // TODO: handle this with xs:any strict?
                        m_context.addWarning("Handling not implemented for unspecified mapping", coll);
                    }
                   
                } else if (comp instanceof StructureElement) {
                   
                    // no children, must be mapping reference
                    StructureElement struct = (StructureElement)comp;
                    MappingElementBase ref = (MappingElementBase)struct.getEffectiveMapping();
                    if (ref == null) {
                       
                        // TODO: handle this with xs:any strict?
                        m_context.addWarning("Handling not implemented for unspecified mapping", struct);
                       
                    } else {
                       
                        // handle mapping reference based on form and name use
                        MappingDetail detail = m_detailDirectory.getMappingDetail(ref);
                        if (ref.isAbstract()) {
                           
                            // abstract inline treated as group
                            GroupRefElement group = new GroupRefElement();
                            setGroupRef(detail.getOtherName(), group, hold);
                            if (comp.isOptional()) {
                                group.setMinOccurs(Count.COUNT_ZERO);
                            }
                            cdef.getParticleList().add(group);
                           
                        } else {
                           
                            // concrete treated as element reference
                            ElementElement elem = new ElementElement();
                            setElementRef(detail.getOtherName(), elem, hold);
                            if (comp.isOptional()) {
                                elem.setMinOccurs(Count.COUNT_ZERO);
                            }
                            addItemDocumentation(struct, elem);
                            cdef.getParticleList().add(elem);
                           
                        }
View Full Code Here

TOP

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

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.