Ignore:
Timestamp:
03/18/10 12:39:15 (15 years ago)
Author:
lgiessmann
Message:

new-datamodel: added the helper function "make-characteristic" for "make-construct"; fixed a bug in all add-<construct> generics that are defined for "VersionedConstruct?"s, so currently adding a charactersistic or pointer calls add-to-version-history with the given revision for the called parent-construct and signals that the parent-construct was changed in the given revision.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/new-datamodel/src/model/datamodel.lisp

    r231 r232  
    126126;;      add-psi, add-locator
    127127
    128 
     128;;TODO: all add-<construct> methods hve to add an version info to the
     129;;      owner-construct
    129130;;TODO: finalize add-reifier
    130131;;TODO: replace add-to-version-history in VersionedAssociationC with a pseudo
     
    663664
    664665;;; generic definitions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     666(defgeneric get-all-characteristics (parent-construct characteristic-symbol)
     667  (:documentation "Returns all characterisitcs of the passed type the parent
     668                   construct was ever associated with."))
     669
     670
    665671(defgeneric equivalent-construct (construct &key start-revision
    666672                                            &allow-other-keys)
     
    811817
    812818;;; TopicMapconstructC
     819(defmethod get-all-characteristics ((parent-construct TopicC)
     820                                    (characteristic-symbol symbol))
     821  (cond ((OccurrenceC-p characteristic-symbol)
     822         (map 'list #'characteristic (slot-p parent-construct 'occurrences)))
     823        ((NameC-p characteristic-symbol)
     824         (map 'list #'characteristic (slot-p parent-construct 'names)))))
     825
     826
    813827(defgeneric TopicMapConstructC-p (class-symbol)
    814828  (:documentation "Returns t if the passed class is equal to TopicMapConstructC
     
    10921106                                   :identifier topic-identifier)))
    10931107               (add-to-version-history assoc :start-revision revision))))
     1108      (when (typep construct 'TopicC)
     1109        (add-to-version-history construct :start-revision revision))
    10941110      construct)))
    10951111
     
    11451161                                   :identifier psi)))
    11461162               (add-to-version-history assoc :start-revision revision))))
     1163      (add-to-version-history construct :start-revision revision)
    11471164      construct)))
    11481165
     
    11981215                                   :identifier locator)))
    11991216               (add-to-version-history assoc :start-revision revision))))
     1217      (add-to-version-history construct :start-revision revision)
    12001218      construct)))
    12011219
     
    12481266                                :characteristic name)))
    12491267            (add-to-version-history assoc :start-revision revision))))
     1268    (add-to-version-history construct :start-revision revision)
    12501269    construct))
    12511270
     
    12971316                                :characteristic occurrence)))
    12981317            (add-to-version-history assoc :start-revision revision))))
     1318    (add-to-version-history construct :start-revision revision)
    12991319    construct))
    13001320
     
    16011621
    16021622;;; NameC
     1623(defmethod get-all-characteristics ((parent-construct NameC)
     1624                                    (characteristic-symbol symbol))
     1625  (when (VariantC-p characteristic-symbol)
     1626    (map 'list #'characteristic (slot-p parent-construct 'variants))))
     1627
     1628
    16031629(defgeneric NameC-p (class-symbol)
    16041630  (:documentation "Returns t if the passed symbol is equal to Name.")
     
    17481774                                :parent-construct construct)))
    17491775            (add-to-version-history assoc :start-revision revision))))
     1776    (add-to-version-history construct :start-revision revision)
    17501777    construct))
    17511778
     
    18431870                                       :parent-construct parent-construct)))
    18441871             (add-to-version-history assoc :start-revision revision)))))
     1872  (add-to-version-history parent-construct :start-revision revision)
    18451873  construct)
    18461874
     
    20002028                                   :identifier item-identifier)))
    20012029               (add-to-version-history assoc :start-revision revision))))
     2030      (when (or (typep construct 'TopicC)
     2031                (typep construct 'AssociationC)
     2032                (typep construct 'TopicMapC))
     2033        (add-to-version-history construct :start-revision revision))
    20022034      construct)))
    20032035
     
    20502082                                     :reifier-topic merged-reifier-topic)))
    20512083                 (add-to-version-history assoc :start-revision revision))))
     2084        (when (or (typep construct 'TopicC)
     2085                  (typep construct 'AssociationC)
     2086                  (typep construct 'TopicMapC))
     2087          (add-to-version-history construct :start-revision revision))
    20522088        construct))))
    20532089
     
    21382174                                :scopable-construct construct)))
    21392175            (add-to-version-history assoc :start-revision revision))))
     2176    (when (typep construct 'AssociationC)
     2177      (add-to-version-history construct :start-revision revision))
    21402178    construct))
    21412179
     
    22082246                                   :typable-construct construct)))
    22092247               (add-to-version-history assoc :start-revision revision)))))
     2248    (when (typep construct 'AssociationC)
     2249      (add-to-version-history construct :start-revision revision))
    22102250    construct))
    22112251
     
    23012341
    23022342
     2343(defun make-characteristic (class-symbol charvalue
     2344                            &key (start-revision *TM-REVISION*)
     2345                            (datatype *xml-string*) (themes nil)
     2346                            (instance-of nil) (variants nil)
     2347                            (parent-construct nil))
     2348  "Returns a characteristic object with the passed parameters.
     2349   If an equivalent construct has already existed this one is returned.
     2350   To check if there is existing an equivalent construct the parameter
     2351   parent-construct must be set."
     2352  (declare (symbol class-symbol) (string charvalue) (integer start-revision)
     2353           (list themes variants)
     2354           (type (or null string) datatype)
     2355           (type (or null TopicC) instance-of)
     2356           (type (or null TopicC NameC) parent-construct))
     2357  (let ((characteristic
     2358         (let ((existing-characteristic
     2359                (when parent-construct
     2360                  (remove-if
     2361                   #'null
     2362                   (map 'list #'(lambda(existing-characteristic)
     2363                                  (when (equivalent-construct
     2364                                         existing-characteristic
     2365                                         :start-revision start-revision
     2366                                         :datatype datatype :themes themes
     2367                                         :instance-of instance-of)
     2368                                    existing-characteristic))
     2369                        (get-all-characteristics parent-construct
     2370                                                 class-symbol))))))
     2371           (if existing-characteristic
     2372               existing-characteristic
     2373               (make-instance class-symbol :charvalue charvalue
     2374                              :datatype datatype)))))
     2375    (dolist (theme themes)
     2376      (add-theme characteristic theme :revision start-revision))
     2377    (when instance-of
     2378      (add-type characteristic instance-of :revision start-revision))
     2379    (dolist (variant variants)
     2380      (add-variant characteristic variant :revision start-revision))
     2381    (when parent-construct
     2382      (add-parent characteristic parent-construct :revision start-revision))))
     2383
    23032384
    23042385(defun make-pointer (class-symbol uri
    23052386                     &key (start-revision *TM-REVISION*) (xtm-id nil)
    23062387                     (identified-construct nil))
    2307   "Returns a pointer object with the specified parameters."
     2388  "Returns a pointer object with the specified parameters.
     2389   If an equivalen construct has already existed this one is returned."
    23082390  (declare (symbol class-symbol) (string uri) (integer start-revision)
    23092391           (type (or null string) xtm-id)
Note: See TracChangeset for help on using the changeset viewer.