]> code.delx.au - gnu-emacs/blobdiff - lisp/net/soap-inspect.el
* net/tramp-sh.el (tramp-sh-handle-file-acl): Delete empty lines
[gnu-emacs] / lisp / net / soap-inspect.el
index 4ea6bef0d8c62d8b9e826521abeebeb329bc863a..877ac71f4c1b3442cb7ee878e6face001d41228b 100644 (file)
@@ -1,28 +1,30 @@
 ;;;; 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)
@@ -62,6 +66,15 @@ use `soap-sample-value' instead."
     ;; 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
@@ -111,6 +124,9 @@ use `soap-sample-value' instead."
   (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)
 
@@ -148,12 +164,12 @@ entire WSDL can be inspected."
       (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)
@@ -200,6 +216,16 @@ entire WSDL can be inspected."
   (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")
@@ -252,11 +278,13 @@ entire WSDL can be inspected."
     (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)
@@ -325,6 +353,9 @@ entire WSDL can be inspected."
   (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)
 
@@ -335,7 +366,7 @@ entire WSDL can be inspected."
        '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)