Coverage Report - net.wotonomy.control.EOKeyValueArchiver
 
Classes in this File Line Coverage Branch Coverage Complexity
EOKeyValueArchiver
0% 
0% 
2.375
 
 1  
 /*
 2  
 Wotonomy: OpenStep design patterns for pure Java applications.
 3  
 Copyright (C) 2001 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.NSArray;
 21  
 import net.wotonomy.foundation.NSDictionary;
 22  
 import net.wotonomy.foundation.NSMutableDictionary;
 23  
 import net.wotonomy.foundation.NSSelector;
 24  
 
 25  
 /**
 26  
 * @author ezamudio@nasoft.com
 27  
 * @author $Author: cgruber $
 28  
 * @version $Revision: 894 $
 29  
 */
 30  0
 public class EOKeyValueArchiver {
 31  
 
 32  
         //for the delegate
 33  0
         public static final NSSelector sel = new NSSelector("referenceToEncodeForObject",
 34  0
                 new Class[]{ Object.class });
 35  0
         NSMutableDictionary dict = new NSMutableDictionary();
 36  
         private Object _delegate;
 37  
 
 38  
         public EOKeyValueArchiver() {
 39  0
                 super();
 40  0
         }
 41  
 
 42  
         public void encodeBool(boolean flag, String key) {
 43  0
                 String v = flag ? "true" : "false";
 44  0
                 dict.setObjectForKey(v, key);
 45  0
         }
 46  
 
 47  
         public void encodeInt(int value, String key) {
 48  0
                 dict.setObjectForKey(new Integer(value), key);
 49  0
         }
 50  
 
 51  
         public void encodeObject(Object obj, String key) {
 52  0
                 if (obj == null)
 53  0
                         return;
 54  0
                 if (obj instanceof NSArray || obj instanceof NSDictionary) {
 55  0
                         dict.setObjectForKey(obj, key);
 56  0
                         return;
 57  
                 }
 58  0
                 if (obj instanceof EOKeyValueArchiving) {
 59  0
                         EOKeyValueArchiver arch = new EOKeyValueArchiver();
 60  0
                         ((EOKeyValueArchiving)obj).encodeWithKeyValueArchiver(arch);
 61  0
                         dict.setObjectForKey(arch.dictionary(), key);
 62  0
                         return;
 63  
                 }
 64  0
                 if (obj instanceof String)
 65  0
                         dict.setObjectForKey(obj, key);
 66  0
         }
 67  
 
 68  
         public void encodeReferenceToObject(Object obj, String key) {
 69  0
                 if (_delegate != null) {
 70  0
                         if (sel.implementedByObject(obj)) {
 71  
                                 try {
 72  0
                                         Object ref = sel.invoke(_delegate, obj);
 73  0
                                         if (ref != null)
 74  0
                                                 dict.setObjectForKey(ref, key);
 75  0
                                 } catch (Exception e) {
 76  0
                                 }
 77  
                         }
 78  
                 }
 79  0
         }
 80  
 
 81  
         public NSDictionary dictionary() {
 82  0
                 return new NSDictionary(dict);
 83  
         }
 84  
 
 85  
         public void setDelegate(Object delegate) {
 86  0
                 _delegate = delegate;
 87  0
         }
 88  
         public Object delegate() {
 89  0
                 return _delegate;
 90  
         }
 91  
 
 92  
 }
 93  
 /*
 94  
  * $Log$
 95  
  * Revision 1.2  2006/02/16 16:47:14  cgruber
 96  
  * Move some classes in to "internal" packages and re-work imports, etc.
 97  
  *
 98  
  * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions.
 99  
  *
 100  
  * Revision 1.1  2006/02/16 13:19:57  cgruber
 101  
  * Check in all sources in eclipse-friendly maven-enabled packages.
 102  
  *
 103  
  * Revision 1.1  2003/08/09 01:17:53  chochos
 104  
  * Part of the EOKeyValueArchiving protocol (archives objects into NSDictionaries and vice-versa)
 105  
  *
 106  
  */