001 // SECTION-START[License Header] 002 // <editor-fold defaultstate="collapsed" desc=" Generated License "> 003 /* 004 * Copyright (c) 2010 The JOMC Project 005 * Copyright (c) 2005 Christian Schulte <schulte2005@users.sourceforge.net> 006 * All rights reserved. 007 * 008 * Redistribution and use in source and binary forms, with or without 009 * modification, are permitted provided that the following conditions 010 * are met: 011 * 012 * o Redistributions of source code must retain the above copyright 013 * notice, this list of conditions and the following disclaimer. 014 * 015 * o Redistributions in binary form must reproduce the above copyright 016 * notice, this list of conditions and the following disclaimer in 017 * the documentation and/or other materials provided with the 018 * distribution. 019 * 020 * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS" 021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 022 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 023 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR 024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 027 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 028 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 029 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 030 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 031 * 032 * $Id: SequenceChangeEvent.java 2244 2010-06-29 07:58:09Z schulte2005 $ 033 * 034 */ 035 // </editor-fold> 036 // SECTION-END 037 package org.jomc.sequences; 038 039 import java.io.Serializable; 040 import java.util.EventObject; 041 import java.util.HashMap; 042 import java.util.LinkedList; 043 import java.util.List; 044 import java.util.Map; 045 046 // SECTION-START[Documentation] 047 // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> 048 /** 049 * A "SequenceChange" event gets delivered whenever the state of a sequence changes. 050 * 051 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 052 * @version $Id: SequenceChangeEvent.java 2244 2010-06-29 07:58:09Z schulte2005 $ 053 */ 054 // </editor-fold> 055 // SECTION-END 056 // SECTION-START[Annotations] 057 // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> 058 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) 059 // </editor-fold> 060 // SECTION-END 061 public class SequenceChangeEvent extends EventObject 062 { 063 // SECTION-START[SequenceChangeEvent] 064 065 /** Status of a {@code SequenceChangeEvent}. */ 066 public static class Status implements Serializable 067 { 068 069 /** Constant for an information. */ 070 public static final int INFORMATION = 1; 071 072 /** Constant for a notification. */ 073 public static final int NOTIFICATION = 2; 074 075 /** Constant for a warning. */ 076 public static final int WARNING = 3; 077 078 /** Constant for an error. */ 079 public static final int ERROR = 3; 080 081 /** Serial version UID for backwards compatibility with 1.0.x classes. */ 082 private static final long serialVersionUID = 489933079268603831L; 083 084 /** 085 * Type of the status. 086 * @serial 087 */ 088 private int type; 089 090 /** 091 * Identifier of the status. 092 * @serial 093 */ 094 private String identifier; 095 096 /** 097 * Creates a new {@code Status} instance taking a type constant and an identifier of the instance. 098 * 099 * @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 }