Source code: org/media/mn8/protocol/jabber/datablocks/Login.java
1 /*
2 * $COPYRIGHT$
3 * $Id: Login.java,v 1.1 2002/04/09 16:47:46 crow Exp $
4 *
5 * Date Author Changes
6 * APR 08 2002 Szabo Csaba Created
7 */
8 package org.media.mn8.protocol.jabber.datablocks;
9
10 import org.media.mn8.protocol.jabber.*;
11
12 /**
13 * The class representing the login message.
14 *
15 * This has no incomming constructor as login messages are never
16 * received from the server.
17 */
18 public class Login extends JabberDataBlock {
19
20 /**
21 * Constructor. Builds the string ready for sending to the server.
22 *
23 * @param username The username to log in with
24 * @param password The password to log in with
25 * @param resource The resource name to use
26 */
27 public Login( String username, String password, String resource ) {
28 super( );
29
30 setAttribute( "id", "logon" );
31 setAttribute( "type", "set" );
32
33 JabberDataBlock queryBlock = new JabberDataBlock( "query", null, null );
34 queryBlock.setAttribute( "xmlns", "jabber:iq:auth" );
35
36 addChild(queryBlock);
37 if( username != null ) {
38 JabberDataBlock usernameBlock = new JabberDataBlock( "username", null, null );
39 usernameBlock.addText( username );
40 queryBlock.addChild( usernameBlock );
41 }
42
43 if( password != null ) {
44 JabberDataBlock passwordBlock = new JabberDataBlock( "password", null, null );
45 passwordBlock.addText( password );
46 queryBlock.addChild( passwordBlock );
47 }
48
49 if( resource != null ) {
50 JabberDataBlock resourceBlock = new JabberDataBlock( "resource", null, null );
51 resourceBlock.addText( resource );
52 queryBlock.addChild( resourceBlock );
53 }
54 }
55
56
57 /**
58 * Method to return the tag name
59 *
60 * @return Always the string "iq".
61 */
62 public String getTagName() {
63 return "iq";
64 }
65 }