aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/msofficecomm/MessengerContact.java
blob: e63789aa935d4dec28bad511aa052b8252569da2 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.plugin.msofficecomm;

import net.java.sip.communicator.util.*;

/**
 * Represents the Java counterpart of a native <tt>IMessengerContact</tt>
 * implementation.
 *
 * @author Lyubomir Marinov
 */
public class MessengerContact
{
    /**
     * The <tt>Logger</tt> used by the <tt>MessengerContact</tt> class and its
     * instances for logging output.
     */
    private static final Logger logger
        = Logger.getLogger(MessengerContact.class);

    /**
     * The sign-in name associated with the native <tt>IMessengerContact</tt>
     * implementation represented by this instance.
     */
    public final String signinName;

    /**
     * Initializes a new <tt>MessengerContact</tt> instance which is to
     * represent the Java counterpart of a native <tt>IMessengerContact</tt>
     * implementation associated with a specific sign-in name.
     *
     * @param signinName the sign-in name associated with the native
     * <tt>IMessengerContact</tt> implementation which is to be represented by
     * the new instance
     */
    public MessengerContact(String signinName)
    {
        this.signinName = signinName;
    }

    /**
     * Gets the phone number information of the contact associated with this
     * instance.
     *
     * @param a member of the <tt>MPHONE_TYPE</tt> enumerated type which
     * specifies the type of the phone number information to be retrieved
     * @return the phone number information of the contact associated with this
     * instance
     */
    public String getPhoneNumber(int type)
    {
        try
        {
            return Messenger.getPhoneNumber(this, type);
        }
        catch (Throwable t)
        {
            /*
             * The native counterpart will swallow any exception. Even if it
             * didn't, it would still not use a Logger instance to describe the
             * exception. So describe it on the Java side and rethrow it.
             */
            if (t instanceof ThreadDeath)
                throw (ThreadDeath) t;
            else if (t instanceof OutOfMemoryError)
                throw (OutOfMemoryError) t;
            else
            {
                logger.error(
                        "Failed to retrieve the phone number information of an"
                            + " IMessengerContact with sign-in name: "
                            + signinName,
                        t);
                throw new RuntimeException(t);
            }
        }
    }

    /**
     * Gets the connection/presence status of the contact associated with this
     * instance in the form of a <tt>MISTATUS</tt> value.
     *
     * @return a <tt>MISTATUS</tt> value which specifies the connection/presence
     * status of the contact associated with this instance
     */
    public int getStatus()
    {
        try
        {
            return Messenger.getStatus(this);
        }
        catch (Throwable t)
        {
            /*
             * The native counterpart will swallow any exception. Even if it
             * didn't, it would still not use a Logger instance to describe the
             * exception. So describe it on the Java side and rethrow it.
             */
            if (t instanceof ThreadDeath)
                throw (ThreadDeath) t;
            else if (t instanceof OutOfMemoryError)
                throw (OutOfMemoryError) t;
            else
            {
                logger.error(
                        "Failed to determine the status of an IMessengerContact"
                            + " with sign-in name: "
                            + signinName,
                        t);
                throw new RuntimeException(t);
            }
        }
    }

    /**
     * Gets the indicator which determines whether this
     * <tt>MessengerContact</tt> is the same user as the current client user.
     *
     * @return <tt>true</tt> if this <tt>MessengerContact</tt> is the same user
     * as the current client user; otherwise, <tt>false</tt>
     */
    public boolean isSelf()
    {
        return Messenger.isSelf(this);
    }
}