aboutsummaryrefslogtreecommitdiffstats
path: root/src/native/addrbook/msoutlook/MsOutlookMAPIHResultException.cxx
blob: 706a5de71cd31e14be8cc75e062a0b48762ff053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

#include "MsOutlookMAPIHResultException.h"

void
MsOutlookMAPIHResultException_throwNew
    (JNIEnv *jniEnv, HRESULT hResult, LPCSTR file, ULONG line)
{
    jclass clazz;

    clazz
        = jniEnv->FindClass(
                "net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookMAPIHResultException");
    if (clazz)
    {
        LPCSTR message;

        switch (hResult)
        {
        case MAPI_E_LOGON_FAILED:
            message = "MAPI_E_LOGON_FAILED";
            break;
        case MAPI_E_NO_ACCESS:
            message = "MAPI_E_NO_ACCESS";
            break;
        case MAPI_E_NO_SUPPORT:
            message = "MAPI_E_NO_SUPPORT";
            break;
        case MAPI_E_NOT_ENOUGH_MEMORY:
            message = "MAPI_E_NOT_ENOUGH_MEMORY";
            break;
        case MAPI_E_NOT_FOUND:
            message = "MAPI_E_NOT_FOUND";
            break;
        case MAPI_E_NOT_INITIALIZED:
            message = "MAPI_E_NOT_INITIALIZED";
            break;
        case MAPI_E_TIMEOUT:
            message = "MAPI_E_TIMEOUT";
            break;
        case MAPI_E_UNKNOWN_ENTRYID:
            message = "MAPI_E_UNKNOWN_ENTRYID";
            break;
        case MAPI_E_USER_CANCEL:
            message = "MAPI_E_USER_CANCEL";
            break;
        case MAPI_W_ERRORS_RETURNED:
            message = "MAPI_W_ERRORS_RETURNED";
            break;
        case S_OK:
            message = "S_OK";
            break;
        default:
            message = NULL;
            break;
        }

        if (message)
        {
            jmethodID methodID
                = jniEnv->GetMethodID(
                        clazz,
                        "<init>",
                        "(JLjava/lang/String;)V");

            if (methodID)
            {
                jstring jmessage = jniEnv->NewStringUTF(message);

                if (jmessage)
                {
                    jobject t
                        = jniEnv->NewObject(
                                clazz,
                                methodID,
                                (jlong) hResult, jmessage);

                    if (t)
                    {
                        jniEnv->Throw((jthrowable) t);

                        jniEnv->DeleteLocalRef(t);
                    }
                    jniEnv->DeleteLocalRef(jmessage);
                }
                return;
            }
        }

        {
            jmethodID methodID = jniEnv->GetMethodID(clazz, "<init>", "(J)V");

            if (methodID)
            {
                jobject t = jniEnv->NewObject(clazz, methodID, hResult);

                if (t)
                {
                    jniEnv->Throw((jthrowable) t);

                    jniEnv->DeleteLocalRef(t);
                }
                return;
            }
        }

        jniEnv->ThrowNew(clazz, message);

        jniEnv->DeleteLocalRef(clazz);
    }
}