001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (C) 2012  Paul Ferraro
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package net.sf.hajdbc.util;
019
020import java.io.IOException;
021import java.io.ObjectInputStream;
022import java.io.ObjectOutputStream;
023import java.util.EventObject;
024
025/**
026 * @author Paul Ferraro
027 */
028public class Event<T> extends EventObject
029{
030        private static final long serialVersionUID = 1032680699193401944L;
031
032        public Event(T source)
033        {
034                super(source);
035        }
036
037        @Override
038        public T getSource()
039        {
040                return (T) this.source;
041        }
042
043        @Override
044        public boolean equals(Object object)
045        {
046                return ((object != null) && this.getClass().isInstance(object)) ? this.source.equals(this.getClass().cast(object).source) : false;
047        }
048
049        @Override
050        public int hashCode()
051        {
052                return this.source.hashCode();
053        }
054
055        @Override
056        public String toString()
057        {
058                return this.source.toString();
059        }
060
061        private void writeObject(ObjectOutputStream out) throws IOException
062        {
063                out.defaultWriteObject();
064                // this.source is transient, so we need to explicitly write it to the output stream
065                out.writeObject(this.source);
066        }
067        
068        private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
069        {
070                in.defaultReadObject();
071                // this.source is transient, so we need to explicitly read it from the input stream
072                this.source = in.readObject();
073        }
074}