1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Benjamin Smedberg <benjamin@smedbergs.us>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "mozilla/ModuleUtils.h"
41 #include "nsIFactory.h"
42 #include "nsRDFService.h"
43 #include "nsIRDFContainer.h"
44 #include "nsIRDFContainerUtils.h"
45 #include "nsIRDFCompositeDataSource.h"
46 #include "nsIRDFContentSink.h"
47 #include "nsISupports.h"
48 #include "nsRDFBaseDataSources.h"
49 #include "nsRDFBuiltInDataSources.h"
50 #include "nsFileSystemDataSource.h"
52 #include "nsIComponentManager.h"
54 #include "nsIServiceManager.h"
55 #include "nsILocalStore.h"
56 #include "nsRDFXMLParser.h"
57 #include "nsRDFXMLSerializer.h"
59 #include "rdfISerializer.h"
61 //----------------------------------------------------------------------
63 // Functions used to create new instances of a given object by the
66 #define MAKE_CTOR(_func,_new,_ifname) \
68 CreateNew##_func(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
71 return NS_ERROR_INVALID_POINTER; \
75 return NS_ERROR_NO_AGGREGATION; \
78 nsresult rv = NS_New##_new(&inst); \
79 if (NS_FAILED(rv)) { \
83 rv = inst->QueryInterface(aIID, aResult); \
84 if (NS_FAILED(rv)) { \
87 NS_RELEASE(inst); /* get rid of extra refcnt */ \
92 NS_NewDefaultResource(nsIRDFResource
** aResult
);
94 MAKE_CTOR(RDFXMLDataSource
,RDFXMLDataSource
,RDFDataSource
)
95 MAKE_CTOR(RDFCompositeDataSource
,RDFCompositeDataSource
,RDFCompositeDataSource
)
96 MAKE_CTOR(RDFContainer
,RDFContainer
,RDFContainer
)
98 MAKE_CTOR(RDFContainerUtils
,RDFContainerUtils
,RDFContainerUtils
)
100 MAKE_CTOR(RDFContentSink
,RDFContentSink
,RDFContentSink
)
101 MAKE_CTOR(RDFDefaultResource
,DefaultResource
,RDFResource
)
103 #define MAKE_RDF_CTOR(_func,_new,_ifname) \
105 CreateNew##_func(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
108 return NS_ERROR_INVALID_POINTER; \
112 return NS_ERROR_NO_AGGREGATION; \
114 rdfI##_ifname* inst; \
115 nsresult rv = NS_New##_new(&inst); \
116 if (NS_FAILED(rv)) { \
120 rv = inst->QueryInterface(aIID, aResult); \
121 if (NS_FAILED(rv)) { \
124 NS_RELEASE(inst); /* get rid of extra refcnt */ \
129 NS_NewTriplesSerializer(rdfISerializer
** aResult
);
131 MAKE_RDF_CTOR(TriplesSerializer
, TriplesSerializer
, Serializer
)
133 NS_DEFINE_NAMED_CID(NS_RDFCOMPOSITEDATASOURCE_CID
);
134 NS_DEFINE_NAMED_CID(NS_RDFFILESYSTEMDATASOURCE_CID
);
135 NS_DEFINE_NAMED_CID(NS_RDFINMEMORYDATASOURCE_CID
);
136 NS_DEFINE_NAMED_CID(NS_RDFXMLDATASOURCE_CID
);
137 NS_DEFINE_NAMED_CID(NS_RDFDEFAULTRESOURCE_CID
);
138 NS_DEFINE_NAMED_CID(NS_RDFCONTENTSINK_CID
);
139 NS_DEFINE_NAMED_CID(NS_RDFCONTAINER_CID
);
140 NS_DEFINE_NAMED_CID(NS_RDFCONTAINERUTILS_CID
);
141 NS_DEFINE_NAMED_CID(NS_RDFSERVICE_CID
);
142 NS_DEFINE_NAMED_CID(NS_RDFXMLPARSER_CID
);
143 NS_DEFINE_NAMED_CID(NS_RDFXMLSERIALIZER_CID
);
144 NS_DEFINE_NAMED_CID(NS_RDFNTRIPLES_SERIALIZER_CID
);
145 NS_DEFINE_NAMED_CID(NS_LOCALSTORE_CID
);
148 static const mozilla::Module::CIDEntry kRDFCIDs
[] = {
149 { &kNS_RDFCOMPOSITEDATASOURCE_CID
, false, NULL
, CreateNewRDFCompositeDataSource
},
150 { &kNS_RDFFILESYSTEMDATASOURCE_CID
, false, NULL
, FileSystemDataSource::Create
},
151 { &kNS_RDFINMEMORYDATASOURCE_CID
, false, NULL
, NS_NewRDFInMemoryDataSource
},
152 { &kNS_RDFXMLDATASOURCE_CID
, false, NULL
, CreateNewRDFXMLDataSource
},
153 { &kNS_RDFDEFAULTRESOURCE_CID
, false, NULL
, CreateNewRDFDefaultResource
},
154 { &kNS_RDFCONTENTSINK_CID
, false, NULL
, CreateNewRDFContentSink
},
155 { &kNS_RDFCONTAINER_CID
, false, NULL
, CreateNewRDFContainer
},
156 { &kNS_RDFCONTAINERUTILS_CID
, false, NULL
, CreateNewRDFContainerUtils
},
157 { &kNS_RDFSERVICE_CID
, false, NULL
, RDFServiceImpl::CreateSingleton
},
158 { &kNS_RDFXMLPARSER_CID
, false, NULL
, nsRDFXMLParser::Create
},
159 { &kNS_RDFXMLSERIALIZER_CID
, false, NULL
, nsRDFXMLSerializer::Create
},
160 { &kNS_RDFNTRIPLES_SERIALIZER_CID
, false, NULL
, CreateNewTriplesSerializer
},
161 { &kNS_LOCALSTORE_CID
, false, NULL
, NS_NewLocalStore
},
165 static const mozilla::Module::ContractIDEntry kRDFContracts
[] = {
166 { NS_RDF_DATASOURCE_CONTRACTID_PREFIX
"composite-datasource", &kNS_RDFCOMPOSITEDATASOURCE_CID
},
167 { NS_RDF_DATASOURCE_CONTRACTID_PREFIX
"files", &kNS_RDFFILESYSTEMDATASOURCE_CID
},
168 { NS_RDF_DATASOURCE_CONTRACTID_PREFIX
"in-memory-datasource", &kNS_RDFINMEMORYDATASOURCE_CID
},
169 { NS_RDF_DATASOURCE_CONTRACTID_PREFIX
"xml-datasource", &kNS_RDFXMLDATASOURCE_CID
},
170 { NS_RDF_RESOURCE_FACTORY_CONTRACTID
, &kNS_RDFDEFAULTRESOURCE_CID
},
171 { NS_RDF_CONTRACTID
"/content-sink;1", &kNS_RDFCONTENTSINK_CID
},
172 { NS_RDF_CONTRACTID
"/container;1", &kNS_RDFCONTAINER_CID
},
173 { NS_RDF_CONTRACTID
"/container-utils;1", &kNS_RDFCONTAINERUTILS_CID
},
174 { NS_RDF_CONTRACTID
"/rdf-service;1", &kNS_RDFSERVICE_CID
},
175 { NS_RDF_CONTRACTID
"/xml-parser;1", &kNS_RDFXMLPARSER_CID
},
176 { NS_RDF_CONTRACTID
"/xml-serializer;1", &kNS_RDFXMLSERIALIZER_CID
},
177 { NS_RDF_SERIALIZER
"ntriples", &kNS_RDFNTRIPLES_SERIALIZER_CID
},
178 { NS_LOCALSTORE_CONTRACTID
, &kNS_LOCALSTORE_CID
},
185 if (RDFServiceImpl::gRDFService
) {
186 NS_ERROR("Leaked the RDF service from a previous startup.");
187 RDFServiceImpl::gRDFService
= nsnull
;
196 if (RDFServiceImpl::gRDFService
) {
197 // XXX make this an assertion!
198 NS_WARNING("Leaking the RDF Service.");
202 static const mozilla::Module kRDFModule
= {
203 mozilla::Module::kVersion
,
212 NSMODULE_DEFN(nsRDFModule
) = &kRDFModule
;