Package org.jibx.schema.codegen.custom

Examples of org.jibx.schema.codegen.custom.SchemaCustom


        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            ISchemaResolver resolver = schema.getResolver();
            s_logger.debug("Assigning customization for schema " + ++count + ": " + resolver.getName());
            SchemasetCustom owner = findSchemaset(schema, m_global);
            SchemaCustom custom = owner.forceCustomization(resolver.getName(), resolver.getId(), schema,
                m_validationContext);
            custom.validate(m_validationContext);
            custom.extend(null, m_validationContext);
        }
       
        // check all the customizations
        m_global.checkSchemas(m_validationContext);
        return !reportProblems(m_validationContext);
View Full Code Here


        }
       
        // finish by flagging global definitions requiring separate classes
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            SchemaCustom custom = findSchemaset(schema, m_global).getCustomization(schema.getResolver().getId());
            if (custom.isGenerateAll()) {
                int count = schema.getChildCount();
                for (int i = 0; i < count; i++) {
                    SchemaBase comp = schema.getChild(i);
                    if (comp.type() == SchemaBase.ELEMENT_TYPE || comp.type() == SchemaBase.COMPLEXTYPE_TYPE) {
                        Object obj = comp.getExtension();
View Full Code Here

        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            ISchemaResolver resolver = schema.getResolver();
            s_logger.debug("Assigning customization for schema " + ++count + ": " + resolver.getName());
            SchemasetCustom owner = findSchemaset(schema, m_global);
            SchemaCustom custom = owner.forceCustomization(resolver.getName(), resolver.getId(), schema,
                m_validationContext);
            custom.validate(m_validationContext);
            String pname = custom.getPackage();
            PackageHolder holder = null;
            if (pname == null) {
                String uri = schema.getEffectiveNamespace();
                if (uri == null) {
                    uri = "";
                }
                holder = m_packageDirectory.getPackageForUri(uri);
            } else {
                holder = m_packageDirectory.getPackage(pname);
            }
            custom.extend(holder, m_validationContext);
        }
       
        // check all the customizations
        m_global.checkSchemas(m_validationContext);
        return !m_validationContext.reportProblems(handler);
View Full Code Here

       
        // finish by flagging global definitions requiring separate classes
        TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
        for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) {
            SchemaElement schema = (SchemaElement)iter.next();
            SchemaCustom custom = ((SchemaExtension)schema.getExtension()).getCustom();
            if (custom.isGenerateAll()) {
                int count = schema.getChildCount();
                for (int i = 0; i < count; i++) {
                   
                    // check if this global needs a class
                    SchemaBase comp = schema.getChild(i);
View Full Code Here

        // count the actual values in the structure
        int count = 0;
        for (Item item = group.getFirstChild(); item != null; item = item.getNext()) {
           
            // get the schema customization information
            SchemaCustom custom = ((SchemaExtension)item.getSchemaComponent().getSchema().getExtension()).getCustom();
           
            // handle inlining of references
            if (item instanceof ReferenceItem) {
               
                // first make sure the definition has been checked for inlining
                ReferenceItem reference = (ReferenceItem)item;
                DefinitionItem definition = reference.getDefinition();
                checkInline(definition, depth + 1, defs);
                if (definition.isInline()) {
                   
                    // convert the reference to an inline copy of the definition
                    item = reference.inlineReference();
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug(SchemaUtils.getIndentation(depth) + "converted reference to "
                            + SchemaUtils.describeComponent(definition.getSchemaComponent()) + " to inline group");
                    }
                   
                }
            }
           
            // handle actual item count, and inlining of child group (may be new, from converted reference)
            if (item instanceof GroupItem) {
               
                // check count for nested group
                GroupItem grpitem = (GroupItem)item;
                int grpcount = computeComplexity(grpitem, depth + 1, defs);
               
                // avoid inlining if an enumeration, or an extension reference; or the nested group is optional or a
                //  collection and has more than one item (or a single item which is itself optional or a collection,
                //  which will be counted as multiple items); or the main group is a choice, and the nested group is a
                //  compositor with more than one element, and the first element is optional (or the first element child
                //  of that element, if inlined) - but allow override from customizations
                boolean inline = true;
                ComponentExtension exten = grpitem.getComponentExtension();
                if (exten.isSeparateClass()) {
                    inline = false;
                } else {
                    if (grpitem.isEnumeration()) {
                        inline = false;
                    } else if (grpitem.isCollection() || grpitem.isOptional()) {
                        if (grpcount > 1) {
                            inline = false;
                        } else {
                           
                            // must be single child, but block inlining if that child is optional or an element or
                            //  attribute with simple value (since we need an object for the optional part, separate
                            //  from the simple value)
                            Item child;
                            GroupItem childgrp = grpitem;
                            boolean named = false;
                            while ((child = childgrp.getFirstChild()) instanceof GroupItem) {
                                childgrp = (GroupItem)child;
                                if (childgrp.isOptional()) {
                                    inline = false;
                                    break;
                                }
                                if (!named && childgrp.isTopmost()) {
                                    int type = childgrp.getSchemaComponent().type();
                                    named = type == SchemaBase.ATTRIBUTE_TYPE || type == SchemaBase.ELEMENT_TYPE;
                                }
                            }
                            if (named && child instanceof ValueItem) {
                                inline = false;
                            }
                           
                        }
                    } else if (grpcount > 1 && group.getSchemaComponent().type() == SchemaBase.CHOICE_TYPE) {
                       
                        // assume no inlining, but dig into structure to make sure first non-inlined element is required
                        inline = false;
                        Item child = grpitem.getFirstChild();
                        while (!child.isOptional()) {
                            if (child.getSchemaComponent().type() == SchemaBase.ELEMENT_TYPE &&
                                !(child instanceof GroupItem && ((GroupItem)child).isInline())) {
                               
                                // required element with simple value or separate class, safe to inline
                                inline = true;
                                break;
                               
                            } else if (child instanceof GroupItem) {
                                child = ((GroupItem)child).getFirstChild();
                                if (child == null) {
                                   
                                    // empty group, safe to inline
                                    inline = true;
                                    break;
                                   
                                }
                            } else {
                               
                                // required reference item, safe to inline
                                inline = true;
                                break;
                               
                            }
                        }
                       
                    }
                }
                if (inline) {
                   
                    // inline the group
                    if (!grpitem.isInline()) {
                        grpitem.setInline(true);
                    }
                    count += grpcount;
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug(SchemaUtils.getIndentation(depth) + "inlining "
                            + (grpitem instanceof DefinitionItem ? "definition " : "group ")
                            + SchemaUtils.describeComponent(grpitem.getSchemaComponent()) + " with item count " +
                            count);
                    }
                   
                } else {
                   
                    // force separate class for group
                    grpitem.setInline(false);
                    count++;
                   
                }
               
            } else {
                count++;
            }
           
            // bump up the complexity if the item is repeated (optionally inlining collection wrappers)
            if (!custom.isNullCollectionAllowed() && item.isCollection()) {
                count++;
            }
        }
        return count > 1 ? 2 : count;
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    private SchemasetCustom defaultSchemasetCustom(Map<String, Element> smap) {
        SchemasetCustom customRoot = new SchemasetCustom((SchemasetCustom)null);
        Set<String> schemaIds = smap.keySet();
        for (String schemaId : schemaIds) {
            SchemaCustom schemaCustom = new SchemaCustom(customRoot);
            schemaCustom.setName(schemaId);
            schemaCustom.setForceTypes(Boolean.TRUE);
            schemaCustom.setNamespace(smap.get(schemaId).getAttribute("targetNamespace"));
            customRoot.getChildren().add(schemaCustom);
        }
        for (JibxSchemaResolver r : resolvers) {
            if (!schemaIds.contains(r.getId())) {
                SchemaCustom schemaCustom = new SchemaCustom(customRoot);
                schemaCustom.setName(r.getName());
                schemaCustom.setNamespace(r.getElement().getAttribute("targetNamespace"));
                schemaCustom.setForceTypes(Boolean.TRUE);
                customRoot.getChildren().add(schemaCustom);
            }
        }
        return customRoot;
    }
View Full Code Here

    }

    private static void forceTypes(SchemasetCustom customRoot) {
        List<?> children = customRoot.getChildren();
        for (Object child : children) {
            SchemaCustom schemaCustom = (SchemaCustom)child;
            schemaCustom.setForceTypes(Boolean.TRUE);
        }
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    private SchemasetCustom defaultSchemasetCustom(Map<String, Element> smap) {
        SchemasetCustom customRoot = new SchemasetCustom((SchemasetCustom)null);
        Set<String> schemaIds = smap.keySet();
        for (String schemaId : schemaIds) {
            SchemaCustom schemaCustom = new SchemaCustom(customRoot);
            schemaCustom.setName(schemaId);
            schemaCustom.setForceTypes(Boolean.TRUE);
            customRoot.getChildren().add(schemaCustom);
        }
        for (ISchemaResolver r : resolvers) {
            SchemaCustom schemaCustom = new SchemaCustom(customRoot);
            schemaCustom.setName(r.getName());
            schemaCustom.setForceTypes(Boolean.TRUE);
            customRoot.getChildren().add(schemaCustom);                   
        }
        return customRoot;
    }
View Full Code Here

    }

    private static void forceTypes(SchemasetCustom customRoot) {
        List<?> children = customRoot.getChildren();
        for (Object child : children) {
            SchemaCustom schemaCustom = (SchemaCustom)child;
            schemaCustom.setForceTypes(Boolean.TRUE);
        }
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    private SchemasetCustom defaultSchemasetCustom(Map<String, Element> smap) {
        SchemasetCustom customRoot = new SchemasetCustom((SchemasetCustom)null);
        Set<String> schemaIds = smap.keySet();
        for (String schemaId : schemaIds) {
            SchemaCustom schemaCustom = new SchemaCustom(customRoot);
            schemaCustom.setName(schemaId);
            schemaCustom.setForceTypes(Boolean.TRUE);
            schemaCustom.setNamespace(smap.get(schemaId).getAttribute("targetNamespace"));
            customRoot.getChildren().add(schemaCustom);
        }
        for (JibxSchemaResolver r : resolvers) {
            if (!schemaIds.contains(r.getId())) {
                SchemaCustom schemaCustom = new SchemaCustom(customRoot);
                schemaCustom.setName(r.getName());
                schemaCustom.setNamespace(r.getElement().getAttribute("targetNamespace"));
                schemaCustom.setForceTypes(Boolean.TRUE);
                customRoot.getChildren().add(schemaCustom);
            }
        }
        return customRoot;
    }
View Full Code Here

TOP

Related Classes of org.jibx.schema.codegen.custom.SchemaCustom

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.