src/com/beem/project/beem/service/XMPPConnectionAdapter.java
author Da Risk <darisk972@gmail.com>
Thu, 19 Mar 2009 22:23:18 +0100
changeset 30 7057a9d3657a
parent 29 a49d1556772c
child 31 85faac00d92c
permissions -rw-r--r--
Add some adapter for smack classes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     1
/**
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     2
 * 
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     3
 */
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     4
package com.beem.project.beem.service;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     5
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     6
import org.jivesoftware.smack.ConnectionConfiguration;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     7
import org.jivesoftware.smack.XMPPConnection;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     8
import org.jivesoftware.smack.XMPPException;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
     9
30
7057a9d3657a Add some adapter for smack classes
Da Risk <darisk972@gmail.com>
parents: 29
diff changeset
    10
import android.os.RemoteException;
7057a9d3657a Add some adapter for smack classes
Da Risk <darisk972@gmail.com>
parents: 29
diff changeset
    11
29
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    12
import com.beem.project.beem.BeemException;
30
7057a9d3657a Add some adapter for smack classes
Da Risk <darisk972@gmail.com>
parents: 29
diff changeset
    13
import com.beem.project.beem.service.aidl.IRoster;
29
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    14
import com.beem.project.beem.service.aidl.IXMPPConnection;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    15
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    16
/**
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    17
 * @author darisk
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    18
 *
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    19
 */
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    20
public class XMPPConnectionAdapter extends IXMPPConnection.Stub {
30
7057a9d3657a Add some adapter for smack classes
Da Risk <darisk972@gmail.com>
parents: 29
diff changeset
    21
  
29
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    22
    private XMPPConnection adaptee;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    23
    private BeemException lastException;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    24
    
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    25
    public XMPPConnectionAdapter(XMPPConnection con) {
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    26
	adaptee = con;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    27
    }
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    28
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    29
    public XMPPConnectionAdapter(String serviceName) {
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    30
	adaptee = new XMPPConnection(serviceName);
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    31
    }
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    32
    
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    33
    public XMPPConnectionAdapter(ConnectionConfiguration config) { 
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    34
    	adaptee = new XMPPConnection(config);
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    35
    }
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    36
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    37
    public boolean connect() {
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    38
	try {
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    39
	    adaptee.connect();
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    40
	    lastException = null;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    41
	    return true;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    42
	} catch (XMPPException e) {
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    43
	    lastException = new BeemException(e);
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    44
	}
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    45
	return false;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    46
    }
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    47
    
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    48
    public boolean disconnect() {
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    49
	adaptee.disconnect();
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    50
	lastException = null;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    51
	return true;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    52
    }
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    53
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    54
    public boolean login(String username, String password, String resource) {
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    55
	try {
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    56
	    adaptee.login(username, password, resource);
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    57
	    lastException = null;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    58
	    return true;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    59
	} catch (XMPPException e) {
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    60
	    lastException = new BeemException(e);
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    61
	}
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    62
	return false;
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    63
    }
30
7057a9d3657a Add some adapter for smack classes
Da Risk <darisk972@gmail.com>
parents: 29
diff changeset
    64
7057a9d3657a Add some adapter for smack classes
Da Risk <darisk972@gmail.com>
parents: 29
diff changeset
    65
    @Override
7057a9d3657a Add some adapter for smack classes
Da Risk <darisk972@gmail.com>
parents: 29
diff changeset
    66
    public IRoster getRoster() throws RemoteException {
7057a9d3657a Add some adapter for smack classes
Da Risk <darisk972@gmail.com>
parents: 29
diff changeset
    67
	return new RosterAdapter(adaptee.getRoster());
7057a9d3657a Add some adapter for smack classes
Da Risk <darisk972@gmail.com>
parents: 29
diff changeset
    68
    }
29
a49d1556772c Starting work on the Service interface.
Da Risk <darisk972@gmail.com>
parents:
diff changeset
    69
}