Package org.jibx.schema.elements

Examples of org.jibx.schema.elements.OpenAttrBase


            }
        }
       
        // handle normal element expansion
        if (root instanceof OpenAttrBase) {
            OpenAttrBase parent = (OpenAttrBase)root;
            int count = parent.getChildCount();
            for (int i = 0; i < count; i++) {
                walkElement(parent.getChild(i), visitor);
            }
        }
    }
View Full Code Here


       
        // TODO: remove this once union handling fully implemented
        SchemaVisitor visitor = new SchemaVisitor() {
           
            public void exit(UnionElement node) {
                OpenAttrBase parent = node.getParent();
                int count = parent.getChildCount();
                for (int i = 0; i < count; i++) {
                    if (parent.getChild(i) == node) {
                        SimpleRestrictionElement empty = new SimpleRestrictionElement();
                        empty.setBase(SchemaTypes.STRING.getQName());
                        parent.replaceChild(i, empty);
                        break;
                    }
                }
            }
           
View Full Code Here

                }
                for (int i = base; i < limit; i++) {
                   
                    // make sure component is a user type (not schema type)
                    AnnotatedBase ref = (AnnotatedBase)m_newReferences.get(i);
                    OpenAttrBase parent = ref.getParent();
                    if (parent instanceof SchemaElement) {
                       
                        // expand reference from this component
                        s_logger.debug(" adding reference closure for " + SchemaUtils.describeComponent(ref));
                        m_tracker.setNameRegister(((SchemaElement)parent).getRegister());
View Full Code Here

     * @param node
     * @return name
     */
    protected static String describe(DataNode node) {
        DataNode current = node;
        OpenAttrBase last;
        String name = null;
        String alttext = null;
        do {
            OpenAttrBase comp = current.getSchemaComponent();
            last = comp;
            if (comp instanceof INamed) {
                String check = ((INamed)comp).getName();
                if (check != null) {
                    int type = comp.type();
                    if (type == SchemaBase.ATTRIBUTE_TYPE || type == SchemaBase.ELEMENT_TYPE) {
                        name = check;
                    } else if (alttext == null) {
                        alttext = "'" + check + "' " + comp.name();
                    }
                }
            }
            if (name == null && comp instanceof IReference) {
                QName ref = ((IReference)comp).getRef();
                if (ref != null) {
                    name = ref.getName();
                }
            }
            if (name != null) {
                return "'" + name + "' " + comp.name();
            }
            current = current.getParent();
        } while (current != null && ((ParentNode)current).getChildren().size() == 1);
        if (alttext == null) {
            return last.name();
View Full Code Here

        } else {
            if (matches.size() > 1) {
                vctx.addWarning("Found " + matches.size() + " matches for customization expression", custom);
            }
            for (Iterator iter = matches.iterator(); iter.hasNext();) {
                OpenAttrBase target = (OpenAttrBase)iter.next();
                custom.apply((ComponentExtension)target.getExtension(), vctx);
            }
        }
    }
View Full Code Here

        if (m_includes != null || m_excludes != null) {
            foundset = new HashSet();
        }
        TreeWalker wlkr = new TreeWalker(null, new SchemaContextTracker());
        for (Iterator iter = globals.iterator(); iter.hasNext();) {
            OpenAttrBase global = (OpenAttrBase)iter.next();
            if (global instanceof INamed) {
               
                // set up the basic global definition extension
                GlobalExtension exten = new GlobalExtension(m_extension, global);
                String name = ((INamed)global).getName();
                boolean exclude = exclset.contains(name);
                exten.setRemoved(exclude);
                if (exclude) {
                    foundset.add(name);
                }
                boolean include = inclset.contains(name);
                exten.setIncluded(include);
                if (include) {
                    foundset.add(name);
                }
               
                // initialize extensions for full tree of non-excluded global definition components
                if (!exten.isRemoved()) {
                    extendGlobal(builder, wlkr, exten);
                } else if (global.type() == SchemaBase.SIMPLETYPE_TYPE ||
                    global.type() == SchemaBase.COMPLEXTYPE_TYPE) {
                    setReplacement(((INamed)global).getQName(), null);
                }
            }
        }
        // TreeWalker.setLogging(level);
       
        // report any names not found
        if (foundset.size() < exclset.size() + inclset.size()) {
            Set mergeset = new HashSet();
            mergeset.addAll(exclset);
            mergeset.addAll(inclset);
            for (Iterator iterator = mergeset.iterator(); iterator.hasNext();) {
                String name = (String)iterator.next();
                if (!foundset.contains(name)) {
                    vctx.addWarning("Name '" + name + "' not found in schema", this);
                }
            }
        }
       
        // use child customizations to amend the generated extensions
        int size = getChildren().size();
        for (int i = 0; i < size; i++) {
            ComponentCustom custom = (ComponentCustom)getChildren().get(i);
            SchemaPath path = custom.buildPath(vctx);
            if (path != null) {
                if (path.isWildStart()) {
                    vctx.addError("Top level customizations cannot use wildcard as first step", custom);
                } else {
                   
                    // match only the first path step
                    OpenAttrBase match = path.partialMatchUnique(0, 0, m_schema);
                    if (s_logger.isDebugEnabled()) {
                        if (match == null) {
                            s_logger.debug("No global schema component found for customization " + custom);
                        } else {
                            s_logger.debug("Matched customization " + custom + " to global schema component "
                                + SchemaUtils.describeComponent(match));
                        }
                    }
                    if (match != null) {
                        String name = ((INamed)match).getName();
                        GlobalExtension exten = (GlobalExtension)match.getExtension();
                        if (custom.isExcluded()) {
                           
                            // check if customization applies to descendant of global definition component
                            if (path.getPathLength() == 1) {
                               
                                // force exclude if generation skipped by customization
                                if (exten.isIncluded()) {
                                    vctx.addWarning("Name '" + name
                                        + "' is on include list for schema, but excluded by customization", custom);
                                }
                                exten.setIncluded(false);
                                exten.setRemoved(true);
                               
                            } else {
                               
                                // apply customization to target component extension(s)
                                applyRemainingCustomizationPath(path, match, custom, vctx);
                               
                            }
                           
                        } else {
                           
                            // check for customization for global excluded at schema level
                            if (exten.isRemoved()) {
                                vctx.addWarning("Name '" + name
                                    + "' is on excludes list for schema, but has a customization", custom);
                                exten.setRemoved(false);
                                extendGlobal(builder, wlkr, exten);
                            }
                           
                            // check if customization applies to descendant of global definition component
                            if (path.getPathLength() > 1) {
                                applyRemainingCustomizationPath(path, match, custom, vctx);
                            } else {
                                custom.apply((ComponentExtension)match.getExtension(), vctx);
                            }
                           
                        }
                    }
                }
            }
        }
       
        // flag extensions for facets to be removed from schema
        SchemaVisitor visitor = new FacetRemoverVisitor(this);
        for (Iterator iter = globals.iterator(); iter.hasNext();) {
            OpenAttrBase global = (OpenAttrBase)iter.next();
            ComponentExtension exten = (ComponentExtension)global.getExtension();
            if (exten != null && !exten.isRemoved()) {
                wlkr.walkElement(global, visitor);
            }
        }
    }
View Full Code Here

     */
    public void checkRemovable() {
        if (!isRemoved()) {
            if (m_referenceCount > 0) {
                if (s_logger.isDebugEnabled()) {
                    OpenAttrBase component = getComponent();
                    s_logger.debug("Retaining " + ((INamed)component).getQName() + " from schema " +
                        ((SchemaElement)component.getParent()).getResolver().getName() + " with " + m_referenceCount +
                        " references");
                }
            } else if (!m_included && !isRemoved() && m_referenceCount == 0) {
               
                // flag definition for deletion
                setRemoved(true);
                if (s_logger.isDebugEnabled()) {
                    OpenAttrBase component = getComponent();
                    s_logger.debug(" Flagging deletion of " + ((INamed)component).getQName() + " from schema " +
                        ((SchemaElement)component.getParent()).getResolver().getName());
                }
               
                // recursively adjust the usage counts for dependencies
                for (int j = 0; j < getDependencyCount(); j++) {
                    GlobalExtension dependency = getDependency(j);
View Full Code Here

     * @param vctx validation context
     */
    public void applyAndCountUsage(ValidationContext vctx) {
       
        // handle type substitutions for this component
        OpenAttrBase component = getComponent();
        boolean delete = false;
        switch (component.type())
        {
           
            case SchemaBase.ATTRIBUTE_TYPE:
            {
                if (isIgnored()) {
                    delete = true;
                } 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);
                        }
                    }
                    if (changed) {
                        if (repls.size() > 0) {
                            union.setMemberTypes((QName[])repls.toArray(new QName[repls.size()]));
                        } else {
                            union.setMemberTypes(null);
                        }
                    }
                }
                break;
            }
               
        }
        if (delete) {
           
            // raise deletion to containing removable component
            SchemaBase parent = component;
            SchemaBase remove = null;
            loop: while (parent != null) {
                switch (parent.type())
                {
                   
                    case SchemaBase.ATTRIBUTE_TYPE:
                    case SchemaBase.ATTRIBUTEGROUP_TYPE:
                    case SchemaBase.ELEMENT_TYPE:
                    case SchemaBase.GROUP_TYPE:
                        remove = parent;
                        break loop;
                   
                    case SchemaBase.COMPLEXTYPE_TYPE:
                    case SchemaBase.SIMPLETYPE_TYPE:
                        remove = parent;
                        parent = parent.getParent();
                        break;
                   
                    default:
                        if (remove == null) {
                            parent = parent.getParent();
                            break;
                        } else {
                            break loop;
                        }
                       
                }
            }
            if (remove == null) {
                throw new IllegalStateException("Internal error: no removable ancestor found for component "
                    + SchemaUtils.describeComponent(component));
            } else {
                ((ComponentExtension)remove.getExtension()).setRemoved(true);
            }
           
        } else {
           
            // process all child component extensions
            boolean modified = false;
            for (int i = 0; i < component.getChildCount(); i++) {
                SchemaBase child = component.getChild(i);
                ComponentExtension exten = (ComponentExtension)child.getExtension();
                if (!exten.isRemoved()) {
                    exten.applyAndCountUsage(vctx);
                }
                if (exten.isRemoved()) {
                    removeChild(i);
                    modified = true;
                }
            }
            if (modified) {
                component.compactChildren();
            }
        }
    }
View Full Code Here

    protected boolean normalize(int depth) {
       
        // initialize debug handling
        String path = null;
        String lead = null;
        OpenAttrBase topcomp = getComponent();
        if (s_logger.isDebugEnabled()) {
            path = SchemaUtils.componentPath(topcomp);
            lead = SchemaUtils.getIndentation(depth);
            s_logger.debug(lead + "entering normalization for node " + path);
        }
       
        // normalize each child component in turn
        int count = topcomp.getChildCount();
        boolean modified = false;
        boolean compact = false;
        for (int i = 0; i < count; i++) {
            SchemaBase child = topcomp.getChild(i);
            if (child instanceof OpenAttrBase) {
               
                // start by normalizing the child component content
                OpenAttrBase childcomp = (OpenAttrBase)child;
                ComponentExtension childext = (ComponentExtension)childcomp.getExtension();
                if (childext.normalize(depth+1)) {
                    modified = true;
                }
               
                // check for child components with special normalization handling
                switch (childcomp.type()) {
                   
                    case SchemaBase.ALL_TYPE:
                    case SchemaBase.CHOICE_TYPE:
                    case SchemaBase.SEQUENCE_TYPE:
                    {
                        // child component is a compositor, so see if it can be deleted or replaced
                        CommonCompositorDefinition compositor = (CommonCompositorDefinition)childcomp;
                        int size = compositor.getParticleList().size();
                        if (size == 0) {
                           
                            // empty compositor, just remove (always safe to do this)
                            childext.setRemoved(true);
                            modified = true;
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug(lead + "eliminated empty compositor " + path);
                            }
                           
                        } else if (size == 1) {
                           
                            // single component in compositor, first try to convert compositor to singleton
                            OpenAttrBase grandchild = (OpenAttrBase)compositor.getParticleList().get(0);
                            IArity particle = (IArity)grandchild;
                            if (SchemaUtils.isRepeated(compositor)) {
                                if (!SchemaUtils.isRepeated(particle)) {
                                   
                                    // repeated compositor with non-repeated particle, so pass repeat to particle
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug(lead + "passing repeat from compositor " +
                                            SchemaUtils.componentPath(childcomp) + " to only child " +
                                            SchemaUtils.describeComponent(grandchild));
                                    }
                                    particle.setMaxOccurs(compositor.getMaxOccurs());
                                    ((ComponentExtension)grandchild.getExtension()).setRepeated(true);
                                    compositor.setMaxOccurs(null);
                                    ((ComponentExtension)compositor.getExtension()).setRepeated(false);
                                   
                                } else if ((compositor.getMaxOccurs().isUnbounded() &&
                                    particle.getMaxOccurs().isUnbounded())) {
                                   
                                    // unbounded compositor with unbounded particle, just wipe repeat from compositor
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug(lead + "clearing unbounded from compositor " +
                                            SchemaUtils.componentPath(childcomp) + " with unbounded only child " +
                                            SchemaUtils.describeComponent(grandchild));
                                    }
                                    compositor.setMaxOccurs(null);
                                    ((ComponentExtension)compositor.getExtension()).setRepeated(false);
                                   
                                }
                            }
                            if (SchemaUtils.isOptional(compositor)) {
                                if (SchemaUtils.isOptional(particle)) {
                                   
                                    // optional compositor with optional particle, just wipe optional from compositor
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug(lead + "clearing optional from compositor " +
                                            SchemaUtils.componentPath(childcomp) + " with optional only child " +
                                            SchemaUtils.describeComponent(grandchild));
                                    }
                                    compositor.setMinOccurs(null);
                                    ((ComponentExtension)compositor.getExtension()).setOptional(false);
                                   
                                } else if (Count.isCountEqual(1, particle.getMinOccurs())) {
                                   
                                    // optional compositor with required particle, so pass optional to particle
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug(lead + "passing optional from compositor " +
                                            SchemaUtils.componentPath(childcomp) + " to required only child " +
                                            SchemaUtils.describeComponent(grandchild));
                                    }
                                    particle.setMinOccurs(Count.COUNT_ZERO);
                                    ((ComponentExtension)grandchild.getExtension()).setOptional(true);
                                    compositor.setMinOccurs(null);
                                    ((ComponentExtension)compositor.getExtension()).setOptional(false);
                                   
                                }
                            }
View Full Code Here

                        List matches = path.partialMatchMultiple(0, path.getPathLength()-1, exten.getComponent());
                        if (matches.size() == 0) {
                            vctx.addWarning("No matches found for customization expression", child);
                        } else {
                            for (Iterator iter = matches.iterator(); iter.hasNext();) {
                                OpenAttrBase target = (OpenAttrBase)iter.next();
                                child.apply((ComponentExtension)target.getExtension(), vctx);
                            }
                        }
                    }
                }
            }
View Full Code Here

TOP

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

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.