|
Revision 2045, 1.5 kB
(checked in by hhubner, 2 years ago)
|
merge back from branches/xml-class-rework to trunk
|
- Property svn:executable set to
*
|
| Line | |
|---|
| 1 |
(in-package :bknr.impex) |
|---|
| 2 |
|
|---|
| 3 |
;;; sax parser for xml impex updater, reads updates to objects from an xml file |
|---|
| 4 |
|
|---|
| 5 |
(defclass xml-class-updater (xml-class-importer) |
|---|
| 6 |
()) |
|---|
| 7 |
|
|---|
| 8 |
(defun class-find-slot (class slot-name) |
|---|
| 9 |
(find-if #'(lambda (slot) |
|---|
| 10 |
(equal (slot-definition-name slot) slot-name)) |
|---|
| 11 |
(mop:class-slots class))) |
|---|
| 12 |
|
|---|
| 13 |
(defmethod importer-finalize ((handler xml-class-updater) |
|---|
| 14 |
(instance xml-class-instance)) |
|---|
| 15 |
(with-slots (class slots) instance |
|---|
| 16 |
(if (and (xml-class-unique-id-slot class) |
|---|
| 17 |
(xml-class-unique-id-reader class)) |
|---|
| 18 |
(let* ((id-slot (class-find-slot class (xml-class-unique-id-slot class))) |
|---|
| 19 |
(id-value (gethash id-slot slots)) |
|---|
| 20 |
(obj (when id-value (funcall (xml-class-unique-id-reader class) id-value)))) |
|---|
| 21 |
(if (and obj id-value) |
|---|
| 22 |
(progn |
|---|
| 23 |
(loop for slot being the hash-keys of slots using (hash-value value) |
|---|
| 24 |
when (not (equal (slot-definition-name slot) (xml-class-unique-id-slot class))) |
|---|
| 25 |
do |
|---|
| 26 |
(format t "updating slot ~A with ~S~%" (slot-definition-name slot) |
|---|
| 27 |
value) |
|---|
| 28 |
(setf (slot-value obj (slot-definition-name slot)) |
|---|
| 29 |
value)) |
|---|
| 30 |
obj) |
|---|
| 31 |
(progn |
|---|
| 32 |
(warn "no id-value or object found, creating new~%") |
|---|
| 33 |
(call-next-method)))) |
|---|
| 34 |
|
|---|
| 35 |
(call-next-method)))) |
|---|
| 36 |
|
|---|
| 37 |
(defun parse-xml-update-file (xml-file classes &key (recoder #'cxml::rod-string) |
|---|
| 38 |
(importer-class 'xml-class-updater)) |
|---|
| 39 |
(parse-xml-file xml-file classes :recoder recoder :importer-class importer-class)) |
|---|