home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / Palettes / ConnectDemo / EDBConnector.m < prev    next >
Encoding:
Text File  |  1993-03-10  |  3.0 KB  |  178 lines

  1.  
  2. #import "EDBConnector.h"
  3. #import "EDBConnections.h"
  4. #import <ctype.h>
  5.  
  6. #define    NOLDEBUG
  7.  
  8. @implementation EDBConnector
  9.  
  10. - init
  11. {
  12.     return [self initWithSource:nil andDestination:nil forOutlet:NULL
  13.         andSel:NULL];
  14. }
  15.  
  16. - initWithSource:s andDestination:d forOutlet:(const char *)name
  17.     andSel:(const char *)sel
  18. {
  19.     [super init];
  20.     source = s;
  21.     destination = d;
  22.     outletName = (name!=NULL) ? NXUniqueString(name) : NULL;
  23.     selName = (sel!=NULL) ? NXCopyStringBuffer(sel) : NULL;
  24.     sequence = 0;
  25.  
  26.     return self;
  27. }
  28.  
  29. - free
  30. {
  31.     if (selName)
  32.         free((char *)selName);
  33.     return [super free];
  34. }
  35.  
  36. - source
  37. {
  38.     return source;
  39. }
  40.  
  41. - destination
  42. {
  43.     return destination;
  44. }
  45.  
  46. - establishConnection
  47. {
  48.     char    string    [1000];
  49.     SEL        sel;
  50.     SEL        actionSel;
  51.  
  52.     sprintf(string,"set%s:",outletName);
  53.     if (string[3]>='a' && string[3]<='z')
  54.         string[3] = toupper(string[3]);
  55.     sel = sel_getUid(string);
  56.     if (sel!=NULL && [source respondsTo:sel])
  57.         [source perform:sel with:destination];
  58.     else if ([source respondsTo:@selector(establishEDBConnection:)])
  59.     {
  60.         [source establishEDBConnection:self];
  61.         return self;
  62.     }
  63.     else
  64.         object_setInstanceVariable(source,outletName,destination);
  65.  
  66.     if (selName != NULL)
  67.     {
  68.         sprintf(string,"set%sAction:",outletName);
  69.         if (string[3]>='a' && string[3]<='z')
  70.             string[3] = toupper(string[3]);
  71.         sel = sel_getUid(string);
  72.         actionSel = sel_getUid(selName);
  73.         if (sel!=NULL && [source respondsTo:sel])
  74.             [source perform:sel with:(id)actionSel];
  75.         else
  76.         {
  77.             sprintf(string,"%sAction",outletName);
  78.             object_setInstanceVariable(source,string,actionSel);
  79.         }
  80.     }
  81.  
  82.     return self;
  83. }
  84.  
  85. - nibInstantiate
  86. {
  87.     source = [source nibInstantiate];
  88.     destination = [destination nibInstantiate];
  89.     return self;
  90. }
  91.  
  92. - renewObject:old to:new
  93. {
  94.     if (old == source)
  95.         source = new;
  96.     else if (old == destination)
  97.         destination = new;
  98.     return self;
  99. }
  100.  
  101. - read:(NXTypedStream *)stream
  102. {
  103.     u_short        dummy;
  104.  
  105. #ifdef LDEBUG
  106.     fprintf(stderr,"%s read:\n",[self name]);
  107. #endif
  108.  
  109.     [super read:stream];
  110.     source = NXReadObject(stream);
  111.     destination = NXReadObject(stream);
  112.     NXReadType(stream,"%",&outletName);
  113.     NXReadType(stream,"*",&selName);
  114.     NXReadTypes(stream,"SS",&sequence,&dummy);
  115.  
  116. #ifdef LDEBUG
  117.     fprintf(stderr,"destination=%lx,name=%s\n",
  118.         (u_long)destination,[destination name]);
  119. #endif
  120.  
  121.     return self;
  122. }
  123.  
  124. - write:(NXTypedStream *)stream
  125. {
  126.     u_short        dummy = 0;
  127.  
  128. #ifdef LDEBUG
  129.     fprintf(stderr,"%s write:\n",[self name]);
  130. #endif
  131.  
  132.     [super write:stream];
  133.     NXWriteObjectReference(stream,source);
  134.     NXWriteObjectReference(stream,destination);
  135.     NXWriteType(stream,"%",&outletName);
  136.     NXWriteType(stream,"*",&selName);
  137.     NXWriteTypes(stream,"SS",&sequence,&dummy);
  138.  
  139.     return self;
  140. }
  141.  
  142. - (NXAtom)outletName
  143. {
  144.     return outletName;
  145. }
  146.  
  147. - setOutletName:(NXAtom)name
  148. {
  149.     outletName = name;
  150.     return self;
  151. }
  152.  
  153. - (const char *)selName
  154. {
  155.     return selName;
  156. }
  157.  
  158. - setSelName:(const char *)name
  159. {
  160.     if (selName != NULL)
  161.         free((char *)selName);
  162.     selName = (name==NULL) ? NULL : NXCopyStringBuffer(name);
  163.     return self;
  164. }
  165.  
  166. - (u_short)sequence
  167. {
  168.     return sequence;
  169. }
  170.  
  171. - setSequence:(u_short)seq
  172. {
  173.     sequence = seq;
  174.     return self;
  175. }
  176.  
  177. @end
  178.