dojox/wire/ml/Service.js

  • Provides:

    • dojox.wire.ml.Service
  • Requires:

    • dijit._Widget in common in project dijit
    • dojox.xml.parser in common
    • dojox.wire._base in common
    • dojox.wire.ml.util in common
  • dojox.wire.ml.Service

    • type
      Function
    • chains:
      • dijit._Widget: (prototype)
      • dijit._Widget: (call)
    • summary
      A widget for a service
    • description
      This widget represents a service defined by a service description
      specified with 'url' attribute.
      If 'serviceType' and 'serviceUrl' attributes are specified, 'url'
      attribute can be omitted.
  • dojox.wire.ml.Service.url

    • type
      A
    • summary
      URL to a service description
  • dojox.wire.ml.Service.serviceUrl

    • type
      A
    • summary
      URL to a service
  • dojox.wire.ml.Service.serviceType

    • type
      A
    • summary
      service type
  • dojox.wire.ml.Service.handlerClass

    • type
      A
    • summary
      service handler class name
  • dojox.wire.ml.Service.preventCache

    • summary
  • dojox.wire.ml.Service.postCreate

    • type
      Function
    • source: [view]
        this.handler = this._createHandler();
    • summary
      Call _createHandler()
    • description
      See _createHandler().
  • dojox.wire.ml.Service._handlerClasses

    • type
      Object
    • summary
  • dojox.wire.ml.Service._createHandler

    • type
      Function
    • source: [view]
        if(this.url){
         var self = this;
         var d = dojo.xhrGet({
          url: this.url,
          handleAs: "json",
          sync: true
         });
         d.addCallback(function(result){
          self.smd = result;
         });
         if(this.smd && !this.serviceUrl){
          this.serviceUrl = (this.smd.serviceUrl || this.smd.serviceURL);
         }
        }
        var handlerClass = undefined;
        if(this.handlerClass){
         handlerClass = dojox.wire._getClass(this.handlerClass);
        }else if(this.serviceType){
         handlerClass = this._handlerClasses[this.serviceType];
         if(handlerClass && dojo.isString(handlerClass)){
          handlerClass = dojox.wire._getClass(handlerClass);
          this._handlerClasses[this.serviceType] = handlerClass;
         }
        }else if(this.smd && this.smd.serviceType){
         handlerClass = this._handlerClasses[this.smd.serviceType];
         if(handlerClass && dojo.isString(handlerClass)){
          handlerClass = dojox.wire._getClass(handlerClass);
          this._handlerClasses[this.smd.serviceType] = handlerClass;
         }
        }
        if(!handlerClass){
         return null; //null
        }
        return new handlerClass(); //Object
    • summary
      Create a service handler
      desription:
      A service handler class is determined by:
      1. 'handlerClass' attribute
      2. 'serviceType' attribute
      3. 'serviceType' property in a service description
    • return_summary
      A service handler
    • returns
      null|Object
  • dojox.wire.ml.Service.callMethod

    • type
      Function
    • parameters:
      • method: (typeof A)
        method name
      • parameters: (typeof An)
        array parameters
    • source: [view]
        var deferred = new dojo.Deferred();
        this.handler.bind(method, parameters, deferred, this.serviceUrl);
        return deferred;
    • summary
      Call a service method with parameters
  • dojox.wire.ml.Service.handler

    • summary
  • dojox.wire.ml.Service._handlerClasses.TEXT

    • summary
  • dojox.wire.ml.Service._handlerClasses.XML

    • summary
  • dojox.wire.ml.Service._handlerClasses.JSON

    • summary
  • dojox.wire.ml.Service._handlerClasses.JSON-RPC

    • summary
  • dojox.wire.ml.RestHandler

    • type
      Function
    • summary
      A REST service handler
    • description
      This class serves as a base REST service.
      Sub-classes may override _getContent() and _getResult() to handle
      specific content types.
  • dojox.wire.ml.RestHandler.contentType

    • summary
  • dojox.wire.ml.RestHandler.handleAs

    • summary
  • dojox.wire.ml.RestHandler.bind

    • type
      Function
    • parameters:
      • method: (typeof A)
        method name
      • parameters: (typeof An)
        array of parameters
      • deferred: (typeof Deferred)
      • url: (typeof A)
        URL for the method
    • source: [view]
        method = method.toUpperCase();
        var self = this;
        var args = {
         url: this._getUrl(method, parameters, url),
         contentType: this.contentType,
         handleAs: this.handleAs,
         headers: this.headers,
         preventCache: this.preventCache
        };
        var d = null;
        if(method == "POST"){
         args.postData = this._getContent(method, parameters);
         d = dojo.rawXhrPost(args);
        }else if(method == "PUT"){
         args.putData = this._getContent(method, parameters);
         d = dojo.rawXhrPut(args);
        }else if(method == "DELETE"){
         d = dojo.xhrDelete(args);
        }else{ // "GET"
         d = dojo.xhrGet(args);
        }
        d.addCallbacks(function(result){
         deferred.callback(self._getResult(result));
        }, function(error){
         deferred.errback(error);
        });
    • summary
      Call a service method with parameters.
    • description
      A service is called with a URL generated by _getUrl() and
      an HTTP method specified with 'method'.
      For "POST" and "PUT", a content is generated by _getContent().
      When data is loaded, _getResult() is used to pass the result to
      Deferred.callback().
  • dojox.wire.ml.RestHandler._getUrl

    • type
      Function
    • parameters:
      • method: (typeof String)
        A method name
      • parameters: (typeof Array)
        An array of parameters
      • url: (typeof String)
        A base URL
    • source: [view]
        var query;
        if(method == "GET" || method == "DELETE"){
         if(parameters.length > 0){
          query = parameters[0];
         }
        }else{ // "POST" || "PUT"
         if(parameters.length > 1){
          query = parameters[1];
         }
        }
        if(query){
         var queryString = "";
         for(var name in query){
          var value = query[name];
          if(value){
           value = encodeURIComponent(value);
           var variable = "{" + name + "}";
           var index = url.indexOf(variable);
           if(index >= 0){ // encode in path
            url = url.substring(0, index) + value + url.substring(index + variable.length);
           }else{ // encode as query string
            if(queryString){
             queryString += "&";
            }
            queryString += (name + "=" + value);
           }
          }
         }
         if(queryString){
          url += "?" + queryString;
         }
        }
        return url; //String
    • summary
      Generate a URL
    • description
      If 'method' is "GET" or "DELETE", a query string is generated
      from a query object specified to the first parameter in
      'parameters' and appended to 'url'.
      If 'url' contains variable seguments ("{parameter_name}"),
      they are replaced with corresponding parameter values, instead.
    • return_summary
      A URL
    • returns
      String
  • dojox.wire.ml.RestHandler._getContent

    • type
      Function
    • parameters:
      • method: (typeof String)
        A method name
      • parameters: (typeof Array)
        An array of parameters
    • source: [view]
        if(method == "POST" || method == "PUT"){
         return (parameters ? parameters[0] : null); //anything
        }else{
         return null; //null
        }
    • summary
      Generate a request content
    • description
      If 'method' is "POST" or "PUT", the first parameter in
      'parameters' is returned.
    • return_summary
      A request content
    • returns
      anything|null
  • dojox.wire.ml.RestHandler._getResult

    • type
      Function
    • parameters:
      • data: (typeof anything)
        A response data returned by a service
    • source: [view]
        return data; //anything
    • summary
      Extract a result
    • description
      A response data is returned as is.
    • return_summary
      A result object
    • returns
      anything
  • dojox.wire.ml.XmlHandler

    • type
      Function
    • chains:
      • dojox.wire.ml.RestHandler: (prototype)
      • dojox.wire.ml.RestHandler: (call)
    • summary
      A REST service handler for XML
    • description
      This class provides XML handling for a REST service.
  • dojox.wire.ml.XmlHandler.contentType

    • summary
  • dojox.wire.ml.XmlHandler.handleAs

    • summary
  • dojox.wire.ml.XmlHandler._getContent

    • type
      Function
    • parameters:
      • method: (typeof String)
        A method name
      • parameters: (typeof Array)
        An array of parameters
    • source: [view]
        var content = null;
        if(method == "POST" || method == "PUT"){
         var p = parameters[0];
         if(p){
          if(dojo.isString(p)){
           content = p;
          }else{
           var element = p;
           if(element instanceof dojox.wire.ml.XmlElement){
            element = element.element;
           }else if(element.nodeType === 9 /* DOCUMENT_NODE */){
            element = element.documentElement;
           }
           var declaration = ""; // TODO: encoding?
           content = declaration + dojox.xml.parser.innerXML(element);
          }
         }
        }
        return content;
    • description
      If 'method' is "POST" or "PUT", the first parameter in
      'parameters' is used to generate an XML content.
    • return_summary
      A request content
    • summary
  • dojox.wire.ml.XmlHandler._getResult

    • type
      Function
    • parameters:
      • data: (typeof Document)
        A response data returned by a service
    • source: [view]
        if(data){
         data = new dojox.wire.ml.XmlElement(data);
        }
        return data;
    • summary
      Extract a result
    • description
      A response data (XML Document) is returned wrapped with
      XmlElement.
    • return_summary
      A result object
  • dojox.wire.ml.JsonHandler

    • type
      Function
    • chains:
      • dojox.wire.ml.RestHandler: (prototype)
      • dojox.wire.ml.RestHandler: (call)
    • summary
      A REST service handler for JSON
    • description
      This class provides JSON handling for a REST service.
  • dojox.wire.ml.JsonHandler.contentType

    • summary
  • dojox.wire.ml.JsonHandler.handleAs

    • summary
  • dojox.wire.ml.JsonHandler.headers

    • type
      Object
    • summary
  • dojox.wire.ml.JsonHandler._getContent

    • type
      Function
    • parameters:
      • method: (typeof String)
        A method name
      • parameters: (typeof Array)
        An array of parameters
    • source: [view]
        var content = null;
        if(method == "POST" || method == "PUT"){
         var p = (parameters ? parameters[0] : undefined);
         if(p){
          if(dojo.isString(p)){
           content = p;
          }else{
           content = dojo.toJson(p);
          }
         }
        }
        return content; //String
    • summary
      Generate a request content
    • description
      If 'method' is "POST" or "PUT", the first parameter in
      'parameter' is used to generate a JSON content.
    • return_summary
      A request content
    • returns
      String
  • dojox.wire.ml.JsonHandler.headers.Accept

    • summary
  • dojox.wire.ml

    • type
      Object
    • summary
  • dojox.wire

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary