r5167: *** empty log message ***
[hyperobject.git] / mop.lisp
index 19e2743b011c7c5ab6183a6e349da03dccae7a48..3c9ac2e268dc6069c01070753c70f382ba13d05e 100644 (file)
--- a/mop.lisp
+++ b/mop.lisp
@@ -11,7 +11,7 @@
 ;;;; in Text, HTML, and XML formats. This includes hyperlinking\r
 ;;;; capability and sub-objects.\r
 ;;;;\r
-;;;; $Id: mop.lisp,v 1.76 2003/06/06 21:59:29 kevin Exp $\r
+;;;; $Id: mop.lisp,v 1.77 2003/06/20 08:35:21 kevin Exp $\r
 ;;;;\r
 ;;;; This file is Copyright (c) 2000-2003 by Kevin M. Rosenberg\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
+   (direct-rules :initarg :direct-rules :initform nil\r
+                :accessor dirst-rules\r
+                :documentation "Rules to fire on slot changes")\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
     (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
-  (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
+(defmethod compute-effective-slot-definition :around ((cl hyperobject-class)\r
+                                                     #+ho-normal-cesd name\r
+                                                     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
+    (multiple-value-bind (sql-type sql-length) \r
+       (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
+      (setf (slot-value esd 'sql-length) sql-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
+    (setf (slot-value esd 'sql-name)\r
+      (aif (slot-value dsd 'sql-name)\r
+          it\r
+          (lisp-name-to-sql-name (slot-definition-name dsd))))\r
+    (setf (slot-value esd 'sql-name)\r
+      (aif (slot-value dsd 'sql-name)\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
                                   (user-name cl))\r
                    2)))\r
 \r
-  (dolist (name '(user-name description))\r
+  (dolist (name '(user-name description version guid sql-name))\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