;;;; soap-inspect.el -- Interactive inspector for soap WSDL structures
-;; Copyright (C) 2010-2011 Alex Harsanyi <AlexHarsanyi@gmail.com>
+;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
-;; This program is free software: you can redistribute it and/or modify
+;; Author: Alexandru Harsanyi <AlexHarsanyi@gmail.com>
+;; Created: October 2010
+;; Keywords: soap, web-services, comm, hypermedia
+;; Package: soap-client
+;; Homepage: http://code.google.com/p/emacs-soap-client
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
-;; This program is distributed in the hope that it will be useful,
+;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-;; Author: Alexandru Harsanyi (AlexHarsanyi@gmail.com)
-;; Created: October 2010
-;; Keywords: soap, web-services
-;; Homepage: http://code.google.com/p/emacs-soap-client
-;;
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
-;;
+;;
;; This package provides an inspector for a WSDL document loaded with
;; `soap-load-wsdl' or `soap-load-wsdl-from-url'. To use it, evaluate:
;;
;; and types to explore the structure of the wsdl document.
;;
-(require 'soap-client)
-
\f
;;; Code:
+(eval-when-compile (require 'cl))
+
+(require 'soap-client)
+
;;; sample-value
(defun soap-sample-value (type)
;; TODO: we need better sample values for more types.
(t (format "%s" (soap-basic-type-kind type)))))
+(defun soap-sample-value-for-simple-type (type)
+ "Provide a sample value for TYPE which is a simple type.
+This is a specific function which should not be called directly,
+use `soap-sample-value' instead."
+ (let ((enumeration (soap-simple-type-enumeration type)))
+ (if (> (length enumeration) 1)
+ (elt enumeration (random (length enumeration)))
+ (soap-sample-value-for-basic-type type))))
+
(defun soap-sample-value-for-seqence-type (type)
"Provide a sample value for TYPE which is a sequence type.
Values for sequence types are ALISTS of (slot-name . VALUE) for
(put (aref (make-soap-basic-type) 0) 'soap-sample-value
'soap-sample-value-for-basic-type)
+ (put (aref (make-soap-simple-type) 0) 'soap-sample-value
+ 'soap-sample-value-for-simple-type)
+
(put (aref (make-soap-sequence-type) 0) 'soap-sample-value
'soap-sample-value-for-seqence-type)
(setq buffer-read-only t)
(let ((inhibit-read-only t))
(erase-buffer)
-
+
(when soap-inspect-current-item
(push soap-inspect-current-item
soap-inspect-previous-items))
(setq soap-inspect-current-item element)
-
+
(funcall inspect element)
(unless (null soap-inspect-previous-items)
(insert "\nSample value\n")
(pp (soap-sample-value basic-type) (current-buffer)))
+(defun soap-inspect-simple-type (simple-type)
+ "Insert information about SIMPLE-TYPE into the current buffer"
+ (insert "Simple type: " (soap-element-fq-name simple-type) "\n")
+ (insert "Base: " (symbol-name (soap-basic-type-kind simple-type)) "\n")
+ (let ((enumeration (soap-simple-type-enumeration simple-type)))
+ (when (> (length enumeration) 1)
+ (insert "Valid values: ")
+ (dolist (e enumeration)
+ (insert "\"" e "\" ")))))
+
(defun soap-inspect-sequence-type (sequence)
"Insert information about SEQUENCE into the current buffer."
(insert "Sequence type: " (soap-element-fq-name sequence) "\n")
(insert "\tOutput: " (symbol-name (car output)) " (")
(soap-insert-describe-button (cdr output))
(insert ")\n"))
-
+
(insert "\n\nSample invocation:\n")
- (let ((sample-message-value (soap-sample-value (cdr (soap-operation-input operation))))
+ (let ((sample-message-value
+ (soap-sample-value (cdr (soap-operation-input operation))))
(funcall (list 'soap-invoke '*WSDL* "SomeService" (soap-element-name operation))))
- (let ((sample-invocation (append funcall (mapcar 'cdr sample-message-value))))
+ (let ((sample-invocation
+ (append funcall (mapcar 'cdr sample-message-value))))
(pp sample-invocation (current-buffer)))))
(defun soap-inspect-port-type (port-type)
(put (aref (make-soap-basic-type) 0) 'soap-inspect
'soap-inspect-basic-type)
+ (put (aref (make-soap-simple-type) 0) 'soap-inspect
+ 'soap-inspect-simple-type)
+
(put (aref (make-soap-sequence-type) 0) 'soap-inspect
'soap-inspect-sequence-type)
'soap-inspect-message)
(put (aref (make-soap-operation) 0) 'soap-inspect
'soap-inspect-operation)
-
+
(put (aref (make-soap-port-type) 0) 'soap-inspect
'soap-inspect-port-type)