1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: hyperobject-tests.lisp
6 ;;;; Purpose: Hyperobject tests file
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2003
10 ;;;; $Id: tests.lisp,v 1.1 2003/04/28 16:03:57 kevin Exp $
12 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
14 ;;;; *************************************************************************
16 (in-package :hyperobject-user)
18 (defclass person (hyperobject)
19 ((first-name :value-type (varchar 20) :initarg :first-name :accessor first-name
20 :value-constraint stringp :null-allowed nil)
21 (last-name :value-type (varchar 30) :initarg :last-name :accessor last-name
22 :value-constraint stringp
23 :hyperlink find-person-by-last-name :null-allowed nil)
24 (full-name :value-type string :stored nil)
25 (dob :value-type integer :initarg :dob :accessor dob :print-formatter format-date
26 :value-constraint integerp :input-filter convert-to-date)
27 (resume :value-type string :initarg :resume :accessor resume
28 :value-constraint stringp)
29 ;; (addresses :value-type (list-of subobject) :initarg :addresses :accessor addresses))
30 (addresses :subobject t :initarg :addresses :accessor addresses))
31 (:metaclass hyperobject-class)
32 (:default-initargs :first-name "" :last-name "" :dob 0 :resume nil)
33 (:default-print-slots first-name last-name dob resume)
35 (:description "A Person")
37 (:rule-1 (:dependants (last-name first-name) :volatile full-name)
38 (setf full-name (concatenate 'string first-name " " last-name)))))
40 (defun format-date (ut)
41 (when (typep ut 'integer)
42 (multiple-value-bind (sec min hr day mon year dow daylight-p zone)
43 (decode-universal-time ut)
44 (declare (ignore daylight-p zone))
45 (format nil "~[Mon~;Tue~;Wed~;Thu~;Fri~;Sat~;Sun~], ~d ~[Jan~;Feb~;Mar~;Apr~;May~;Jun~;Jul~;Aug~;Sep~;Oct~;Nov~;Dec~] ~d ~2,'0d:~2,'0d:~2,'0d"
52 (defclass address (hyperobject)
53 ((title :value-type (varchar 20) :initarg :title :accessor title
54 :value-constraint stringp)
55 (street :value-type (varchar 30) :initarg :street :accessor street
56 :value-constraint stringp)
57 (phones :subobject t :initarg :phones :accessor phones))
58 (:metaclass hyperobject-class)
59 (:default-initargs :title nil :street nil)
60 (:user-name "Address")
61 (:default-print-slots title street)
62 (:description "An address"))
64 (defclass phone (hyperobject)
65 ((title :value-type (varchar 20) :initarg :title :accessor title
66 :value-constraint stringp)
67 (phone-number :value-type (varchar 16) :initarg :phone-number :accessor phone-number
68 :value-constraint stringp))
69 (:metaclass hyperobject-class)
70 (:user-name "Phone Number")
71 (:default-initargs :title nil :phone-number nil)
72 (:default-print-slots title phone-number)
73 (:description "A phone number"))
76 (defparameter home-phone-1 (make-instance 'phone :title "Voice" :phone-number "367-9812"))
77 (defparameter home-phone-2 (make-instance 'phone :title "Fax" :phone-number "367-9813"))
79 (defparameter office-phone-1 (make-instance 'phone :title "Main line" :phone-number "123-0001"))
80 (defparameter office-phone-2 (make-instance 'phone :title "Staff line" :phone-number "123-0002"))
81 (defparameter office-phone-3 (make-instance 'phone :title "Fax" :phone-number "123-0005"))
83 (defparameter home (make-instance 'address :title "Home" :street "321 Shady Lane"
84 :phones (list home-phone-1 home-phone-2)))
86 (defparameter office (make-instance 'address :title "Office" :street "113 Main St."
87 :phones (list office-phone-1 office-phone-2 office-phone-3)))
90 (defparameter mary (make-instance 'person :first-name "Mary" :last-name "Jackson"
91 :dob (get-universal-time)
92 :addresses (list home office)
93 :resume "Style & Grace"))
96 (format t "~&Text Format~%")
97 (view mary :subobjects t)
99 (format t "~&XML Format with field labels and hyperlinks~%")
100 (view mary :subobjects t :category :xml-link-labels)