cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From torehal...@apache.org
Subject svn commit: r448337 - in /incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne: CAYObjAttribute.h CAYObjAttribute.m CAYPersistentObject.m
Date Wed, 20 Sep 2006 20:51:49 GMT
Author: torehalset
Date: Wed Sep 20 13:51:48 2006
New Revision: 448337

URL: http://svn.apache.org/viewvc?view=rev&rev=448337
Log:
started to check attribute type

Modified:
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjAttribute.h
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjAttribute.m
    incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjAttribute.h
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjAttribute.h?view=diff&rev=448337&r1=448336&r2=448337
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjAttribute.h (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjAttribute.h Wed Sep 20 13:51:48
2006
@@ -26,11 +26,16 @@
 @interface CAYObjAttribute : NSObject <NSCoding> {
 
     NSString *name;
+    NSString *javaType;
     CAYObjEntity *objEntity;
     
 }
 
 -(void)setName:(NSString *)n;
 -(NSString *)name;
+-(void)setJavaType:(NSString *)t;
+-(NSString *)javaType;
+
+-(BOOL)isValueOfOkType:(id)value;
 
 @end

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjAttribute.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjAttribute.m?view=diff&rev=448337&r1=448336&r2=448337
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjAttribute.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYObjAttribute.m Wed Sep 20 13:51:48
2006
@@ -26,13 +26,15 @@
 {
 	[super init];
 	[self setName:[coder decodeObjectForKey:@"name"]];
+	[self setJavaType:[coder decodeObjectForKey:@"type"]];
     
 	return self;
 }
 
 -(void)encodeWithCoder:(NSCoder*)coder
 {
-	[coder encodeObject:name forKey:@"name"];
+	[coder encodeObject:[self name] forKey:@"name"];
+	[coder encodeObject:[self javaType] forKey:@"type"];
 }
 
 -(void)setName:(NSString *)n
@@ -47,9 +49,47 @@
 	return name;
 }
 
+-(void)setJavaType:(NSString *)t
+{
+    [t retain];
+    [javaType release];
+    javaType = t;
+}
+
+-(NSString *)javaType
+{
+    return javaType;
+}
+
+-(BOOL)isValueOfOkType:(id)value
+{
+    // TODO: create a Dictionary like class mapper. perhaps two, one for each direction.
+    if([[self javaType] isEqualToString:@"java.lang.String"])
+    {
+        return [value isKindOfClass:[NSString class]];
+    }
+    else if([[self javaType] isEqualToString:@"java.util.Date"])
+    {
+        return [value isKindOfClass:[NSDate class]];
+    }
+    else
+    {
+        NSLog(@"ERROR: unhandled java type %@", self);
+        return NO;
+    }
+}
+
+-(NSString *)description
+{
+    NSString *result = [[NSString alloc] initWithFormat:@"CAYObjAttribute {name = %@; javaType
= %@}", [self name], [self javaType]];
+    [result autorelease];
+    return result;
+}
+
 -(void)dealloc
 {
 	[self setName:nil];
+    [self setJavaType:nil];
 	[super dealloc];
 }
 

Modified: incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m
URL: http://svn.apache.org/viewvc/incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m?view=diff&rev=448337&r1=448336&r2=448337
==============================================================================
--- incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m (original)
+++ incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne/CAYPersistentObject.m Wed Sep 20 13:51:48
2006
@@ -27,6 +27,7 @@
 #import "CAYFault.h"
 #import "CAYToManyFault.h"
 #import "CAYToOneFault.h"
+#import "CAYObjAttribute.h"
 
 @implementation CAYPersistentObject
 
@@ -188,8 +189,22 @@
     else
     {
         // a none-relationship property
-        [[self objectContext] propertyChanged:self forProperty:key fromOld:[values objectForKey:key]
toNew:value];
-		[values setValue:value forKey:key];
+        id oldValue = [self valueForKey:key];
+
+        // check value type
+        CAYObjAttribute *attribute = [[objEntity attributes] valueForKey:key];
+        if(![attribute isValueOfOkType:value])
+        {
+            NSLog(@"ERROR: %@.%@: %@(%@) not valid value type for attribute %@", [objEntity
name], key, value, [value class], attribute);
+        }
+        else
+        {
+            [[self objectContext] propertyChanged:self forProperty:key fromOld:[values objectForKey:key]
toNew:value];
+            [values setValue:value forKey:key];
+        }
+        
+        NSLog(@"DEBUG: %@.%@. attribute: %@. oldValue: %@. oldValue class: %@. ok: %d",[objEntity
name], key, attribute, oldValue, [oldValue class], [attribute isValueOfOkType:value]);
+        
     }
 }
 



Mime
View raw message