/*
* Copyright (c) 2005 Thomas Weise
*
* E-Mail : tweise@gmx.de
* Creation Date : 2005-07-14 08:02:45
* Original Filename: org.sfc.events.SfcEvent.java
* Version : 3.0.0
* Last modification: 2006-04-10
* by: Thomas Weise
*
* License : GNU LESSER GENERAL PUBLIC LICENSE
* Version 2.1, February 1999
* You should have received a copy of this license along
* with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307, USA or download the license under
* http://www.gnu.org/copyleft/lesser.html.
*
* Warranty : This software is provided "as is" without any
* warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose.
* See the Gnu Lesser General Public License for more
* details.
*/
package org.sfc.events;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.EventObject;
/**
* This is the default event implementation all sfc-events should inherite
* from. It is serializable even if the event's source isn't. In this case,
* just the sources class name will be serialized. So whenever you check
* for the source of an SfcEvent, you might as well encounter a class name
* instead of an object.
* @author Thomas Weise
*/
public class SfcEvent extends EventObject
{
/**
* The serial version uid.
*/
private static final long serialVersionUID = 2;
/**
* Create a new SfcEvent
. You cannot do this directly,
* but can create derived class instances.
* @param p_source The source of the event.
*/
protected SfcEvent(final Object p_source)
{
super(p_source);
}
/**
* Reconstitute the SfcEvent
instance from a stream (that is,
* deserialize it).
* @param p_s The input stream.
* @throws IOException If something io-like went wrong.
* @throws ClassNotFoundException If a needed class could not be found.
*/
private final void readObject(final ObjectInputStream p_s)
throws IOException, ClassNotFoundException
{
p_s.defaultReadObject();
this.source = p_s.readObject();
}
/**
* Stores the SfcEvent
into the stream.
* @param p_s The output stream.
* @throws IOException If something io-like went wrong.
*/
private final void writeObject(final ObjectOutputStream p_s)
throws IOException
{
Object l_s;
p_s.defaultWriteObject();
l_s = this.source;
if(l_s == null)
{
p_s.writeObject(null);
}
else
{
if(l_s instanceof Serializable)
{
p_s.writeObject(l_s);
}
else
{
p_s.writeObject(l_s.getClass().toString());
}
}
}
}