KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > core > NextNonce


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19
20 package sync4j.framework.core;
21
22 import sync4j.framework.tools.Base64;
23
24 /**
25  * Corresponds to <NextNonce> tag that specifies the nonce string to be
26  * used in any subsequent communication
27  *
28  * @author Stefano Fornari @ Funambol
29  *
30  * @version $Id: NextNonce.java,v 1.4 2005/03/02 20:57:37 harrie Exp $
31  */

32 public final class NextNonce
33 implements java.io.Serializable JavaDoc {
34
35     // ------------------------------------------------------------ Private data
36

37     private byte[] value;
38     
39     // ------------------------------------------------------------ Constructors
40
/**
41      * For serialization purposes
42      */

43     protected NextNonce() {
44         setValue(new byte[0]);
45     }
46
47     /**
48      * Creates a new NextNonce object with the given information (as byte[])
49      *
50      * @param value the value of next nonce NOT NULL
51      *
52      */

53     public NextNonce(final byte[] value) {
54         setValue(value);
55         }
56     
57     /**
58      * Creates a new NextNonce object with the given information (as String)
59      *
60      * @param value the value of next nonce NOT NULL
61      *
62      */

63     public NextNonce(final String JavaDoc value) {
64         setValueAsString(value);
65     }
66
67     // ---------------------------------------------------------- Public methods
68

69     /**
70      * Gets the value
71      *
72      * @return value
73      */

74     public byte[] getValue() {
75         return this.value;
76     }
77     
78     public void setValue(final byte[] value) {
79         if (value == null) {
80             this.value = new byte[0];
81             return;
82         }
83         
84         this.value = value;
85     }
86     
87     public void setValueAsString(final String JavaDoc value) {
88         if (value == null) {
89             this.value = new byte[0];
90             return;
91         }
92         
93         this.value = value.getBytes();
94     }
95
96     /**
97      * Gets the value in Base64 encoded
98      *
99      * @return the value in Base64 encoded form
100      */

101     public String JavaDoc getValueAsBase64() {
102         return new String JavaDoc(Base64.encode(value));
103     }
104     
105     public String JavaDoc toString() {
106         return getValueAsBase64();
107     }
108 }
109
Popular Tags