Coverage Report - net.wotonomy.foundation.NSKeyValueCodingAdditions
 
Classes in this File Line Coverage Branch Coverage Complexity
NSKeyValueCodingAdditions
0% 
0% 
1.667
 
 1  
 /*
 2  
 Wotonomy: OpenStep design patterns for pure Java applications.
 3  
 Copyright (C) 2001 Intersect Software Corporation
 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  
 
 19  
 package net.wotonomy.foundation;
 20  
 
 21  
 import java.util.List;
 22  
 import java.util.Map;
 23  
 
 24  
 /**
 25  
 * NSKeyValueCodingAdditions defines an interface for classes
 26  
 * that need to have more control over the wotonomy's bulk 
 27  
 * property copying and cloning facilities.  <br><br>
 28  
 *
 29  
 * @author michael@mpowers.net
 30  
 * @author $Author: cgruber $
 31  
 * @version $Revision: 893 $
 32  
 */
 33  
 public interface NSKeyValueCodingAdditions extends NSKeyValueCoding
 34  
 {
 35  
     /**
 36  
     * Returns the value for the specified key path, which is
 37  
     * a series of keys delimited by ".", for example:
 38  
     * "createTime.year.length".
 39  
     */
 40  
     Object valueForKeyPath( String aKeyPath );
 41  
 
 42  
     /**
 43  
     * Sets the value for the specified key path, which is
 44  
     * a series of keys delimited by ".", for example:
 45  
     * "createTime.year.length".
 46  
     * The value is set for the last object referenced by
 47  
     * the key path.
 48  
     */
 49  
     void takeValueForKeyPath( Object aValue, String aKeyPath );
 50  
     
 51  
     /**
 52  
     * Returns a Map of the specified keys to their values,
 53  
     * each of which might be obtained by calling valueForKey.
 54  
     */
 55  
     NSDictionary valuesForKeys( List aKeyList );
 56  
     
 57  
     /**
 58  
     * Takes the keys from the specified map as properties
 59  
     * and applies the corresponding values, each of which
 60  
     * might be set by calling takeValueForKey.
 61  
     */
 62  
     void takeValuesFromDictionary( Map aMap );
 63  
     
 64  
     
 65  
     /**
 66  
     * Static utility methods that
 67  
     * call the appropriate method if the object implements
 68  
     * NSKeyValueCodingAdditions, otherwise calls the method
 69  
     * on DefaultImplementation.
 70  
     */
 71  0
     public class Utility
 72  
     {
 73  
         /**
 74  
         * Calls the appropriate method if the object implements
 75  
         * NSKeyValueCodingAdditions, otherwise calls the method
 76  
         * on DefaultImplementation.
 77  
         */
 78  
         public static void takeValuesFromDictionary(
 79  
             Object object, Map dictionary)
 80  
         {
 81  0
             if (object instanceof NSKeyValueCodingAdditions) {
 82  0
                 ((NSKeyValueCodingAdditions)object).takeValuesFromDictionary(dictionary);
 83  0
             } else {
 84  0
                 DefaultImplementation.takeValuesFromDictionary(object, dictionary);
 85  
             }
 86  0
          }
 87  
             
 88  
         /**
 89  
         * Calls the appropriate method if the object implements
 90  
         * NSKeyValueCodingAdditions, otherwise calls the method
 91  
         * on DefaultImplementation.
 92  
         */
 93  
         public static void takeValueForKeyPath(
 94  
             Object object, Object aValue, String aKeyPath)
 95  
         {
 96  0
             if (object instanceof NSKeyValueCodingAdditions) {
 97  0
                 ((NSKeyValueCodingAdditions)object).takeValueForKeyPath(aValue, aKeyPath);
 98  0
             } else {
 99  0
                 DefaultImplementation.takeValueForKeyPath(object, aValue, aKeyPath);
 100  
             }
 101  0
         }
 102  
         
 103  
         /**
 104  
         * Calls the appropriate method if the object implements
 105  
         * NSKeyValueCodingAdditions, otherwise calls the method
 106  
         * on DefaultImplementation.
 107  
         */
 108  
         public static NSDictionary valuesForKeys(
 109  
             Object object, List keys)
 110  
         {
 111  0
             if (object instanceof NSKeyValueCodingAdditions) {
 112  0
                 return ((NSKeyValueCodingAdditions)object).valuesForKeys(keys);
 113  
             } else {
 114  0
                 return DefaultImplementation.valuesForKeys(object, keys);
 115  
             }
 116  
         }
 117  
         
 118  
         /**
 119  
         * Calls the appropriate method if the object implements
 120  
         * NSKeyValueCodingAdditions, otherwise calls the method
 121  
         * on DefaultImplementation.
 122  
         */
 123  
         public static Object valueForKeyPath(
 124  
             Object object, String aKeyPath)
 125  
         {
 126  0
             if (object instanceof NSKeyValueCodingAdditions) {
 127  0
                 return ((NSKeyValueCodingAdditions)object).valueForKeyPath(aKeyPath);
 128  
             } else {
 129  0
                 return DefaultImplementation.valueForKeyPath(object, aKeyPath);
 130  
             }
 131  
         }
 132  
     }
 133  
     
 134  
     /**
 135  
     * Provides a reflection-based implementation for classes that
 136  
     * don't implement NSKeyValueCodingAdditions.
 137  
     */
 138  0
     public class DefaultImplementation 
 139  
     {
 140  
         /**
 141  
         * Provides a reflection-based implementation for classes that
 142  
         * don't implement NSKeyValueCodingAdditions.
 143  
         */
 144  
         public static void takeValuesFromDictionary(
 145  
             Object object, Map dictionary)
 146  
         {
 147  0
             throw new RuntimeException( "Not implemented yet." );
 148  
          }
 149  
             
 150  
         /**
 151  
         * Provides a reflection-based implementation for classes that
 152  
         * don't implement NSKeyValueCodingAdditions.
 153  
         */
 154  
         public static void takeValueForKeyPath(
 155  
             Object object, Object aValue, String aKeyPath)
 156  
         {
 157  
             // currently, NSKeyValueCoding.takeValueForKey accepts paths
 158  0
             NSKeyValueCoding.DefaultImplementation.takeValueForKey( object, aValue, aKeyPath );
 159  0
         }
 160  
         
 161  
         /**
 162  
         * Provides a reflection-based implementation for classes that
 163  
         * don't implement NSKeyValueCodingAdditions.
 164  
         */
 165  
         public static NSDictionary valuesForKeys(
 166  
             Object object, List keys)
 167  
         {
 168  0
             throw new RuntimeException( "Not implemented yet." );
 169  
         }
 170  
         
 171  
         /**
 172  
         * Provides a reflection-based implementation for classes that
 173  
         * don't implement NSKeyValueCodingAdditions.
 174  
         */
 175  
         public static Object valueForKeyPath(
 176  
             Object object, String aKeyPath)
 177  
         {
 178  
             // currently, NSKeyValueCoding.valueForKey accepts paths
 179  0
             return NSKeyValueCoding.DefaultImplementation.valueForKey( object, aKeyPath );
 180  
         }
 181  
     }
 182  
 }
 183  
 
 184  
 /*
 185  
  * $Log$
 186  
  * Revision 1.2  2006/02/16 13:15:00  cgruber
 187  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 188  
  *
 189  
  * Revision 1.2  2003/01/18 23:30:42  mpowers
 190  
  * WODisplayGroup now compiles.
 191  
  *
 192  
  * Revision 1.1  2003/01/17 14:40:49  mpowers
 193  
  * Adding files to fix build.
 194  
  *
 195  
  * Revision 1.3  2001/12/10 15:25:11  mpowers
 196  
  * Now properly extending NSKeyValueCoding.
 197  
  *
 198  
  * Revision 1.2  2001/04/28 14:12:23  mpowers
 199  
  * Refactored cloning/copying into KeyValueCodingUtilities.
 200  
  *
 201  
  * Revision 1.1  2001/03/29 03:29:49  mpowers
 202  
  * Now using KeyValueCoding and Support instead of Introspector.
 203  
  *
 204  
  * Revision 1.2  2001/03/28 16:12:30  mpowers
 205  
  * Documented interface.
 206  
  *
 207  
  * Revision 1.1  2001/03/27 23:25:05  mpowers
 208  
  * Contributing interface, no docs yet.
 209  
  *
 210  
  *
 211  
  */
 212  
     
 213