KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > naming > reference > DeserializingReference


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
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.apache.geronimo.naming.reference;
18
19 import java.io.ByteArrayInputStream JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.ObjectInputStream JavaDoc;
22
23 import org.apache.geronimo.kernel.ObjectInputStreamExt;
24
25 /**
26  * @version $Rev: $ $Date: $
27  */

28 public class DeserializingReference extends SimpleAwareReference {
29
30     private final byte[] bytes;
31     private transient Object JavaDoc content;
32
33     public DeserializingReference(byte[] bytes) {
34         this.bytes = bytes;
35     }
36
37     public Object JavaDoc getContent() {
38         return content;
39     }
40
41     public void setClassLoader(ClassLoader JavaDoc classLoader) {
42         super.setClassLoader(classLoader);
43         ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(bytes);
44         try {
45             ObjectInputStream JavaDoc is = new ObjectInputStreamExt(bais, classLoader);
46             try {
47                 content = is.readObject();
48             } finally {
49                 is.close();
50             }
51         } catch (IOException JavaDoc e) {
52             throw new RuntimeException JavaDoc("Could not deserialize content", e);
53         } catch (ClassNotFoundException JavaDoc e) {
54             throw new RuntimeException JavaDoc("Could not deserialize content", e);
55         }
56     }
57
58 }
59
Popular Tags