﻿

var Opscl = Class.create();

Opscl.extend({
    initialize : function()
    {
        this.xmlDom = new ActiveXObject("MSXML2.DOMDocument"); 
        this.psList = new HashTable();
    },
    
    exec : function(ocl)
    {
        this.xmlDom.loadXML(ocl);
        
        var doc = this.xmlDom.documentElement;
        
        this._Parse(doc);
    },
    
    $ : function(key)
    {
        return this.psList.$V(key);
    },
    
    _Parse : function(xmlOcl,p_pso)
    {
        var c_pso = null;
        var _bind = null;
        
        //
        //解决当前节点
        //
        if(xmlOcl.tagName == "pso")
        {
            var temp = this._CreatePso(xmlOcl,p_pso);
            
            c_pso = temp[0];
            _bind = temp[1];
        }
        
        //
        //解决子节点
        //        
        var list = xmlOcl.childNodes;
        var len  = list.length;
        for(var i=0; i<len; i++)
             this._Parse(list[i],c_pso);
        
        //
        //执行绑定工作
        //
        if(c_pso != null)
        {     
            if(_bind != null && _bind.length > 4)
                eval("c_pso.bind(" + _bind + ")");
        }
    },
    
    _CreatePso : function(xmlPso,p_pso)
    {
        var key  = xmlPso.getAttribute("key");
        var type = xmlPso.getAttribute("type");
        var bind = xmlPso.getAttribute("bind");
        
        var temp = null;
        
        temp = OPS.New(key,type);
        
        if(p_pso != null)
            temp.setParent(p_pso);
        
        this.psList.add(key,temp);
                
        return [temp,bind];        
    }
    
});

Opscl.single = null;

Opscl.exec = function(ocl)
{
    Opscl.single = new Opscl();
    
    Opscl.single.exec(ocl);
}

Opscl.$ = function(key)
{
    return Opscl.single.$(key);
}
