Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Public Attributes | Protected Attributes | Static Protected Attributes
nsRDFResource Class Reference

This simple base class implements nsIRDFResource, and can be used as a superclass for more sophisticated resource implementations. More...

#include <nsRDFResource.h>

Inheritance diagram for nsRDFResource:
Inheritance graph
[legend]
Collaboration diagram for nsRDFResource:
Collaboration graph
[legend]

List of all members.

Classes

struct  DelegateEntry

Public Member Functions

NS_DECL_ISUPPORTS NS_IMETHOD EqualsNode (nsIRDFNode *aNode, PRBool *aResult)
NS_IMETHOD Init (const char *aURI)
NS_IMETHOD GetValue (char **aURI)
NS_IMETHOD GetValueUTF8 (nsACString &aResult)
NS_IMETHOD GetValueConst (const char **aURI)
NS_IMETHOD EqualsString (const char *aURI, PRBool *aResult)
NS_IMETHOD GetDelegate (const char *aKey, REFNSIID aIID, void **aResult)
NS_IMETHOD ReleaseDelegate (const char *aKey)
 nsRDFResource (void)
virtual ~nsRDFResource (void)
void GetValueConst ([shared] out string aConstValue)
 An unscriptable version used to avoid a string copy.
void Init (in string uri)
 This method is called by the nsIRDFService after constructing a resource object to initialize it's URI.
boolean EqualsString (in string aURI)
 Determine if the resource has the given URI.
void GetDelegate (in string aKey, in nsIIDRef aIID,[iid_is(aIID), retval] out nsQIResult aResult)
 Retrieve the "delegate" object for this resource.
void ReleaseDelegate (in string aKey)
 Force a delegate to be "unbound" from the resource.
boolean EqualsNode (in nsIRDFNode aNode)

Public Attributes

readonly attribute string Value
 The single-byte string value of the resource.
readonly attribute AUTF8String ValueUTF8
 The UTF-8 URI of the resource.

Protected Attributes

nsCString mURI
DelegateEntrymDelegates

Static Protected Attributes

static nsIRDFServicegRDFService = nsnull
static nsrefcnt gRDFServiceRefCnt = 0

Detailed Description

This simple base class implements nsIRDFResource, and can be used as a superclass for more sophisticated resource implementations.

Definition at line 53 of file nsRDFResource.h.


Class Documentation

struct nsRDFResource::DelegateEntry

Definition at line 81 of file nsRDFResource.h.

Collaboration diagram for nsRDFResource::DelegateEntry:
Class Members
nsCOMPtr< nsISupports > mDelegate
nsCString mKey
DelegateEntry * mNext

Constructor & Destructor Documentation

Definition at line 55 of file nsRDFResource.cpp.

Definition at line 60 of file nsRDFResource.cpp.

{
    // Release all of the delegate objects
    while (mDelegates) {
        DelegateEntry* doomed = mDelegates;
        mDelegates = mDelegates->mNext;
        delete doomed;
    }

    if (!gRDFService)
        return;

    gRDFService->UnregisterResource(this);

    if (--gRDFServiceRefCnt == 0)
        NS_RELEASE(gRDFService);
}

Here is the call graph for this function:


Member Function Documentation

boolean nsIRDFNode::EqualsNode ( in nsIRDFNode  aNode) [inherited]

Definition at line 84 of file nsRDFResource.cpp.

{
    NS_PRECONDITION(aNode != nsnull, "null ptr");
    if (! aNode)
        return NS_ERROR_NULL_POINTER;

    nsresult rv;
    nsIRDFResource* resource;
    rv = aNode->QueryInterface(NS_GET_IID(nsIRDFResource), (void**)&resource);
    if (NS_SUCCEEDED(rv)) {
        *aResult = (NS_STATIC_CAST(nsIRDFResource*, this) == resource);
        NS_RELEASE(resource);
        return NS_OK;
    }
    else if (rv == NS_NOINTERFACE) {
        *aResult = PR_FALSE;
        return NS_OK;
    }
    else {
        return rv;
    }
}
NS_IMETHODIMP nsRDFResource::EqualsString ( const char *  aURI,
PRBool aResult 
)

Definition at line 156 of file nsRDFResource.cpp.

{
    NS_PRECONDITION(aURI != nsnull, "null ptr");
    if (! aURI)
        return NS_ERROR_NULL_POINTER;

    NS_PRECONDITION(aResult, "null ptr");

    *aResult = mURI.Equals(aURI);
    return NS_OK;
}

Determine if the resource has the given URI.

NS_IMETHODIMP nsRDFResource::GetDelegate ( const char *  aKey,
REFNSIID  aIID,
void **  aResult 
)

Definition at line 169 of file nsRDFResource.cpp.

{
    NS_PRECONDITION(aKey != nsnull, "null ptr");
    if (! aKey)
        return NS_ERROR_NULL_POINTER;

    nsresult rv;
    *aResult = nsnull;

    DelegateEntry* entry = mDelegates;
    while (entry) {
        if (entry->mKey.Equals(aKey)) {
            rv = entry->mDelegate->QueryInterface(aIID, aResult);
            return rv;
        }

        entry = entry->mNext;
    }

    // Construct a ContractID of the form "@mozilla.org/rdf/delegate/[key]/[scheme];1
    nsCAutoString contractID(NS_RDF_DELEGATEFACTORY_CONTRACTID_PREFIX);
    contractID.Append(aKey);
    contractID.Append("&scheme=");

    PRInt32 i = mURI.FindChar(':');
    contractID += StringHead(mURI, i);

    nsCOMPtr<nsIRDFDelegateFactory> delegateFactory =
             do_CreateInstance(contractID.get(), &rv);
    if (NS_FAILED(rv)) return rv;

    rv = delegateFactory->CreateDelegate(this, aKey, aIID, aResult);
    if (NS_FAILED(rv)) return rv;

    // Okay, we've successfully created a delegate. Let's remember it.
    entry = new DelegateEntry;
    if (! entry) {
        NS_RELEASE(*NS_REINTERPRET_CAST(nsISupports**, aResult));
        return NS_ERROR_OUT_OF_MEMORY;
    }
    
    entry->mKey      = aKey;
    entry->mDelegate = do_QueryInterface(*NS_REINTERPRET_CAST(nsISupports**, aResult), &rv);
    if (NS_FAILED(rv)) {
        NS_ERROR("nsRDFResource::GetDelegate(): can't QI to nsISupports!");

        delete entry;
        NS_RELEASE(*NS_REINTERPRET_CAST(nsISupports**, aResult));
        return NS_ERROR_FAILURE;
    }

    entry->mNext     = mDelegates;

    mDelegates = entry;

    return NS_OK;
}

Here is the call graph for this function:

void nsIRDFResource::GetDelegate ( in string  aKey,
in nsIIDRef  aIID,
[iid_is(aIID), retval] out nsQIResult  aResult 
) [inherited]

Retrieve the "delegate" object for this resource.

A resource may have several delegate objects, each of whose lifetimes is bound to the life of the resource object.

This method will return the delegate for the given key after QueryInterface()-ing it to the requested IID.

If no delegate exists for the specified key, this method will attempt to create one using the component manager. Specifically, it will combine aKey with the resource's URI scheme to produce a ContractID as follows:

component:/rdf/delegate-factory/[key]/[scheme]

This ContractID will be used to locate a factory using the FindFactory() method of nsIComponentManager. If the nsIFactory exists, it will be used to create a "delegate factory"; that is, an object that supports nsIRDFDelegateFactory. The delegate factory will be used to construct the delegate object.

Here is the caller graph for this function:

Definition at line 129 of file nsRDFResource.cpp.

{
    NS_ASSERTION(aURI, "Null out param.");
    
    *aURI = ToNewCString(mURI);

    if (!*aURI)
        return NS_ERROR_OUT_OF_MEMORY;

    return NS_OK;
}

Here is the call graph for this function:

void nsIRDFResource::GetValueConst ( [shared] out string  aConstValue) [inherited]

An unscriptable version used to avoid a string copy.

Meant for use as a performance optimization. The string is encoded in UTF-8.

Definition at line 149 of file nsRDFResource.cpp.

{
    *aURI = mURI.get();
    return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRDFResource::GetValueUTF8 ( nsACString &  aResult)

Definition at line 142 of file nsRDFResource.cpp.

{
    aResult = mURI;
    return NS_OK;
}

Reimplemented in nsAbOSXDirectory, NS_MSG_BASE, nsAbMDBDirectory, nsAbOutlookDirectory, nsAbOSXCard, nsAbLDAPDirectory, nsAbOutlookCard, and nsAbDirectoryRDFResource.

Definition at line 111 of file nsRDFResource.cpp.

{
    NS_PRECONDITION(aURI != nsnull, "null ptr");
    if (! aURI)
        return NS_ERROR_NULL_POINTER;

    mURI = aURI;

    if (gRDFServiceRefCnt++ == 0) {
        nsresult rv = CallGetService(kRDFServiceCID, &gRDFService);
        if (NS_FAILED(rv)) return rv;
    }

    // don't replace an existing resource with the same URI automatically
    return gRDFService->RegisterResource(this, PR_TRUE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIRDFResource::Init ( in string  uri) [inherited]

This method is called by the nsIRDFService after constructing a resource object to initialize it's URI.

You would not normally call this method directly

Definition at line 228 of file nsRDFResource.cpp.

{
    NS_PRECONDITION(aKey != nsnull, "null ptr");
    if (! aKey)
        return NS_ERROR_NULL_POINTER;

    DelegateEntry* entry = mDelegates;
    DelegateEntry** link = &mDelegates;

    while (entry) {
        if (entry->mKey.Equals(aKey)) {
            *link = entry->mNext;
            delete entry;
            return NS_OK;
        }

        link = &(entry->mNext);
        entry = entry->mNext;
    }

    NS_WARNING("nsRDFResource::ReleaseDelegate() no delegate found");
    return NS_OK;
}

Force a delegate to be "unbound" from the resource.

Normally, a delegate object's lifetime will be identical to that of the resource to which it is bound; this method allows a delegate to unlink itself from an RDF resource prematurely.


Member Data Documentation

Definition at line 75 of file nsRDFResource.h.

nsrefcnt nsRDFResource::gRDFServiceRefCnt = 0 [static, protected]

Definition at line 76 of file nsRDFResource.h.

Definition at line 87 of file nsRDFResource.h.

Definition at line 79 of file nsRDFResource.h.

readonly attribute string nsIRDFResource::Value [inherited]

The single-byte string value of the resource.

Note:
THIS IS OBSOLETE. C++ should use GetValueConst and script should use .valueUTF8

Definition at line 53 of file nsIRDFResource.idl.

readonly attribute AUTF8String nsIRDFResource::ValueUTF8 [inherited]

The UTF-8 URI of the resource.

Definition at line 58 of file nsIRDFResource.idl.


The documentation for this class was generated from the following files: