现在的位置: 首页 > 综合 > 正文

用于js组件开发的js基类(模拟.net的WebControl的体系)(1)

2012年06月19日 ⁄ 综合 ⁄ 共 6927字 ⁄ 字号 评论关闭

    第一次申请个blog,在博客园安个家。希望大家常来窜门~~

    这一段在编写DateEditor和配合使用的DatePicker的WebContorl,客户端使用htc实现。客户端的HTC组件通过 VimeJsFramework 实现强大的样式配制管理。

    以下是 ClassTree:

   

  • 以下是基本框架文件 VmSystem.js。

       
/*

    Copyright (c) 2005 Vime. All rights reserved.

    Version 1.0.1.18

    

    对象基类支持。

*/


//支持 VimeJsFramework 类层次结构中的所有类,并为派生类提供低级别服务。



VmObject 
= function()

{

    
var hashCode = null;

    
this.GetHashCode = function VmObject_GetHashCode()

    {

        
if(hashCode ==null)

            hashCode 
= Math.round(Math.random()*10000);

        
return hashCode;

    }

    
this.Equals = function VmObject_Equals(o)

    {

        
if(VmObject.prototype.isPrototypeOf(o))

            
return o.GetHashCode() == this.GetHashCode();

        
new VmInterfaceException(this.GetType(),this.GetType()).Throw();

    }

    
this.Dispose = function VmObject_Dispose()

    {

    }

    
this.GetType = function VmObject_GetType()

    {

        
return "VmObject";

    }

    
//Protected 获得调用方法的名称

    this._GetFunctionName = function VmObject__GetFunctionName(s)

    {

        
return s.substr(0,s.indexOf("{")).replace("function ","").replace("\r\n","").replace("\t","").replace(" ","").replace("_",".").replace("_","");

    }

};

VmObject.prototype 
= new Object();

VmObject.Equals 
= function VmObject_Equals_(oa,ob)

{

    
if(!VmObject.prototype.isPrototypeOf(oa))

        
new VmInterfaceException("VmObject.Equals","VmObject").Throw();

    
if(!VmObject.prototype.isPrototypeOf(ob))

        
new VmInterfaceException("VmObject.Equals","VmObject").Throw();

    
return oa.GetHashCode() == ob.GetHashCode();

};

VmObject.prototype 
= new Object();



//VimeJsFrameWrok 信息

VmFrameWork = function()

{

    
this.GetType = function VmFrameWork_GetType()

    {

        
return "VmFrameWork";

    }

}

VmFrameWork.prototype 
= new VmObject();

VmFrameWork.Version 
= "1.00";

VmFrameWork.Author 
= "vme";



//有关浏览器的信息

VmBrowerInfo = function()

{

    
this.GetType = function VmBrowerInfo_GetType()

    {

        
return "VmBrowerInfo";

    }

    

    
var ua=navigator.userAgent;

    
this._IsIE= /msie/i.test(ua);

    

    
/MSIE\s+([^\);]+)(\)| ;) /.test(ua);

    
this._IEVersion=RegExp.$1;

    

    
this._IsAboveVersion = function _VmBrowerInfo_IsAboveVersion(v)

    {

        
var nv = parseFloat(this._IEVersion);

        
return nv>=v;

    }

}

VmBrowerInfo.prototype 
= new VmObject();

var vmbi = new VmBrowerInfo();

VmBrowerInfo.IsIE 
= vmbi._IsIE;

VmBrowerInfo.IEVersion 
= vmbi._IEVersion;

VmBrowerInfo.IsAboveVersion 
= function(v)

{

    
return vmbi._IsAboveVersion(v);

}


//表示在程序执行期间发生的异常。

VmException = function(s,m)

{

    
this.GetType = function VmException_GetType()

    {

        
return "VmException";

    }

    
this.getSource = function VmException_getSource()

    {

        
return s;

    }

    
this.getMessage = function VmException_getMessage()

    {

        
return m;

    }

    
this._Throw = function VmException__Throw(e)

    {

        
var invokeTrace = new Array();

        
var o=this.Throw.caller;

        
while(o!=null)

        {

            invokeTrace.push(
this._GetFunctionName(o.toString()));

            o
=o.caller;

        }

        
var deepthTab="    ";

        
var invokeString = "";

        
while(invokeTrace.length>0)

        {

            invokeString 
+= deepthTab + ((deepthTab.length==4)?"":""+ invokeTrace.pop() + "\r\n";

            deepthTab 
+="  ";

        }

        alert(e 
+ "\r\n\r\n错误源: " + this.getSource() + "\r\n信息: " + this.getMessage() + "\r\n调用堆栈: \r\n" + invokeString);

        
throw this;

    }

    
this.Throw = function VmException_Throw()

    {

        
this._Throw(this.GetType());

    }

};

VmException.prototype 
= new VmObject();



//不实现某类接口产生的异常。

VmInterfaceException = function(s,i)

{

    
this.GetType = function VmInterfaceException_GetType()

    {

        
return "VmInterfaceException";

    }

    
this.getSource = function VmInterfaceException_getSource()

    {

        
return s;

    }

    
this.getMessage = function VmInterfaceException_getMessage()

    {

        
return "不实现某类接口产生的异常。" + "\r\n类接口: " + i;

    }

    
this.Throw = function VmInterfaceException_Throw()

    {

        
this._Throw(this.GetType());

    }

};

VmInterfaceException.prototype 
= new VmException();



//在向方法提供的其中一个参数无效时引发的异常。

VmArgumentException = function(s,a)

{

    
this.GetType = function VmArgumentException_GetType()

    {

        
return "VmArgumentException";

    }

    
this.getSource = function VmArgumentException_getSource()

    {

        
return s;

    }

    
this.getMessage = function VmArgumentException_getMessage()

    {

        
return "无效的参数。" + "\r\n参数名: " + a;

    }

    
this.Throw = function VmArgumentException_Throw()

    {

        
this._Throw(this.GetType());

    }

}

VmArgumentException.prototype 
= new VmException();


//当参数值超出调用的方法所定义的允许取值范围时引发的异常。

VmArgumentOutOfRangeException = function(s,a)

{

    
this.GetType = function VmArgumentOutOfRangeException_GetType()

    {

        
return "VmArgumentOutOfRangeException";

    }

    
this.getSource = function VmArgumentOutOfRangeException_getSource()

    {

        
return s;

    }

    
this.getMessage = function VmArgumentOutOfRangeException_getMessage()

    {

        
return "参数值超出调用的方法所定义的允许取值范围。" + "\r\n参数名: " + a;

    }

    
this.Throw = function VmArgumentOutOfRangeException_Throw()

    {

        
this._Throw(this.GetType());

    }

}

VmArgumentOutOfRangeException.prototype 
= new VmException();



//表示可按照索引单独访问的一组对象。

VmCollectionBase = function()

{

    
this.GetType = function VmCollectionBase_GetType()

    {

        
return "VmCollectionBase";

    }

    
var c = new Array();

    
this.getCount = function VmCollectionBase_getCount()

    {

        
return c.length;

    }

    
this.getItem = function VmCollectionBase_getItem(index)

    {

        
if(index<0 || index>=c.length)

            
new VmArgumentOutOfRangeException("VmCollectionBase.getItem","index").Throw();

        
return c[index];

    }

    
this.setItem = function VmCollectionBase_setItem(index,v)

    {

        
if(index<0 || index>=c.length)

            
new VmArgumentOutOfRangeException("VmCollectionBase.setItem","index").Throw();

        c[index]
=v;

    }

    
this.Add = function VmCollectionBase_Add(v)

    {

        
return c.push(v)-1;

    }

    
this.Clear = function VmCollectionBase_Clear()

    {

        c.splice(
0,c.length);

    }

    
this.Contains = function VmCollectionBase_Contains(v)

    {

        
return this.indexOf(v)!= -1;

    }

    
this.IndexOf = function VmCollectionBase_IndexOf(v)

    {

        
for(var j=0;j<c.length;j++)

        {

            
if(c[j]==v)

                
return j;

        }

        
return -1;

    }

    
this.Insert = function VmCollectionBase_Insert(i,v)

    {

        
if(i<0 || i>=c.length)

            
new VmArgumentOutOfRangeException("VmCollectionBase.Insert","index").Throw();

        c.splice(i,
0,v);

    }

    
this.Remove = function VmCollectionBase_Remove(v)

    {

        
var i=this.IndexOf(v);

        
if(i!= -1)

            c.splice(i,
1);

    }

    
this.RemoveAt = function VmCollectionBase_RemoveAt(i)

    {

        
if(i<0 || i>=c.length)

            
new VmArgumentOutOfRangeException("VmCollectionBase.RemoveAt","index").Throw();

        c.splice(i,
1);

    }

}

VmCollectionBase.prototype 
= new VmObject();



//为枚举提供基类。

VmEnum = function()

{

    
this._Value =

抱歉!评论已关闭.