Back to index

lightning-sunbird  0.9+nobinonly
nsSOAPEncoding.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsSOAPEncoding_h__
00039 #define nsSOAPEncoding_h__
00040 
00041 #include "nsString.h"
00042 #include "nsIDOMElement.h"
00043 #include "nsISOAPEncoding.h"  // contains nsISOAPEncodingRegistry too
00044 #include "nsISOAPEncoder.h"
00045 #include "nsISOAPDecoder.h"
00046 #include "nsCOMPtr.h"
00047 #include "nsHashtable.h"
00048 #include "nsISchema.h"
00049 
00050 // Notes regarding the ownership model between the nsSOAPEncoding (encoding)
00051 //   and the nsSOAPEncodingRegsitry (registry). To avoid cyclic referencing
00052 //   and thereby leaking encodings and the registry holding them the registry 
00053 //   was given ownership of the encodings. In the encoding specialized 
00054 //   AddRef() and Release() functions were written to pass the refcounting
00055 //   to the registry. Instead of ref couting the encodings all refs are
00056 //   accumulated in the registry. When the registry is the only thing holding
00057 //   on to the encodings it's own refcount will hit zero causing it to 
00058 //   go away and take with it any encodings stored in its hashtable. To make
00059 //   this work the registry had to be a weak reference (*-style pointer)
00060 //   in each encoding and the storage of the encodings had to be weak as
00061 //   well (*-style pointers in the nsObjectHashtable).
00062 
00063 class nsSOAPEncodingRegistry : public nsISOAPEncodingRegistry
00064 {
00065 
00066 public:
00067   NS_DECL_ISUPPORTS 
00068   NS_DECL_NSISOAPENCODINGREGISTRY
00069 
00070   nsSOAPEncodingRegistry(nsISOAPEncoding *aEncoding);
00071 
00072   // the nsObjectHashtable has a callback to delete all the encodings
00073   //    the callback is defined in nsSOAPEncoding.cpp
00074   virtual ~nsSOAPEncodingRegistry() {}
00075 
00076 protected:
00077   nsObjectHashtable mEncodings;
00078   nsCOMPtr<nsISchemaCollection> mSchemaCollection;
00079 
00080 };
00081 
00082 
00083 class nsSOAPEncoding : public nsISOAPEncoding
00084 {
00085 
00086 public:
00087   NS_DECL_ISUPPORTS
00088   NS_DECL_NSISOAPENCODING 
00089   
00090   nsSOAPEncoding();
00091   nsSOAPEncoding(const nsAString &aStyleURI,
00092                  nsSOAPEncodingRegistry *aRegistry,
00093                  nsISOAPEncoding *aDefaultEncoding);
00094   virtual ~nsSOAPEncoding() {}
00095 
00096 protected:
00097   nsString mStyleURI;
00098   nsSupportsHashtable mEncoders;
00099   nsSupportsHashtable mDecoders;
00100 
00101   // Weak Reference to avoid cyclic refs and leaks. See notes above.
00102   nsISOAPEncodingRegistry *mRegistry;
00103 
00104   nsCOMPtr<nsISOAPEncoding> mDefaultEncoding;
00105   nsCOMPtr<nsISOAPEncoder> mDefaultEncoder;
00106   nsCOMPtr<nsISOAPDecoder> mDefaultDecoder;
00107   nsSupportsHashtable mMappedInternal;
00108   nsSupportsHashtable mMappedExternal;
00109 
00110 };
00111 #endif