1////////////////////////////////////////////////////////////////////////////////
2//
3//  ADOBE SYSTEMS INCORPORATED
4//  Copyright 2006-2007 Adobe Systems Incorporated
5//  All Rights Reserved.
6//
7//  NOTICE: Adobe permits you to use, modify, and distribute this file
8//  in accordance with the terms of the license agreement accompanying it.
9//
10////////////////////////////////////////////////////////////////////////////////
11
12package mx.rpc.wsdl
13{
14
15import mx.utils.StringUtil;
16import mx.utils.URLUtil;
17
18[ExcludeClass]
19
20/**
21 * Manages the constants for a particular version of WSDL (and its
22 * accompanying version of SOAP).
23 *
24 * The default version is WSDL 1.1.
25 *
26 * @private
27 */
28public class WSDLConstants
29{
30    public function WSDLConstants(wsdlNS:Namespace = null, soapNS:Namespace = null)
31    {
32        super();
33
34        // Default to WSDl 1.1 and SOAP 1.1
35        if (wsdlNS == null)
36            wsdlNS = new Namespace(WSDL_PREFIX, WSDL_URI);
37        if (soapNS == null)
38            soapNS = new Namespace(WSDL_SOAP_PREFIX, WSDL_SOAP_URI);
39
40        _wsdlNS = wsdlNS;
41        _soapNS = soapNS;
42
43        definitionsQName = new QName(wsdlURI, "definitions");
44        importQName = new QName(wsdlURI, "import");
45        typesQName = new QName(wsdlURI, "types");
46        messageQName = new QName(wsdlURI, "message");
47        portTypeQName = new QName(wsdlURI, "portType");
48        bindingQName = new QName(wsdlURI, "binding");
49        serviceQName = new QName(wsdlURI, "service");
50        documentationQName = new QName(wsdlURI, "documentation");
51        portQName = new QName(wsdlURI, "port");
52        operationQName = new QName(wsdlURI, "operation");
53        inputQName = new QName(wsdlURI, "input");
54        outputQName = new QName(wsdlURI, "output");
55        partQName = new QName(wsdlURI, "part");
56        faultQName = new QName(wsdlURI, "fault");
57        wsdlArrayTypeQName = new QName(wsdlURI, "arrayType");
58
59        soapAddressQName = new QName(soapURI, "address");
60        soapBindingQName = new QName(soapURI, "binding");
61        soapOperationQName = new QName(soapURI, "operation");
62        soapBodyQName = new QName(soapURI, "body");
63        soapFaultQName = new QName(soapURI, "fault");
64        soapHeaderQName = new QName(soapURI, "header");
65        soapHeaderFaultQName = new QName(soapURI, "headerfault");
66    }
67
68
69    //--------------------------------------------------------------------------
70    //
71    // Properties
72    //
73    //--------------------------------------------------------------------------
74
75    public function get soapURI():String
76    {
77        return soapNamespace.uri;
78    }
79
80    public function get wsdlURI():String
81    {
82        return wsdlNamespace.uri;
83    }
84
85    public function get soapNamespace():Namespace
86    {
87        return _soapNS;
88    }
89
90    public function get wsdlNamespace():Namespace
91    {
92        return _wsdlNS;
93    }
94
95
96    //--------------------------------------------------------------------------
97    //
98    // Methods
99    //
100    //--------------------------------------------------------------------------
101
102    public static function getConstants(xml:XML):WSDLConstants
103    {
104        var wsdlNS:Namespace;
105        var soapNS:Namespace;
106
107        if (xml != null)
108        {
109            var nsArray:Array = xml.inScopeNamespaces();
110            for each (var ns:Namespace in nsArray)
111            {
112                if (URLUtil.urisEqual(ns.uri, WSDL_URI))
113                {
114                    wsdlNS = ns;
115                }
116                else if (URLUtil.urisEqual(ns.uri, WSDL20_URI))
117                {
118                    wsdlNS = ns;
119                }
120                if (URLUtil.urisEqual(ns.uri, WSDL_SOAP_URI))
121                {
122                    soapNS = ns;
123                }
124                else if (URLUtil.urisEqual(ns.uri, WSDL20_SOAP_URI))
125                {
126                    soapNS = ns;
127                }
128                else if (URLUtil.urisEqual(ns.uri, WSDL20_SOAP12_URI))
129                {
130                    soapNS = ns;
131                }
132            }
133        }
134
135        // Default to WSDL 1.1
136        if (wsdlNS == null)
137            wsdlNS = new Namespace(WSDL_PREFIX, WSDL_URI);
138
139        if (soapNS == null)
140            soapNS = new Namespace(WSDL_SOAP_PREFIX, WSDL_SOAP_URI);
141
142        if (constantsCache == null)
143            constantsCache = {};
144
145        var constants:WSDLConstants = constantsCache[wsdlNS.uri];
146        if (constants == null)
147        {
148            constants = new WSDLConstants(wsdlNS, soapNS);
149            constantsCache[wsdlNS.uri] = constants;
150        }
151
152        return constants;
153    }
154
155
156    //--------------------------------------------------------------------------
157    //
158    // Variables
159    //
160    //--------------------------------------------------------------------------
161
162    // WSDL QNames
163    public var definitionsQName:QName;
164    public var typesQName:QName;
165    public var messageQName:QName;
166    public var portTypeQName:QName;
167    public var bindingQName:QName;
168    public var serviceQName:QName;
169    public var importQName:QName;
170    public var documentationQName:QName;
171    public var portQName:QName;
172    public var operationQName:QName;
173    public var inputQName:QName;
174    public var outputQName:QName;
175    public var partQName:QName;
176    public var faultQName:QName;
177    public var wsdlArrayTypeQName:QName;
178
179    // WSDL SOAP QNames
180    public var soapAddressQName:QName;
181    public var soapBindingQName:QName;
182    public var soapOperationQName:QName;
183    public var soapBodyQName:QName;
184    public var soapFaultQName:QName;
185    public var soapHeaderQName:QName;
186    public var soapHeaderFaultQName:QName;
187
188    /**
189     * The namespace representing the version of SOAP used by a WSDL,
190     * currently 1.1 is supported.
191     * FIXME: Need SOAP 1.2 support.
192     */
193    private var _soapNS:Namespace;
194
195    /**
196     * The namespace representing the version of WSDL, currently only 1.1 is
197     * supported.
198     * TODO: Need WSDL 2.0 support.
199     */
200    private var _wsdlNS:Namespace;
201
202    private static var constantsCache:Object;
203
204
205    //--------------------------------------------------------------------------
206    //
207    // Constants
208    //
209    //--------------------------------------------------------------------------
210
211    // SOAP Binding Constants
212    public static const SOAP_HTTP_URI:String = "http://schemas.xmlsoap.org/soap/http/";
213
214    public static const MODE_IN:int = 0;
215    public static const MODE_OUT:int = 1;
216    public static const MODE_FAULT:int = 2;
217    public static const MODE_HEADER:int = 3;
218
219    //WSDL 1.1 Namespaces
220    public static const WSDL_URI:String = "http://schemas.xmlsoap.org/wsdl/";
221    public static const WSDL_SOAP_URI:String = "http://schemas.xmlsoap.org/wsdl/soap/";
222    public static const WSDL_SOAP12_URI:String = "http://schemas.xmlsoap.org/wsdl/soap12/";
223    public static const WSDL_HTTP_URI:String = "http://schemas.xmlsoap.org/wsdl/http/";
224
225    //WSDL 2.0 Namespaces
226    public static const WSDL20_URI:String = "http://www.w3.org/2006/01/wsdl";
227    public static const WSDL20_SOAP_URI:String = "http://www.w3.org/2006/01/wsdl/soap";
228    public static const WSDL20_SOAP12_URI:String = "http://www.w3.org/2006/01/wsdl/soap";
229    public static const WSDL20_HTTP_URI:String = "http://www.w3.org/2006/01/wsdl/http";
230
231    // WSDL Namespace Prefix
232    public static const WSDL_PREFIX:String = "wsdl";
233    public static const WSDL_SOAP_PREFIX:String = "wsoap";
234
235    public static const DEFAULT_STYLE:String = "document";
236    public static const DEFAULT_WSDL_VERSION:String = "1.1";
237}
238
239}