KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > JacObjectInputStream


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

18
19 package org.objectweb.jac.core;
20
21 import java.io.InputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.io.ObjectInputStream JavaDoc;
24
25 /**
26  * <code>JacObjectInputStream</code> is used to read JAC objects from
27  * an input stream during a deserialization process.
28  *
29  * <p>This stream is used when deserializing an array of bytes with
30  * <code>JacObject.deserialize()</code>. All the objects that are not
31  * serialized JAC objects are deserialized with the default
32  * procedure. When a serialized JAC object is encountered, a
33  * <code>whenDeserialized</code> event is thrown on the current AC
34  * manager so that the aspect components can parametrize the
35  * deserialization process.
36  *
37  * <p>A symetric process for serialization is implemented by
38  * <code>JacObjectOutputStream</code>.
39  *
40  * @see ACManager#whenDeserialized(SerializedJacObject,Wrappee)
41  * @see JacObjectOutputStream
42  *
43  * @author Renaud Pawlak
44  * @author Lionel Seinturier
45  */

46  
47 public class JacObjectInputStream extends ObjectInputStream JavaDoc {
48
49    /**
50     * Creates a JacObjectInputStream.
51     *
52     * @param is the input stream from which the bytes are read. */

53
54    public JacObjectInputStream(InputStream JavaDoc is) throws IOException JavaDoc {
55       super(is);
56       enableResolveObject(true);
57    }
58    
59    
60    /**
61     * This method is upcalled by the Java deserialization process each
62     * time a new object to deserialize is encountered.
63     *
64     * <p>If a serialized JAC object is encountered (instance of
65     * <code>SerializedJacObject</code>), the aspect component manager
66     * is upcalled to parametrize the deserialization.
67     *
68     * @param obj the encountered serialized JAC object
69     * @return the final deserialized JAC object
70     *
71     * @see SerializedJacObject
72     * @see ACManager#whenDeserialized(SerializedJacObject,Wrappee)
73     */

74    
75    protected Object JavaDoc resolveObject(Object JavaDoc obj) throws IOException JavaDoc {
76
77       Object JavaDoc o = null;
78       
79       if (obj instanceof SerializedJacObject) {
80          
81          try {
82             // WAS THIS USEFULL?????
83
//JacObject.remoteInstantiation = true;
84
o = Class.forName( ((SerializedJacObject)obj).getJacObjectClassName() )
85                .newInstance();
86
87             if (o instanceof AspectComponent) {
88                return o;
89             }
90
91             // WAS THIS USEFULL?????
92
// JacObject.remoteInstantiation = false;
93
} catch (Exception JavaDoc e) {
94             e.printStackTrace();
95          }
96       
97          return ((ACManager)ACManager.get()).whenDeserialized(
98             (SerializedJacObject)obj,(Wrappee)o);
99       
100          //return Collaboration.get().getAttribute( "finalObject" );
101
} else if(obj instanceof SerializedMethodItem) {
102          return ((SerializedMethodItem)obj).getMethod();
103       }
104       return obj;
105    }
106    
107    
108 }
109
110
111
112
Popular Tags