Package org.jibx.binding.model

Examples of org.jibx.binding.model.MappingElement


        JavaClass clas = cf.getRawClass();
        if (m_verbose) {
            System.out.println("\nBuilding mapping definition for " +
                clas.getClassName());
        }
        MappingElementBase element = new MappingElement();
        element.setAbstract(abstr || clas.isAbstract() || clas.isInterface());
        String name = clas.getClassName();
        element.setClassName(name);
        if (abstr) {
            element.setAbstract(true);
        } else {
            element.setName((String)m_mappedNames.get(name));
        }
        m_structureStack.push(name);
        defineStructure(cf, element);
        m_structureStack.pop();
        return element;
View Full Code Here


       
        // finish with custom mapping definitions
        for (Iterator iter = customs.keySet().iterator(); iter.hasNext();) {
            String cname = (String)iter.next();
            String mname = (String)customs.get(cname);
            MappingElementBase mapping = new MappingElement();
            mapping.setComment(" specified mapping for class " + cname);
            mapping.setClassName(cname);
            mapping.setName((String)m_mappedNames.get(cname));
            mapping.setMarshallerName(mname);
            mapping.setUnmarshallerName(mname);
            binding.addTopChild(mapping);
        }
       
        // list classes handled if verbose
        if (m_verbose) {
View Full Code Here

            m_context.tourTree((BindingElement)iter.next(), visitor);
        }
       
        // flag all mappings referenced as base types to be defined as types
        for (Iterator iter = m_forceTypeMappings.iterator(); iter.hasNext();) {
            MappingElement mapping = (MappingElement)iter.next();
            MappingDetail detail = (MappingDetail)m_mappingMap.get(mapping);
            detail.setType(true);
        }
    }
View Full Code Here

                   
                    // find implied mapping, if one defined
                    String type = itype.getName();
                    TemplateElementBase ref = collect.getDefinitions().getSpecificTemplate(type);
                    if (ref instanceof MappingElement) {
                        MappingElement mapref = (MappingElement)ref;
                        MappingDetail detail = forceMappingDetail(mapref);
                        detail.setElement(true);
                    }
                }
               
                // check for nested type reference(s)
                checkReferences(collect, null);
               
            } else if (child instanceof StructureElement) {
               
                // structure, check for nested definition
                StructureElement struct = (StructureElement)child;
                if (struct.children().size() > 0) {
                   
                    // just handle references from nested components
                    checkReferences(struct, null);
                   
                } else {
                   
                    // no nested definition, check for mapping reference
                    MappingElement ref = (MappingElement)struct.getEffectiveMapping();
                    if (ref == null) {
                        m_context.addError("No handling defined for empty structure with no mapping reference", struct);
                    } else {
                       
                        // get the referenced mapping information
                        MappingDetail detail = forceMappingDetail(ref);
                        if (struct.hasDirectName()) {
                            if (ref.isAbstract()) {
                               
                                // named element referencing the mapping implies it's a type definition
                                detail.setType(true);
                               
                            } else {
                               
                                // concrete with name should never happen
                                m_context.addError("No handling defined for name on concrete mapping reference", struct);
                               
                            }
                        } else {
                            if (ref.getName() == null) {
                               
                                // abstract inline treated as group
                                detail.setGroup(true);
                               
                            } else {
View Full Code Here

     * @return detail
     */
    private MappingDetail addDetail(MappingElement map) {
       
        // check structure of mapping definition for schema type extension
        MappingElement base = null;
        StructureElement baseref = null;
        ArrayList contents = map.getContentComponents();
        if (contents.size() > 0) {
           
            // type extension requires reference as first content component
            Object content = contents.get(0);
            if (content instanceof StructureElement) {
                StructureElement struct = (StructureElement)content;
                if (isTypeDerivation(struct)) {
                    base = (MappingElement)struct.getEffectiveMapping();
                    baseref = struct;
                }
            }
        }
       
        // next search recursively for text and/or child element components this is done at this point (with loop
        //  recursion, if needed) so that the flags can be set when creating the detail instance
        boolean haschild = false;
        boolean hastext = false;
        ArrayList expands = new ArrayList();
        expands.add(map);
        for (int i = 0; i < expands.size(); i++) {
           
            // check for container with element name or text content
            ContainerElementBase contain = (ContainerElementBase)expands.get(i);
            contents = contain.getContentComponents();
            for (int j = 0; j < contents.size(); j++) {
                IComponent comp = (IComponent)contents.get(j);
                if (comp.hasName()) {
                   
                    // component with name means child element
                    haschild = true;
                   
                } else if (comp instanceof ValueElement) {
                   
                    // value with no name implies text content
                    hastext = true;
                   
                } else if (comp instanceof CollectionElement) {
                   
                    // collection implies child element (repeating)
                    haschild = true;
                   
                } else {
                   
                    // structure, check for mapping reference
                    StructureElement struct = (StructureElement)comp;
                    if (struct.children().size() > 0) {
                       
                        // add container structure to expansion list
                        expands.add(comp);
                       
                    } else {
                        MappingElementBase ref = (MappingElementBase)struct.getEffectiveMapping();
                        if (ref != null) {
                           
                            // mapping element reference, check if named
                            if (ref.getName() != null) {
                                haschild = true;
                            } else {
                                expands.add(ref);
                                m_forceTypeMappings.add(ref);
                            }
                        }
                    }
                }
            }
        }
       
        // get the names for this mapping
        ClassCustom custom = m_custom.addClassCustomization(map.getClassName());
        QName tname = map.getTypeQName();
        if (tname == null) {
            NamespaceElement dfltns = map.getDefinitions().getElementDefaultNamespace();
            if (dfltns != null) {
                tname = new QName(dfltns.getUri(), custom.getTypeQName().getName());
            } else {
                tname = custom.getTypeQName();
            }
        }
        QName oname = null;
        String name = map.getName();
        if (name == null) {
            oname = custom.getElementQName();
        } else {
            oname = new QName(map.getNamespace().getUri(), name);
        }
       
        // add new mapping detail based on information found
        MappingDetail detail = new MappingDetail(map, haschild, hastext, base, tname, oname);
        m_mappingMap.put(map, detail);
       
        // check for mapping to element name
        if (map.getName() == null) {
           
            // require base type generation as type
            if (base != null) {
                MappingDetail basedetail = forceMappingDetail(base);
                basedetail.setType(true);
            }
           
        } else {
           
            // force generating an element for this mapping
            detail.setElement(true);
        }
       
        // error if mapping extension doesn't map to type extension
        MappingElement extended = map.getExtendsMapping();
        if (extended != null) {
           
            // recursively check for extension type match
            boolean isext = false;
            MappingElement ancest = base;
            while (ancest != null) {
                if (ancest.getClassName().equals(extended.getClassName())) {
                    isext = true;
                    break;
                } else {
                    ancest = forceMappingDetail(ancest).getExtensionBase();
                }
View Full Code Here

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

            // check for either not an array, or plain doc/lit
            String type = value.getWorkingType();
            if (doclit || !type.endsWith("[]")) {
               
                // create abstract mapping for collection class type
                MappingElementBase mapping = new MappingElement();
                mapping.setClassName(type);
                mapping.setAbstract(true);
                mapping.setCreateType(value.getCreateType());
                mapping.setFactoryName(value.getFactoryMethod());
               
                // generate the mapping type name from item class name and suffix
                String suffix;
                GlobalCustom global = m_generationParameters.getGlobal();
                IClass clas = global.getClassInfo(type);
                if (clas.isImplements("Ljava/util/List;")) {
                    suffix = "List";
                } else if (clas.isImplements("Ljava/util/Set;")) {
                    suffix = "Set";
                } else {
                    suffix = "Collection";
                }
                String itype = value.getItemType();
                ClassCustom cust = global.addClassCustomization(itype);
               
                // register the type name for mapping
                String name = cust.getSimpleName() + suffix;
                String uri = bind.getNamespace();
                qname = new QName(uri, CustomBase.convertName(name, CustomBase.CAMEL_CASE_NAMES));
                mapping.setTypeQName(qname);
                bind.addTypeNameReference(uri, uri);
                typemap.put(ptype, qname);
               
                // add collection definition details
                CollectionElement coll = new CollectionElement();
                m_bindingGenerator.defineCollection(itype, value.getItemName(), coll, bind);
                mapping.addChild(coll);
               
                // add mapping to binding
                bind.addMapping(mapping);
            }
        }
View Full Code Here

           
            // fill details directly to this mapping unless abstract also created
            mainmapping = mapcon;
           
        }
        MappingElement mapabs = null;
        if (detail.isUseAbstract()) {
           
            // create abstract mapping
            mapabs = createMapping(type, cust);
            mapabs.setAbstract(true);
            qname = detail.getTypeQName();
            mapabs.setTypeQName(qname);
            detail.setAbstractMapping(mapabs);
           
            // use abstract mapping for details (concrete will reference this one)
            mainmapping = mapabs;
           
View Full Code Here

     * @param type
     * @param cust
     * @return mapping
     */
    private MappingElement createMapping(String type, ClassCustom cust) {
        MappingElement mapabs;
        mapabs = new MappingElement();
        mapabs.setClassName(type);
        mapabs.setCreateType(cust.getCreateType());
        mapabs.setFactoryName(cust.getFactoryMethod());
        return mapabs;
    }
View Full Code Here

                m_bindingDirectory.addFormat(format);
               
            } else {
               
                // construct mapping element
                MappingElementBase mapping = new MappingElement();
                mapping.setClassName(clas.getBindingName());
                if (comp.type() == SchemaBase.ELEMENT_TYPE) {
                   
                    // abstract or concrete mapping for element
                    ElementElement element = (ElementElement)comp;
                    setName(element.getEffectiveQName(), mapping, holder);
                    mapping.setAbstract(element.isAbstract());
                    QName group = element.getSubstitutionGroup();
                    if (group != null) {
                        ElementElement base = m_validationContext.findElement(group);
                        DefinitionItem basedef = ((GlobalExtension)base.getExtension()).getDefinition();
                        mapping.setExtendsName(basedef.getGenerateClass().getFullName());
                    }
                   
                } else {
                   
                    // abstract mapping for type definition or group
                    mapping.setAbstract(true);
                    QName qname = definition.getQName();
                    mapping.setTypeQName(qname);
                    String uri = qname.getUri();
                    if (uri != null) {
                        m_bindingDirectory.addTypeNameReference(holder, uri, schema);
                    }
                   
                }
               
                // add the mapping to binding and set on class
                holder.addMapping(mapping);
                ((StructureClassHolder)clas).setBinding(mapping);
                DefinitionItem elementdef = (DefinitionItem)typeinst.get(definition);
                if (elementdef != null) {
                   
                    // create mapping for element name linked to type
                    ElementElement element = (ElementElement)elementdef.getSchemaComponent();
                    SchemaElement elschema = element.getSchema();
                    MappingElementBase elmapping = new MappingElement();
                    elmapping.setClassName(clas.getBindingName());
                    elmapping.setAbstract(element.isAbstract());
                   
                    // handle linking to substitution group head using extends mapping
                    QName group = element.getSubstitutionGroup();
                    if (group != null) {
                        ElementElement base = m_validationContext.findElement(group);
                        DefinitionItem basedef = ((GlobalExtension)base.getExtension()).getDefinition();
                        elmapping.setExtendsName(basedef.getGenerateClass().getFullName());
                    }
                   
                    // create single structure child invoking the type mapping
                    holder = m_bindingDirectory.getRequiredBinding(elschema);
                    setName(element.getEffectiveQName(), elmapping, holder);
                    StructureElement struct = new StructureElement();
                    QName qname = mapping.getTypeQName();
                    String uri = qname.getUri();
                    if (uri != null) {
                        m_bindingDirectory.addTypeNameReference(holder, uri, schema);
                    }
                    struct.setMapAsQName(qname);
                    elmapping.addChild(struct);
                    holder.addMapping(elmapping);
                   
                }
            }
           
View Full Code Here

TOP

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

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.