]> err.no Git - sope/commitdiff
started CoreData demo
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 1 Aug 2005 20:56:49 +0000 (20:56 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Mon, 1 Aug 2005 20:56:49 +0000 (20:56 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@956 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

18 files changed:
sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/ChangeLog [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/CoreDataBlog.conf [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/CoreDataBlog.m [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/GNUmakefile [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/GNUmakefile.postamble [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/GNUmakefile.preamble [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/Main.m [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/Main.wo/Main.html [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/Main.wo/Main.wod [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/README [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/Session.m [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/WOCoreDataApplication.h [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/WOCoreDataApplication.m [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/WOSession+CoreData.h [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/WOSession+CoreData.m [new file with mode: 0644]
sope-appserver/samples/CoreDataBlog/common.h [new file with mode: 0644]

diff --git a/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements b/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements
new file mode 100644 (file)
index 0000000..7b9099d
Binary files /dev/null and b/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/elements differ
diff --git a/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout b/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout
new file mode 100644 (file)
index 0000000..3a70bb8
Binary files /dev/null and b/sope-appserver/samples/CoreDataBlog/BlogDemo_DataModel.xcdatamodel/layout differ
diff --git a/sope-appserver/samples/CoreDataBlog/ChangeLog b/sope-appserver/samples/CoreDataBlog/ChangeLog
new file mode 100644 (file)
index 0000000..7aeb8c5
--- /dev/null
@@ -0,0 +1,3 @@
+2005-08-01  Helge Hess  <helge.hess@opengroupware.org>
+
+       * started CoreData demo
diff --git a/sope-appserver/samples/CoreDataBlog/CoreDataBlog.conf b/sope-appserver/samples/CoreDataBlog/CoreDataBlog.conf
new file mode 100644 (file)
index 0000000..f7bad53
--- /dev/null
@@ -0,0 +1,12 @@
+# SLog config
+
+<LocationMatch "^/CoreDataBlog*">
+SetHandler ngobjweb-adaptor
+SetAppPort 20000
+</LocationMatch>
+
+<LocationMatch "^/CoreDataBlog.woa/WebServerResources/*">
+SetHandler ngobjweb-adaptor
+SetAppPort 20000
+</LocationMatch>
+
diff --git a/sope-appserver/samples/CoreDataBlog/CoreDataBlog.m b/sope-appserver/samples/CoreDataBlog/CoreDataBlog.m
new file mode 100644 (file)
index 0000000..6a4a2de
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+  Copyright (C) 2005 SKYRIX Software AG
+  Copyright (C) 2005 by Scott Stevenson
+  
+  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 "WOCoreDataApplication.h"
+
+@interface CoreDataBlog : WOCoreDataApplication
+{
+}
+
+@end
+
+#include "common.h"
+
+@implementation CoreDataBlog
+
+- (id)init {
+  if ((self = [super init]) != nil) {
+    [self logWithFormat:@"Store coordinator: %@", 
+         [self defaultPersistentStoreType]];
+  }
+  return self;
+}
+
+- (NSString *)applicationSupportFolder {
+  // TODO: simplify that
+  unsigned char path[1024];
+  NSString *p;
+  FSRef foundRef;
+  OSErr err;
+  
+  err = FSFindFolder(kUserDomain, kApplicationSupportFolderType, 
+                    kDontCreateFolder, &foundRef);
+  if (err != noErr) {
+    [self errorWithFormat:@"Can't find application support folder."];
+    return nil;
+  }
+  
+  FSRefMakePath(&foundRef, path, sizeof(path));
+  p = [NSString stringWithUTF8String:(char *)path]; // TODO: is UTF-8 ok?
+  p = [p stringByAppendingPathComponent:@"BlogDemo"];
+  return p;
+}
+
+- (NSURL *)defaultPersistentStoreURL {
+  NSString *s;
+  
+  s = @"BlogDemo.xml";
+  s = [[self applicationSupportFolder] stringByAppendingPathComponent:s];
+  return [NSURL fileURLWithPath:s];
+}
+
+@end /* CoreDataBlog */
+
+
+/* starting the app */
+
+int main(int argc, char **argv, char **env) {
+  NSAutoreleasePool *pool;
+
+  pool = [[NSAutoreleasePool alloc] init];
+#if LIB_FOUNDATION_LIBRARY
+  [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
+#endif
+  
+  WOApplicationMain(@"CoreDataBlog", argc, (void*)argv);
+
+  [pool release];
+  return 0;
+}
diff --git a/sope-appserver/samples/CoreDataBlog/GNUmakefile b/sope-appserver/samples/CoreDataBlog/GNUmakefile
new file mode 100644 (file)
index 0000000..5b1cb2d
--- /dev/null
@@ -0,0 +1,23 @@
+# GNUstep makefile
+
+-include ../../../config.make
+include $(GNUSTEP_MAKEFILES)/common.make
+
+WOAPP_NAME = CoreDataBlog
+
+CoreDataBlog_OBJC_FILES += \
+       WOCoreDataApplication.m \
+       WOSession+CoreData.m    \
+       \
+       CoreDataBlog.m          \
+       Session.m               \
+       Main.m
+
+CoreDataBlog_COMPONENTS += Main.wo
+
+CoreDataBlog_COREDATA_MODELS += \
+       BlogDemo_DataModel.xcdatamodel
+
+-include GNUmakefile.preamble
+include $(GNUSTEP_MAKEFILES)/woapp.make
+-include GNUmakefile.postamble
diff --git a/sope-appserver/samples/CoreDataBlog/GNUmakefile.postamble b/sope-appserver/samples/CoreDataBlog/GNUmakefile.postamble
new file mode 100644 (file)
index 0000000..03379b1
--- /dev/null
@@ -0,0 +1,17 @@
+# compilation targets
+
+compile-coredata-models :: $($(WOAPP_NAME)_MOM_FILES)
+
+clean ::
+       rm -f $(patsubst %.xcdatamodel,%.mom,$($(WOAPP_NAME)_COREDATA_MODELS))
+
+
+# this is triggered by woapp.make
+woapp-resource-files :: compile-coredata-models
+
+
+MOMC="/Library/Application Support/Apple/Developer Tools/Plug-ins/XDCoreDataModel.xdplugin/Contents/Resources/momc"
+
+# rule for compilation of CoreData models
+%.mom :: %.xcdatamodel
+       $(MOMC) $< $@
diff --git a/sope-appserver/samples/CoreDataBlog/GNUmakefile.preamble b/sope-appserver/samples/CoreDataBlog/GNUmakefile.preamble
new file mode 100644 (file)
index 0000000..744528b
--- /dev/null
@@ -0,0 +1,23 @@
+# compile settings
+
+
+# CoreData files
+
+$(WOAPP_NAME)_MOM_FILES += \
+       $(patsubst %.xcdatamodel,%.mom,$($(WOAPP_NAME)_COREDATA_MODELS))
+
+$(WOAPP_NAME)_RESOURCE_FILES += \
+       $($(WOAPP_NAME)_MOM_FILES)
+
+
+# static references required for Mach linker
+
+ADDITIONAL_LDFLAGS += \
+       -framework CoreData     \
+       -framework CoreServices
+
+ADDITIONAL_TOOL_LIBS += \
+       -lEOControl                     \
+       -lDOM -lXmlRpc -lSaxObjC
+
+ADDITIONAL_LIB_DIRS += -L/usr/local/lib -L/usr/lib
diff --git a/sope-appserver/samples/CoreDataBlog/Main.m b/sope-appserver/samples/CoreDataBlog/Main.m
new file mode 100644 (file)
index 0000000..1c4eef7
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+  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 <NGObjWeb/WOComponent.h>
+
+@class NSArray;
+
+@interface Main : WOComponent
+{
+}
+
+@end
+
+#include "common.h"
+
+@implementation Main
+
+- (id)initWithContext:(id)_ctx {
+  if ((self = [super initWithContext:_ctx])) {
+  }
+  return self;
+}
+
+- (void)dealloc {
+  [super dealloc];
+}
+
+/* accessors */
+
+
+@end /* Main */
diff --git a/sope-appserver/samples/CoreDataBlog/Main.wo/Main.html b/sope-appserver/samples/CoreDataBlog/Main.wo/Main.html
new file mode 100644 (file)
index 0000000..7632fe1
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+  <head>
+    <title>SOPE CoreData Test</title>
+  </head>
+
+  <body>
+    <h1>SOPE CoreData Test</h1>
+
+Ctx: <#Test/><br />
+
+<hr />
+     <#Entities>
+       <li><#Entity/></li>
+     </#Entities>
+<hr />
+     <#Posts>
+       <li><#Post/></li>
+     </#Posts>
+
+    <hr>
+    <address
+      ><a href="mailto:helge.hess@opengroupware.org">Helge Hess</a></address>
+  </body>
+</html>
diff --git a/sope-appserver/samples/CoreDataBlog/Main.wo/Main.wod b/sope-appserver/samples/CoreDataBlog/Main.wo/Main.wod
new file mode 100644 (file)
index 0000000..4341740
--- /dev/null
@@ -0,0 +1,24 @@
+/* bind template to controller */
+
+Test: WOString {
+  value = session.defaultManagedObjectContext;
+}
+
+Entities: WORepetition {
+  list = session.defaultManagedObjectContext.persistentStoreCoordinator.managedObjectModel.entities;
+  item = item;
+}
+
+Entity: WOString {
+  value = item.name;
+}
+
+
+Posts: WORepetition {
+  list = session.posts;
+  item = item;
+}
+
+Post: WOString {
+  value = item.title;
+}
diff --git a/sope-appserver/samples/CoreDataBlog/README b/sope-appserver/samples/CoreDataBlog/README
new file mode 100644 (file)
index 0000000..8d3ebea
--- /dev/null
@@ -0,0 +1,7 @@
+CoreDataBlog
+============
+
+A sample SOPE application which access some CoreData storage.
+
+Works on the same data like:
+  http://www.cocoadevcentral.com/articles/000085.php
diff --git a/sope-appserver/samples/CoreDataBlog/Session.m b/sope-appserver/samples/CoreDataBlog/Session.m
new file mode 100644 (file)
index 0000000..c652547
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+  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 <NGObjWeb/WOSession.h>
+
+@interface Session : WOSession
+@end
+
+#include "WOSession+CoreData.h"
+#include "WOCoreDataApplication.h"
+#include "common.h"
+
+@implementation Session
+
+- (NSArray *)posts {
+  NSFetchRequest *fs;
+  NSArray *a;
+  NSError *error = nil;
+  
+  fs = [[[NSFetchRequest alloc] init] autorelease];
+  
+  [fs setEntity:[[[[self application] managedObjectModel] 
+                  entitiesByName] objectForKey:@"Post"]];
+  [self logWithFormat:@"entity: %@", [fs entity]];
+  
+  a = [[self defaultManagedObjectContext] executeFetchRequest:fs error:&error];
+  [self logWithFormat:@"a: %@", a];
+  
+  if (error != nil)
+    [self errorWithFormat:@"FETCH FAILED: %@", error];
+  
+  return a;
+}
+
+@end /* Session */
diff --git a/sope-appserver/samples/CoreDataBlog/WOCoreDataApplication.h b/sope-appserver/samples/CoreDataBlog/WOCoreDataApplication.h
new file mode 100644 (file)
index 0000000..a7ca683
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+  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 __WOCoreDataApplication_H__
+#define __WOCoreDataApplication_H__
+
+#include <NGObjWeb/WOApplication.h>
+
+@class NSString, NSURL;
+@class NSManagedObjectContext, NSManagedObjectModel;
+@class NSPersistentStoreCoordinator;
+
+@interface WOCoreDataApplication : WOApplication
+{
+  NSManagedObjectModel         *managedObjectModel;
+  NSPersistentStoreCoordinator *storeCoordinator;
+}
+
+/* accessors */
+
+- (NSManagedObjectModel *)managedObjectModel;
+- (NSPersistentStoreCoordinator *)persistentStoreCoordinator;
+
+/* locating the default store */
+
+- (NSString *)applicationSupportFolder;
+- (NSURL *)defaultPersistentStoreURL;
+- (NSString *)defaultPersistentStoreType;
+
+/* creating editing contexts */
+
+- (NSManagedObjectContext *)createManagedObjectContext;
+
+@end
+
+#endif /* __WOCoreDataApplication_H__ */
diff --git a/sope-appserver/samples/CoreDataBlog/WOCoreDataApplication.m b/sope-appserver/samples/CoreDataBlog/WOCoreDataApplication.m
new file mode 100644 (file)
index 0000000..ace3fd9
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+  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 "WOCoreDataApplication.h"
+#include "common.h"
+
+@implementation WOCoreDataApplication
+
+- (void)dealloc {
+  [self->storeCoordinator   release];
+  [self->managedObjectModel release];
+  [super dealloc];
+}
+
+/* accessors */
+
+- (NSManagedObjectModel *)managedObjectModel {
+  NSMutableSet *allBundles;
+  
+  if (self->managedObjectModel != nil)
+    return [self->managedObjectModel isNotNull] ? self->managedObjectModel:nil;
+
+  allBundles = [[NSMutableSet alloc] initWithCapacity:16];
+  [allBundles addObject:[NSBundle mainBundle]];
+  [allBundles addObject:[NSBundle allFrameworks]];
+    
+  /* 'nil' says: just scan the mainbundle */
+  self->managedObjectModel =
+    [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
+    
+  [allBundles release]; allBundles = nil;
+  
+  if (self->managedObjectModel == nil)
+    [self errorWithFormat:@"Could not create the managed object model!"];
+  
+  return self->managedObjectModel;
+}
+
+- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
+  NSFileManager *fileManager;
+  NSError *error;
+  BOOL    ok;
+  
+  if (self->storeCoordinator != nil)
+    return [self->storeCoordinator isNotNull] ? self->storeCoordinator : nil;
+
+  /* create support folder */
+  
+  fileManager = [NSFileManager defaultManager];
+  if (![fileManager fileExistsAtPath:[self applicationSupportFolder]
+                   isDirectory:NULL] ) {
+    [fileManager createDirectoryAtPath:[self applicationSupportFolder]
+                attributes:nil];
+  }
+    
+  /* create store coordinator */
+  
+  self->storeCoordinator = 
+    [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:
+                                           [self managedObjectModel]];
+
+  ok = [self->storeCoordinator 
+           addPersistentStoreWithType:[self defaultPersistentStoreType]
+           configuration:nil
+           URL:[self defaultPersistentStoreURL]
+           options:nil error:&error] != nil ? YES : NO;
+  if (!ok) {
+    [self errorWithFormat:
+           @"Failed to create persistent store coordinator: %@", error];
+    
+    [self->storeCoordinator release]; self->storeCoordinator = nil;
+    
+    self->storeCoordinator = [[NSNull null] retain];
+    return nil;
+  }
+  
+  return self->storeCoordinator;
+}
+
+/* locating the default store */
+
+- (NSString *)applicationSupportFolder {
+  unsigned char path[1024];
+  NSString *p;
+  FSRef foundRef;
+  OSErr err;
+  
+  err = FSFindFolder(kUserDomain, kApplicationSupportFolderType, 
+                    kDontCreateFolder, &foundRef);
+  if (err != noErr) {
+    [self errorWithFormat:@"Can't find application support folder."];
+    return nil;
+  }
+  
+  FSRefMakePath(&foundRef, path, sizeof(path));
+  p = [NSString stringWithUTF8String:(char *)path]; // TODO: is UTF-8 ok?
+  p = [p stringByAppendingPathComponent:[self name]];
+  return p;
+}
+
+- (NSURL *)defaultPersistentStoreURL {
+  NSString *s;
+  
+  s = [[self name] stringByDeletingPathExtension];
+  s = [s stringByAppendingPathExtension:@"xml"];
+  s = [[self applicationSupportFolder] stringByAppendingPathComponent:s];
+  return [NSURL fileURLWithPath:s];
+}
+- (NSString *)defaultPersistentStoreType {
+  return [[[self defaultPersistentStoreURL] path] hasSuffix:@".xml"]
+    ? NSXMLStoreType : NSSQLiteStoreType;
+}
+
+/* creating editing contexts */
+
+- (NSManagedObjectContext *)createManagedObjectContext {
+  NSManagedObjectContext *ctx;
+  
+  ctx = [[[NSManagedObjectContext alloc] init] autorelease];
+  [ctx setPersistentStoreCoordinator:[self persistentStoreCoordinator]];
+  return ctx;
+}
+
+@end /* WOCoreDataApplication */
diff --git a/sope-appserver/samples/CoreDataBlog/WOSession+CoreData.h b/sope-appserver/samples/CoreDataBlog/WOSession+CoreData.h
new file mode 100644 (file)
index 0000000..900611c
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+  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 __WOSession_CoreData_H__
+#define __WOSession_CoreData_H__
+
+#include <NGObjWeb/WOSession.h>
+
+@class NSManagedObjectContext;
+
+@interface WOSession(CoreData)
+
+- (void)setDefaultManagedObjectContext:(NSManagedObjectContext *)_ctx;
+- (NSManagedObjectContext *)defaultManagedObjectContext;
+
+@end
+
+#endif /* __WOSession_CoreData_H__ */
diff --git a/sope-appserver/samples/CoreDataBlog/WOSession+CoreData.m b/sope-appserver/samples/CoreDataBlog/WOSession+CoreData.m
new file mode 100644 (file)
index 0000000..5a156da
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+  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 "WOSession+CoreData.h"
+#include "WOCoreDataApplication.h"
+#include "common.h"
+
+@implementation WOSession(CoreData)
+
+static NSString *NSManagedObjectContextKey = @"NSManagedObjectContext";
+
+- (void)setDefaultManagedObjectContext:(NSManagedObjectContext *)_ctx {
+  if ([_ctx isNotNull])
+    [self setObject:_ctx forKey:NSManagedObjectContextKey];
+  else
+    [self removeObjectForKey:NSManagedObjectContextKey];
+}
+
+- (NSManagedObjectContext *)defaultManagedObjectContext {
+  NSManagedObjectContext *ctx;
+  
+  if ([(ctx = [self objectForKey:NSManagedObjectContextKey]) isNotNull])
+    return ctx;
+  
+  if ((ctx = [[self application] createManagedObjectContext]) == nil) {
+    [self errorWithFormat:
+           @"Failed to create NSManagedObjectContext for session!"];
+    return nil;
+  }
+
+  [self setObject:ctx forKey:NSManagedObjectContextKey];
+  return ctx;
+}
+
+@end /* WOSession(CoreData) */
+
diff --git a/sope-appserver/samples/CoreDataBlog/common.h b/sope-appserver/samples/CoreDataBlog/common.h
new file mode 100644 (file)
index 0000000..5dd9b66
--- /dev/null
@@ -0,0 +1,5 @@
+
+#import <Foundation/Foundation.h>
+#include <NGObjWeb/NGObjWeb.h>
+
+#import <CoreData/CoreData.h>