From bde4681e51050e403a490087d7c3d2338a7057fc Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Mon, 4 Nov 2002 22:02:09 +0000 Subject: [PATCH] r3295: *** empty log message *** --- hyperobject-example.lisp | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 hyperobject-example.lisp diff --git a/hyperobject-example.lisp b/hyperobject-example.lisp new file mode 100644 index 0000000..d400870 --- /dev/null +++ b/hyperobject-example.lisp @@ -0,0 +1,92 @@ +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- +;;;; ************************************************************************* +;;;; FILE IDENTIFICATION +;;;; +;;;; Name: hyperobject.lisp +;;;; Purpose: Hyper Object Metaclass +;;;; Programmer: Kevin M. Rosenberg +;;;; Date Started: Apr 2000 +;;;; +;;;; This metaclass as functions to classes to allow display +;;;; in Text, HTML, and XML formats. This includes hyperlinking +;;;; capability and sub-objects. +;;;; +;;;; $Id: hyperobject-example.lisp,v 1.1 2002/11/04 22:02:09 kevin Exp $ +;;;; +;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg +;;;; +;;;; ************************************************************************* + +(in-package :hyperobject-user) + + +(defclass person (hyperobject) + ((first-name :type string :initarg :first-name :reader first-name) + (last-name :type string :initarg :last-name :reader last-name) + (dob :type integer :initarg :dob :reader dob) + (resume :initarg :resume :reader resume) + (addresses :initarg :addresses :reader addresses)) + (:metaclass hyperobject-class) + (:default-initargs + :first-name nil :last-name nil :resume nil :dob 0 :addresses nil) + (:title "Person") + (:subobjects-lists (addresses address)) + (:fields (first-name :string) (last-name :string) (dob :integer format-date) + (resume :cdata)) + (:ref-fields (last-name find-person-by-last-name))) + +(defun format-date (ut) + (when (typep ut 'integer) + (multiple-value-bind (sec min hr day mon year dow daylight-p zone) + (decode-universal-time ut) + (declare (ignore daylight-p zone)) + (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" + dow + day + (1- mon) + year + hr min sec)))) + +(defclass address (hyperobject) + ((title :type string :initarg :title :reader title) + (street :type string :initarg :street :reader street) + (phones :initarg :phones :reader phones)) + (:metaclass hyperobject-class) + (:default-initargs :title nil :street nil :phones nil) + (:title "Address") + (:subobjects-lists (phones phone)) + (:fields (title :string) (street :string))) + + +(defclass phone (hyperobject) + ((phone-number :type string :initarg :phone-number :reader phone-number)) + (:metaclass hyperobject-class) + (:title "Phone Number") + (:fields (phone-number :string))) + + +(defparameter home-phone-1 (make-instance 'phone :phone-number "367-9812")) +(defparameter home-phone-2 (make-instance 'phone :phone-number "367-9813")) + +(defparameter office-phone-1 (make-instance 'phone :phone-number "123-0001")) +(defparameter office-phone-2 (make-instance 'phone :phone-number "123-0002")) +(defparameter office-phone-3 (make-instance 'phone :phone-number "123-0005")) + +(defparameter home (make-instance 'address :title "Home" :street "321 Shady Lane" + :phones (list home-phone-1 home-phone-2))) + +(defparameter office (make-instance 'address :title "Office" :street "113 Main St." + :phones (list office-phone-1 office-phone-2 office-phone-3))) + + +(defparameter mary (make-instance 'person :first-name "Mary" :last-name "Jackson" + :dob (get-universal-time) + :addresses (list home office) + :resume "Style & Grace")) + + +(format t "~&Text Format~%") +(print-hyperobject mary :subobjects t) + +(format t "~&XML Format with field labels and hyperlinks~%") +(print-hyperobject mary :subobjects t :label t :format :xmlref) -- 2.34.1