diff options
| author | Benjamin Culkin <scorpress@gmail.com> | 2024-05-19 17:56:33 -0400 |
|---|---|---|
| committer | Benjamin Culkin <scorpress@gmail.com> | 2024-05-19 17:56:33 -0400 |
| commit | aedc34d55462a75e329bbf342251ff6504cd117e (patch) | |
| tree | bcc8f1f2352582717b484df302aeea6696b8f000 /projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOKeyComparisonQualifier.java | |
Initial import from SVN
Diffstat (limited to 'projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOKeyComparisonQualifier.java')
| -rw-r--r-- | projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOKeyComparisonQualifier.java | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOKeyComparisonQualifier.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOKeyComparisonQualifier.java new file mode 100644 index 0000000..97baaab --- /dev/null +++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOKeyComparisonQualifier.java @@ -0,0 +1,151 @@ +/* +Wotonomy: OpenStep design patterns for pure Java applications. +Copyright (C) 2000 Michael Powers + +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.NSMutableDictionary; +import net.wotonomy.foundation.NSSelector; +import net.wotonomy.foundation.internal.WotonomyException; + +/** +* @author ezamudio@nasoft.com +* @author $Author: cgruber $ +* @version $Revision: 894 $ +*/ +public class EOKeyComparisonQualifier + extends EOQualifier + implements EOKeyValueArchiving, EOQualifierEvaluation { + + private String _leftKey; + private String _rightKey; + private NSSelector _selector; + + public EOKeyComparisonQualifier(String leftKey, NSSelector selector, String rightKey) { + super(); + _leftKey = leftKey; + _rightKey = rightKey; + _selector = selector; + } + + public String leftKey() { + return _leftKey; + } + + public String rightKey() { + return _rightKey; + } + + public NSSelector selector() { + return _selector; + } + + /** + * Evaluates this qualifier for the specified object, + * and returns whether the object is qualified. + * selector() is invoked on the value for key() on the + * specified object, with value() as the parameter. + */ + public boolean evaluateWithObject(Object eo) { + try { + Object lvalue, rvalue; + if ( eo instanceof EOKeyValueCoding) { + lvalue = ((EOKeyValueCoding)eo).valueForKey(leftKey()); + rvalue = ((EOKeyValueCoding)eo).valueForKey(rightKey()); + } else { + lvalue = EOKeyValueCodingSupport.valueForKey(eo, leftKey()); + rvalue = EOKeyValueCodingSupport.valueForKey(eo, rightKey()); + } + return ((Boolean)_selector.invoke( lvalue, rvalue)).booleanValue(); + } catch (Exception exc) { + throw new WotonomyException( exc ); + } + } + + /* (non-Javadoc) + * @see net.wotonomy.control.EOKeyValueArchiving#encodeWithKeyValueArchiver(net.wotonomy.control.EOKeyValueArchiver) + */ + public void encodeWithKeyValueArchiver(EOKeyValueArchiver arch) { + arch.encodeObject("EOKeyComparisonQualifier", "class"); + arch.encodeObject(_leftKey, "key"); + NSMutableDictionary d = new NSMutableDictionary(2); + arch.encodeObject(_rightKey, "value"); + String selname = null; + if (_selector.equals(EOQualifier.QualifierOperatorCaseInsensitiveLike)) + selname = "caseInsensitiveLike:"; + else if (_selector.equals(EOQualifier.QualifierOperatorContains)) + selname = "contains:"; + else if (_selector.equals(EOQualifier.QualifierOperatorEqual)) + selname = "isEqualTo:"; + else if (_selector.equals(EOQualifier.QualifierOperatorGreaterThan)) + selname = "greaterThan:"; + else if (_selector.equals(EOQualifier.QualifierOperatorGreaterThanOrEqualTo)) + selname = "greaterThanOrEqualTo:"; + else if (_selector.equals(EOQualifier.QualifierOperatorLessThan)) + selname = "lessThan:"; + else if (_selector.equals(EOQualifier.QualifierOperatorLessThanOrEqualTo)) + selname = "lessThanOrEqualTo:"; + else if (_selector.equals(EOQualifier.QualifierOperatorLike)) + selname = "like:"; + else if (_selector.equals(EOQualifier.QualifierOperatorNotEqual)) + selname = "isNotEqualTo:"; + else + selname = _selector.name() + ":"; + arch.encodeObject(selname, "selectorName"); + } + + public static Object decodeWithKeyValueArchiver(EOKeyValueUnarchiver arch) { + String k = (String)arch.decodeObjectForKey("key"); + String v = (String)arch.decodeObjectForKey("value"); + NSSelector sel = null; + String sname = (String)arch.decodeObjectForKey("selectorName"); + if (sname.equals("isEqualTo:")) + sel = EOQualifier.QualifierOperatorEqual; + else if (sname.equals("isNotEqualTo:")) + sel = EOQualifier.QualifierOperatorNotEqual; + else if (sname.equals("caseInsensitiveLike:")) + sel = EOQualifier.QualifierOperatorCaseInsensitiveLike; + else if (sname.equals("contains:")) + sel = EOQualifier.QualifierOperatorContains; + else if (sname.equals("greaterThan:")) + sel = EOQualifier.QualifierOperatorGreaterThan; + else if (sname.equals("greaterThanOrEqualTo:")) + sel = EOQualifier.QualifierOperatorGreaterThanOrEqualTo; + else if (sname.equals("lessThan:")) + sel = EOQualifier.QualifierOperatorLessThan; + else if (sname.equals("lessThanOrEqualTo:")) + sel = EOQualifier.QualifierOperatorLessThanOrEqualTo; + else if (sname.equals("like:")) + sel = EOQualifier.QualifierOperatorLike; + EOKeyComparisonQualifier q = new EOKeyComparisonQualifier(k, sel, v); + return q; + } + +} +/* + * $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.1 2003/08/12 01:42:36 chochos + * this qualifier was missing + * + */ |
