Back to index

lightning-sunbird  0.9+nobinonly
nsRDFModule.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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) 1998
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 of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or 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 #include "nsCOMPtr.h"
00038 #include "nsIGenericFactory.h"
00039 #include "nsIModule.h"
00040 
00041 #include "nsRDFModule.h"
00042 #include "nsIFactory.h"
00043 #include "nsIRDFContainer.h"
00044 #include "nsIRDFContainerUtils.h"
00045 #include "nsIRDFCompositeDataSource.h"
00046 #include "nsIRDFContentSink.h"
00047 #include "nsIRDFService.h"
00048 #include "nsISupports.h"
00049 #include "nsRDFBaseDataSources.h"
00050 #include "nsRDFBuiltInDataSources.h"
00051 #include "nsIRDFFileSystem.h"
00052 #include "nsRDFCID.h"
00053 #include "nsIComponentManager.h"
00054 #include "rdf.h"
00055 #include "nsIServiceManager.h"
00056 #include "nsILocalStore.h"
00057 #include "nsRDFXMLParser.h"
00058 #include "nsRDFXMLSerializer.h"
00059 
00060 #include "rdfISerializer.h"
00061 
00062 //----------------------------------------------------------------------
00063 
00064 // Functions used to create new instances of a given object by the
00065 // generic factory.
00066 
00067 #define MAKE_CTOR(_func,_new,_ifname)                                \
00068 static NS_IMETHODIMP                                                 \
00069 CreateNew##_func(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
00070 {                                                                    \
00071     if (!aResult) {                                                  \
00072         return NS_ERROR_INVALID_POINTER;                             \
00073     }                                                                \
00074     if (aOuter) {                                                    \
00075         *aResult = nsnull;                                           \
00076         return NS_ERROR_NO_AGGREGATION;                              \
00077     }                                                                \
00078     nsI##_ifname* inst;                                              \
00079     nsresult rv = NS_New##_new(&inst);                               \
00080     if (NS_FAILED(rv)) {                                             \
00081         *aResult = nsnull;                                           \
00082         return rv;                                                   \
00083     }                                                                \
00084     rv = inst->QueryInterface(aIID, aResult);                        \
00085     if (NS_FAILED(rv)) {                                             \
00086         *aResult = nsnull;                                           \
00087     }                                                                \
00088     NS_RELEASE(inst);             /* get rid of extra refcnt */      \
00089     return rv;                                                       \
00090 }
00091 
00092 extern nsresult
00093 NS_NewDefaultResource(nsIRDFResource** aResult);
00094 
00095 MAKE_CTOR(RDFService,RDFService,RDFService)
00096 MAKE_CTOR(RDFXMLDataSource,RDFXMLDataSource,RDFDataSource)
00097 MAKE_CTOR(RDFFileSystemDataSource,RDFFileSystemDataSource,RDFDataSource)
00098 MAKE_CTOR(RDFCompositeDataSource,RDFCompositeDataSource,RDFCompositeDataSource)
00099 MAKE_CTOR(RDFContainer,RDFContainer,RDFContainer)
00100 
00101 MAKE_CTOR(RDFContainerUtils,RDFContainerUtils,RDFContainerUtils)
00102 
00103 MAKE_CTOR(RDFContentSink,RDFContentSink,RDFContentSink)
00104 MAKE_CTOR(RDFDefaultResource,DefaultResource,RDFResource)
00105 
00106 #define MAKE_RDF_CTOR(_func,_new,_ifname)                            \
00107 static NS_IMETHODIMP                                                 \
00108 CreateNew##_func(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
00109 {                                                                    \
00110     if (!aResult) {                                                  \
00111         return NS_ERROR_INVALID_POINTER;                             \
00112     }                                                                \
00113     if (aOuter) {                                                    \
00114         *aResult = nsnull;                                           \
00115         return NS_ERROR_NO_AGGREGATION;                              \
00116     }                                                                \
00117     rdfI##_ifname* inst;                                             \
00118     nsresult rv = NS_New##_new(&inst);                               \
00119     if (NS_FAILED(rv)) {                                             \
00120         *aResult = nsnull;                                           \
00121         return rv;                                                   \
00122     }                                                                \
00123     rv = inst->QueryInterface(aIID, aResult);                        \
00124     if (NS_FAILED(rv)) {                                             \
00125         *aResult = nsnull;                                           \
00126     }                                                                \
00127     NS_RELEASE(inst);             /* get rid of extra refcnt */      \
00128     return rv;                                                       \
00129 }
00130 
00131 extern nsresult
00132 NS_NewTriplesSerializer(rdfISerializer** aResult);
00133 
00134 MAKE_RDF_CTOR(TriplesSerializer, TriplesSerializer, Serializer)
00135 
00136 // The list of components we register
00137 static const nsModuleComponentInfo components[] = 
00138 {   // register our build-in datasources:
00139     { 
00140      "RDF Composite Data Source", 
00141      NS_RDFCOMPOSITEDATASOURCE_CID,
00142      NS_RDF_DATASOURCE_CONTRACTID_PREFIX "composite-datasource", 
00143      CreateNewRDFCompositeDataSource
00144     },
00145 
00146     { 
00147      "RDF File System Data Source", 
00148      NS_RDFFILESYSTEMDATASOURCE_CID,
00149      NS_RDF_DATASOURCE_CONTRACTID_PREFIX "files", 
00150      CreateNewRDFFileSystemDataSource
00151     },
00152     
00153     { "RDF In-Memory Data Source", 
00154       NS_RDFINMEMORYDATASOURCE_CID,
00155       NS_RDF_DATASOURCE_CONTRACTID_PREFIX "in-memory-datasource", 
00156       NS_NewRDFInMemoryDataSource
00157     },
00158 
00159     { "RDF XML Data Source", 
00160       NS_RDFXMLDATASOURCE_CID,
00161       NS_RDF_DATASOURCE_CONTRACTID_PREFIX "xml-datasource", 
00162       CreateNewRDFXMLDataSource
00163     },
00164 
00165     // register our built-in resource factories:
00166     { "RDF Default Resource Factory", 
00167       NS_RDFDEFAULTRESOURCE_CID,
00168       // Note: default resource factory has no name= part
00169       NS_RDF_RESOURCE_FACTORY_CONTRACTID, 
00170       CreateNewRDFDefaultResource
00171     },
00172 
00173     // register all the other rdf components:
00174     { "RDF Content Sink", 
00175       NS_RDFCONTENTSINK_CID,
00176       NS_RDF_CONTRACTID "/content-sink;1", 
00177       CreateNewRDFContentSink
00178     },
00179     
00180     { "RDF Container", 
00181       NS_RDFCONTAINER_CID,
00182       NS_RDF_CONTRACTID "/container;1", 
00183       CreateNewRDFContainer
00184     },
00185     
00186     { "RDF Container Utilities", 
00187       NS_RDFCONTAINERUTILS_CID,
00188       NS_RDF_CONTRACTID "/container-utils;1", 
00189       CreateNewRDFContainerUtils
00190     },
00191     
00192     { "RDF Service", 
00193       NS_RDFSERVICE_CID,
00194       NS_RDF_CONTRACTID "/rdf-service;1",
00195       CreateNewRDFService 
00196     },
00197 
00198     { "RDF/XML Parser",
00199       NS_RDFXMLPARSER_CID,
00200       NS_RDF_CONTRACTID "/xml-parser;1",
00201       nsRDFXMLParser::Create
00202     },
00203 
00204     { "RDF/XML Serializer",
00205       NS_RDFXMLSERIALIZER_CID,
00206       NS_RDF_CONTRACTID "/xml-serializer;1",
00207       nsRDFXMLSerializer::Create
00208     },
00209 
00210     { "RDF/NTriples Serializer",
00211       NS_RDFNTRIPLES_SERIALIZER_CID,
00212       NS_RDF_SERIALIZER "ntriples",
00213       CreateNewTriplesSerializer
00214     },
00215 
00216     // XXX move this to XPFE at some point.
00217     { "Local Store", NS_LOCALSTORE_CID,
00218       NS_LOCALSTORE_CONTRACTID, NS_NewLocalStore },
00219 };
00220 
00221 NS_IMPL_NSGETMODULE(nsRDFModule, components)