1 jls.loader.provide('jls.net.http.HttpContext');
  2 
  3 /**
  4  * @class This class represents the context of an HTTP root URI path in a HttpServer.
  5  * It defines the HTTP exchange handler(function) that is called once the request header has been proceed.
  6  */
  7 jls.net.http.HttpContext = jls.lang.Class.create(/** @lends jls.net.http.HttpContext.prototype */
  8 {
  9     initialize : function(path) {
 10         this._path = path;
 11         this._attributes = {};
 12     },
 13     hasAttribute : function(key) {
 14         return key in this._attributes;
 15     },
 16     /**
 17      * Sets an attribute for this context.
 18      * 
 19      * @param {String} key The key of the attribute.
 20      * @param {String} value The value of the attribute.
 21      * @returns {String} the previous value or null is there is no previous value.
 22      */
 23     setAttribute : function(key, value) {
 24         var old = null;
 25         if (key in this._attributes) {
 26             old = this._attributes[key];
 27         }
 28         this._attributes[key] = value;
 29         return old;
 30     },
 31     /**
 32      * Gets an attribute for this context.
 33      * 
 34      * @param {String} key The key of the attribute.
 35      * @returns {String} the value of the attribute.
 36      */
 37     getAttribute : function(key) {
 38         if (key in this._attributes) {
 39             return this._attributes[key];
 40         }
 41         return null;
 42     },
 43     setAttributes : function(values) {
 44         for (var key in values) {
 45           this.setAttribute(key, values[key]);
 46         }
 47         return this;
 48     },
 49     getAttributes : function() {
 50         return this._attributes;
 51     },
 52     getFilters : function() {
 53         return [];
 54     },
 55     getPath : function() {
 56         return this._path;
 57     },
 58     getHandler : function() {
 59         return this._handler;
 60     },
 61     setHandler : function(handler) {
 62         this._handler = handler;
 63     }
 64 });
 65 
 66