nsRDFModule.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nsCOMPtr.h"
  6. #include "mozilla/ModuleUtils.h"
  7. #include "nsIFactory.h"
  8. #include "nsRDFService.h"
  9. #include "nsIRDFContainer.h"
  10. #include "nsIRDFContainerUtils.h"
  11. #include "nsIRDFCompositeDataSource.h"
  12. #include "nsIRDFContentSink.h"
  13. #include "nsISupports.h"
  14. #include "nsRDFBaseDataSources.h"
  15. #include "nsRDFBuiltInDataSources.h"
  16. #include "nsFileSystemDataSource.h"
  17. #include "nsRDFCID.h"
  18. #include "nsIComponentManager.h"
  19. #include "rdf.h"
  20. #include "nsIServiceManager.h"
  21. #include "nsILocalStore.h"
  22. #include "nsRDFXMLParser.h"
  23. #include "nsRDFXMLSerializer.h"
  24. #include "rdfISerializer.h"
  25. //----------------------------------------------------------------------
  26. // Functions used to create new instances of a given object by the
  27. // generic factory.
  28. #define MAKE_CTOR(_func,_new,_ifname) \
  29. static nsresult \
  30. CreateNew##_func(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
  31. { \
  32. if (!aResult) { \
  33. return NS_ERROR_INVALID_POINTER; \
  34. } \
  35. if (aOuter) { \
  36. *aResult = nullptr; \
  37. return NS_ERROR_NO_AGGREGATION; \
  38. } \
  39. nsI##_ifname* inst; \
  40. nsresult rv = NS_New##_new(&inst); \
  41. if (NS_FAILED(rv)) { \
  42. *aResult = nullptr; \
  43. return rv; \
  44. } \
  45. rv = inst->QueryInterface(aIID, aResult); \
  46. if (NS_FAILED(rv)) { \
  47. *aResult = nullptr; \
  48. } \
  49. NS_RELEASE(inst); /* get rid of extra refcnt */ \
  50. return rv; \
  51. }
  52. extern nsresult
  53. NS_NewDefaultResource(nsIRDFResource** aResult);
  54. MAKE_CTOR(RDFXMLDataSource,RDFXMLDataSource,RDFDataSource)
  55. MAKE_CTOR(RDFCompositeDataSource,RDFCompositeDataSource,RDFCompositeDataSource)
  56. MAKE_CTOR(RDFContainer,RDFContainer,RDFContainer)
  57. MAKE_CTOR(RDFContainerUtils,RDFContainerUtils,RDFContainerUtils)
  58. MAKE_CTOR(RDFContentSink,RDFContentSink,RDFContentSink)
  59. MAKE_CTOR(RDFDefaultResource,DefaultResource,RDFResource)
  60. #define MAKE_RDF_CTOR(_func,_new,_ifname) \
  61. static nsresult \
  62. CreateNew##_func(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
  63. { \
  64. if (!aResult) { \
  65. return NS_ERROR_INVALID_POINTER; \
  66. } \
  67. if (aOuter) { \
  68. *aResult = nullptr; \
  69. return NS_ERROR_NO_AGGREGATION; \
  70. } \
  71. rdfI##_ifname* inst; \
  72. nsresult rv = NS_New##_new(&inst); \
  73. if (NS_FAILED(rv)) { \
  74. *aResult = nullptr; \
  75. return rv; \
  76. } \
  77. rv = inst->QueryInterface(aIID, aResult); \
  78. if (NS_FAILED(rv)) { \
  79. *aResult = nullptr; \
  80. } \
  81. NS_RELEASE(inst); /* get rid of extra refcnt */ \
  82. return rv; \
  83. }
  84. extern nsresult
  85. NS_NewTriplesSerializer(rdfISerializer** aResult);
  86. MAKE_RDF_CTOR(TriplesSerializer, TriplesSerializer, Serializer)
  87. NS_DEFINE_NAMED_CID(NS_RDFCOMPOSITEDATASOURCE_CID);
  88. NS_DEFINE_NAMED_CID(NS_RDFFILESYSTEMDATASOURCE_CID);
  89. NS_DEFINE_NAMED_CID(NS_RDFINMEMORYDATASOURCE_CID);
  90. NS_DEFINE_NAMED_CID(NS_RDFXMLDATASOURCE_CID);
  91. NS_DEFINE_NAMED_CID(NS_RDFDEFAULTRESOURCE_CID);
  92. NS_DEFINE_NAMED_CID(NS_RDFCONTENTSINK_CID);
  93. NS_DEFINE_NAMED_CID(NS_RDFCONTAINER_CID);
  94. NS_DEFINE_NAMED_CID(NS_RDFCONTAINERUTILS_CID);
  95. NS_DEFINE_NAMED_CID(NS_RDFSERVICE_CID);
  96. NS_DEFINE_NAMED_CID(NS_RDFXMLPARSER_CID);
  97. NS_DEFINE_NAMED_CID(NS_RDFXMLSERIALIZER_CID);
  98. NS_DEFINE_NAMED_CID(NS_RDFNTRIPLES_SERIALIZER_CID);
  99. NS_DEFINE_NAMED_CID(NS_LOCALSTORE_CID);
  100. static const mozilla::Module::CIDEntry kRDFCIDs[] = {
  101. { &kNS_RDFCOMPOSITEDATASOURCE_CID, false, nullptr, CreateNewRDFCompositeDataSource },
  102. { &kNS_RDFFILESYSTEMDATASOURCE_CID, false, nullptr, FileSystemDataSource::Create },
  103. { &kNS_RDFINMEMORYDATASOURCE_CID, false, nullptr, NS_NewRDFInMemoryDataSource },
  104. { &kNS_RDFXMLDATASOURCE_CID, false, nullptr, CreateNewRDFXMLDataSource },
  105. { &kNS_RDFDEFAULTRESOURCE_CID, false, nullptr, CreateNewRDFDefaultResource },
  106. { &kNS_RDFCONTENTSINK_CID, false, nullptr, CreateNewRDFContentSink },
  107. { &kNS_RDFCONTAINER_CID, false, nullptr, CreateNewRDFContainer },
  108. { &kNS_RDFCONTAINERUTILS_CID, false, nullptr, CreateNewRDFContainerUtils },
  109. { &kNS_RDFSERVICE_CID, false, nullptr, RDFServiceImpl::CreateSingleton },
  110. { &kNS_RDFXMLPARSER_CID, false, nullptr, nsRDFXMLParser::Create },
  111. { &kNS_RDFXMLSERIALIZER_CID, false, nullptr, nsRDFXMLSerializer::Create },
  112. { &kNS_RDFNTRIPLES_SERIALIZER_CID, false, nullptr, CreateNewTriplesSerializer },
  113. { &kNS_LOCALSTORE_CID, false, nullptr, NS_NewLocalStore },
  114. { nullptr }
  115. };
  116. static const mozilla::Module::ContractIDEntry kRDFContracts[] = {
  117. { NS_RDF_DATASOURCE_CONTRACTID_PREFIX "composite-datasource", &kNS_RDFCOMPOSITEDATASOURCE_CID },
  118. { NS_RDF_DATASOURCE_CONTRACTID_PREFIX "files", &kNS_RDFFILESYSTEMDATASOURCE_CID },
  119. { NS_RDF_DATASOURCE_CONTRACTID_PREFIX "in-memory-datasource", &kNS_RDFINMEMORYDATASOURCE_CID },
  120. { NS_RDF_DATASOURCE_CONTRACTID_PREFIX "xml-datasource", &kNS_RDFXMLDATASOURCE_CID },
  121. { NS_RDF_RESOURCE_FACTORY_CONTRACTID, &kNS_RDFDEFAULTRESOURCE_CID },
  122. { NS_RDF_CONTRACTID "/content-sink;1", &kNS_RDFCONTENTSINK_CID },
  123. { NS_RDF_CONTRACTID "/container;1", &kNS_RDFCONTAINER_CID },
  124. { NS_RDF_CONTRACTID "/container-utils;1", &kNS_RDFCONTAINERUTILS_CID },
  125. { NS_RDF_CONTRACTID "/rdf-service;1", &kNS_RDFSERVICE_CID },
  126. { NS_RDF_CONTRACTID "/xml-parser;1", &kNS_RDFXMLPARSER_CID },
  127. { NS_RDF_CONTRACTID "/xml-serializer;1", &kNS_RDFXMLSERIALIZER_CID },
  128. { NS_RDF_SERIALIZER "ntriples", &kNS_RDFNTRIPLES_SERIALIZER_CID },
  129. { NS_LOCALSTORE_CONTRACTID, &kNS_LOCALSTORE_CID },
  130. { nullptr }
  131. };
  132. static const mozilla::Module kRDFModule = {
  133. mozilla::Module::kVersion,
  134. kRDFCIDs,
  135. kRDFContracts,
  136. nullptr,
  137. nullptr,
  138. nullptr,
  139. nullptr
  140. };
  141. NSMODULE_DEFN(nsRDFModule) = &kRDFModule;