michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: #include "nsIRDFResource.idl" michael@0: #include "nsIRDFLiteral.idl" michael@0: #include "nsIRDFDataSource.idl" michael@0: michael@0: michael@0: /** michael@0: * The RDF service interface. This is a singleton object which should be michael@0: * obtained from the nsServiceManager. michael@0: */ michael@0: [scriptable, uuid(BFD05261-834C-11d2-8EAC-00805F29F370)] michael@0: interface nsIRDFService : nsISupports { michael@0: /** michael@0: * Construct an RDF resource from a single-byte URI. nsIRDFService michael@0: * caches resources that are in-use, so multiple calls to GetResource() michael@0: * for the same uri will return identical pointers. FindResource michael@0: * is used to find out whether there already exists a resource corresponding to that url. michael@0: */ michael@0: nsIRDFResource GetResource(in AUTF8String aURI); michael@0: michael@0: /** michael@0: * Construct an RDF resource from a Unicode URI. This is provided michael@0: * as a convenience method, allowing automatic, in-line C++ michael@0: * conversion from nsString objects. The uri will michael@0: * be converted to a single-byte representation internally. michael@0: */ michael@0: nsIRDFResource GetUnicodeResource(in AString aURI); michael@0: michael@0: nsIRDFResource GetAnonymousResource(); michael@0: michael@0: /** michael@0: * Construct an RDF literal from a Unicode string. michael@0: */ michael@0: nsIRDFLiteral GetLiteral(in wstring aValue); michael@0: michael@0: /** michael@0: * Construct an RDF literal from a PRTime. michael@0: */ michael@0: nsIRDFDate GetDateLiteral(in PRTime aValue); michael@0: michael@0: /** michael@0: * Construct an RDF literal from an int. michael@0: */ michael@0: nsIRDFInt GetIntLiteral(in long aValue); michael@0: michael@0: /** michael@0: * Construct an RDF literal from a data blob michael@0: */ michael@0: [noscript] nsIRDFBlob getBlobLiteral(in const_octet_ptr aValue, in long aLength); michael@0: michael@0: boolean IsAnonymousResource(in nsIRDFResource aResource); michael@0: michael@0: /** michael@0: * Registers a resource with the RDF system, making it unique w.r.t. michael@0: * GetResource. michael@0: * michael@0: * An implementation of nsIRDFResource should call this in its michael@0: * Init() method if it wishes the resource to be globally unique michael@0: * (which is usually the case). michael@0: * michael@0: * @note that the resource will not be ref-counted by the michael@0: * RDF service: the assumption is that the resource implementation michael@0: * will call nsIRDFService::UnregisterResource() when the last michael@0: * reference to the resource is released. michael@0: * michael@0: * @note that the nsIRDFService implementation may choose to michael@0: * maintain a reference to the resource's URI; therefore, the michael@0: * resource implementation should ensure that the resource's URI michael@0: * (accessible via nsIRDFResource::GetValue(const char* *aURI)) is michael@0: * valid before calling RegisterResource(). Furthermore, the michael@0: * resource implementation should ensure that this pointer michael@0: * remains valid for the lifetime of the resource. (The michael@0: * implementation of the resource cache in nsIRDFService uses the michael@0: * URI maintained "internally" in the resource as a key into the michael@0: * cache rather than copying the resource URI itself.) michael@0: */ michael@0: void RegisterResource(in nsIRDFResource aResource, in boolean aReplace); michael@0: michael@0: /** michael@0: * Called to notify the resource manager that a resource is no michael@0: * longer in use. This method should only be called from the michael@0: * destructor of a "custom" resource implementation to notify the michael@0: * RDF service that the last reference to the resource has been michael@0: * released, so the resource is no longer valid. michael@0: * michael@0: * @note As mentioned in nsIRDFResourceFactory::CreateResource(), michael@0: * the RDF service will use the result of michael@0: * nsIRDFResource::GetValue() as a key into its cache. For this michael@0: * reason, you must always un-cache the resource before michael@0: * releasing the storage for the const char* URI. michael@0: */ michael@0: void UnregisterResource(in nsIRDFResource aResource); michael@0: michael@0: /** michael@0: * Register a named data source. The RDF service will call michael@0: * nsIRDFDataSource::GetURI() to determine the URI under michael@0: * which to register the data source. michael@0: * michael@0: * @note that the data source will not be refcounted by the michael@0: * RDF service! The assumption is that an RDF data source michael@0: * registers with the service once it is initialized (via michael@0: * nsIRDFDataSource::Init()), and unregisters when the michael@0: * last reference to the data source is released. michael@0: */ michael@0: void RegisterDataSource(in nsIRDFDataSource aDataSource, michael@0: in boolean aReplace); michael@0: michael@0: /** michael@0: * Unregister a named data source. The RDF service will call michael@0: * nsIRDFDataSource::GetURI() to determine the URI under which the michael@0: * data source was registered. michael@0: */ michael@0: void UnregisterDataSource(in nsIRDFDataSource aDataSource); michael@0: michael@0: /** michael@0: * Get the named data source corresponding to the URI. If a data michael@0: * source has been registered via RegisterDataSource(), that michael@0: * data source will be returned. michael@0: * michael@0: * If no data source is currently michael@0: * registered for the specified URI, and a data source constructor michael@0: * function has been registered via RegisterDatasourceConstructor(), michael@0: * the RDF service will call the constructor to attempt to construct a michael@0: * new data source. If construction is successful, the data source will michael@0: * be initialized via nsIRDFDataSource::Init(). michael@0: */ michael@0: nsIRDFDataSource GetDataSource(in string aURI); michael@0: michael@0: /** michael@0: * Same as GetDataSource, but if a remote/XML data source needs to be michael@0: * constructed, then this method will issue a blocking Refresh michael@0: * call on that data source. michael@0: */ michael@0: nsIRDFDataSource GetDataSourceBlocking(in string aURI); michael@0: }; michael@0: michael@0: %{C++ michael@0: extern nsresult michael@0: NS_NewRDFService(nsIRDFService** result); michael@0: %} michael@0: