1 /***
2 *
3 * Copyright 2003-2005 Core Developers Network Ltd.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.codehaus.wadi.core.motable;
18
19 import java.io.IOException;
20 import java.io.ObjectInput;
21 import java.io.ObjectOutput;
22
23
24
25 /***
26 * A very Simple implementation of Motable, with the Bytes field represented as a byte[]
27 *
28 * @author <a href="mailto:jules@coredevelopers.net">Jules Gosnell</a>
29 * @version $Revision: 2293 $
30 */
31
32 public class SimpleMotable extends AbstractMotable {
33 protected byte[] _bytes;
34
35 public synchronized byte[] getBodyAsByteArray() {
36 return _bytes;
37 }
38
39 public synchronized void setBodyAsByteArray(byte[] bytes) {
40 _bytes = bytes;
41 }
42
43 public synchronized void readExternal(ObjectInput oi) throws IOException, ClassNotFoundException {
44 super.readExternal(oi);
45 _bytes = (byte[]) oi.readObject();
46 }
47
48 public synchronized void writeExternal(ObjectOutput oo) throws IOException {
49 super.writeExternal(oo);
50 oo.writeObject(_bytes);
51 }
52
53 public boolean equals(Object object) {
54 if (this==object)
55 return true;
56 if (!(object instanceof Motable))
57 return false;
58 try {
59 Motable motable = (Motable) object;
60 byte[] bytes=motable.getBodyAsByteArray();
61 int l=_bytes.length;
62 if (l!=bytes.length)
63 return false;
64 else {
65 for (int i=0; i<l; i++)
66 if (_bytes[i]!=bytes[i])
67 return false;
68 return true;
69 }
70 } catch (Exception e) {
71
72 e.printStackTrace();
73 return false;
74 }
75 }
76 }
77
78