001/* 002 GRANITE DATA SERVICES 003 Copyright (C) 2011 GRANITE DATA SERVICES S.A.S. 004 005 This file is part of Granite Data Services. 006 007 Granite Data Services is free software; you can redistribute it and/or modify 008 it under the terms of the GNU Library General Public License as published by 009 the Free Software Foundation; either version 2 of the License, or (at your 010 option) any later version. 011 012 Granite Data Services is distributed in the hope that it will be useful, but 013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License 015 for more details. 016 017 You should have received a copy of the GNU Library General Public License 018 along with this library; if not, see <http://www.gnu.org/licenses/>. 019*/ 020 021package flex.messaging.io; 022 023import java.io.Externalizable; 024import java.io.IOException; 025import java.io.ObjectInput; 026import java.io.ObjectOutput; 027import java.util.ArrayList; 028import java.util.Collection; 029 030/** 031 * @author Franck WOLFF 032 */ 033public class ArrayCollection extends ArrayList<Object> implements Externalizable { 034 035 private static final long serialVersionUID = 1L; 036 037 public ArrayCollection() { 038 super(); 039 } 040 041 public ArrayCollection(int capacity) { 042 super(capacity); 043 } 044 045 public ArrayCollection(Collection<?> col) { 046 super(col); 047 } 048 049 public ArrayCollection(Object[] array) { 050 super(); 051 addAll(array); 052 } 053 054 public void addAll(Object[] array) { 055 for (Object o : array) 056 add(o); 057 } 058 059 public void writeExternal(ObjectOutput out) throws IOException { 060 out.writeObject(toArray()); 061 } 062 063 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 064 Object o = in.readObject(); 065 if (o != null) { 066 if (o instanceof Collection<?>) 067 addAll((Collection<?>)o); 068 else if (o.getClass().isArray()) 069 addAll((Object[])o); 070 else // should we throw an exception ? 071 add(o); 072 } 073 } 074 075 @Override 076 public String toString() { 077 return super.toString(); 078 } 079}