private void setRestrictionBaseAndValues()

in src/wsdl/org/apache/axis/wsdl/wsdl2ws/info/WSDLInfo.java [932:1162]


    private void setRestrictionBaseAndValues(Type typedata, Node node)  throws WrapperFault
    {
        if (node == null)
            return;

        // If the node kind is an element, dive into it.
        QName nodeKind = Utils.getNodeQName(node);
        if (nodeKind != null &&
            nodeKind.getLocalPart().equals("element") &&
            Constants.isSchemaXSD(nodeKind.getNamespaceURI())) 
        {
            NodeList children = node.getChildNodes();
            Node simpleNode = null;
            for (int j = 0; j < children.getLength() && simpleNode == null; j++) 
            {
                QName simpleKind = Utils.getNodeQName(children.item(j));
                if (simpleKind != null &&
                    simpleKind.getLocalPart().equals("simpleType") &&
                    Constants.isSchemaXSD(simpleKind.getNamespaceURI())) 
                {
                    simpleNode = children.item(j);
                    node = simpleNode;
                }
            }
        }
        
        // Get the node kind, expecting a schema simpleType
        nodeKind = Utils.getNodeQName(node);
        if (nodeKind != null &&
            nodeKind.getLocalPart().equals("simpleType") &&
            Constants.isSchemaXSD(nodeKind.getNamespaceURI())) 
        {
             
            // Under the simpleType there may be a restriction, list, or union.
            // (There may be other #text nodes, which we will ignore).            
            // We do something special for unions and lists.  We treat them
            // as strings and ignore the processing of restriction nodes.
            Node restrictionNode = null;
            boolean isListOrUnionNode = false;
            restrictionNode = CSchemaUtils.getListOrUnionNode(node);
            
            if (restrictionNode != null)
                isListOrUnionNode = true;

            if (!isListOrUnionNode)
            {
                NodeList children = node.getChildNodes();
                for (int j = 0; j < children.getLength() && restrictionNode == null; j++) 
                {
                    QName restrictionKind = Utils.getNodeQName(children.item(j));
                    if (restrictionKind != null &&
                        restrictionKind.getLocalPart().equals("restriction") &&
                        Constants.isSchemaXSD(restrictionKind.getNamespaceURI()))
                        restrictionNode = children.item(j);
                }
            }
            
            // If no restriction or union or list node, just return
            if (restrictionNode == null)
                return;

            // The restriction node indicates the type being restricted
            // (the base attribute contains this type). For list or union types, 
            // treat as xsd:string.
            QName baseType;
            
            if (!isListOrUnionNode)
                baseType = Utils.getTypeQName(restrictionNode, new BooleanHolder(), false);
            else
                baseType = new QName("http://www.w3.org/2001/XMLSchema", "string");
            
            TypeEntry baseEType = c_symbolTable.getType(baseType);
            
            if (baseEType != null) 
            {
                QName  typedataQName     = typedata.getName();
                String typedataLocalpart = typedataQName.getLocalPart();
                String baseTypeLocalpart = baseEType.getQName().getLocalPart();
                
                QName  typedataQNameSanitized     = null;
                String typedataLocalpartSanitized = null;
                String baseTypeLocalpartSanitized = null;
                
                String methodSuffix = null;
                
                String primitiveXSDType          = null;
                String initValueForType          = null;
                String classForPrimitiveType     = null;
                
                if (TypeMap.isAnonymousType(typedataLocalpart))
                {
                    typedataQNameSanitized     = new QName(typedataQName.getNamespaceURI(), CUtils.sanitizeString(typedataLocalpart));
                    typedataLocalpartSanitized =  CUtils.sanitizeString(typedataLocalpart);
                }
                
                if (TypeMap.isAnonymousType(baseTypeLocalpart))
                    baseTypeLocalpartSanitized =  CUtils.sanitizeString(baseTypeLocalpart);
                
                String class4qname          = null;
                String class4qnameSanitized = null;
                
                String javaName = CUtils.getPrimitiveType(baseEType.getQName());
                boolean isBaseTypePrimitive = javaName != null;
                
                QName primitiveBaseTypeQName = null;
                
                if (javaName == null)
                {
                    // No mapping - ensure that the base type is simple - if it is, then this 
                    // must be a user-defined simple type that is based on another user-defined
                    // simple type.
                    if (!baseEType.isSimpleType()
                            && !SchemaUtils.isSimpleSchemaType(baseEType.getQName())) 
                        return;

                    // Get the primitive base type
                    TypeEntry primitiveBaseType = CSchemaUtils.getBaseType(baseEType, c_symbolTable);
                    primitiveBaseTypeQName      = primitiveBaseType.getQName();
                }
                else if (javaName.equals("boolean"))
                    return;
                else
                    primitiveBaseTypeQName = baseEType.getQName();
                
                if (c_verbose)
                    System.out.println("primitiveBaseTypeQName=" + primitiveBaseTypeQName);
                
                classForPrimitiveType =  CUtils.getSimpleType(primitiveBaseTypeQName);
                while (classForPrimitiveType == null)
                {
                    createTypeInfo(primitiveBaseTypeQName);
                    classForPrimitiveType =  CUtils.getSimpleType(primitiveBaseTypeQName);
                }
                
                if (c_verbose)
                    System.out.println("classForPrimitiveType=" + classForPrimitiveType);

                initValueForType      =  CUtils.getInitValueForType(classForPrimitiveType);
                
                // Set the base type for Type
                typedata.setBaseType(primitiveBaseTypeQName);
                
                // We will map the user-defined type to the user-defined type, so set
                // mapping for the type.
                class4qname          = typedataLocalpart;
                class4qnameSanitized = typedataLocalpartSanitized;
                
                // Update some commonly-used mapping tables to reflect the user-defined
                // simple type. If anonymous type, we need to update mapping tables twice: once
                // with the anonymous names, and once with the sanitized names. 
                
                boolean isPointerType = CUtils.isPointerType(primitiveBaseTypeQName);
                primitiveXSDType = CUtils.getXSDEnumeratorForType(classForPrimitiveType);

                if (!isBaseTypePrimitive)
                {
                    typedata.setRestrictionBaseType(baseTypeLocalpart);
                    if (isPointerType)
                        CUtils.addPointerType(baseTypeLocalpart);
                }
                if (isPointerType)
                    CUtils.addPointerType(typedataLocalpart);                    

                methodSuffix = (String)CUtils.getDeserializerMethodSuffixForType(classForPrimitiveType);
                CUtils.addXSDEnumeratorForType(typedataLocalpart, primitiveXSDType);

                if (initValueForType != null)
                    CUtils.addInitValueForType(typedataLocalpart, initValueForType);
                CUtils.addDeserializerMethodSuffixForType(typedataLocalpart, methodSuffix);
                
                if (!isBaseTypePrimitive)
                {
                    CUtils.addXSDEnumeratorForType(baseTypeLocalpart, primitiveXSDType);
                    if (initValueForType != null)
                        CUtils.addInitValueForType(baseTypeLocalpart, initValueForType);
                    CUtils.addDeserializerMethodSuffixForType(baseTypeLocalpart, methodSuffix);
                }

                if (typedataQNameSanitized != null)
                {
                    if (isPointerType)
                        CUtils.addPointerType(typedataLocalpartSanitized); 
                    CUtils.addXSDEnumeratorForType(typedataLocalpartSanitized, primitiveXSDType);
                    if (initValueForType != null)
                        CUtils.addInitValueForType(typedataLocalpartSanitized, initValueForType);
                    CUtils.addDeserializerMethodSuffixForType(typedataLocalpartSanitized, methodSuffix);
                }
                
                if (baseTypeLocalpartSanitized != null)
                {
                    if (isPointerType)
                        CUtils.addPointerType(baseTypeLocalpartSanitized);
                    CUtils.addXSDEnumeratorForType(baseTypeLocalpartSanitized, primitiveXSDType);
                    if (initValueForType != null)
                        CUtils.addInitValueForType(baseTypeLocalpartSanitized, initValueForType);
                    CUtils.addDeserializerMethodSuffixForType(baseTypeLocalpartSanitized, methodSuffix);
                }         
                
                // Process the enumeration elements underneath the restriction node
                Vector v = new Vector();  
                if (!isListOrUnionNode)
                {
                    NodeList enums = restrictionNode.getChildNodes();
                    for (int i=0; i < enums.getLength(); i++) 
                    {
                        QName enumKind = Utils.getNodeQName(enums.item(i));
                        if (enumKind != null && Constants.isSchemaXSD(enumKind.getNamespaceURI())) 
                        {
                            Node enumNode = enums.item(i);
                            String value = Utils.getAttribute(enumNode, "value");
        
                            if (value.indexOf(':')>0)                                                        
                                    value=value.substring(value.indexOf(':')+1,value.length());
                            v.add(new QName(value, enumKind.getLocalPart()));
                        }
                    }
                }
                
                // The first element in the vector is a TypeEntry.
                v.add(0,baseEType);
                typedata.setRestrictiondata(v);
                typedata.setRestriction(true);
                
                // Add schema-defined simple type to mapping table - TODO: not sure we need this anymore.
                CUtils.addSchemaDefinedSimpleType(typedataQName, class4qname);
                if (typedataQNameSanitized != null)
                    CUtils.addSchemaDefinedSimpleType(typedataQNameSanitized, class4qnameSanitized);
            }
        }
        return;
    }