private void walk()

in xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaScope.java [314:489]


    private void walk(boolean isMixed, XmlSchemaContent content) {
        if (content instanceof XmlSchemaComplexContentExtension) {
            XmlSchemaComplexContentExtension ext = (XmlSchemaComplexContentExtension)content;

            XmlSchemaType baseType = schemasByNamespace.getTypeByName(ext.getBaseTypeName());

            XmlSchemaParticle baseParticle = null;
            XmlSchemaAnyAttribute baseAnyAttr = null;
            XmlSchemaScope parentScope = null;

            if (baseType != null) {
                /*
                 * Complex content extensions add attributes and elements in
                 * addition to what was retrieved from the parent. Since there
                 * will be no collisions, it is safe to perform a straight add.
                 */
                parentScope = getScope(baseType);
                attributes = createAttributeMap(ext.getAttributes());

                if (attributes == null) {
                    attributes = parentScope.attributes;
                } else if (parentScope.attributes != null) {
                    attributes.putAll(parentScope.attributes);
                }

                baseParticle = parentScope.getParticle();
                baseAnyAttr = parentScope.anyAttr;
            }

            /*
             * An extension of a complex type is equivalent to creating a
             * sequence of two particles: the parent particle followed by the
             * child particle.
             */
            if (ext.getParticle() == null) {
                child = baseParticle;
            } else if (baseParticle == null) {
                child = ext.getParticle();
            } else {
                XmlSchemaSequence seq = new XmlSchemaSequence();
                seq.getItems().add((XmlSchemaSequenceMember)baseParticle);
                seq.getItems().add((XmlSchemaSequenceMember)ext.getParticle());
                child = seq;
            }

            /*
             * An extension of an anyAttribute means the child defines the
             * processContents field, while a union of all namespaces between
             * the parent and child is taken.
             */
            if (baseAnyAttr == null) {
                anyAttr = ext.getAnyAttribute();
            } else if (ext.getAnyAttribute() == null) {
                anyAttr = baseAnyAttr;
            } else {
                String[] baseNamespaces = baseAnyAttr.getNamespace().split(" ");
                String[] childNamespaces = ext.getAnyAttribute().getNamespace().split(" ");

                HashSet<String> namespaces = new HashSet<String>();
                for (String baseNs : baseNamespaces) {
                    if (baseNs.length() > 0) {
                        namespaces.add(baseNs);
                    }
                }
                for (String childNs : childNamespaces) {
                    if (childNs.length() > 0) {
                        namespaces.add(childNs);
                    }
                }

                StringBuilder nsAsString = new StringBuilder();
                for (String namespace : namespaces) {
                    nsAsString.append(namespace).append(" ");
                }

                anyAttr = new XmlSchemaAnyAttribute();
                anyAttr.setNamespace(nsAsString.toString());
                anyAttr.setProcessContent(ext.getAnyAttribute().getProcessContent());
                anyAttr.setAnnotation(ext.getAnyAttribute().getAnnotation());
                anyAttr.setId(ext.getAnyAttribute().getId());
                anyAttr.setLineNumber(ext.getAnyAttribute().getLineNumber());
                anyAttr.setLinePosition(ext.getAnyAttribute().getLinePosition());
                anyAttr.setMetaInfoMap(ext.getAnyAttribute().getMetaInfoMap());
                anyAttr.setSourceURI(ext.getAnyAttribute().getSourceURI());
                anyAttr.setUnhandledAttributes(ext.getUnhandledAttributes());
            }

            final XmlSchemaTypeInfo parentTypeInfo = (parentScope == null) ? null : parentScope.getTypeInfo();

            if ((parentTypeInfo != null) && !parentTypeInfo.getType().equals(XmlSchemaTypeInfo.Type.COMPLEX)) {
                typeInfo = parentScope.getTypeInfo();
            } else {
                typeInfo = new XmlSchemaTypeInfo(isMixed);
            }

        } else if (content instanceof XmlSchemaComplexContentRestriction) {
            final XmlSchemaComplexContentRestriction rstr = (XmlSchemaComplexContentRestriction)content;

            final XmlSchemaType baseType = schemasByNamespace.getTypeByName(rstr.getBaseTypeName());

            XmlSchemaScope parentScope = null;
            if (baseType != null) {
                parentScope = getScope(baseType);

                attributes = mergeAttributes(parentScope.attributes, createAttributeMap(rstr.getAttributes()));

                child = parentScope.getParticle();
            }

            /*
             * There is no inheritance when restricting particles. If the schema
             * writer wishes to include elements in the parent type, (s)he must
             * redefine them in the child.
             */
            if (rstr.getParticle() != null) {
                child = rstr.getParticle();
            }

            /*
             * There is no inheritance when restricting attribute wildcards. The
             * only requirement is that the namespaces of the restricted type is
             * a subset of the namespaces of the base type. This will not be
             * checked here (all schemas are assumed correct).
             */
            anyAttr = rstr.getAnyAttribute();

            final XmlSchemaTypeInfo parentTypeInfo = (parentScope == null) ? null : parentScope.getTypeInfo();

            if ((parentTypeInfo != null) && !parentTypeInfo.getType().equals(XmlSchemaTypeInfo.Type.COMPLEX)) {
                typeInfo = parentTypeInfo;
            } else {
                typeInfo = new XmlSchemaTypeInfo(isMixed);
            }

        } else if (content instanceof XmlSchemaSimpleContentExtension) {
            XmlSchemaSimpleContentExtension ext = (XmlSchemaSimpleContentExtension)content;
            attributes = createAttributeMap(ext.getAttributes());

            XmlSchemaType baseType = schemasByNamespace.getTypeByName(ext.getBaseTypeName());

            if (baseType != null) {
                final XmlSchemaScope parentScope = getScope(baseType);
                typeInfo = parentScope.getTypeInfo();

                if (attributes == null) {
                    attributes = parentScope.attributes;
                } else if (parentScope.attributes != null) {
                    attributes.putAll(parentScope.attributes);
                }
            }

            anyAttr = ext.getAnyAttribute();

        } else if (content instanceof XmlSchemaSimpleContentRestriction) {
            XmlSchemaSimpleContentRestriction rstr = (XmlSchemaSimpleContentRestriction)content;
            attributes = createAttributeMap(rstr.getAttributes());

            XmlSchemaType baseType = null;
            if (rstr.getBaseType() != null) {
                baseType = rstr.getBaseType();
            } else {
                baseType = schemasByNamespace.getTypeByName(rstr.getBaseTypeName());
            }

            if (baseType != null) {
                XmlSchemaScope parentScope = getScope(baseType);
                typeInfo = restrictTypeInfo(parentScope.getTypeInfo(),
                                            mergeFacets(parentScope.getTypeInfo().getFacets(),
                                                        rstr.getFacets()));

                attributes = mergeAttributes(parentScope.attributes, attributes);
            }

            anyAttr = rstr.getAnyAttribute();
        }
    }