1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: hyperobject-example.lisp
6 ;;;; Purpose: Hyperobject Example file
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Oct 2002
10 ;;;; A simple example file for hyperobjects
12 ;;;; $Id: person.lisp,v 1.6 2002/12/14 21:52:48 kevin Exp $
14 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
16 ;;;; *************************************************************************
18 (in-package :hyperobject-user)
20 (defclass person (hyperobject)
21 ((first-name :value-type (varchar 20) :initarg :first-name :accessor first-name
22 :value-constraint stringp :null-allowed nil)
23 (last-name :value-type (varchar 30) :initarg :last-name :accessor last-name
24 :value-constraint stringp
25 :hyperlink find-person-by-last-name :null-allowed nil)
26 (full-name :value-type string :stored nil)
27 (dob :value-type integer :initarg :dob :accessor dob :print-formatter format-date
28 :value-constraint integerp :input-filter convert-to-date)
29 (resume :value-type string :initarg :resume :accessor resume
30 :value-constraint stringp)
31 ;; (addresses :value-type (list-of subobject) :initarg :addresses :accessor addresses))
32 (addresses :subobject t :initarg :addresses :accessor addresses))
33 (:metaclass hyperobject-class)
34 (:default-initargs :first-name "" :last-name "" :dob 0 :resume nil)
35 (:default-print-slots first-name last-name dob resume)
37 (:description "A Person")
39 (:rule-1 (:dependants (last-name first-name) :volatile full-name)
40 (setf full-name (concatenate 'string first-name " " last-name)))))
42 (defun format-date (ut)
43 (when (typep ut 'integer)
44 (multiple-value-bind (sec min hr day mon year dow daylight-p zone)
45 (decode-universal-time ut)
46 (declare (ignore daylight-p zone))
47 (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"
54 (defclass address (hyperobject)
55 ((title :value-type (varchar 20) :initarg :title :accessor title
56 :value-constraint stringp)
57 (street :value-type (varchar 30) :initarg :street :accessor street
58 :value-constraint stringp)
59 (phones :subobject t :initarg :phones :accessor phones))
60 (:metaclass hyperobject-class)
61 (:default-initargs :title nil :street nil)
62 (:user-name "Address")
63 (:default-print-slots title street)
64 (:description "An address"))
66 (defclass phone (hyperobject)
67 ((title :value-type (varchar 20) :initarg :title :accessor title
68 :value-constraint stringp)
69 (phone-number :value-type (varchar 16) :initarg :phone-number :accessor phone-number
70 :value-constraint stringp))
71 (:metaclass hyperobject-class)
72 (:user-name "Phone Number")
73 (:default-initargs :title nil :phone-number nil)
74 (:default-print-slots title phone-number)
75 (:description "A phone number"))
78 (defparameter home-phone-1 (make-instance 'phone :title "Voice" :phone-number "367-9812"))
79 (defparameter home-phone-2 (make-instance 'phone :title "Fax" :phone-number "367-9813"))
81 (defparameter office-phone-1 (make-instance 'phone :title "Main line" :phone-number "123-0001"))
82 (defparameter office-phone-2 (make-instance 'phone :title "Staff line" :phone-number "123-0002"))
83 (defparameter office-phone-3 (make-instance 'phone :title "Fax" :phone-number "123-0005"))
85 (defparameter home (make-instance 'address :title "Home" :street "321 Shady Lane"
86 :phones (list home-phone-1 home-phone-2)))
88 (defparameter office (make-instance 'address :title "Office" :street "113 Main St."
89 :phones (list office-phone-1 office-phone-2 office-phone-3)))
92 (defparameter mary (make-instance 'person :first-name "Mary" :last-name "Jackson"
93 :dob (get-universal-time)
94 :addresses (list home office)
95 :resume "Style & Grace"))
98 (format t "~&Text Format~%")
99 (view mary :subobjects t)
101 (format t "~&XML Format with field labels and hyperlinks~%")
102 (view mary :subobjects t :category :xml-link-labels)