1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2000 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: PersistentString.java,v 1.7 2003/08/17 01:32:25 tanderson Exp $
44 *
45 * Date Author Changes
46 * $Date jimm Created
47 */
48
49
50 package org.exolab.jms.persistence;
51
52 import java.io.Externalizable;
53 import java.io.IOException;
54 import java.io.ObjectInput;
55 import java.io.ObjectOutput;
56
57 import org.exolab.core.foundation.PersistentObject;
58
59
60 /***
61 * A simple helper class to wrap strings, and make object referenses easier.
62 *
63 * @version $Revision: 1.7 $ $Date: 2003/08/17 01:32:25 $
64 * @author <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
65 */
66 public class PersistentString
67 extends PersistentObject
68 implements Externalizable {
69
70 // Used for serialization
71 static final long serialVersionUID = 1;
72
73
74 // The String holder
75 private String id_;
76
77 /***
78 * The default constructor initialises an empty String
79 *
80 */
81 public PersistentString() {
82 super();
83 id_ = "";
84 }
85
86
87 /***
88 * Initialise to the given String value
89 *
90 * @param id The string to assign
91 *
92 */
93 public PersistentString(String id) {
94 super();
95 id_ = id;
96 }
97
98
99 /***
100 * Assign the given String value
101 *
102 * @param id The string to assign
103 *
104 */
105 public void update(String id) {
106 id_ = id;
107 }
108
109
110 /***
111 * Return the internal String
112 *
113 * @return String The internal String
114 *
115 */
116 public String toString() {
117 return id_;
118 }
119
120
121 /***
122 * Return the length of the internal String
123 *
124 * @return int The internal String length
125 *
126 */
127 public int length() {
128 return (id_ == null ? 0 : id_.length());
129 }
130
131 // override Object.equals
132 public boolean equals(Object obj) {
133
134 boolean result = false;
135
136 if ((obj instanceof PersistentString) &&
137 (id_.equals(((PersistentString) obj).id_))) {
138 result = true;
139 }
140
141 return result;
142 }
143
144 // override Object.hashCode
145 public int hashCode() {
146 return id_.hashCode();
147 }
148
149 // implementation of Externalizable.writeExternal
150 public void writeExternal(ObjectOutput stream)
151 throws IOException {
152 stream.writeLong(serialVersionUID);
153 stream.writeObject(id_);
154 super.writeExternal(stream);
155 }
156
157 // implementation of Externalizable.writeExternal
158 public void readExternal(ObjectInput stream)
159 throws IOException, ClassNotFoundException {
160 long version = stream.readLong();
161 if (version == serialVersionUID) {
162 id_ = (String) stream.readObject();
163 super.readExternal(stream);
164 } else {
165 throw new IOException("PersistentString with version " +
166 version + " is not supported.");
167 }
168 }
169 } // End PersistentString
This page was automatically generated by Maven