• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007-2008 Esmertec AG.
3  * Copyright (C) 2007-2008 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package com.android.im.imps;
19 
20 import com.android.im.engine.Contact;
21 import com.android.im.engine.ContactList;
22 import com.android.im.engine.ContactListManager;
23 import com.android.im.engine.ImEntity;
24 
25 public class ImpsUserAddress extends ImpsAddress{
26 
27     /**
28      * Default Constructor. Required by AddressParcelHelper.
29      */
ImpsUserAddress()30     public ImpsUserAddress() {
31     }
32 
ImpsUserAddress(String full, boolean verify)33     public ImpsUserAddress(String full, boolean verify) {
34         super(full, verify);
35         if(verify && (mUser == null || mResource != null)) {
36             throw new IllegalArgumentException();
37         }
38     }
39 
ImpsUserAddress(String full)40     public ImpsUserAddress(String full) {
41         this(full, false);
42     }
43 
ImpsUserAddress(String user, String domain)44     public ImpsUserAddress(String user, String domain) {
45         super(user, null, domain);
46     }
47 
48     @Override
toPrimitiveElement()49     public PrimitiveElement toPrimitiveElement() {
50         PrimitiveElement user = new PrimitiveElement(ImpsTags.User);
51         user.addChild(ImpsTags.UserID, getFullName());
52         return user;
53     }
54 
55     @Override
getScreenName()56     public String getScreenName() {
57         return mUser;
58     }
59 
60     @Override
getEntity(ImpsConnection connection)61     public ImEntity getEntity(ImpsConnection connection) {
62         ContactListManager manager = connection.getContactListManager();
63         for(ContactList list : manager.getContactLists()) {
64             Contact contact = list.getContact(this);
65             if(contact != null) {
66                 return contact;
67             }
68         }
69         //TODO: add to a stranger list?
70         return new Contact(this, this.getUser());
71     }
72 }
73