001: /*
002: * ====================================================================
003: * JAFFA - Java Application Framework For All
004: *
005: * Copyright (C) 2002 JAFFA Development Group
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * Redistribution and use of this software and associated documentation ("Software"),
022: * with or without modification, are permitted provided that the following conditions are met:
023: * 1. Redistributions of source code must retain copyright statements and notices.
024: * Redistributions must also contain a copy of this document.
025: * 2. Redistributions in binary form must reproduce the above copyright notice,
026: * this list of conditions and the following disclaimer in the documentation
027: * and/or other materials provided with the distribution.
028: * 3. The name "JAFFA" must not be used to endorse or promote products derived from
029: * this Software without prior written permission. For written permission,
030: * please contact mail to: jaffagroup@yahoo.com.
031: * 4. Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
032: * appear in their names without prior written permission.
033: * 5. Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
034: *
035: * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
039: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
040: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
041: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
042: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
043: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
044: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
045: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
046: * SUCH DAMAGE.
047: * ====================================================================
048: */
049:
050: package org.jaffa.metadata;
051:
052: import org.jaffa.datatypes.Defaults;
053:
054: /**
055: * An instance of this class will hold meta information for a String field.
056: */
057: public class StringFieldMetaData extends FieldMetaData {
058:
059: /** Default width.*/
060: public static final int DEFAULT_WIDTH = 20;
061:
062: // NOTE: keep the equals(), clone(), compareTo(), hashCode() methods in sync
063: private String m_pattern = null;
064: private Integer m_length = null;
065: private String m_caseType = null;
066: private Integer m_minLength = null;
067:
068: /** Creates an instance.
069: */
070: public StringFieldMetaData() {
071: super (null, Defaults.STRING, null, null);
072: }
073:
074: /** Creates an instance.
075: * @param name The field name.
076: * @param labelToken The token used for displaying labels.
077: * @param isMandatory Indicates if the field is mandatory.
078: * @param pattern The pattern.
079: * @param length The maximum length.
080: * @param caseType The case type (upper, lower or mixed).
081: */
082: public StringFieldMetaData(String name, String labelToken,
083: Boolean isMandatory, String pattern, Integer length,
084: String caseType) {
085: this (name, labelToken, isMandatory, pattern, length, caseType,
086: null);
087: }
088:
089: /** Creates an instance.
090: * @param name The field name.
091: * @param labelToken The token used for displaying labels.
092: * @param isMandatory Indicates if the field is mandatory.
093: * @param pattern The pattern.
094: * @param length The maximum length.
095: * @param caseType The case type (upper, lower or mixed).
096: * @param minLength The minimum length.
097: */
098: public StringFieldMetaData(String name, String labelToken,
099: Boolean isMandatory, String pattern, Integer length,
100: String caseType, Integer minLength) {
101: super (name, Defaults.STRING, labelToken, isMandatory);
102: m_pattern = pattern;
103: m_length = length;
104: m_caseType = caseType;
105: m_minLength = minLength;
106: }
107:
108: /** Getter for property pattern.
109: * @return Value of property pattern.
110: */
111: public String getPattern() {
112: return m_pattern;
113: }
114:
115: /** Getter for property length.
116: * @return Value of property length.
117: */
118: public Integer getLength() {
119: return m_length;
120: }
121:
122: /** Getter for property caseType.
123: * @return Value of property caseType.
124: */
125: public String getCaseType() {
126: return m_caseType;
127: }
128:
129: /** Getter for property minLength.
130: * @return Value of property minLength.
131: */
132: public Integer getMinLength() {
133: return m_minLength;
134: }
135:
136: /** Returns a clone of the object.
137: * @return a clone of the object.
138: */
139: public Object clone() {
140: // no more processing required since the fields are immutable
141: return super .clone();
142: }
143:
144: /** Returns the hash code.
145: * @return the hash code.
146: */
147: public int hashCode() {
148: int i = 0;
149: i = super .hashCode();
150: if (m_pattern != null)
151: i += m_pattern.hashCode();
152: if (m_length != null)
153: i += m_length.hashCode();
154: if (m_caseType != null)
155: i += m_caseType.hashCode();
156: if (m_minLength != null)
157: i += m_minLength.hashCode();
158: return i;
159: }
160:
161: /** Compares this object with another StringFieldMetaData object.
162: * Returns a true if both the objects have the same properties.
163: * @param obj the other StringFieldMetaData object.
164: * @return a true if both the objects have the same properties.
165: */
166: public boolean equals(Object obj) {
167: boolean isEqual = false;
168: if (obj instanceof StringFieldMetaData) {
169: StringFieldMetaData field2 = (StringFieldMetaData) obj;
170: if (super .equals(field2)) {
171: if (((m_pattern != null && m_pattern
172: .equals(field2.m_pattern)) || (m_pattern == null && field2.m_pattern == null))
173: && ((m_length != null && m_length
174: .equals(field2.m_length)) || (m_length == null && field2.m_length == null))
175: && ((m_caseType != null && m_caseType
176: .equals(field2.m_caseType)) || (m_caseType == null && field2.m_caseType == null))
177: && ((m_minLength != null && m_minLength
178: .equals(field2.m_minLength)) || (m_minLength == null && field2.m_minLength == null)))
179: isEqual = true;
180: }
181: }
182: return isEqual;
183: }
184:
185: /** Compares this object with another StringFieldMetaData object.
186: * Note: this class has a natural ordering that is inconsistent with equals
187: * @param obj the other StringFieldMetaData object.
188: * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
189: */
190: public int compareTo(Object obj) {
191: // NOTE: this isnt a perfect compare !!!
192: return super .compareTo(obj);
193: }
194:
195: /** Returns the diagnostic information.
196: * @return the diagnostic information.
197: */
198: public String toString() {
199: String comma = ", ";
200: String equals = "=";
201: StringBuffer buffer = new StringBuffer(super .toString());
202:
203: buffer.append(comma);
204: buffer.append("Pattern");
205: buffer.append(equals);
206: buffer.append(m_pattern);
207: buffer.append(comma);
208: buffer.append("Length");
209: buffer.append(equals);
210: buffer.append(m_length);
211: buffer.append(comma);
212: buffer.append("CaseType");
213: buffer.append(equals);
214: buffer.append(m_caseType);
215: buffer.append(comma);
216: buffer.append("MinLength");
217: buffer.append(equals);
218: buffer.append(m_minLength);
219:
220: return buffer.toString();
221: }
222:
223: /** Getter for property width.
224: * @return Value of property width.
225: */
226: public int getWidth() {
227: int i = 0;
228: if (m_length == null)
229: i = DEFAULT_WIDTH;
230: else
231: i = m_length.intValue();
232: return i;
233: }
234: }
|