Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Private Member Functions | Private Attributes
txVariable Class Reference

#include <txMozillaXSLTProcessor.h>

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

List of all members.

Public Member Functions

 txVariable (nsIVariant *aValue)
 txVariable (txAExprResult *aValue)
nsresult getValue (txAExprResult **aValue)
nsresult getValue (nsIVariant **aValue)
void setValue (nsIVariant *aValue)
void setValue (txAExprResult *aValue)

Static Private Member Functions

static nsresult Convert (nsIVariant *aValue, txAExprResult **aResult)

Private Attributes

nsCOMPtr< nsIVariantmValue
nsRefPtr< txAExprResultmTxValue

Detailed Description

Definition at line 73 of file txMozillaXSLTProcessor.h.


Constructor & Destructor Documentation

txVariable::txVariable ( nsIVariant aValue) [inline]

Definition at line 76 of file txMozillaXSLTProcessor.h.

                                   : mValue(aValue)
    {
        NS_ASSERTION(aValue, "missing value");
    }
txVariable::txVariable ( txAExprResult aValue) [inline]

Definition at line 80 of file txMozillaXSLTProcessor.h.

                                      : mTxValue(aValue)
    {
        NS_ASSERTION(aValue, "missing value");
    }

Member Function Documentation

nsresult txVariable::Convert ( nsIVariant aValue,
txAExprResult **  aResult 
) [static, private]

Definition at line 1246 of file txMozillaXSLTProcessor.cpp.

{
    *aResult = nsnull;

    PRUint16 dataType;
    aValue->GetDataType(&dataType);
    switch (dataType) {
        // Number
        case nsIDataType::VTYPE_INT8:
        case nsIDataType::VTYPE_INT16:
        case nsIDataType::VTYPE_INT32:
        case nsIDataType::VTYPE_INT64:
        case nsIDataType::VTYPE_UINT8:
        case nsIDataType::VTYPE_UINT16:
        case nsIDataType::VTYPE_UINT32:
        case nsIDataType::VTYPE_UINT64:
        case nsIDataType::VTYPE_FLOAT:
        case nsIDataType::VTYPE_DOUBLE:
        {
            double value;
            nsresult rv = aValue->GetAsDouble(&value);
            NS_ENSURE_SUCCESS(rv, rv);

            *aResult = new NumberResult(value, nsnull);
            NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);

            NS_ADDREF(*aResult);

            return NS_OK;
        }

        // Boolean
        case nsIDataType::VTYPE_BOOL:
        {
            PRBool value;
            nsresult rv = aValue->GetAsBool(&value);
            NS_ENSURE_SUCCESS(rv, rv);

            *aResult = new BooleanResult(value);
            NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);

            NS_ADDREF(*aResult);

            return NS_OK;
        }

        // String
        case nsIDataType::VTYPE_CHAR:
        case nsIDataType::VTYPE_WCHAR:
        case nsIDataType::VTYPE_DOMSTRING:
        case nsIDataType::VTYPE_CHAR_STR:
        case nsIDataType::VTYPE_WCHAR_STR:
        case nsIDataType::VTYPE_STRING_SIZE_IS:
        case nsIDataType::VTYPE_WSTRING_SIZE_IS:
        case nsIDataType::VTYPE_UTF8STRING:
        case nsIDataType::VTYPE_CSTRING:
        case nsIDataType::VTYPE_ASTRING:
        {
            nsAutoString value;
            nsresult rv = aValue->GetAsAString(value);
            NS_ENSURE_SUCCESS(rv, rv);

            *aResult = new StringResult(value, nsnull);
            NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);

            NS_ADDREF(*aResult);

            return NS_OK;
        }

        // Nodeset
        case nsIDataType::VTYPE_INTERFACE:
        case nsIDataType::VTYPE_INTERFACE_IS:
        {
            nsCOMPtr<nsISupports> supports;
            nsresult rv = aValue->GetAsISupports(getter_AddRefs(supports));
            NS_ENSURE_SUCCESS(rv, rv);

            nsCOMPtr<nsIDOMNode> node = do_QueryInterface(supports);
            if (node) {
                nsAutoPtr<txXPathNode> xpathNode(txXPathNativeNode::createXPathNode(node));
                if (!xpathNode) {
                    return NS_ERROR_FAILURE;
                }

                *aResult = new txNodeSet(*xpathNode, nsnull);
                if (!*aResult) {
                    return NS_ERROR_OUT_OF_MEMORY;
                }

                NS_ADDREF(*aResult);

                return NS_OK;
            }

            nsCOMPtr<nsIXPathResult> xpathResult = do_QueryInterface(supports);
            if (xpathResult) {
                return xpathResult->GetExprResult(aResult);
            }

            nsCOMPtr<nsIDOMNodeList> nodeList = do_QueryInterface(supports);
            if (nodeList) {
                nsRefPtr<txNodeSet> nodeSet = new txNodeSet(nsnull);
                if (!nodeSet) {
                    return NS_ERROR_OUT_OF_MEMORY;
                }

                PRUint32 length;
                nodeList->GetLength(&length);

                nsCOMPtr<nsIDOMNode> node;
                PRUint32 i;
                for (i = 0; i < length; ++i) {
                    nodeList->Item(i, getter_AddRefs(node));

                    nsAutoPtr<txXPathNode> xpathNode(
                        txXPathNativeNode::createXPathNode(node));
                    if (!xpathNode) {
                        return NS_ERROR_FAILURE;
                    }

                    nodeSet->add(*xpathNode);
                }

                NS_ADDREF(*aResult = nodeSet);

                return NS_OK;
            }

            // Convert random JS Objects to a string.
            nsCOMPtr<nsIXPConnectJSObjectHolder> holder =
                do_QueryInterface(supports);
            if (holder) {
                nsCOMPtr<nsIXPConnect> xpc =
                    do_GetService(nsIXPConnect::GetCID(), &rv);
                NS_ENSURE_SUCCESS(rv, rv);
                
                nsCOMPtr<nsIXPCNativeCallContext> cc;
                rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
                NS_ENSURE_SUCCESS(rv, rv);

                JSContext* cx;
                rv = cc->GetJSContext(&cx);
                NS_ENSURE_SUCCESS(rv, rv);

                JSObject *jsobj;
                rv = holder->GetJSObject(&jsobj);
                NS_ENSURE_SUCCESS(rv, rv);

                JSString *str = JS_ValueToString(cx, OBJECT_TO_JSVAL(jsobj));
                NS_ENSURE_TRUE(str, NS_ERROR_FAILURE);

                const PRUnichar *strChars =
                    NS_REINTERPRET_CAST(const PRUnichar*,
                                        ::JS_GetStringChars(str));
                nsDependentString value(strChars, ::JS_GetStringLength(str));

                *aResult = new StringResult(value, nsnull);
                if (!*aResult) {
                    return NS_ERROR_OUT_OF_MEMORY;
                }

                NS_ADDREF(*aResult);

                return NS_OK;
            }

            break;
        }

        case nsIDataType::VTYPE_ARRAY:
        {
            PRUint16 type;
            nsIID iid;
            PRUint32 count;
            void* array;
            nsresult rv = aValue->GetAsArray(&type, &iid, &count, &array);
            NS_ENSURE_SUCCESS(rv, rv);

            NS_ASSERTION(type == nsIDataType::VTYPE_INTERFACE ||
                         type == nsIDataType::VTYPE_INTERFACE_IS,
                         "Huh, we checked this in SetParameter?");

            nsISupports** values = NS_STATIC_CAST(nsISupports**, array);

            nsRefPtr<txNodeSet> nodeSet = new txNodeSet(nsnull);
            if (!nodeSet) {
                NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, values);

                return NS_ERROR_OUT_OF_MEMORY;
            }

            PRUint32 i;
            for (i = 0; i < count; ++i) {
                nsISupports *supports = values[i];
                nsCOMPtr<nsIDOMNode> node = do_QueryInterface(supports);
                NS_ASSERTION(node, "Huh, we checked this in SetParameter?");

                nsAutoPtr<txXPathNode> xpathNode(
                    txXPathNativeNode::createXPathNode(node));
                if (!xpathNode) {
                    while (i < count) {
                        NS_RELEASE(values[i++]);
                    }
                    nsMemory::Free(array);

                    return NS_ERROR_FAILURE;
                }

                nodeSet->add(*xpathNode);

                NS_RELEASE(supports);
            }

            nsMemory::Free(array);

            NS_ADDREF(*aResult = nodeSet);

            return NS_OK;
        }
    }

    return NS_ERROR_ILLEGAL_VALUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult txVariable::getValue ( txAExprResult **  aValue) [inline, virtual]

Implements txIGlobalParameter.

Definition at line 84 of file txMozillaXSLTProcessor.h.

    {
        NS_ASSERTION(mValue || mTxValue, "variablevalue is null");

        if (!mTxValue) {
            nsresult rv = Convert(mValue, getter_AddRefs(mTxValue));
            NS_ENSURE_SUCCESS(rv, rv);
        }

        *aValue = mTxValue;
        NS_ADDREF(*aValue);

        return NS_OK;
    }

Here is the call graph for this function:

nsresult txVariable::getValue ( nsIVariant **  aValue) [inline]

Definition at line 98 of file txMozillaXSLTProcessor.h.

    {
        *aValue = mValue;
        NS_ADDREF(*aValue);
        return NS_OK;
    }

Here is the call graph for this function:

void txVariable::setValue ( nsIVariant aValue) [inline]

Definition at line 104 of file txMozillaXSLTProcessor.h.

    {
        NS_ASSERTION(aValue, "setting variablevalue to null");
        mValue = aValue;
        mTxValue = nsnull;
    }

Here is the caller graph for this function:

void txVariable::setValue ( txAExprResult aValue) [inline]

Definition at line 110 of file txMozillaXSLTProcessor.h.

    {
        NS_ASSERTION(aValue, "setting variablevalue to null");
        mValue = nsnull;
        mTxValue = aValue;
    }

Member Data Documentation

Definition at line 121 of file txMozillaXSLTProcessor.h.

Definition at line 120 of file txMozillaXSLTProcessor.h.


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