// Resolve element references
 public void ResolveElements(SdlParser parser)
 {
     Util.Log("URTNamespace.ResolveElements "+Name);
     for(int i=0;i<_elmDecls.Count;i++)
         ((ElementDecl) _elmDecls[i]).Resolve(parser);
 }
            // Resolves internal references
            public void ResolveTypes(SdlParser parser)
            {
                Util.Log("URTNamespace.ResolveTypes "+Name);
                for(int i=0;i<_URTComplexTypes.Count;i++)
                {
                    if(_URTComplexTypes[i] != null)
                        ((URTComplexType)_URTComplexTypes[i]).ResolveTypes(parser);
                }

                for(int i=0;i<_URTInterfaces.Count;i++)
                    ((URTInterface)_URTInterfaces[i]).ResolveTypes(parser);
            }
            public void Resolve(SdlParser parser)
            {
                Util.Log("ElementDecl.Resolve "+TypeName+" "+TypeNS);
                // Return immediately for element declaration of primitive types
                if(_bPrimitive)
                    return;

                // Lookup the type from the element declaration
                URTNamespace typeNS = parser.LookupNamespace(TypeNS);
                if(typeNS == null)
                {
                    throw new SUDSParserException(
                        String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveSchemaNS"),
                                      TypeNS));
                }
                BaseType type = typeNS.LookupType(TypeName);
                if(type == null)
                {
                    throw new SUDSParserException(
                        String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveTypeInNS"),
                                      TypeName, TypeNS));
                }

                type.ElementName = Name;
                type.ElementNS = Namespace;

                return;
            }
 // Constructor
 public URTNamespace(String name, SdlParser parser)
 {
     Util.Log("URTNamespace.URTNamespace name "+name);
     _name = name;
     _nsType = parser.IsURTExportedType(name, out _namespace, out _assemName);
     if(_nsType == UrtType.Interop)
         _encodedNS = "InteropProxy";
     else
         _encodedNS = _namespace;
     _elmDecls = new ArrayList();
     _URTComplexTypes = new ArrayList();
     _numURTComplexTypes = 0;
     _URTSimpleTypes = new ArrayList();
     _numURTSimpleTypes = 0;
     _URTInterfaces = new ArrayList();
     _anonymousSeqNum = 0;
 }
            internal void Implements(String iFaceName, String iFaceNS, SdlParser parser)
            {
                Util.Log("URTComplexType.Implements IFaceName "+iFaceName+" iFaceNS "+iFaceNS);
                _implIFaceNames.Add(iFaceName);
                _implIFaceNames.Add(iFaceNS);
                // Urt namespace will not have schema, they need to be recorded.
                URTNamespace parsingNamespace = parser.LookupNamespace(iFaceNS);
                if(parsingNamespace == null)
                {
                    parsingNamespace = new URTNamespace(iFaceNS, parser);
                    parser._URTNamespaces.Add(parsingNamespace);
                }

                URTInterface parsingInterface = parsingNamespace.LookupInterface(iFaceName);            
                if(parsingInterface == null)
                {
                    parsingInterface = new URTInterface(iFaceName, parsingNamespace.Namespace, parsingNamespace.EncodedNS);                 
                    parsingNamespace.AddInterface(parsingInterface);
                }
            }
            internal void ResolveTypes(SdlParser parser)
            {
                Util.Log("URTComplexType.ResolveTypes "+Name+" _baseTypeName "+_baseTypeName+" IsSUDSType "+IsSUDSType);
                String baseTypeNS = null;
                String baseTypeAssemName = null;
                if(_baseTypeName != null)
                {
                    Util.Log("URTComplexType.ResolveTypes 1 ");
                    UrtType urtType = parser.IsURTExportedType(_baseTypeXmlNS, out baseTypeNS, out baseTypeAssemName);
                    if ((urtType == UrtType.Interop) && baseTypeNS.StartsWith("System"))
                    {
                        _baseType = new SystemType(_baseTypeName, baseTypeNS, baseTypeAssemName);
                    }
                    else
                    {
                        URTNamespace ns = parser.LookupNamespace(_baseTypeXmlNS);
                        if(ns == null)
                        {
                            throw new SUDSParserException(
                                String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveSchemaNS"),
                                              _baseTypeXmlNS));
                        }
                        _baseType = ns.LookupComplexType(_baseTypeName);
                        if(_baseType == null)
                        {
                            throw new SUDSParserException(
                                String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveTypeInNS"),
                                              _baseTypeName, _baseTypeXmlNS));
                        }
                    }
                }
                else if(IsSUDSType)
                {
                    Util.Log("URTComplexType.ResolveTypes 2 SUDSType "+ ((Enum)_sudsType).ToString());                  
                    if (_sudsType == SUDSType.ClientProxy)
                    {
                        Util.Log("URTComplexType.ResolveTypes 3 ");                     
                        _baseTypeName = "RemotingClientProxy";
                        _baseTypeXmlNS = SoapServices.CodeXmlNamespaceForClrTypeNamespace("System.Runtime.Remoting","System.Runtime.Remoting");
                        baseTypeNS = "System.Runtime.Remoting.Services";
                        baseTypeAssemName = "System.Runtime.Remoting";
                    }
                    else if (_sudsType == SUDSType.MarshalByRef)
                    {
                        Util.Log("URTComplexType.ResolveTypes 4 ");                                             
                        _baseTypeName = "MarshalByRefObject";
                        _baseTypeXmlNS = SoapServices.CodeXmlNamespaceForClrTypeNamespace("System", null);
                        baseTypeNS = "System";
                        baseTypeAssemName = null;
                    }
                    _baseType = new SystemType(_baseTypeName, baseTypeNS, baseTypeAssemName);
                }
                else
                {
                    Util.Log("URTComplexType.ResolveTypes 5 ");                                         
                    _baseType = new SystemType("Object", "System", null);
                }
                for(int i=0;i<_implIFaceNames.Count;i=i+2)
                {
                    String implIFaceName = (String) _implIFaceNames[i];
                    String implIFaceXmlNS = (String) _implIFaceNames[i+1];
                    String implIFaceNS, implIFaceAssemName;
                    BaseInterface iFace;


                    UrtType iType = parser.IsURTExportedType(implIFaceXmlNS, out implIFaceNS,
                                                         out implIFaceAssemName);

                    if ((iType == UrtType.UrtSystem) && implIFaceNS.StartsWith("System"))
                    {
                        iFace = new SystemInterface(implIFaceName, implIFaceNS);
                    }
                    else
                    {
                        URTNamespace ns = parser.LookupNamespace(implIFaceXmlNS);
                        if(ns == null)
                        {
                            throw new SUDSParserException(
                                String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveSchemaNS"),
                                              implIFaceXmlNS));
                        }
                        iFace = ns.LookupInterface(implIFaceName);
                        if(iFace == null)
                        {
                            throw new SUDSParserException(
                                String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveTypeInNS"),
                                              implIFaceName, implIFaceXmlNS));
                        }
                    }
                    _implIFaces.Add(iFace);
                }
                for(int i=0;i<_methods.Count;i++)
                    ((URTMethod) _methods[i]).ResolveTypes(parser);
            }
 internal virtual void ResolveTypes(SdlParser parser)
 {
 }
            internal void ResolveTypes(SdlParser parser)
            {
                Util.Log("URTSimpleType.ResolveTypes "+Name);               
                if(_baseTypeName != null)
                {
                    if(SdlParser.IsPrimitiveType(_baseTypeXmlNS, _baseTypeName))
                    {
                        if(IsEnum == false)
                            _baseName = SdlParser.MapSchemaTypesToCSharpTypes(_baseTypeName);
                    }
                    else
                    {
                        URTNamespace ns = parser.LookupNamespace(_baseTypeXmlNS);
                        if(ns == null)
                        {
                            throw new SUDSParserException(
                                String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveSchemaNS"),
                                              _baseTypeXmlNS));
                        }
                        _baseType = ns.LookupComplexType(_baseTypeName);
                        if(_baseType == null)
                        {
                            throw new SUDSParserException(
                                String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveTypeInNS"),
                                              _baseTypeName, _baseTypeXmlNS));
                        }
                    }
                }

                for(int i=0;i<_facets.Count;i++)
                    ((SchemaFacet) _facets[i]).ResolveTypes(parser);

                return;
            }
            internal void ResolveTypes(SdlParser parser)
            {
                Util.Log("URTInterface.ResolveTypes "+Name);                
                for(int i=0;i<_baseIFaceNames.Count;i=i+2)
                {
                    String baseIFaceName = (String) _baseIFaceNames[i];
                    String baseIFaceXmlNS = (String) _baseIFaceNames[i+1];
                    String baseIFaceNS, baseIFaceAssemName;
                    BaseInterface iFace;
                    UrtType iType = parser.IsURTExportedType(baseIFaceXmlNS, out baseIFaceNS,
                                                         out baseIFaceAssemName);

                    Util.Log("URTInterface.ResolveTypes Is System "+Name+" iType "+((Enum)iType).ToString()+" baseIFaceNS "+baseIFaceNS);                                   
                    if ((iType != UrtType.Interop) && baseIFaceNS.StartsWith("System"))
                    {
                        iFace = new SystemInterface(baseIFaceName, baseIFaceNS);
                    }
                    else
                    {
                        URTNamespace ns = parser.LookupNamespace(baseIFaceXmlNS);
                        if(ns == null)
                        {
                            throw new SUDSParserException(
                                String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveSchemaNS"),
                                              baseIFaceXmlNS));
                        }
                        iFace = ns.LookupInterface(baseIFaceName);
                        if(iFace == null)
                        {
                            throw new SUDSParserException(
                                String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveTypeInNS"),
                                              baseIFaceName, baseIFaceXmlNS));
                        }
                    }
                    _baseIFaces.Add(iFace);
                }
                for(int i=0;i<_methods.Count;i++)
                    ((URTMethod) _methods[i]).ResolveTypes(parser);
            }
 internal URTField(String name, String typeName, String xmlNS, SdlParser parser,
                 bool bPrimitive, bool bEmbedded, bool bAttribute, bool bOptional,
                 bool bArray, String arraySize)
 {
     Util.Log("URTField.URTField "+name+" typeName "+typeName+" xmlNS "+xmlNS+" bPrimitive "+bPrimitive+" bEmbedded "+bEmbedded+" bAttribute "+bAttribute);
     _name = name;
     _typeName = typeName;
     String typeAssemName;
     UrtType urtType = parser.IsURTExportedType(xmlNS, out _typeNS, out typeAssemName);
     if(urtType == UrtType.Interop)
         _encodedNS = "InteropProxy";
     else
      _encodedNS = _typeNS;
     _primitiveField = bPrimitive;
     _embeddedField = bEmbedded;
     _attributeField = bAttribute;
     _optionalField = bOptional;
     _arrayField = bArray;
     _arraySize = arraySize;
 }
            internal void Extends(String baseName, String baseNS, SdlParser parser)
            {
                Util.Log("URTInterface.Extends baseName "+baseName+" baseNSf "+baseNS);
                _baseIFaceNames.Add(baseName);
                _baseIFaceNames.Add(baseNS);
                // Urt namespace will not have schema, they need to be recorded.
                URTNamespace parsingNamespace = parser.LookupNamespace(baseNS);
                if(parsingNamespace == null)
                {
                    parsingNamespace = new URTNamespace(baseNS, parser);
                    parser._URTNamespaces.Add(parsingNamespace);
                }

                URTInterface parsingInterface = parsingNamespace.LookupInterface(baseName);         
                if(parsingInterface == null)
                {
                    parsingInterface = new URTInterface(baseName, parsingNamespace.Namespace, parsingNamespace.EncodedNS);                  
                    parsingNamespace.AddInterface(parsingInterface);
                }
                
            }
 // Resolves the method
 internal override void ResolveTypes(SdlParser parser)
 {
     Util.Log("OnewayMethod.ResolveTypes name "+ _messageElementName);
     ResolveParams(parser, _messageElementNS, _messageElementName, true);
     return;
 }
 // Resolves the method
 internal override void ResolveTypes(SdlParser parser)
 {
     Util.Log("RRMethod.ResolveTypes "+_requestElementName+" "+_responseElementName);                                
     ResolveParams(parser, _requestElementNS, _requestElementName, true);
     ResolveParams(parser, _responseElementNS, _responseElementName, false);
     return;
 }
            // Helper method used by Resolve
            protected void ResolveParams(SdlParser parser, String targetNS, String targetName,
                                         bool bRequest)
            {
                Util.Log("URTMethod.ResolveParams targetName "+targetName+"targetNS "+targetNS+" bRequest "+bRequest);                              
                // Lookup the element declaration using target namespace and type name
                URTNamespace elmNS = parser.LookupNamespace(targetNS);
                if(elmNS == null)
                {
                    throw new SUDSParserException(
                        String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveSchemaNS"),
                                      targetNS));
                }
                ElementDecl elm = elmNS.LookupElementDecl(targetName);
                if(elm == null)
                {
                    throw new SUDSParserException(
                        String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveElementInNS"),
                                      targetName, targetNS));
                }

                // Lookup the type from the element declaration
                URTNamespace typeNS = parser.LookupNamespace(elm.TypeNS);
                if(typeNS == null)
                {
                    throw new SUDSParserException(
                        String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveSchemaNS"),
                                      elm.TypeNS));
                }
                URTComplexType type = typeNS.LookupComplexType(elm.TypeName);
                if(type == null)
                {
                    throw new SUDSParserException(
                        String.Format(CoreChannel.GetResourceString("Remoting_Suds_CantResolveTypeInNS"),
                                      elm.TypeName, elm.TypeNS));
                }
                Util.Log("URTMethod.ResolveParams Before RemoveComplexType ");
                typeNS.RemoveComplexType(type);

                // The fields of the type are the params of the method
                ArrayList fields = type.Fields;
                for(int i=0;i<fields.Count;i++)
                {
                    URTField field = (URTField) fields[i];
                    URTParamType pType = bRequest ? URTParamType.IN : URTParamType.OUT;
                    AddParam(new URTParam(field.Name, field.TypeName, field.TypeNS, field.EncodedNS,
                                          pType, field.IsEmbedded));
                }

                return;
            }
 // This method is called when the parsing is complete
 // and is useful for derived types
 internal abstract void ResolveTypes(SdlParser parser);