summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EONotQualifier.java
blob: 1068fd7bef9d244d87f18bda1f9f5c1889be8f57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
Wotonomy: OpenStep design patterns for pure Java applications.
Copyright (C) 2001 Intersect Software Corporation

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see http://www.gnu.org
*/

package net.wotonomy.control;

import net.wotonomy.foundation.internal.WotonomyException;

/**
 * EONotQualifiier negates a specified qualifier, evaluating to the opposite of
 * the specified qualifier.
 *
 * @author michael@mpowers.net
 * @author yjcheung@intersectsoft.com
 * @author $Author: cgruber $
 * @version $Revision: 894 $
 */
public class EONotQualifier extends EOQualifier implements EOKeyValueArchiving, EOQualifierEvaluation {
	private EOQualifier qualifier;

	public EONotQualifier(EOQualifier aQualifier) {
		qualifier = aQualifier;
	}

	/**
	 * Returns the qualifier that this qualifier negates.
	 */
	public EOQualifier qualifier() {
		return qualifier;
	}

	/**
	 * Evaluates this qualifier for the specified object, and returns whether the
	 * object is qualified. evaluateWithObject is invoked on qualifier and the
	 * result is negated and returned.
	 */
	public boolean evaluateWithObject(Object anObject) {
		return !(qualifier.evaluateWithObject(anObject));
	}

	/**
	 * Returns a string representation of this qualifier.
	 */
	public String toString() {
		return (new StringBuffer("Not ").append(qualifier.toString()).toString());
	}

	public static Object decodeWithKeyValueUnarchiver(EOKeyValueUnarchiver arch) {
		EOQualifier q = (EOQualifier) arch.decodeObjectForKey("qualifier");
		if (q == null)
			return null;
		return new EONotQualifier(q);
	}

	public void encodeWithKeyValueArchiver(EOKeyValueArchiver arch) {
		arch.encodeObject("EONotQualifier", "class");
		if (qualifier instanceof EOKeyValueArchiving) {
			EOKeyValueArchiver ar2 = new EOKeyValueArchiver();
			((EOKeyValueArchiving) qualifier).encodeWithKeyValueArchiver(ar2);
			arch.encodeObject(ar2.dictionary(), "qualifiers");
		} else
			throw new WotonomyException("Cannot archive instance of " + qualifier.getClass().getName());
	}

}

/*
 * $Log$ Revision 1.2 2006/02/16 16:47:14 cgruber Move some classes in to
 * "internal" packages and re-work imports, etc.
 *
 * Also use UnsupportedOperationExceptions where appropriate, instead of
 * WotonomyExceptions.
 *
 * Revision 1.1 2006/02/16 13:19:57 cgruber Check in all sources in
 * eclipse-friendly maven-enabled packages.
 *
 * Revision 1.9 2003/08/12 01:43:04 chochos formally implement
 * EOQualifierEvaluation
 *
 * Revision 1.8 2003/08/11 19:39:30 chochos special conditions for
 * NSKeyValueCoding.NullValue -> EONull
 *
 * Revision 1.7 2003/08/09 01:24:19 chochos implements EOKeyValueArchiving
 *
 * Revision 1.6 2003/08/06 23:07:52 chochos general code cleanup (mostly,
 * removing unused imports)
 *
 * Revision 1.5 2001/10/31 15:25:14 mpowers Cleanup of qualifiers.
 *
 * Revision 1.4 2001/10/30 22:57:28 mpowers EOQualifier framework is now
 * working.
 *
 * Revision 1.3 2001/09/13 15:42:20 mpowers Fixed another cut/paste typo.
 *
 * Revision 1.2 2001/09/13 15:41:34 mpowers Fixed typo.
 *
 * Revision 1.1 2001/09/13 15:38:19 mpowers Started implementation of the
 * EOQualifier framework.
 *
 *
 */