Return-Path: Delivered-To: apmail-incubator-cayenne-commits-archive@locus.apache.org Received: (qmail 72135 invoked from network); 20 Sep 2006 20:51:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Sep 2006 20:51:53 -0000 Received: (qmail 41509 invoked by uid 500); 20 Sep 2006 20:51:53 -0000 Delivered-To: apmail-incubator-cayenne-commits-archive@incubator.apache.org Received: (qmail 41493 invoked by uid 500); 20 Sep 2006 20:51:53 -0000 Mailing-List: contact cayenne-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cayenne-dev@incubator.apache.org Delivered-To: mailing list cayenne-commits@incubator.apache.org Received: (qmail 41484 invoked by uid 99); 20 Sep 2006 20:51:52 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Sep 2006 13:51:52 -0700 X-ASF-Spam-Status: No, hits=-9.8 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [140.211.166.113] ([140.211.166.113:54916] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 55/1E-01963-7E9A1154 for ; Wed, 20 Sep 2006 13:51:51 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 5F8991A981A; Wed, 20 Sep 2006 13:51:49 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r448337 - in /incubator/cayenne/sandbox/CocoaCayenne/CocoaCayenne: CAYObjAttribute.h CAYObjAttribute.m CAYPersistentObject.m Date: Wed, 20 Sep 2006 20:51:49 -0000 To: cayenne-commits@incubator.apache.org From: torehalset@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060920205149.5F8991A981A@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 { 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]); + } }