1 18 19 package alt.jiapi.event; 20 21 import java.util.EventObject ; 22 23 32 public class JiapiEvent extends EventObject { 33 protected int id; 34 protected Object sourceObject; 35 protected Object target; 36 protected String targetName; 37 38 46 public JiapiEvent(EventProducer ep, Object sourceObject, String targetName, 47 int id) { 48 this(ep, sourceObject, targetName, null, id); 49 } 50 51 61 public JiapiEvent(EventProducer ep, Object sourceObject, 62 String targetName, Object target, int id) { 63 super(ep); 64 65 this.sourceObject = sourceObject; 66 this.targetName = targetName; 67 this.target = target; 68 this.id = id; 69 } 70 71 75 public Object getSourceObject() { 76 return sourceObject; 77 } 78 79 80 86 public String getTargetName() { 87 return targetName; 88 } 89 90 91 95 public Object getTarget() { 96 return target; 97 } 98 99 100 120 public void protect() { 121 ((EventProducer)getSource()).protect(this); 122 } 123 124 131 public void release() { 132 ((EventProducer)getSource()).release(this); 133 } 134 135 private boolean testProtection = false; public String toString() { 137 if(testProtection) { 138 String s = null; 139 140 if (sourceObject != null) { 141 protect(); 142 s = sourceObject.toString(); 143 release(); 144 } 145 146 return s; 147 } 148 149 StringBuffer sb = new StringBuffer (super.toString()); 150 sb.append(", source="); 151 152 if (sourceObject instanceof String ) { 153 sb.append(sourceObject); 154 } 155 else if (sourceObject instanceof Class ) { 156 sb.append(sourceObject.toString()); 157 } 158 else { 159 sb.append(sourceObject.getClass().getName()); 160 } 161 162 sb.append(", target name="); 163 sb.append(targetName); 164 sb.append(", target=" ); 165 166 if (target != null) { 167 sb.append(target.getClass().getName()); 168 } 169 else { 170 sb.append("null"); 171 } 172 173 sb.append(", id="); 174 sb.append(id); 175 176 return sb.toString(); 177 } 181 182 183 187 public void finalize() { 188 try { 189 ((EventProducer)getSource()).release(this); 190 } 191 catch (Throwable t) { 192 } 194 } 195 } 196 197 | Popular Tags |