Coverage Report - net.wotonomy.control.EOKeyComparisonQualifier
 
Classes in this File Line Coverage Branch Coverage Complexity
EOKeyComparisonQualifier
0% 
0% 
4.143
 
 1  
 /*
 2  
 Wotonomy: OpenStep design patterns for pure Java applications.
 3  
 Copyright (C) 2000 Michael Powers
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, see http://www.gnu.org
 17  
 */
 18  
 package net.wotonomy.control;
 19  
 
 20  
 import net.wotonomy.foundation.NSMutableDictionary;
 21  
 import net.wotonomy.foundation.NSSelector;
 22  
 import net.wotonomy.foundation.internal.WotonomyException;
 23  
 
 24  
 /**
 25  
 * @author ezamudio@nasoft.com
 26  
 * @author $Author: cgruber $
 27  
 * @version $Revision: 894 $
 28  
 */
 29  
 public class EOKeyComparisonQualifier
 30  
         extends EOQualifier
 31  
         implements EOKeyValueArchiving, EOQualifierEvaluation {
 32  
 
 33  
         private String _leftKey;
 34  
         private String _rightKey;
 35  
         private NSSelector _selector;
 36  
 
 37  
         public EOKeyComparisonQualifier(String leftKey, NSSelector selector, String rightKey) {
 38  0
                 super();
 39  0
                 _leftKey = leftKey;
 40  0
                 _rightKey = rightKey;
 41  0
                 _selector = selector;
 42  0
         }
 43  
 
 44  
         public String leftKey() {
 45  0
                 return _leftKey;
 46  
         }
 47  
 
 48  
         public String rightKey() {
 49  0
                 return _rightKey;
 50  
         }
 51  
 
 52  
         public NSSelector selector() {
 53  0
                 return _selector;
 54  
         }
 55  
 
 56  
         /**
 57  
         * Evaluates this qualifier for the specified object,
 58  
         * and returns whether the object is qualified.
 59  
         * selector() is invoked on the value for key() on the
 60  
         * specified object, with value() as the parameter.
 61  
         */
 62  
         public boolean evaluateWithObject(Object eo) {
 63  
                 try {
 64  
                         Object lvalue, rvalue;
 65  0
                         if ( eo instanceof EOKeyValueCoding) {
 66  0
                                 lvalue = ((EOKeyValueCoding)eo).valueForKey(leftKey());
 67  0
                                 rvalue = ((EOKeyValueCoding)eo).valueForKey(rightKey());
 68  0
                         } else {
 69  0
                                 lvalue = EOKeyValueCodingSupport.valueForKey(eo, leftKey());
 70  0
                                 rvalue = EOKeyValueCodingSupport.valueForKey(eo, rightKey());
 71  
                         }
 72  0
                         return ((Boolean)_selector.invoke( lvalue, rvalue)).booleanValue();
 73  0
                 } catch (Exception exc) {
 74  0
                         throw new WotonomyException( exc );
 75  
                 }
 76  
         }
 77  
 
 78  
         /* (non-Javadoc)
 79  
          * @see net.wotonomy.control.EOKeyValueArchiving#encodeWithKeyValueArchiver(net.wotonomy.control.EOKeyValueArchiver)
 80  
          */
 81  
         public void encodeWithKeyValueArchiver(EOKeyValueArchiver arch) {
 82  0
                 arch.encodeObject("EOKeyComparisonQualifier", "class");
 83  0
                 arch.encodeObject(_leftKey, "key");
 84  0
                 NSMutableDictionary d = new NSMutableDictionary(2);
 85  0
                 arch.encodeObject(_rightKey, "value");
 86  0
                 String selname = null;
 87  0
                 if (_selector.equals(EOQualifier.QualifierOperatorCaseInsensitiveLike))
 88  0
                         selname = "caseInsensitiveLike:";
 89  0
                 else if (_selector.equals(EOQualifier.QualifierOperatorContains))
 90  0
                         selname = "contains:";
 91  0
                 else if (_selector.equals(EOQualifier.QualifierOperatorEqual))
 92  0
                         selname = "isEqualTo:";
 93  0
                 else if (_selector.equals(EOQualifier.QualifierOperatorGreaterThan))
 94  0
                         selname = "greaterThan:";
 95  0
                 else if (_selector.equals(EOQualifier.QualifierOperatorGreaterThanOrEqualTo))
 96  0
                         selname = "greaterThanOrEqualTo:";
 97  0
                 else if (_selector.equals(EOQualifier.QualifierOperatorLessThan))
 98  0
                         selname = "lessThan:";
 99  0
                 else if (_selector.equals(EOQualifier.QualifierOperatorLessThanOrEqualTo))
 100  0
                         selname = "lessThanOrEqualTo:";
 101  0
                 else if (_selector.equals(EOQualifier.QualifierOperatorLike))
 102  0
                         selname = "like:";
 103  0
                 else if (_selector.equals(EOQualifier.QualifierOperatorNotEqual))
 104  0
                         selname = "isNotEqualTo:";
 105  
                 else
 106  0
                         selname = _selector.name() + ":";
 107  0
                 arch.encodeObject(selname, "selectorName");
 108  0
         }
 109  
 
 110  
         public static Object decodeWithKeyValueArchiver(EOKeyValueUnarchiver arch) {
 111  0
                 String k = (String)arch.decodeObjectForKey("key");
 112  0
                 String v = (String)arch.decodeObjectForKey("value");
 113  0
                 NSSelector sel = null;
 114  0
                 String sname = (String)arch.decodeObjectForKey("selectorName");
 115  0
                 if (sname.equals("isEqualTo:"))
 116  0
                         sel = EOQualifier.QualifierOperatorEqual;
 117  0
                 else if (sname.equals("isNotEqualTo:"))
 118  0
                         sel = EOQualifier.QualifierOperatorNotEqual;
 119  0
                 else if (sname.equals("caseInsensitiveLike:"))
 120  0
                         sel = EOQualifier.QualifierOperatorCaseInsensitiveLike;
 121  0
                 else if (sname.equals("contains:"))
 122  0
                         sel = EOQualifier.QualifierOperatorContains;
 123  0
                 else if (sname.equals("greaterThan:"))
 124  0
                         sel = EOQualifier.QualifierOperatorGreaterThan;
 125  0
                 else if (sname.equals("greaterThanOrEqualTo:"))
 126  0
                         sel = EOQualifier.QualifierOperatorGreaterThanOrEqualTo;
 127  0
                 else if (sname.equals("lessThan:"))
 128  0
                         sel = EOQualifier.QualifierOperatorLessThan;
 129  0
                 else if (sname.equals("lessThanOrEqualTo:"))
 130  0
                         sel = EOQualifier.QualifierOperatorLessThanOrEqualTo;
 131  0
                 else if (sname.equals("like:"))
 132  0
                         sel = EOQualifier.QualifierOperatorLike;
 133  0
                 EOKeyComparisonQualifier q = new EOKeyComparisonQualifier(k, sel, v);
 134  0
                 return q;
 135  
         }
 136  
 
 137  
 }
 138  
 /*
 139  
  * $Log$
 140  
  * Revision 1.2  2006/02/16 16:47:14  cgruber
 141  
  * Move some classes in to "internal" packages and re-work imports, etc.
 142  
  *
 143  
  * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions.
 144  
  *
 145  
  * Revision 1.1  2006/02/16 13:19:57  cgruber
 146  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 147  
  *
 148  
  * Revision 1.1  2003/08/12 01:42:36  chochos
 149  
  * this qualifier was missing
 150  
  *
 151  
  */