001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.common.tagging;
009:
010: //base classes
011: import java.util.ArrayList;
012: import java.util.HashSet;
013:
014: //project specific classes
015: import org.jfolder.common.StandardDataTypes;
016: import org.jfolder.common.UnexpectedSystemException;
017: import org.jfolder.common.utils.misc.MiscHelper;
018:
019: //other classes
020:
021: public class DynamicConceptTagValidatorPart {
022:
023: //
024: private final static int COMMAND_NULL = -1;
025: //
026: protected final static int COMMAND_FLAG_PRESENT = 1;
027: protected final static int COMMAND_FLAG_NOT_PRESENT = 2;
028: protected final static int COMMAND_FLAG_EQUAL = 3;
029: protected final static int COMMAND_FLAG_NOT_EQUAL = 4;
030: protected final static int COMMAND_FLAG_LESS_THAN = 5;
031: protected final static int COMMAND_FLAG_GREATER_THAN = 6;
032: protected final static int COMMAND_FLAG_GREATER_THAN_OR_EQUAL = 7;
033: protected final static int COMMAND_FLAG_LESS_THAN_OR_EQUAL = 8;
034: protected final static int COMMAND_CONTAINS_PARENT_NODE = 9;
035: protected final static int COMMAND_DOES_NOT_CONTAIN_PARENT_NODE = 10;
036: protected final static int COMMAND_DOES_RETURN = 11;
037: protected final static int COMMAND_DOES_NOT_RETURN = 12;
038: protected final static int COMMAND_SUB_VALIDATE = 13;
039: //
040: protected final static int COMMAND_IS_CLASS = 14;
041:
042: //
043: private int commandType = 0;
044: //
045: private String ctNs = null;
046: private String ctName = null;
047: //
048: private String flagNs = null;
049: private String flagName = null;
050: private Object flagValue = null;
051: //
052: private String errorMessage = null;
053: //
054: private HashSet setForClasses = null;
055: //
056: private DynamicConceptTagValidator subDctv = null;
057: //
058: private Integer cachedHashCode = null;
059:
060: private DynamicConceptTagValidatorPart(int inCommandType) {
061: reset();
062: this .commandType = inCommandType;
063: }
064:
065: public int hashCode() {
066:
067: int outValue = 0;
068:
069: if (this .cachedHashCode != null) {
070: outValue = this .cachedHashCode.intValue();
071: } else {
072: outValue += this .commandType;
073: outValue += MiscHelper.hashCodeOrZero(this .ctNs);
074: outValue += MiscHelper.hashCodeOrZero(this .ctName);
075: outValue += MiscHelper.hashCodeOrZero(this .flagNs);
076: outValue += MiscHelper.hashCodeOrZero(this .flagName);
077: outValue += MiscHelper.hashCodeOrZero(this .flagValue);
078: outValue += MiscHelper.hashCodeOrZero(this .errorMessage);
079: outValue += this .setForClasses.hashCode();
080: outValue += MiscHelper.hashCodeOrZero(this .subDctv);
081: //
082: this .cachedHashCode = new Integer(outValue);
083: }
084:
085: return outValue;
086: }
087:
088: public boolean equals(Object inObj) {
089:
090: boolean outValue = true;
091:
092: if (inObj instanceof DynamicConceptTagValidatorPart) {
093: DynamicConceptTagValidatorPart nextDctvp = ((DynamicConceptTagValidatorPart) inObj);
094: //
095: outValue &= (this .commandType == nextDctvp.commandType);
096: outValue &= MiscHelper.equalsOrNull(this .ctNs,
097: nextDctvp.ctNs);
098: outValue &= MiscHelper.equalsOrNull(this .ctName,
099: nextDctvp.ctName);
100: outValue &= MiscHelper.equalsOrNull(this .flagNs,
101: nextDctvp.flagNs);
102: outValue &= MiscHelper.equalsOrNull(this .flagName,
103: nextDctvp.flagName);
104: outValue &= MiscHelper.equalsOrNull(this .flagValue,
105: nextDctvp.flagValue);
106: outValue &= MiscHelper.equalsOrNull(this .errorMessage,
107: nextDctvp.errorMessage);
108: outValue &= this .setForClasses
109: .equals(nextDctvp.setForClasses);
110: outValue &= MiscHelper.equalsOrNull(this .subDctv,
111: nextDctvp.subDctv);
112: } else {
113: outValue &= false;
114: }
115:
116: return outValue;
117: }
118:
119: //
120: public final static DynamicConceptTagValidatorPart newCommandIsClass(
121: Class inClass[], String inError) {
122:
123: DynamicConceptTagValidatorPart outValue = null;
124:
125: outValue = new DynamicConceptTagValidatorPart(COMMAND_IS_CLASS);
126: for (int i = 0; i < inClass.length; i++) {
127: outValue.setForClasses.add(inClass[i]);
128: }
129: outValue.errorMessage = inError;
130:
131: return outValue;
132: }
133:
134: public final static DynamicConceptTagValidatorPart newCommandDoesReturn(
135: Class inClass[], String inError) {
136:
137: DynamicConceptTagValidatorPart outValue = null;
138:
139: outValue = new DynamicConceptTagValidatorPart(
140: COMMAND_DOES_RETURN);
141: for (int i = 0; i < inClass.length; i++) {
142: outValue.setForClasses.add(inClass[i]);
143: }
144: outValue.errorMessage = inError;
145:
146: return outValue;
147: }
148:
149: public final static DynamicConceptTagValidatorPart newCommandDoesNotReturn(
150: Class inClass[], String inError) {
151:
152: DynamicConceptTagValidatorPart outValue = null;
153:
154: outValue = new DynamicConceptTagValidatorPart(
155: COMMAND_DOES_NOT_RETURN);
156: for (int i = 0; i < inClass.length; i++) {
157: outValue.setForClasses.add(inClass[i]);
158: }
159: outValue.errorMessage = inError;
160:
161: return outValue;
162: }
163:
164: public final static DynamicConceptTagValidatorPart newCommandFlagPresent(
165: String inNs, String inName, String inError) {
166:
167: DynamicConceptTagValidatorPart outValue = null;
168:
169: outValue = new DynamicConceptTagValidatorPart(
170: COMMAND_FLAG_PRESENT);
171: outValue.flagNs = inNs;
172: outValue.flagName = inName;
173: outValue.errorMessage = inError;
174:
175: return outValue;
176: }
177:
178: public final static DynamicConceptTagValidatorPart newCommandFlagNotPresent(
179: String inNs, String inName, String inError) {
180:
181: DynamicConceptTagValidatorPart outValue = null;
182:
183: outValue = new DynamicConceptTagValidatorPart(
184: COMMAND_FLAG_NOT_PRESENT);
185: outValue.flagNs = inNs;
186: outValue.flagName = inName;
187: outValue.errorMessage = inError;
188:
189: return outValue;
190: }
191:
192: public final static DynamicConceptTagValidatorPart newCommandFlagEqual(
193: String inNs, String inName, Object inValue, String inError) {
194:
195: DynamicConceptTagValidatorPart outValue = null;
196:
197: outValue = new DynamicConceptTagValidatorPart(
198: COMMAND_FLAG_EQUAL);
199: outValue.flagNs = inNs;
200: outValue.flagName = inName;
201: outValue.flagValue = inValue;
202: outValue.errorMessage = inError;
203:
204: return outValue;
205: }
206:
207: public void reset() {
208: this .commandType = COMMAND_NULL;
209: this .setForClasses = new HashSet();
210: }
211:
212: //
213: public int getCommandType() {
214: return this .commandType;
215: }
216:
217: //
218: public String getErrorMessage() {
219: return this .errorMessage;
220: }
221:
222: //
223: public boolean isCommandFlagPresent() {
224: return (this .commandType == COMMAND_FLAG_PRESENT);
225: }
226:
227: public boolean isCommandFlagNotPresent() {
228: return (this .commandType == COMMAND_FLAG_NOT_PRESENT);
229: }
230:
231: public boolean isCommandFlagEqual() {
232: return (this .commandType == COMMAND_FLAG_EQUAL);
233: }
234:
235: public boolean isCommandFlagNotEqual() {
236: return (this .commandType == COMMAND_FLAG_NOT_EQUAL);
237: }
238:
239: public boolean isCommandFlagLessThan() {
240: return (this .commandType == COMMAND_FLAG_LESS_THAN);
241: }
242:
243: public boolean isCommandFlagGreaterThan() {
244: return (this .commandType == COMMAND_FLAG_GREATER_THAN);
245: }
246:
247: public boolean isCommandFlagGreaterThanOrEqual() {
248: return (this .commandType == COMMAND_FLAG_GREATER_THAN_OR_EQUAL);
249: }
250:
251: public boolean isCommandFlagLessThanOrEqual() {
252: return (this .commandType == COMMAND_FLAG_LESS_THAN_OR_EQUAL);
253: }
254:
255: public boolean isCommandContainsParentNode() {
256: return (this .commandType == COMMAND_CONTAINS_PARENT_NODE);
257: }
258:
259: public boolean isCommandDoesNotContainParentNode() {
260: return (this .commandType == COMMAND_DOES_NOT_CONTAIN_PARENT_NODE);
261: }
262:
263: public boolean isCommandDoesReturn() {
264: return (this .commandType == COMMAND_DOES_RETURN);
265: }
266:
267: public boolean isCommandDoesNotReturn() {
268: return (this .commandType == COMMAND_DOES_NOT_RETURN);
269: }
270:
271: public boolean isCommandSubValidate() {
272: return (this .commandType == COMMAND_SUB_VALIDATE);
273: }
274:
275: public boolean isCommandIsClass() {
276: return (this .commandType == COMMAND_IS_CLASS);
277: }
278:
279: //
280: public String getFlagNamespace() {
281: return this .flagNs;
282: }
283:
284: public String getFlagName() {
285: return this .flagName;
286: }
287:
288: public Object getFlagValue() {
289: return this .flagValue;
290: }
291:
292: //
293: public Class[] getClasses() {
294: return ((Class[]) this .setForClasses.toArray(new Class[0]));
295: }
296:
297: //
298: public DynamicConceptTagValidator getSubValidator() {
299: return this.subDctv;
300: }
301: }
|