Annotation of Examples/EnterpriseObjects/Archiving/ArchivingObject/Owner.m, revision 1.1

1.1     ! root        1: /* Owner.m
        !             2:  *
        !             3:  * You may freely copy, distribute, and reuse the code in this example.
        !             4:  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
        !             5:  * fitness for any particular use.
        !             6:  *
        !             7:  * 
        !             8:  *
        !             9:  * Written by: Mai Nguyen, NeXT Developer Support
        !            10:  */
        !            11: 
        !            12: 
        !            13: #import <eointerface/eointerface.h>
        !            14: #import "Owner.h"
        !            15: #import "Author.h"
        !            16: 
        !            17: #define ARCHIVE_FILE   "ObjectArchive"
        !            18: 
        !            19: @implementation Owner
        !            20: 
        !            21:  
        !            22: - appDidInit:sender
        !            23: {
        !            24:        EOAdaptorChannel        *adaptorChannel;
        !            25:        
        !            26:        /* set up the adaptor channel for debugging */
        !            27:     adaptorChannel = [[dataSource databaseChannel] adaptorChannel]; 
        !            28:     [(EOAdaptorChannel *)adaptorChannel setDelegate: self];
        !            29:     return self;
        !            30: }
        !            31: 
        !            32:     
        !            33: - (void)adaptorChannel:channel didEvaluateExpression:(NSString *)expression
        !            34: {
        !            35:     NSLog (expression);
        !            36: }
        !            37: 
        !            38: /*     Archive the first object in the array of selected objects.
        !            39:  *  In this example, only one object is selected at a time.
        !            40:  */
        !            41: - writeObject:sender
        !            42: {
        !            43:        eoArray = [controller selectedObjects];
        !            44:     // Archive the first object in the array of selected objects.
        !            45:     //  In this example, only one object is selected at a time.
        !            46:        if ([eoArray count] == 0) {
        !            47:                NXRunAlertPanel(NULL, "No object to archive!", NULL, NULL, NULL);
        !            48:                return self;
        !            49:                }
        !            50:                
        !            51:        eoAuthor = [eoArray objectAtIndex:0];
        !            52:        [self archiveThisObject:eoAuthor]; 
        !            53:        
        !            54:        return self;
        !            55: }
        !            56: 
        !            57: - readObject:sender
        !            58: {
        !            59:        eoAuthor = (Author *)[self unarchiveObject];
        !            60:        return self;
        !            61: }
        !            62: 
        !            63: 
        !            64: - (BOOL) archiveThisObject:(Object *)object
        !            65: {
        !            66:     NXTypedStream *stream;
        !            67:        char    archivePath[MAXPATHLEN+1];
        !            68:     BOOL b = YES;
        !            69:     
        !            70:     if (!object)
        !            71:                return NO;
        !            72:         
        !            73:     NS_DURING
        !            74:     
        !            75:        sprintf(archivePath, "%s/%s", [[self applicationPath] cString], ARCHIVE_FILE);
        !            76:        stream = NXOpenTypedStreamForFile(archivePath, NX_WRITEONLY);
        !            77:     NXWriteRootObject(stream, object);
        !            78:     NXCloseTypedStream(stream);
        !            79: 
        !            80:     NS_HANDLER
        !            81:     
        !            82:        [textObject appendText:"Object archiving failed\n"];
        !            83:     b = NO;
        !            84:     
        !            85:     NS_ENDHANDLER
        !            86:     
        !            87:     if (b == YES)   
        !            88:                [textObject appendText:"Object archiving succeeded\n"];
        !            89:           
        !            90:     return b;
        !            91: }
        !            92: 
        !            93: -(Object *)unarchiveObject 
        !            94: {
        !            95:     NXTypedStream *stream;
        !            96:     Object *object;
        !            97:     char archivePath[MAXPATHLEN+1];
        !            98:     char buf[1024];
        !            99:         
        !           100:    
        !           101:     sprintf(archivePath, "%s/%s", [[self applicationPath] cString], ARCHIVE_FILE);
        !           102:     stream = NXOpenTypedStreamForFile(archivePath, NX_READONLY);
        !           103:     if (!stream) {
        !           104:        object = nil;
        !           105:        [textObject appendText:"Object unarchiving failed\n"];
        !           106:        return object;
        !           107:     }
        !           108:         
        !           109:     object = NXReadObject(stream);
        !           110:  
        !           111:     NXCloseTypedStream(stream);
        !           112:     [textObject appendText:"Object unarchiving succeeded\n"]; 
        !           113:     sprintf(buf, "%s\n",[[(Author *)object description] cString]);
        !           114:     [textObject appendText: "Author contents:"];
        !           115:     [textObject appendText:buf];
        !           116:                
        !           117:     return [object autorelease];
        !           118: }
        !           119: 
        !           120: - (NSString *)applicationPath 
        !           121: {
        !           122:        int           i;
        !           123:        NSString   *appPathName = nil;
        !           124: 
        !           125:        for (i = strlen(NXArgv[0]) - 1; (i >= 0) && (NXArgv[0][i] != '/'); i--);
        !           126:        appPathName = [NSString stringWithCString:NXArgv[0] length:i];
        !           127:        if (NXArgv[0][0] != '/') {
        !           128:                char path[MAXPATHLEN+1];
        !           129:                appPathName = [NSString stringWithFormat:@"%s/%@", getwd(path), appPathName];
        !           130:        }
        !           131:        return appPathName;
        !           132: }
        !           133: 
        !           134: @end
        !           135: 
        !           136: 
        !           137: @implementation Text(printResults)
        !           138: 
        !           139: - appendText:(const char *)newText
        !           140: {
        !           141:        int currentLength = [self textLength];
        !           142: 
        !           143:        [self setSel:currentLength :currentLength];
        !           144:        [self replaceSel:newText];
        !           145:        [self scrollSelToVisible];
        !           146:        return self;
        !           147: }
        !           148: 
        !           149: @end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.