[Improve deserialization protocol clinton@unknownlamer.org**20090505060941 Ignore-this: 7d9e1961cc9353df22c7ab2d46fc8045 * Added `parse-instance' and `make-xml-tag-instance' to allow for a bit more customization of initialization * Renamed high level methods to all be in the form `handle-EVENT' ] hunk ./src/parse.lisp 31 -(defun parse-and-make-instance (stream) - (with-open-source (source (cxml:make-source stream)) - (parse-and-make-instance-1 source))) - -(defun parse-and-make-instance-1 (source) - (multiple-value-bind (key uri lname qname) - (find-event source :start-element) - (declare (ignore key qname)) - (let ((instance (make-instance (find-xml-class uri lname)))) +(defmethod parse-instance ((source klacks:source) (parent null) uri lname) + (let ((instance (make-xml-tag-instance parent uri lname))) hunk ./src/parse.lisp 37 - (set-attribute-value instance - (xml-name->symbol uri lname) - value))) + (handle-attribute-value instance + (xml-name->symbol uri lname) + value))) hunk ./src/parse.lisp 50 - (declare (ignore qname)) + (declare (ignore qname key)) hunk ./src/parse.lisp 52 - (add-subobject instance - (xml-name->symbol uri lname) - (parse-and-make-instance-1 source)))) + (finished-parsing (parse-instance source instance uri lname)))) hunk ./src/parse.lisp 55 - (add-character-data instance - (current-characters source) - (current-cdata-section-p source))) + (handle-character-data instance + (current-characters source) + (current-cdata-section-p source))) hunk ./src/parse.lisp 63 - #+nil(break "created instance ~A" instance) - (finished-parsing instance)))) + instance + #+nil(break "created instance ~A" instance))) + +(defun parse-and-make-instance (stream) + (with-open-source (source (cxml:make-source stream)) + (multiple-value-bind (key uri lname qname) + (find-event source :start-element) + (declare (ignore key qname)) + (finished-parsing (parse-instance source nil uri lname))))) hunk ./src/protocol.lisp 4 -(defgeneric set-attribute-value (serializer attribute-name xml-value)) -(defgeneric add-subobject (serializer tag-name subobject)) -(defgeneric add-character-data (serializer character-data cdatap)) +(defgeneric handle-attribute-value (serializer attribute-name xml-value)) +(defgeneric handle-subobject (serializer tag-name subobject)) +(defgeneric handle-character-data (serializer character-data cdatap)) hunk ./src/protocol.lisp 9 + +;; parsing (not generally needed) +(defgeneric parse-instance (source parent-object ns lname)) +(defgeneric make-xml-tag-instance (parent uri lname) + (:method (parent uri lname) + (make-instance (find-xml-class uri lname)))) hunk ./src/serializer-class.lisp 6 +(defmethod parse-instance ((source klacks:source) (parent xml-serializer) ns lname) + (let ((subobject (parse-instance source nil ns lname))) + (handle-subobject parent + (xml-name->symbol ns lname) + subobject) + subobject)) + hunk ./src/serializer-class.lisp 21 -(defmethod set-attribute-value ((object xml-serializer) attribute-name xml-value) +(defmethod handle-attribute-value ((object xml-serializer) attribute-name xml-value) hunk ./src/serializer-class.lisp 29 -(defmethod add-subobject ((object xml-serializer) tag-name subobject) +(defmethod handle-subobject ((object xml-serializer) tag-name subobject) hunk ./src/serializer-class.lisp 47 -(defmethod add-character-data ((object xml-serializer) character-data cdatap) +(defmethod handle-character-data ((object xml-serializer) character-data cdatap)