| 1 | // SECTION-START[License Header] |
| 2 | // <editor-fold defaultstate="collapsed" desc=" Generated License "> |
| 3 | /* |
| 4 | * Copyright (c) 2010 The JOMC Project |
| 5 | * Copyright (c) 2005 Christian Schulte <schulte2005@users.sourceforge.net> |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * |
| 12 | * o Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * |
| 15 | * o Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in |
| 17 | * the documentation and/or other materials provided with the |
| 18 | * distribution. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS" |
| 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 22 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR |
| 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 27 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 28 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 30 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | * $Id: SequenceChangeEvent.java 2244 2010-06-29 07:58:09Z schulte2005 $ |
| 33 | * |
| 34 | */ |
| 35 | // </editor-fold> |
| 36 | // SECTION-END |
| 37 | package org.jomc.sequences; |
| 38 | |
| 39 | import java.io.Serializable; |
| 40 | import java.util.EventObject; |
| 41 | import java.util.HashMap; |
| 42 | import java.util.LinkedList; |
| 43 | import java.util.List; |
| 44 | import java.util.Map; |
| 45 | |
| 46 | // SECTION-START[Documentation] |
| 47 | // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> |
| 48 | /** |
| 49 | * A "SequenceChange" event gets delivered whenever the state of a sequence changes. |
| 50 | * |
| 51 | * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 |
| 52 | * @version $Id: SequenceChangeEvent.java 2244 2010-06-29 07:58:09Z schulte2005 $ |
| 53 | */ |
| 54 | // </editor-fold> |
| 55 | // SECTION-END |
| 56 | // SECTION-START[Annotations] |
| 57 | // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> |
| 58 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
| 59 | // </editor-fold> |
| 60 | // SECTION-END |
| 61 | public class SequenceChangeEvent extends EventObject |
| 62 | { |
| 63 | // SECTION-START[SequenceChangeEvent] |
| 64 | |
| 65 | /** Status of a {@code SequenceChangeEvent}. */ |
| 66 | public static class Status implements Serializable |
| 67 | { |
| 68 | |
| 69 | /** Constant for an information. */ |
| 70 | public static final int INFORMATION = 1; |
| 71 | |
| 72 | /** Constant for a notification. */ |
| 73 | public static final int NOTIFICATION = 2; |
| 74 | |
| 75 | /** Constant for a warning. */ |
| 76 | public static final int WARNING = 3; |
| 77 | |
| 78 | /** Constant for an error. */ |
| 79 | public static final int ERROR = 3; |
| 80 | |
| 81 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ |
| 82 | private static final long serialVersionUID = 489933079268603831L; |
| 83 | |
| 84 | /** |
| 85 | * Type of the status. |
| 86 | * @serial |
| 87 | */ |
| 88 | private int type; |
| 89 | |
| 90 | /** |
| 91 | * Identifier of the status. |
| 92 | * @serial |
| 93 | */ |
| 94 | private String identifier; |
| 95 | |
| 96 | /** |
| 97 | * Creates a new {@code Status} instance taking a type constant and an identifier of the instance. |
| 98 | * |
| 99 | * @param type The type of the new status. |
| 100 | * @param identifier The identifier of the status. |
| 101 | */ |
| 102 | public Status( final int type, final String identifier ) |
| 103 | { |
| 104 | this.type = type; |
| 105 | this.identifier = identifier; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Gets the type of the status. |
| 110 | * |
| 111 | * @return The type of the status. |
| 112 | */ |
| 113 | public int getType() |
| 114 | { |
| 115 | return this.type; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Gets the identifier of status. |
| 120 | * |
| 121 | * @return The identifier of the status. |
| 122 | */ |
| 123 | public String getIdentifier() |
| 124 | { |
| 125 | return this.identifier; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Returns a string representation of the object. |
| 130 | * |
| 131 | * @return A string representation of the object. |
| 132 | */ |
| 133 | @Override |
| 134 | public String toString() |
| 135 | { |
| 136 | final StringBuffer str = new StringBuffer().append( "{" ); |
| 137 | str.append( "type=" ).append( this.type ). |
| 138 | append( ", identifier=" ).append( this.getIdentifier() ). |
| 139 | append( '}' ); |
| 140 | |
| 141 | return super.toString() + str.toString(); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Indicates whether some other object is "equal to" this one by comparing the value of property |
| 146 | * {@code identifier}. |
| 147 | * |
| 148 | * @param o The reference object with which to compare. |
| 149 | * @return {@code true} if this object is the same as the obj argument; {@code false} otherwise. |
| 150 | */ |
| 151 | @Override |
| 152 | public boolean equals( final Object o ) |
| 153 | { |
| 154 | boolean equal = this == o; |
| 155 | if ( !equal && o instanceof Status ) |
| 156 | { |
| 157 | final Status that = (Status) o; |
| 158 | equal = this.getIdentifier().equals( that.getIdentifier() ); |
| 159 | } |
| 160 | return equal; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Returns a hash code value for the object. |
| 165 | * |
| 166 | * @return A hash code value for this object. |
| 167 | */ |
| 168 | @Override |
| 169 | public int hashCode() |
| 170 | { |
| 171 | int hash = 5; |
| 172 | hash = 47 * hash + ( this.identifier != null ? this.identifier.hashCode() : 0 ); |
| 173 | return hash; |
| 174 | } |
| 175 | |
| 176 | } |
| 177 | |
| 178 | /** A mandatory property is missing a value. */ |
| 179 | public static final Status MANDATORY_VALUE = |
| 180 | new Status( Status.ERROR, Sequence.class.getName() + ".MANDATORY_VALUE" ); |
| 181 | |
| 182 | /** A property value is illegal. */ |
| 183 | public static final Status ILLEGAL_VALUE = |
| 184 | new Status( Status.ERROR, Sequence.class.getName() + ".ILLEGAL_VALUE" ); |
| 185 | |
| 186 | /** A property value is of illegal length. */ |
| 187 | public static final Status ILLEGAL_LENGTH = |
| 188 | new Status( Status.ERROR, Sequence.class.getName() + ".ILLEGAL_LENGTH" ); |
| 189 | |
| 190 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ |
| 191 | private static final long serialVersionUID = 4189816896435679868L; |
| 192 | |
| 193 | /** |
| 194 | * The entity getting changed. |
| 195 | * @serial |
| 196 | */ |
| 197 | private Sequence oldSequence; |
| 198 | |
| 199 | /** |
| 200 | * The the entity the old sequence is changed to. |
| 201 | * @serial |
| 202 | */ |
| 203 | private Sequence newSequence; |
| 204 | |
| 205 | /** |
| 206 | * The status of the event. |
| 207 | * @serial |
| 208 | */ |
| 209 | private Map<String, List<Status>> status; |
| 210 | |
| 211 | /** |
| 212 | * Creates a new {@code SequenceChangeEvent} instance. |
| 213 | * |
| 214 | * @param source The source of the event. |
| 215 | * @param oldSequence The entity getting changed or {@code null} if {@code newValue} is about to be added to |
| 216 | * {@code source}. |
| 217 | * @param newSequence The value {@code oldValue} will be changed to or {@code null} if {@code oldValue} is about to |
| 218 | * be removed from {@code source}. |
| 219 | */ |
| 220 | public SequenceChangeEvent( final Object source, final Sequence oldSequence, final Sequence newSequence ) |
| 221 | { |
| 222 | super( source ); |
| 223 | this.oldSequence = oldSequence; |
| 224 | this.newSequence = newSequence; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Gets the entity getting changed. |
| 229 | * |
| 230 | * @return The entity getting changed or {@code null} if a new sequence is added to the source of.the event. |
| 231 | */ |
| 232 | public Sequence getOldSequence() |
| 233 | { |
| 234 | return this.oldSequence; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Gets the entity the old sequence is changed to. |
| 239 | * |
| 240 | * @return The entity the old sequence is changed to or {@code null} if the old sequence is removed from the source |
| 241 | * of the event. |
| 242 | */ |
| 243 | public Sequence getNewSequence() |
| 244 | { |
| 245 | return this.newSequence; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Gets status for a given key. |
| 250 | * |
| 251 | * @param key The key of the status to return. |
| 252 | * |
| 253 | * @return The status for {@code key}. |
| 254 | */ |
| 255 | public List<Status> getStatus( final String key ) |
| 256 | { |
| 257 | if ( this.status == null ) |
| 258 | { |
| 259 | this.status = new HashMap<String, List<Status>>(); |
| 260 | } |
| 261 | |
| 262 | List<Status> list = this.status.get( key ); |
| 263 | if ( list == null ) |
| 264 | { |
| 265 | list = new LinkedList<Status>(); |
| 266 | this.status.put( key, list ); |
| 267 | } |
| 268 | |
| 269 | return list; |
| 270 | } |
| 271 | |
| 272 | // SECTION-END |
| 273 | // SECTION-START[Dependencies] |
| 274 | // SECTION-END |
| 275 | // SECTION-START[Properties] |
| 276 | // SECTION-END |
| 277 | // SECTION-START[Messages] |
| 278 | // SECTION-END |
| 279 | } |