1 /* 2 Copyright (C) 2007 Dirk Huenniger 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 package org.indi.objects; 20 21 import java.io.Serializable; 22 import java.util.Collection; 23 24 /** 25 * the based class of a indi objects. implements composite pattern to accomodate 26 * more indi objects 27 * 28 * @author Dirk Hünniger 29 * 30 * @param <T> 31 * the things the object is composed of. 32 */ 33 public abstract class Object<T extends org.indi.objects.Object> implements 34 Serializable { 35 /** 36 * 37 */ 38 private static final long serialVersionUID = 1L; 39 @SuppressWarnings("unused") 40 /** 41 * The collection of things this object is composed of 42 */ 43 protected Collection<T> children; 44 /** 45 * the transfertype used to transfer this object 46 */ 47 protected TransferType transferType = null; 48 /** 49 * the message associated with this object 50 */ 51 protected String message = null; 52 53 /** 54 * class constuctur 55 * 56 * @param children 57 * the things this object is composed of 58 */ 59 Object(Collection<T> children) { 60 this.children = children; 61 } 62 63 /** 64 * @return the things this object is composed of 65 */ 66 protected Collection<T> getChildren() { 67 return this.children; 68 } 69 70 /** 71 * return an XML representation of this object 72 * 73 * @param type 74 * the transfertype to be used to generate the XML 75 * @param Message 76 * the message associvated with this object 77 * @return the XML representation of this object 78 */ 79 public String getXML(TransferType type, String Message) { 80 return ""; 81 } 82 83 @SuppressWarnings("unchecked") 84 /** 85 * Checks for equality with an other indi object checking equality in all 86 * subobjects. Thus checking equality of children grandchildren etc. 87 * 88 * @param o 89 * the indiobject. 90 * @return True if the given object matches thsi object 91 */ 92 public boolean treeEquals(org.indi.objects.Object o) { 93 if (this.oEquals(o)) { 94 for (Object c : this.getChildren()) { 95 boolean found = false; 96 for (org.indi.objects.Object ch : (Collection<Object>) o.children) { 97 if (c.treeEquals(ch)) { 98 found = true; 99 break; 100 } 101 } 102 if (!found) { 103 return false; 104 } 105 } 106 return true; 107 } else { 108 return false; 109 } 110 } 111 112 /** 113 * Check the equality with an other object, exculding subobject. So the 114 * equality of children etc. is ignored 115 * 116 * @param o 117 * @return true if the given object is equal to this object 118 */ 119 public abstract boolean oEquals(Object o); 120 121 @Override 122 public boolean equals(java.lang.Object o) { 123 if (o instanceof org.indi.objects.Object) { 124 return this.treeEquals((org.indi.objects.Object) o); 125 } else { 126 return false; 127 } 128 } 129 130 @Override 131 public abstract int hashCode(); 132 133 /** 134 * 135 * @return the transfertype currently used by this object 136 */ 137 public TransferType getTransferType() { 138 return this.transferType; 139 } 140 141 /** 142 * the the transfertype of this object 143 * 144 * @param transferType 145 * the new tranfertype to be set 146 */ 147 public void setTransferType(TransferType transferType) { 148 this.transferType = transferType; 149 }; 150 151 /** 152 * @return the message associated with this object 153 */ 154 public String getMessage() { 155 return this.message; 156 } 157 }