author | František Kučera <franta-hg@frantovo.cz> |
Wed Jun 30 00:26:14 2010 +0200 (2010-06-30) | |
changeset 149 | 8238cdb4113a |
child 151 | d7b5099bf65e |
permissions | -rw-r--r-- |
franta-hg@149 | 1 |
package cz.frantovo.nekurak.chat; |
franta-hg@149 | 2 |
|
franta-hg@149 | 3 |
import java.util.ArrayList; |
franta-hg@149 | 4 |
import java.util.Collection; |
franta-hg@149 | 5 |
import java.util.logging.Level; |
franta-hg@149 | 6 |
import java.util.logging.Logger; |
franta-hg@149 | 7 |
import org.jivesoftware.smack.ConnectionConfiguration; |
franta-hg@149 | 8 |
import org.jivesoftware.smack.XMPPConnection; |
franta-hg@149 | 9 |
import org.jivesoftware.smack.XMPPException; |
franta-hg@149 | 10 |
|
franta-hg@149 | 11 |
/** |
franta-hg@149 | 12 |
* |
franta-hg@149 | 13 |
* @author fiki |
franta-hg@149 | 14 |
*/ |
franta-hg@149 | 15 |
public class Spojeni { |
franta-hg@149 | 16 |
|
franta-hg@149 | 17 |
private XMPPConnection spojeni; |
franta-hg@149 | 18 |
private Collection<MistnostPripojena> mistnosti = new ArrayList<MistnostPripojena>(); |
franta-hg@149 | 19 |
private static final Logger log = Logger.getLogger(Spojeni.class.getSimpleName()); |
franta-hg@149 | 20 |
|
franta-hg@149 | 21 |
public Spojeni(UcetRobota ucet) throws XMPPException { |
franta-hg@149 | 22 |
/** Navážeme spojení */ |
franta-hg@149 | 23 |
ConnectionConfiguration nastaveni = new ConnectionConfiguration(ucet.getAdresaServeru(), ucet.getPort(), ucet.getDomena()); |
franta-hg@149 | 24 |
spojeni = new XMPPConnection(nastaveni); |
franta-hg@149 | 25 |
spojeni.connect(); |
franta-hg@149 | 26 |
spojeni.login(ucet.getUzivatelskeJmeno(), ucet.getUzivatelskeHeslo(), ucet.getProstredek()); |
franta-hg@149 | 27 |
|
franta-hg@149 | 28 |
/** Vstoupíme do místností */ |
franta-hg@149 | 29 |
for (Mistnost m : ucet.getMistnosti()) { |
franta-hg@149 | 30 |
MistnostPripojena mp = new MistnostPripojena(m, this); |
franta-hg@149 | 31 |
mistnosti.add(mp); |
franta-hg@149 | 32 |
} |
franta-hg@149 | 33 |
} |
franta-hg@149 | 34 |
|
franta-hg@149 | 35 |
public void odpoj() { |
franta-hg@149 | 36 |
/** Rozloučíme se ve všech místnostech */ |
franta-hg@149 | 37 |
try { |
franta-hg@149 | 38 |
for (MistnostPripojena mp : mistnosti) { |
franta-hg@149 | 39 |
mp.odejdi(); |
franta-hg@149 | 40 |
} |
franta-hg@149 | 41 |
} catch (Exception e) { |
franta-hg@149 | 42 |
log.log(Level.WARNING, "Nepodařilo se odejít z místnosti před ukončením spojení.", e); |
franta-hg@149 | 43 |
} |
franta-hg@149 | 44 |
|
franta-hg@149 | 45 |
/** Ukončíme spojení */ |
franta-hg@149 | 46 |
spojeni.disconnect(); |
franta-hg@149 | 47 |
} |
franta-hg@149 | 48 |
|
franta-hg@149 | 49 |
public XMPPConnection getSpojeni() { |
franta-hg@149 | 50 |
return spojeni; |
franta-hg@149 | 51 |
} |
franta-hg@149 | 52 |
|
franta-hg@149 | 53 |
public Collection<MistnostPripojena> getMistnosti() { |
franta-hg@149 | 54 |
return mistnosti; |
franta-hg@149 | 55 |
} |
franta-hg@149 | 56 |
} |