home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / rdf / src / che2rdf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.5 KB  |  115 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "rdf-int.h"
  20.  
  21. /* We need to define a new class of urls for cache objects.
  22.    e.g., cache:<something here>
  23.  
  24.   The url for the rdf datastore corresponding to the cache
  25.   is rdf:cache.
  26.  
  27.   The Cache Schema.
  28.    The cache consists of a hierarchy of objects. The standard
  29.    hierarchy relation (RDF_parent). In addition, each object
  30.    may have the following properties.
  31.     lastAccess
  32.     lastModified
  33.  
  34.   container cache objects start with cache:container ...
  35.     
  36.    */
  37.  
  38.  
  39. RDFT gCacheStore = NULL;
  40.  
  41. RDFT MakeCacheStore (char* url) {
  42.   if (startsWith("rdf:cache", url)) {
  43.     if (gCacheStore != NULL) {
  44.       return gCacheStore;
  45.     } else {
  46.       RDF_Translator ntr = (RDF_Translator)getMem(sizeof(RDF_TranslatorStruct));
  47.       ntr->assert = NULL;
  48.       ntr->unassert = NULL;
  49.       ntr->getSlotValue = cacheGetSlotValue;
  50.       ntr->getSlotValues = cacheGetSlotValues;
  51.       ntr->hasAssertion = cacheHasAssertion;
  52.       ntr->nextValue = cacheNextValue;
  53.       ntr->disposeCursor = cacheDisposeCursor;
  54.       gCacheStore = ntr;
  55.       return ntr;
  56.     }
  57.   } else return NULL;
  58. }
  59.  
  60.  
  61. PRBool
  62. cacheHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, 
  63.            RDF_ValueType type, PRBool tv) {
  64.   if ((resourceType(u) == CACHE_RT) && tv) {
  65.     /*e.g., u->id =  cache:http://www.netscape.com/
  66.             s     = gWebData->RDF_size
  67.             v     = 1000
  68.             type  = RDF_INT_TYPE
  69.       return true if the cache object corresponding to u has a size of 1000
  70.      e.g.,  u->id = cache:http://www.netscape.com/
  71.             s     = gCoreVocab->RDF_parent
  72.             type  = RDF_RESOURCE_TYPE
  73.             v->   = "cache:container:MemoryCache"
  74.         */
  75.         
  76.   } else {
  77.     return 0;
  78.   }
  79. }
  80.  
  81.     
  82. RDF_Cursor cacheGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, 
  83.                      RDF_ValueType type,  PRBool inversep, PRBool tv) {
  84.   if ((resourceType(u) == CACHE_RT) && tv && (s == gCoreVocab->RDF_parent) && inversep) {
  85.     RDF_Cursor c;   
  86.     c = (RDF_Cursor) getMem(sizeof(RDF_CursorStruc));
  87.     c->u = u;
  88.     c->count = 0;
  89.     c->pdata = NULL;
  90.     c->type = type;
  91.     return c;
  92.   } else return NULL;
  93. }
  94.  
  95.  
  96. void* cacheNextValue (RDFT rdf, RDF_Cursor c) {
  97.   "return the next value, update count, return NUll when there are no more.
  98.    the children are nodes. to create a new node, call RDF_Create(url, 1);
  99.    If something is a container, after getting the object, do  setContainerp(r, 1);"
  100.     }
  101.  
  102. RDF_Error cacheDisposeCursor (RDFT rdf, RDF_Cursor c) {
  103. "dispose it. c could be NULL"
  104.   }
  105.  
  106.  
  107. void* cacheGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, 
  108.              PRBool inversep,  PRBool tv) {
  109.   if ("willing to answer this") {
  110.     return the value;
  111.   } else {
  112.     return NULL;
  113.   }
  114. }
  115.