01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.axis2.util;
21:
22: import java.io.Externalizable;
23: import java.io.IOException;
24: import java.io.ObjectInput;
25: import java.io.ObjectOutput;
26:
27: public class SelfManagedDataHolder implements Externalizable {
28:
29: private transient String classname;
30: private transient String id;
31: private transient byte[] data;
32:
33: public SelfManagedDataHolder() {
34: // should only be used by the ObjectStateUtils
35: }
36:
37: // TODO better exception
38: public SelfManagedDataHolder(String classname, String id,
39: byte[] data) throws Exception {
40: if ((classname == null) || (id == null)) {
41: throw new Exception("Argument cannot be null: classname = "
42: + classname + ", id = " + id);
43: }
44: this .classname = classname;
45: this .id = id;
46:
47: // TODO deep copy necessary?
48: this .data = new byte[data.length];
49: for (int i = 0; i < data.length; i++) {
50: this .data[i] = data[i];
51: }
52: }
53:
54: public void readExternal(ObjectInput in) throws IOException,
55: ClassNotFoundException {
56: classname = (String) in.readUTF();
57: id = (String) in.readUTF();
58: int datalength = in.readInt();
59: data = new byte[datalength];
60: in.read(data);
61:
62: }
63:
64: public void writeExternal(ObjectOutput out) throws IOException {
65: out.writeUTF(classname);
66: out.writeUTF(id);
67: out.writeInt(data.length);
68: out.write(data);
69: }
70:
71: public String getClassname() {
72: return classname;
73: }
74:
75: public byte[] getData() {
76: return data;
77: }
78:
79: public String getId() {
80: return id;
81: }
82:
83: }
|