home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2003 October / cmycha200310.iso / NHL2004 / NHL2004Demo.exe / fe / COMMON / js / JAX_Object.js < prev    next >
Text File  |  2003-08-20  |  4KB  |  116 lines

  1. function JAX_Object(){}
  2. JAX_Object.prototype.createProtection    = function(BaseClass, BaseClassConstructorArgs)
  3. {
  4.     if (BaseClass) {
  5.         if (!(this instanceof BaseClass)) { 
  6.             throw new Error(1, "the base class passed in is not a super class of this obect");
  7.             return null; 
  8.         };
  9.         this.valueOf                 = Object.prototype.valueOf;
  10.         BaseClass.apply( this, Array.apply(null, arguments).slice(1));
  11.         if ((this.valueOf.toString() != GetProtectedMembers.toString()) && (this.valueOf.toString() != Object.prototype.valueOf.toString()) )
  12.         {
  13.             throw new Error(1, "valueOf Method overidden in " + BaseClass.toString());
  14.             return null;
  15.         };
  16.     } ;
  17.     var protect;
  18.     var ACCESS_KEY = "XXXX";
  19.     function GetProtectedMembers(key)
  20.     {
  21.         var returnValue    = this;
  22.         if ( (key == ACCESS_KEY) &&
  23.               ( (GetProtectedMembers.caller == JAX_Object.prototype.createProtection) ||
  24.                 (GetProtectedMembers.caller == JAX_Object.prototype.getProtection)
  25.                )
  26.              ) { returnValue = protect; };
  27.         return returnValue;
  28.     };
  29.     protect    = this.valueOf(ACCESS_KEY);
  30.     if (protect == this) {
  31.         protect    = new Object();
  32.         this.valueOf = GetProtectedMembers;
  33.     };
  34.     return protect;
  35. };
  36. JAX_Object.prototype.getProtection        = function(BaseClass) { return this.valueOf("XXXX"); };
  37. JAX_Object.prototype.callSuperMethod        = function(BaseClass, MethodName, ArgumentsArray)
  38. {
  39.     if (this instanceof BaseClass) {
  40.         if (BaseClass.prototype[MethodName]) {
  41.             BaseClass.prototype[MethodName].apply(this, Array.apply(null, ArgumentsArray));
  42.         } else {
  43.             throw new Error("Method named --> " + MethodName + " not found in super class");
  44.         };
  45.     } else {
  46.         throw new Error("object not an instance of base class");    
  47.     };
  48. };
  49. JAX_Object.prototype.toXMLString        = function(propsOnly)
  50. {
  51.     var str = "";
  52.     var prop;
  53.     var obj        = this;
  54.     var levelTabStr     = "\t";
  55.     var levelCount    = 0;
  56.     function RecurseObj(someObj, doTab, incrementTab)
  57.     {
  58.         if (someObj) {
  59.             if (!someObj.tagName) {
  60.                 if (someObj instanceof Array) { 
  61.                     str += (doTab) ? (levelTabStr +"<ARRAY>\n") : "<ARRAY>\n";
  62.                 } else {
  63.                     str += (doTab) ? (levelTabStr + "<OBJECT>\n") : "<OBJECT>\n";
  64.                 };
  65.                 if (incrementTab) {
  66.                     levelTabStr += "\t";
  67.                     levelCount    ++;
  68.                 };
  69.                 
  70.                 for (prop in someObj)
  71.                 {
  72.                     if ( !(JAX_Object.prototype[prop]) ) {
  73.                         switch (typeof someObj[prop])
  74.                         {
  75.                             case "function":
  76.                                 if (!propsOnly) {
  77.                                     str +=(doTab) ? (levelTabStr + "<METHOD name='" + prop + "'>\n" + (levelTabStr + "\t") + "<![CDATA[\n" + (levelTabStr + "\t\t") + someObj[prop].toString() + "\n" + (levelTabStr + "\t") + "]]>\n " + levelTabStr + "</METHOD>\n") : "<METHOD name='" + prop + "'><![CDATA[\n" + someObj[prop].toString() + "\n]]></METHOD>\n";
  78.                                 };
  79.                             break;
  80.                             case "object":
  81.                                 RecurseObj(someObj[prop], true, true);
  82.                             break;
  83.                             default:
  84.                                 str += (doTab) ? (levelTabStr + "<PROPERTY name='" + prop + "'>" + someObj[prop].toString() + "</PROPERTY>\n") : "<PROPERTY name='" + prop + "'>" + someObj[prop].toString() + "</PROPERTY>\n";
  85.                             break;
  86.                         };
  87.                     };
  88.                 };
  89.                 var idx         = 0; 
  90.                 var endTabStr = ""
  91.                 var endCount    = levelCount;
  92.                 while (idx < endCount)
  93.                 {
  94.                     endTabStr += "\t";
  95.                     idx++;
  96.                 };
  97.                 if (someObj instanceof Array) { 
  98.                     str += (doTab) ? (endTabStr + "</ARRAY>\n") : "</ARRAY>\n";
  99.                 } else {
  100.                     str += (doTab) ? (endTabStr + "</OBJECT>\n") : "</OBJECT>\n";
  101.                 };
  102.                 levelCount--;
  103.             } else {
  104.                 if (someObj.id) { 
  105.                     str += (doTab) ? (levelTabStr + "<HTMLELEMENT id='" + someObj.id + "' tagName='" + someObj.tagName + "' />\n") : "<HTMLELEMENT id='" + someObj.id + "' tagName='" + someObj.tagName + "' />\n";
  106.                 } else if (someObj.name) {
  107.                     str += (doTab) ? (levelTabStr + "<HTMLELEMENT name='" + someObj.id + "' tagName='" + someObj.tagName + "' />\n") : "<HTMLELEMENT name='" + someObj.id + "' tagName='" + someObj.tagName + "' />\n";
  108.                 } else {
  109.                     str += (doTab) ? (levelTabStr + "<HTMLELEMENT tagName='" + someObj.tagName + "'  />\n") : "<HTMLELEMENT tagName='" + someObj.tagName + "' />\n";
  110.                 };
  111.             };
  112.         };
  113.     };
  114.     RecurseObj(obj, true);
  115.     return str;
  116. };