From: helge Date: Sat, 6 Aug 2005 17:49:49 +0000 (+0000) Subject: more work on EO compatibility X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0d4f1e4e723e451aa87073b23a4b1fe78862608;p=sope more work on EO compatibility git-svn-id: http://svn.opengroupware.org/SOPE/trunk@978 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/EOCoreData/ChangeLog b/sope-core/EOCoreData/ChangeLog index 4cfdc70a..d6d3c700 100644 --- a/sope-core/EOCoreData/ChangeLog +++ b/sope-core/EOCoreData/ChangeLog @@ -1,3 +1,16 @@ +2005-08-06 Helge Hess + + * v4.5.8 + + * NSEntityDescription+EO.m: added -isReadOnly, -classPropertyNames, + -primaryKeyAttributeNames, -relationships, -attributes + + * added NSAttributeDescription+EO category containing the -width + and -allowsNull methods + + * added NSRelationshipDescription+EO category containing the + -sourceAttributes method + 2005-08-04 Helge Hess * EOCoreDataSource.m: print a warning if no object-context was decoded diff --git a/sope-core/EOCoreData/GNUmakefile b/sope-core/EOCoreData/GNUmakefile index 9834c46b..f86d5ffa 100644 --- a/sope-core/EOCoreData/GNUmakefile +++ b/sope-core/EOCoreData/GNUmakefile @@ -11,19 +11,28 @@ libEOCoreData_VERSION=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBMINOR_VERSION) libEOCoreData_HEADER_FILES_DIR = . libEOCoreData_HEADER_FILES_INSTALL_DIR = /EOCoreData -libEOCoreData_HEADER_FILES = \ + +# headers + +libEOCoreData_HEADER_FILES += \ EOCoreData.h \ EOCoreDataSource.h \ \ EOFetchSpecification+CoreData.h \ EOQualifier+CoreData.h \ EOSortOrdering+CoreData.h \ - \ + +libEOCoreData_HEADER_FILES += \ NSExpression+EO.h \ NSPredicate+EO.h \ NSEntityDescription+EO.h \ + NSAttributeDescription+EO.h \ + NSRelationshipDescription+EO.h \ + -libEOCoreData_OBJC_FILES = \ +# implementations + +libEOCoreData_OBJC_FILES += \ EOCoreDataSource.m \ \ EOFetchSpecification+CoreData.m \ @@ -32,10 +41,15 @@ libEOCoreData_OBJC_FILES = \ EOKeyValueQualifier+CoreData.m \ EOKeyComparisonQualifier+CoreData.m \ EOCompoundQualifiers.m \ - \ + +libEOCoreData_OBJC_FILES += \ NSExpression+EO.m \ NSPredicate+EO.m \ NSEntityDescription+EO.m \ + NSAttributeDescription+EO.m \ + NSRelationshipDescription+EO.m \ + NSManagedObject+KVC.m \ + -include GNUmakefile.preamble include $(GNUSTEP_MAKEFILES)/library.make diff --git a/sope-core/EOCoreData/NSAttributeDescription+EO.h b/sope-core/EOCoreData/NSAttributeDescription+EO.h new file mode 100644 index 00000000..467edeaf --- /dev/null +++ b/sope-core/EOCoreData/NSAttributeDescription+EO.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2005 SKYRIX Software AG + + This file is part of SOPE. + + SOPE is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + SOPE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#ifndef __NSAttributeDescription_EO_H__ +#define __NSAttributeDescription_EO_H__ + +#import + +/* + NSAttributeDescription(EO) + + Make an NSAttributeDescription behave like an EOAttribute. This is mostly to + make the CoreData model objects work with DirectToWeb and EO at the same + time. +*/ + +@interface NSAttributeDescription(EO) + +- (unsigned)width; +- (BOOL)allowsNull; + +@end + +#endif /* __NSAttributeDescription_EO_H__ */ diff --git a/sope-core/EOCoreData/NSAttributeDescription+EO.m b/sope-core/EOCoreData/NSAttributeDescription+EO.m new file mode 100644 index 00000000..88b64fb7 --- /dev/null +++ b/sope-core/EOCoreData/NSAttributeDescription+EO.m @@ -0,0 +1,70 @@ +/* + Copyright (C) 2005 SKYRIX Software AG + + This file is part of SOPE. + + SOPE is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + SOPE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include "NSAttributeDescription+EO.h" +#import +#include "common.h" + +@implementation NSAttributeDescription(EO) + +- (unsigned)width { + /* + This scans for a validation predicate checking for the maximum length. The + code looks for: + - an NSComparisonPredicate + - which has the operator <= + - and a keypath LHS with the keypath 'length' + + Note: only scans one level, does not walk NSCompoundPredicates + */ + NSArray *preds; + unsigned i, count; + + if ((preds = [self validationPredicates]) == nil) + return 0; + + if ((count = [preds count]) == 0) + return 0; + + for (i = 0; i < count; i++) { + NSComparisonPredicate *p; + + p = [preds objectAtIndex:i]; + if (![p isKindOfClass:[NSComparisonPredicate class]]) + continue; + + if ([p predicateOperatorType] != NSLessThanOrEqualToPredicateOperatorType) + continue; + + if (![[[p leftExpression] keyPath] isEqualToString:@"length"]) + continue; + + /* found it! */ + return [[[p rightExpression] constantValue] unsignedIntValue]; + } + return 0; +} + +- (BOOL)allowsNull { + return [self isOptional]; +} + +@end /* NSAttributeDescription(EO) */ diff --git a/sope-core/EOCoreData/NSEntityDescription+EO.h b/sope-core/EOCoreData/NSEntityDescription+EO.h index 965dcc3e..184ecb4b 100644 --- a/sope-core/EOCoreData/NSEntityDescription+EO.h +++ b/sope-core/EOCoreData/NSEntityDescription+EO.h @@ -23,6 +23,7 @@ #define __NSEntityDescription_EO_H__ #import + /* NSEntityDescription(EO) @@ -30,10 +31,19 @@ the CoreData model objects work with DirectToWeb and EO at the same time. */ +@class NSString, NSArray; + @interface NSEntityDescription(EO) - (id)relationshipNamed:(NSString *)_name; - (id)attributeNamed:(NSString *)_name; +- (NSArray *)relationships; +- (NSArray *)attributes; + +- (BOOL)isReadOnly; + +- (NSArray *)classPropertyNames; +- (NSArray *)primaryKeyAttributeNames; @end diff --git a/sope-core/EOCoreData/NSEntityDescription+EO.m b/sope-core/EOCoreData/NSEntityDescription+EO.m index 4151cf02..8294855f 100644 --- a/sope-core/EOCoreData/NSEntityDescription+EO.m +++ b/sope-core/EOCoreData/NSEntityDescription+EO.m @@ -32,4 +32,22 @@ return [[self attributesByName] objectForKey:_qname]; } +- (BOOL)isReadOnly { + return NO; /* always read/write, no? */ +} +- (NSArray *)classPropertyNames { + return [[self propertiesByName] allKeys]; +} +- (NSArray *)primaryKeyAttributeNames { + /* such are transparent with CoreData */ + return nil; +} + +- (NSArray *)attributes { + return [[self attributesByName] allValues]; +} +- (NSArray *)relationships { + return [[self relationshipsByName] allValues]; +} + @end /* NSEntityDescription(EO) */ diff --git a/sope-core/EOCoreData/NSManagedObject+KVC.m b/sope-core/EOCoreData/NSManagedObject+KVC.m new file mode 100644 index 00000000..3adbf0b9 --- /dev/null +++ b/sope-core/EOCoreData/NSManagedObject+KVC.m @@ -0,0 +1,32 @@ +/* + Copyright (C) 2005 SKYRIX Software AG + + This file is part of SOPE. + + SOPE is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + SOPE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#import // Note: just including NSManagedObject is a nogo +#include "common.h" + +@implementation NSManagedObject(KVC) + +- (void)takeValue:(id)_value forKey:(NSString *)_key { + /* Yes, I know, deprecated. But hey, don't do this to us! */ + [self setValue:_value forKey:_key]; +} + +@end /* NSManagedObject(KVC) */ diff --git a/sope-core/EOCoreData/NSRelationshipDescription+EO.h b/sope-core/EOCoreData/NSRelationshipDescription+EO.h new file mode 100644 index 00000000..9fd38816 --- /dev/null +++ b/sope-core/EOCoreData/NSRelationshipDescription+EO.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2005 SKYRIX Software AG + + This file is part of SOPE. + + SOPE is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + SOPE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#ifndef __NSRelationshipDescription_EO_H__ +#define __NSRelationshipDescription_EO_H__ + +#import + +/* + NSRelationshipDescription(EO) + + Make an NSRelationshipDescription behave like an EORelationship. This is + mostly to make the CoreData model objects work with DirectToWeb and EO at + the same time. +*/ + +@class NSArray; + +@interface NSRelationshipDescription(EO) + +- (NSArray *)sourceAttributes; + +@end + +#endif /* __NSRelationshipDescription_EO_H__ */ diff --git a/sope-core/EOCoreData/NSRelationshipDescription+EO.m b/sope-core/EOCoreData/NSRelationshipDescription+EO.m new file mode 100644 index 00000000..9a82aec8 --- /dev/null +++ b/sope-core/EOCoreData/NSRelationshipDescription+EO.m @@ -0,0 +1,32 @@ +/* + Copyright (C) 2005 SKYRIX Software AG + + This file is part of SOPE. + + SOPE is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + SOPE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#include "NSRelationshipDescription+EO.h" +#include "common.h" + +@implementation NSRelationshipDescription(EO) + +- (NSArray *)sourceAttributes { + /* such are transparent with CoreData */ + return nil; +} + +@end /* NSRelationshipDescription(EO) */ diff --git a/sope-core/EOCoreData/Version b/sope-core/EOCoreData/Version index e25d7408..46a90fec 100644 --- a/sope-core/EOCoreData/Version +++ b/sope-core/EOCoreData/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=7 +SUBMINOR_VERSION:=8