r5292: *** empty log message ***
[hyperobject.git] / mop.lisp
index 695b4e9ef790e8a5bca7ea8d78e2ba6315999ea3..4ea60683b33184e8e93e2d66b54380639512baf1 100644 (file)
--- a/mop.lisp
+++ b/mop.lisp
 ;;;; in Text, HTML, and XML formats. This includes hyperlinking\r
 ;;;; capability and sub-objects.\r
 ;;;;\r
-;;;; $Id: mop.lisp,v 1.75 2003/05/26 21:43:05 kevin Exp $\r
+;;;; $Id: mop.lisp,v 1.83 2003/07/11 18:02:41 kevin Exp $\r
 ;;;;\r
 ;;;; This file is Copyright (c) 2000-2003 by Kevin M. Rosenberg\r
 ;;;; *************************************************************************\r
  \r
-(in-package :hyperobject)\r
-\r
-(eval-when (:compile-toplevel :execute)\r
-  (declaim (optimize (speed 2) (safety 2) (compilation-speed 0) (debug 2))))\r
+(in-package #:hyperobject)\r
 \r
 ;; Main class\r
 \r
    (version :initarg :version :initform nil\r
            :accessor version\r
            :documentation "Version number for class")\r
-   (sql-name :initarg :sql-name :initform nil)\r
+   (closures :initarg :closures :initform nil\r
+            :accessor closures\r
+            :documentation "Closures to call on slot chnages")\r
+   (sql-name :initarg :sql-name :accessor sql-name :initform nil\r
+            :documentation "SQL Name for this class")\r
+   (guid :initarg :guid :accessor guid :initform nil\r
+        :documentation "ID string for this class")\r
 \r
    ;;; The remainder of these fields are calculated one time\r
    ;;; in finalize-inheritence.\r
@@ -53,6 +56,9 @@
    (direct-rules :type list :initform nil :initarg :direct-rules\r
                 :accessor direct-rules\r
                 :documentation "List of rules to fire on slot changes.")\r
+   (direct-views :type list :initform nil :initarg :direct-views\r
+                :accessor direct-views\r
+                :documentation "List of views")\r
    (class-id :type integer :initform nil\r
             :accessor class-id\r
             :documentation "Unique ID for the class")\r
   (print-unreadable-object (obj s :type t :identity t)\r
     (format s "~S" (name obj))))\r
 \r
-#+(or cmu scl sbcl)\r
 (defmethod validate-superclass ((class hyperobject-class) (superclass standard-class))\r
   t)\r
 \r
       (when (and ,required (null value))\r
        (error "hyperobject class slot ~A must have a value" name))\r
       (list name `',value))\r
-    #+(or allegro sbcl cmu scl)\r
+    #+(or allegro sbcl cmu scl openmcl)\r
     (declare (ignore slot-name required))\r
     )\r
 \r
     (atom\r
      (ensure-keyword vt))\r
     (cons\r
-     (cons (ensure-keyword (car vt)) (cdr vt)))\r
+     (list (ensure-keyword (car vt)) (cadr vt)))\r
     (t\r
      t)))\r
 \r
-#+ignore\r
-(defmethod compute-effective-slot-definition :around ((cl hyperobject-class) #+ho-normal-cesd name dsds)\r
-  #+allegro (declare (ignore name))\r
+(defmethod compute-effective-slot-definition :around ((cl hyperobject-class)\r
+                                                     #+ho-normal-cesd name\r
+                                                     dsds)\r
+  (declare (ignore #+ho-normal-cesd name))\r
+  (let ((esd (call-next-method)))\r
+    (if (typep esd 'hyperobject-esd)\r
+       (compute-hyperobject-esd esd dsds)\r
+       esd)))\r
+\r
+(defun compute-hyperobject-esd (esd dsds)\r
   (let* ((dsd (car dsds))\r
         (value-type (canonicalize-value-type (slot-value dsd 'value-type))))\r
-    (multiple-value-bind (sql-type length) (value-type-to-sql-type value-type)\r
-      (setf (slot-value dsd 'sql-type) sql-type)\r
-      (setf (slot-value dsd 'type) (value-type-to-lisp-type value-type))\r
-      (let ((ia (compute-effective-slot-definition-initargs cl #+lispworks name dsds)))\r
-       (apply\r
-        #'make-instance 'hyperobject-esd \r
-        :value-type value-type\r
-        :sql-type sql-type\r
-        :length length\r
-        :print-formatter (slot-value dsd 'print-formatter)\r
-        :subobject (slot-value dsd 'subobject)\r
-        :hyperlink (slot-value dsd 'hyperlink)\r
-        :hyperlink-parameters (slot-value dsd 'hyperlink-parameters)\r
-        :description (slot-value dsd 'description)\r
-        :user-name (slot-value dsd 'user-name)\r
-        :user-name-plural (slot-value dsd 'user-name-plural)\r
-        :index (slot-value dsd 'index)\r
-        :value-constraint (slot-value dsd 'value-constraint)\r
-        :null-allowed (slot-value dsd 'null-allowed)\r
-        ia)))))\r
-\r
-(defmethod compute-effective-slot-definition :around ((cl hyperobject-class) #+ho-normal-cesd name dsds)\r
-  #+ho-normal-cesd (declare (ignore name))\r
-  (let* ((esd (call-next-method))\r
-        (dsd (car dsds))\r
-        (value-type (canonicalize-value-type (slot-value dsd 'value-type))))\r
-    (multiple-value-bind (sql-type length) (value-type-to-sql-type value-type)\r
-      (setf (slot-value esd 'sql-type) sql-type)\r
-      (setf (slot-value esd 'length) length)\r
-      (setf (slot-value esd 'type) (value-type-to-lisp-type value-type))\r
-      (setf (slot-value esd 'value-type) value-type)\r
-      (setf (slot-value esd 'user-name)\r
-           (aif (slot-value dsd 'user-name)\r
-                it\r
-                (string-downcase (symbol-name (slot-definition-name dsd)))))\r
-      (dolist (name '(print-formatter subobject hyperlink hyperlink-parameters\r
-                     description value-constraint index null-allowed))\r
-       (setf (slot-value esd name) (slot-value dsd name)))\r
-      esd)))\r
-\r
+    (multiple-value-bind (sql-type sql-length) \r
+       (value-type-to-sql-type value-type)\r
+      (setf (esd-sql-type esd) sql-type)\r
+      (setf (esd-sql-length esd) sql-length))\r
+    (setf (slot-value esd 'type) (value-type-to-lisp-type value-type))\r
+    (setf (esd-value-type esd) value-type)\r
+    (setf (esd-user-name esd)\r
+         (aif (dsd-user-name dsd)\r
+              it\r
+              (string-downcase (symbol-name (slot-definition-name dsd)))))\r
+    (setf (esd-sql-name esd)\r
+         (aif (dsd-sql-name dsd)\r
+              it\r
+              (lisp-name-to-sql-name (slot-definition-name dsd))))\r
+    (setf (esd-sql-name esd)\r
+         (aif (dsd-sql-name dsd)\r
+              it\r
+              (lisp-name-to-sql-name (slot-definition-name dsd))))\r
+    (dolist (name '(print-formatter subobject hyperlink hyperlink-parameters\r
+                   description value-constraint indexed null-allowed\r
+                   unique short-description void-text read-only-groups\r
+                   hidden-groups unit disable-predicate view-type\r
+                   list-of-values stored))\r
+      (setf (slot-value esd name) (slot-value dsd name)))\r
+    esd))\r
+\r
+(defun lisp-name-to-sql-name (lisp)\r
+  "Convert a lisp name (atom or list, string or symbol) into a canonical\r
+SQL name"\r
+  (unless (stringp lisp)\r
+    (setq lisp\r
+         (typecase lisp\r
+           (symbol (symbol-name lisp))\r
+           (t (write-to-string lisp)))))\r
+  (do* ((len (length lisp))\r
+       (sql (make-string len))\r
+       (i 0 (1+ i)))\r
+      ((= i len) (string-upcase sql))\r
+    (declare (fixnum i)\r
+            (simple-string sql))\r
+    (setf (schar sql i)\r
+         (let ((c (char lisp i)))\r
+           (case c\r
+             ((#\- #\$ #\+ #\#) #\_)\r
+             (otherwise c))))))\r
 \r
 #+ho-normal-cesd\r
 (setq cl:*features* (delete :ho-normal-cesd cl:*features*))\r
   (or (eq type 'string)\r
       (and (listp type) (some #'(lambda (x) (eq x 'string)) type))))\r
 \r
+(defun base-value-type (value-type)\r
+  (if (atom value-type)\r
+      value-type\r
+    (car value-type)))\r
+\r
 (defun value-type-to-lisp-type (value-type)\r
-  (case (if (atom value-type)\r
-           value-type\r
-           (car value-type))\r
+  (case (base-value-type value-type)\r
     ((:string :cdata :varchar :char)\r
      '(or null string))\r
     (:character\r
      '(or null fixnum))\r
     (:boolean\r
      '(or null boolean))\r
-    (:integer\r
+    ((:integer :long-integer)\r
      '(or null integer))\r
     ((:float :single-float)\r
      '(or null single-float))\r
 \r
 (defun value-type-to-sql-type (value-type)\r
   "Return two values, the sql type and field length."\r
-  (let ((type (if (atom value-type)\r
-                 value-type\r
-                 (car value-type)))\r
+  (let ((type (base-value-type value-type))\r
        (length (when (consp value-type)\r
                  (cadr value-type))))\r
     (values\r
      (case type\r
-       ((:string :cdata)\r
-       :string)\r
+       ((:char :character)\r
+       :char)\r
+       (:varchar\r
+       :varchar)\r
        ((:fixnum :integer)\r
        :integer)\r
+       (:long-integer\r
+       :long-integer)\r
        (:boolean\r
        :boolean)\r
        ((:float :single-float)\r
                   ':function (compile nil method-lambda)\r
                   init-args-values)))))\r
 \r
-#+(or allegro scl)\r
+#+(or allegro scl openmcl)\r
 (progn\r
   ;; One entry for each class with lazy readers defined.  The value is a plist mapping\r
   ;; slot-name to a lazy reader, each of which is a list of a function and slot-names.\r
     (setf (getf (gethash (find-class class-name) *lazy-readers*) slot-name)\r
          nil))\r
   \r
-  ) ;; #+(or allegro scl)\r
+  ) ;; #+(or allegro sc openmcll)\r
 \r
 \r
 (defun finalize-subobjects (cl)\r
                  `(hyperobject::def-lazy-reader ,(name-class subobject)\r
                    ,(name-slot subobject) ,(lookup subobject)\r
                    ,@(lookup-keys subobject)))\r
-                #+(or sbcl cmu lispworks allegro scl)\r
+                #+(or sbcl cmu lispworks allegro scl openmcl)\r
                 (apply #'ensure-lazy-reader \r
                        (name-class subobject) (name-slot subobject)\r
                        (lookup subobject) (lookup-keys subobject)))\r
                                   (user-name cl))\r
                    2)))\r
 \r
-  (dolist (name '(user-name description))\r
+  (dolist (name '(user-name description version guid sql-name\r
+                 direct-views direct-rules))\r
     (awhen (slot-value cl name)\r
           (setf (slot-value cl name)\r
                 (etypecase (slot-value cl name)\r
                   (cons (car it))\r
-                  ((or string symbol) it))))))\r
+                  ((or string symbol) it)))))\r
+  \r
+  (unless (sql-name cl)\r
+    (setf (sql-name cl) (lisp-name-to-sql-name (class-name cl))))\r
+  )\r
 \r
 (defun finalize-documentation (cl)\r
   "Calculate class documentation slot"\r