private void walk()

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


    private void walk(XmlSchemaSimpleType simpleType) {
        XmlSchemaSimpleTypeContent content = simpleType.getContent();

        if (content == null) {
            /*
             * Only anyType contains no content. We reached the root of the type
             * hierarchy.
             */
            typeInfo = new XmlSchemaTypeInfo(XmlSchemaBaseSimpleType.ANYTYPE);

        } else if (content instanceof XmlSchemaSimpleTypeList) {
            XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)content;
            XmlSchemaSimpleType listType = list.getItemType();
            if (listType == null) {
                listType = (XmlSchemaSimpleType)schemasByNamespace.getTypeByName(list.getItemTypeName());
            }
            if (listType == null) {
                throw new IllegalArgumentException("Unrecognized schema type for list "
                                                   + getName(simpleType, "{Anonymous List Type}"));
            }

            XmlSchemaScope parentScope = getScope(listType);

            switch (parentScope.getTypeInfo().getType()) {
            case UNION:
            case ATOMIC:
                break;
            default:
                throw new IllegalStateException("Attempted to create a list from a "
                                                + parentScope.getTypeInfo().getType() + " type.");
            }

            typeInfo = new XmlSchemaTypeInfo(parentScope.getTypeInfo());

        } else if (content instanceof XmlSchemaSimpleTypeUnion) {
            XmlSchemaSimpleTypeUnion union = (XmlSchemaSimpleTypeUnion)content;
            QName[] namedBaseTypes = union.getMemberTypesQNames();
            List<XmlSchemaSimpleType> baseTypes = union.getBaseTypes();

            if (namedBaseTypes != null) {
                if (baseTypes == null) {
                    baseTypes = new ArrayList<XmlSchemaSimpleType>(namedBaseTypes.length);
                }

                for (QName namedBaseType : namedBaseTypes) {
                    XmlSchemaSimpleType baseType = (XmlSchemaSimpleType)schemasByNamespace.getTypeByName(namedBaseType);
                    if (baseType != null) {
                        baseTypes.add(baseType);
                    }
                }
            }

            /*
             * baseTypes cannot be null at this point; there must be a union of
             * types.
             */
            if ((baseTypes == null) || baseTypes.isEmpty()) {
                throw new IllegalArgumentException("Unrecognized base types for union "
                                                   + getName(simpleType, "{Anonymous Union Type}"));
            }

            List<XmlSchemaTypeInfo> childTypes = new ArrayList<XmlSchemaTypeInfo>(baseTypes.size());

            for (XmlSchemaSimpleType baseType : baseTypes) {
                XmlSchemaScope parentScope = getScope(baseType);
                if (parentScope.getTypeInfo().getType().equals(XmlSchemaTypeInfo.Type.UNION)) {
                    childTypes.addAll(parentScope.getTypeInfo().getChildTypes());
                } else {
                    childTypes.add(parentScope.getTypeInfo());
                }
            }

            typeInfo = new XmlSchemaTypeInfo(childTypes);

        } else if (content instanceof XmlSchemaSimpleTypeRestriction) {
            final XmlSchemaSimpleTypeRestriction restr = (XmlSchemaSimpleTypeRestriction)content;

            final List<XmlSchemaFacet> facets = restr.getFacets();

            XmlSchemaTypeInfo parentTypeInfo = null;

            if (XmlSchemaBaseSimpleType.isBaseSimpleType(simpleType.getQName())) {
                // If this is a base simple type, use it!
                typeInfo = new XmlSchemaTypeInfo(XmlSchemaBaseSimpleType.getBaseSimpleTypeFor(simpleType
                    .getQName()), mergeFacets(null, facets));

            } else {
                XmlSchemaSimpleType baseType = restr.getBaseType();
                if (baseType == null) {
                    baseType = (XmlSchemaSimpleType)schemasByNamespace.getTypeByName(restr.getBaseTypeName());
                }

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

                    /*
                     * We need to track the original type as well as the set of
                     * facets imposed on that type. Once the recursion ends, and
                     * we make it all the way back to the first scope, the user
                     * of this type info will know the derived type and all of
                     * its imposed facets. Unions can restrict unions, lists can
                     * restrict lists, and atomic types restrict other atomic
                     * types. We need to follow all of these too.
                     */
                    parentTypeInfo = parentScope.getTypeInfo();

                    HashMap<XmlSchemaRestriction.Type, List<XmlSchemaRestriction>> mergedFacets = mergeFacets(parentTypeInfo
                                                                                                                  .getFacets(),
                                                                                                              facets);

                    typeInfo = restrictTypeInfo(parentTypeInfo, mergedFacets);

                } else {
                    throw new IllegalArgumentException("Unrecognized base type for "
                                                       + getName(simpleType, "{Anonymous Simple Type}"));
                }
            }

            typeInfo.setUserRecognizedType(getUserRecognizedType(simpleType.getQName(), parentTypeInfo));

        } else {
            throw new IllegalArgumentException("XmlSchemaSimpleType "
                                               + getName(simpleType, "{Anonymous Simple Type}")
                                               + "contains unrecognized XmlSchemaSimpleTypeContent "
                                               + content.getClass().getName());
        }
    }