001/**
002 *   GRANITE DATA SERVICES
003 *   Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004 *
005 *   This file is part of the Granite Data Services Platform.
006 *
007 *   Granite Data Services is free software; you can redistribute it and/or
008 *   modify it under the terms of the GNU Lesser General Public
009 *   License as published by the Free Software Foundation; either
010 *   version 2.1 of the License, or (at your option) any later version.
011 *
012 *   Granite Data Services is distributed in the hope that it will be useful,
013 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
014 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
015 *   General Public License for more details.
016 *
017 *   You should have received a copy of the GNU Lesser General Public
018 *   License along with this library; if not, write to the Free Software
019 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
020 *   USA, or see <http://www.gnu.org/licenses/>.
021 */
022package org.granite.tide.data;
023
024import java.io.Externalizable;
025import java.io.IOException;
026import java.io.ObjectInput;
027import java.io.ObjectOutput;
028
029
030/**
031 * @author William DRAI
032 */
033public class ChangeSet implements Externalizable {
034
035    private static final long serialVersionUID = 1L;
036
037        private Change[] changes = new Change[0];
038        
039        
040        public ChangeSet() {            
041        }
042        
043        public ChangeSet(Change[] changes) {
044                this.changes = changes;
045        }
046        
047        public Change[] getChanges() {
048                return changes;
049        }
050        
051        public void setChanges(Change[] changes) {
052                this.changes = changes;
053        }
054
055        public void writeExternal(ObjectOutput out) throws IOException {
056                out.writeObject(changes);
057        }
058        
059        @Override
060        public String toString() {
061                return getChanges() != null ? getChanges().toString() : "[]";
062        }
063        
064//      public static valueToString(Object object) {
065//              if (object == null)
066//                      return "null";
067//              
068//        ClassGetter classGetter = GraniteContext.getCurrentInstance().getGraniteConfig().getClassGetter();
069//              if (!classGetter.isEntity(object))
070//                      return object.toString();
071//              
072//              StringBuilder sb = new StringBuilder("{ ");
073//              List<Object[]> values = classGetter.getFieldValues(object);
074//              for (Object[] value : values) {
075//                      if (classGetter.isEntity(value[1]))
076//                              
077//              }
078//              sb.append(" }");
079//      }
080
081        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
082                Object[] cs = (Object[])in.readObject();
083                changes = new Change[cs.length];
084                for (int i = 0; i < cs.length; i++)
085                        changes[i] = (Change)cs[i];
086        }
087}