phoneEvent.addElement("callerID").setText(callSession.getCallerID());
String callerID = callSession.getCallerID() == null ? "" : callSession.getCallerID(); phoneEvent.addElement("callerID").setText(callerID);
        public void run() {            //everything after the hyphen should be skipped            String device = getDevice(event.getChannel());            PhoneManager phoneManager = null;            try {                phoneManager = getPhoneManager();                PhoneUser phoneUser = phoneManager.getByDevice(device);                //If there is no jid for this device don't do anything else                if (phoneUser == null) {                    Log.debug("Asterisk-IM OnPhoneTask: Could not find device/jid mapping for device " +                            device + " returning");                    return;                }                Log.debug("Asterisk-IM OnPhoneTask called for user " + phoneUser);                CallSession callSession = getCallSessionFactory().getCallSession(event.getUniqueId(), phoneUser.getUsername());                XMPPServer server = getInstance();                // Notify the client that they have answered the phone                Message message = new Message();                message.setFrom(asteriskPlugin.getComponentJID());                message.setID(event.getUniqueId());                PhoneEvent phoneEvent =                        new PhoneEvent(callSession.getId(), Type.ON_PHONE, device);                phoneEvent.addElement("callerID").setText(callSession.getCallerID());                message.getElement().add(phoneEvent);                //Acquire the xmpp sessions for the user                SessionManager sessionManager = server.getSessionManager();                Collection<ClientSession> sessions = sessionManager.getSessions(phoneUser.getUsername());                // We don't care about people without a session                if (sessions.size() == 0) {                    return;                }                Log.debug("Asterisk-IM OnPhoneTask: setting presence to away for " + phoneUser);                // If we haven't determined their original presence, set it                // If there is already and original presence, it means the user is                // receiving an additional phone call. In this case we should not save the presence                // because the current precense would also be "on phone"                synchronized (phoneUser.getUsername().intern()) {                    if (UserPresenceUtil.getPresences(phoneUser.getUsername()) == null ||                            UserPresenceUtil.getPresences(phoneUser.getUsername()).isEmpty()) {                        // Iterate through all of the sessions sending out new presences for each                        Presence presence = new Presence();                        presence.setShow(Presence.Show.away);                        presence.setStatus("On the phone");                        PhoneStatus phoneStatus = new PhoneStatus(Status.ON_PHONE);                        presence.getElement().add(phoneStatus);                        Collection<Presence> prevPresences = new ArrayList<Presence>();                        for (ClientSession session : sessions) {                            message.setTo(session.getAddress());                            asteriskPlugin.sendPacket(message);                            Presence prevPresence = session.getPresence();                            // Only add the presence if it does not contain a phone element                            if (prevPresence.getElement().element(Status.ON_PHONE.name()) == null) {                                prevPresences.add(prevPresence);                                JID fullJID = session.getAddress();                                presence.setFrom(fullJID);                                server.getPresenceRouter().route(presence);                            }                        }                        UserPresenceUtil.setPresences(phoneUser.getUsername(), prevPresences);                    }                }            }            catch (Exception e) {                Log.error(e.getMessage(), e);            }            finally {                close(phoneManager);            }        }