1 package org.apache.ojb.broker; 2 3 17 18 import org.apache.commons.lang.builder.ToStringBuilder; 19 20 28 public final class PBStateEvent extends PersistenceBrokerEvent 29 { 30 31 public static final int KEY_BEFORE_CLOSE = 1; 32 33 public static final int KEY_BEFORE_BEGIN = 2; 34 35 public static final int KEY_BEFORE_COMMIT = 3; 36 37 public static final int KEY_BEFORE_ROLLBACK = 4; 38 39 public static final int KEY_AFTER_BEGIN = 5; 40 41 public static final int KEY_AFTER_COMMIT = 6; 42 43 public static final int KEY_AFTER_OPEN = 7; 44 45 public static final int KEY_AFTER_ROLLBACK = 8; 46 47 private Type eventType; 48 49 55 public PBStateEvent(PersistenceBroker broker, Type eventType) 56 { 57 super(broker); 58 this.eventType = eventType; 59 } 60 61 64 public String toString() 65 { 66 ToStringBuilder buf = new ToStringBuilder(this); 67 buf.append("type", eventType.toString()). 68 append("source object", getSource()); 69 return buf.toString(); 70 } 71 72 77 public Type getEventType() 78 { 79 return eventType; 80 } 81 82 85 public static class Type 86 { 87 88 public static final Type BEFORE_BEGIN = new Type(KEY_BEFORE_BEGIN); 89 90 public static final Type AFTER_BEGIN = new Type(KEY_AFTER_BEGIN); 91 92 public static final Type BEFORE_COMMIT = new Type(KEY_BEFORE_COMMIT); 93 94 public static final Type AFTER_COMMIT = new Type(KEY_AFTER_COMMIT); 95 96 public static final Type BEFORE_ROLLBACK = new Type(KEY_BEFORE_ROLLBACK); 97 98 public static final Type AFTER_ROLLBACK = new Type(KEY_AFTER_ROLLBACK); 99 100 public static final Type AFTER_OPEN = new Type(KEY_AFTER_OPEN); 101 102 public static final Type BEFORE_CLOSE = new Type(KEY_BEFORE_CLOSE); 103 104 private int type; 105 106 111 protected Type(int type) 112 { 113 this.type = type; 114 } 115 116 119 public final boolean equals(Object obj) 120 { 121 if (obj == this) 122 { 123 return true; 124 } 125 if (!(obj instanceof PBStateEvent)) 126 { 127 return false; 128 } 129 130 return type == ((Type) obj).type; 131 } 132 133 136 public final int hashCode() 137 { 138 return type; 139 } 140 141 146 public final int typeId() 147 { 148 return type; 149 } 150 151 154 public String toString() 155 { 156 return this.getClass().getName() + " [type= " + typeAsName(type) + "]"; 157 } 158 159 private String typeAsName(int aType) 160 { 161 if (aType == KEY_AFTER_BEGIN) 162 { 163 return "AFTER_BEGIN"; 164 } 165 else if (aType == KEY_AFTER_COMMIT) 166 { 167 return "AFTER_COMMIT"; 168 } 169 else if (aType == KEY_AFTER_OPEN) 170 { 171 return "AFTER_OPEN"; 172 } 173 else if (aType == KEY_AFTER_ROLLBACK) 174 { 175 return "AFTER_ROLLBACK"; 176 } 177 else if (aType == KEY_BEFORE_BEGIN) 178 { 179 return "BEFORE_BEGIN"; 180 } 181 else if (aType == KEY_BEFORE_CLOSE) 182 { 183 return "BEFORE_CLOSE"; 184 } 185 else if (aType == KEY_BEFORE_COMMIT) 186 { 187 return "BEFORE_COMMIT"; 188 } 189 else if (aType == KEY_BEFORE_ROLLBACK) 190 { 191 return "BEFORE_ROLLBACK"; 192 } 193 else 194 { 195 throw new OJBRuntimeException("Could not find type " + aType); 196 } 197 } 198 } 199 } 200 | Popular Tags |