KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > messenger > spi > BasicStreamIDFactory


1 /**
2  * $RCSfile: BasicStreamIDFactory.java,v $
3  * $Revision: 1.3 $
4  * $Date: 2004/12/10 00:54:27 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.messenger.spi;
13
14 import org.jivesoftware.messenger.StreamID;
15 import org.jivesoftware.messenger.StreamIDFactory;
16 import java.util.Random JavaDoc;
17
18 /**
19  * A basic stream ID factory that produces id's using java.util.Random
20  * and a simple hex representation of a random int.
21  *
22  * @author Iain Shigeoka
23  */

24 public class BasicStreamIDFactory implements StreamIDFactory {
25
26     /**
27      * The random number to use, someone with Java can predict stream IDs if they can guess the current seed *
28      */

29     Random JavaDoc random = new Random JavaDoc();
30
31     public StreamID createStreamID() {
32         return new BasicStreamID(Integer.toHexString(random.nextInt()));
33     }
34
35     public StreamID createStreamID(String JavaDoc name) {
36         return new BasicStreamID(name);
37     }
38
39     private class BasicStreamID implements StreamID {
40         String JavaDoc id;
41
42         public BasicStreamID(String JavaDoc id) {
43             this.id = id;
44         }
45
46         public String JavaDoc getID() {
47             return id;
48         }
49
50         public String JavaDoc toString() {
51             return id;
52         }
53
54         public int hashCode() {
55             return id.hashCode();
56         }
57     }
58 }
59
Popular Tags