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: DefaultVetoableSequenceChangeListener.java 2247 2010-06-29 08:01:42Z schulte2005 $ |
33 | * |
34 | */ |
35 | // </editor-fold> |
36 | // SECTION-END |
37 | package org.jomc.sequences.ri; |
38 | |
39 | import org.jomc.sequences.Sequence; |
40 | import org.jomc.sequences.SequenceChangeEvent; |
41 | import org.jomc.sequences.SequenceVetoException; |
42 | |
43 | // SECTION-START[Documentation] |
44 | // <editor-fold defaultstate="collapsed" desc=" Generated Documentation "> |
45 | /** |
46 | * VetoableSequenceChangeListener reference implementation. |
47 | * <p><b>Specifications</b><ul> |
48 | * <li>{@code 'org.jomc.sequences.VetoableSequenceChangeListener'} {@code (org.jomc.sequences.VetoableSequenceChangeListener)} {@code 1.0} {@code Multiton}</li> |
49 | * </ul></p> |
50 | * <p><b>Properties</b><ul> |
51 | * <li>"{@link #getSequenceNameMaxLength sequenceNameMaxLength}" |
52 | * <blockquote>Property of type {@code int}. |
53 | * <p>Maximum allowed length of a sequence name.</p> |
54 | * </blockquote></li> |
55 | * <li>"{@link #getSequenceNameMinLength sequenceNameMinLength}" |
56 | * <blockquote>Property of type {@code int}. |
57 | * <p>Minimum required length of a sequence name.</p> |
58 | * </blockquote></li> |
59 | * </ul></p> |
60 | * |
61 | * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0 |
62 | * @version $Id: DefaultVetoableSequenceChangeListener.java 2247 2010-06-29 08:01:42Z schulte2005 $ |
63 | */ |
64 | // </editor-fold> |
65 | // SECTION-END |
66 | // SECTION-START[Annotations] |
67 | // <editor-fold defaultstate="collapsed" desc=" Generated Annotations "> |
68 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
69 | // </editor-fold> |
70 | // SECTION-END |
71 | public class DefaultVetoableSequenceChangeListener |
72 | implements |
73 | org.jomc.sequences.VetoableSequenceChangeListener |
74 | { |
75 | // SECTION-START[VetoableSequenceChangeListener] |
76 | |
77 | public void vetoableSequenceChange( final SequenceChangeEvent evt ) |
78 | { |
79 | boolean valid = true; |
80 | |
81 | if ( evt.getNewSequence() != null ) |
82 | { |
83 | if ( evt.getNewSequence().getName() == null ) |
84 | { |
85 | valid = false; |
86 | evt.getStatus( Sequence.PROP_NAME ).add( SequenceChangeEvent.MANDATORY_VALUE ); |
87 | } |
88 | else if ( evt.getNewSequence().getName().length() < this.getSequenceNameMinLength() || |
89 | evt.getNewSequence().getName().length() > this.getSequenceNameMaxLength() ) |
90 | { |
91 | valid = false; |
92 | evt.getStatus( Sequence.PROP_NAME ).add( SequenceChangeEvent.ILLEGAL_LENGTH ); |
93 | } |
94 | if ( evt.getNewSequence().getMaximum() < evt.getNewSequence().getMinimum() || |
95 | evt.getNewSequence().getMinimum() > evt.getNewSequence().getMaximum() ) |
96 | { |
97 | valid = false; |
98 | evt.getStatus( Sequence.PROP_MINIMUM ).add( SequenceChangeEvent.ILLEGAL_VALUE ); |
99 | evt.getStatus( Sequence.PROP_MAXIMUM ).add( SequenceChangeEvent.ILLEGAL_VALUE ); |
100 | } |
101 | if ( evt.getNewSequence().getValue() > evt.getNewSequence().getMaximum() || |
102 | evt.getNewSequence().getValue() < evt.getNewSequence().getMinimum() ) |
103 | { |
104 | valid = false; |
105 | evt.getStatus( Sequence.PROP_VALUE ).add( SequenceChangeEvent.ILLEGAL_VALUE ); |
106 | } |
107 | if ( evt.getNewSequence().getIncrement() <= 0L ) |
108 | { |
109 | valid = false; |
110 | evt.getStatus( Sequence.PROP_INCREMENT ).add( SequenceChangeEvent.ILLEGAL_VALUE ); |
111 | } |
112 | } |
113 | |
114 | if ( !valid ) |
115 | { |
116 | throw new SequenceVetoException( evt ); |
117 | } |
118 | } |
119 | |
120 | // SECTION-END |
121 | // SECTION-START[DefaultVetoableSequenceChangeListener] |
122 | // SECTION-END |
123 | // SECTION-START[Constructors] |
124 | // <editor-fold defaultstate="collapsed" desc=" Generated Constructors "> |
125 | |
126 | /** Creates a new {@code DefaultVetoableSequenceChangeListener} instance. */ |
127 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
128 | public DefaultVetoableSequenceChangeListener() |
129 | { |
130 | // SECTION-START[Default Constructor] |
131 | super(); |
132 | // SECTION-END |
133 | } |
134 | // </editor-fold> |
135 | // SECTION-END |
136 | // SECTION-START[Dependencies] |
137 | // SECTION-END |
138 | // SECTION-START[Properties] |
139 | // <editor-fold defaultstate="collapsed" desc=" Generated Properties "> |
140 | |
141 | /** |
142 | * Gets the value of the {@code sequenceNameMaxLength} property. |
143 | * @return Maximum allowed length of a sequence name. |
144 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
145 | */ |
146 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
147 | private int getSequenceNameMaxLength() |
148 | { |
149 | final java.lang.Integer _p = (java.lang.Integer) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "sequenceNameMaxLength" ); |
150 | assert _p != null : "'sequenceNameMaxLength' property not found."; |
151 | return _p.intValue(); |
152 | } |
153 | |
154 | /** |
155 | * Gets the value of the {@code sequenceNameMinLength} property. |
156 | * @return Minimum required length of a sequence name. |
157 | * @throws org.jomc.ObjectManagementException if getting the property instance fails. |
158 | */ |
159 | @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" ) |
160 | private int getSequenceNameMinLength() |
161 | { |
162 | final java.lang.Integer _p = (java.lang.Integer) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "sequenceNameMinLength" ); |
163 | assert _p != null : "'sequenceNameMinLength' property not found."; |
164 | return _p.intValue(); |
165 | } |
166 | // </editor-fold> |
167 | // SECTION-END |
168 | // SECTION-START[Messages] |
169 | // SECTION-END |
170 | } |