001 /* 002 Copyright (C) 2001-2002 Renaud Pawlak, Lionel Seinturier. 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, but 010 WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA */ 018 019 package org.objectweb.jac.core; 020 021 import java.io.InputStream; 022 import java.io.IOException; 023 import java.io.ObjectInputStream; 024 025 /** 026 * <code>JacObjectInputStream</code> is used to read JAC objects from 027 * an input stream during a deserialization process. 028 * 029 * <p>This stream is used when deserializing an array of bytes with 030 * <code>JacObject.deserialize()</code>. All the objects that are not 031 * serialized JAC objects are deserialized with the default 032 * procedure. When a serialized JAC object is encountered, a 033 * <code>whenDeserialized</code> event is thrown on the current AC 034 * manager so that the aspect components can parametrize the 035 * deserialization process. 036 * 037 * <p>A symetric process for serialization is implemented by 038 * <code>JacObjectOutputStream</code>. 039 * 040 * @see ACManager#whenDeserialized(SerializedJacObject,Wrappee) 041 * @see JacObjectOutputStream 042 * 043 * @author Renaud Pawlak 044 * @author Lionel Seinturier 045 */ 046 047 public class JacObjectInputStream extends ObjectInputStream { 048 049 /** 050 * Creates a JacObjectInputStream. 051 * 052 * @param is the input stream from which the bytes are read. */ 053 054 public JacObjectInputStream(InputStream is) throws IOException { 055 super(is); 056 enableResolveObject(true); 057 } 058 059 060 /** 061 * This method is upcalled by the Java deserialization process each 062 * time a new object to deserialize is encountered. 063 * 064 * <p>If a serialized JAC object is encountered (instance of 065 * <code>SerializedJacObject</code>), the aspect component manager 066 * is upcalled to parametrize the deserialization. 067 * 068 * @param obj the encountered serialized JAC object 069 * @return the final deserialized JAC object 070 * 071 * @see SerializedJacObject 072 * @see ACManager#whenDeserialized(SerializedJacObject,Wrappee) 073 */ 074 075 protected Object resolveObject(Object obj) throws IOException { 076 077 Object o = null; 078 079 if (obj instanceof SerializedJacObject) { 080 081 try { 082 // WAS THIS USEFULL????? 083 //JacObject.remoteInstantiation = true; 084 o = Class.forName( ((SerializedJacObject)obj).getJacObjectClassName() ) 085 .newInstance(); 086 087 if (o instanceof AspectComponent) { 088 return o; 089 } 090 091 // WAS THIS USEFULL????? 092 // JacObject.remoteInstantiation = false; 093 } catch (Exception e) { 094 e.printStackTrace(); 095 } 096 097 return ((ACManager)ACManager.get()).whenDeserialized( 098 (SerializedJacObject)obj,(Wrappee)o); 099 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