class ResourceModelConstructor:
    def __init__(self, model=None):
        self._model = model
        self._resourceModel = ResourceModel()
        self._processModelNode(model[v._resource], d._index, "/")
        
    """ a node in the domain model is a "collection" of events, actions, 
    properties, capabilities, etc.represented as an array of maps that
    describe name, type, etc. where type conforms to the domain schema
    
    This is a recurcive function that performs a depth-first selection.
    Each resource built produces a collection representation which is 
    POSTed to the base resource specfied in its "bn" element
    """    
    
    def _processModelNode(self, node, baseType, basePath):
        self._node = node
        currentBasePath = basePath
        currentBaseType = baseType
        for _resource in self._node:
            _name = _resource[v._name]
            _type = _resource[v._type]
            if d._domainType[_resource[v._type]] in _WoTClass:
                #print currentBasePath, _resource[v._name], _resource[v._type], d._domainType[_resource[v._type]]
                self._class = _WoTClass[d._domainType[_resource[v._type]]]
                self._newNode = self._class(currentBasePath, currentBaseType, _resource).getNode()
                #print self._newNode.serialize()
                self._resourceModel.addNodes( self._newNode )
            for self._property in _resource:
                if self._property in d._collections:
                    self._processModelNode(_resource[self._property], _type, currentBasePath + _name + "/")
                elif self._property in d._content:
                    self._processContentNode(_resource[self._property], self._property, currentBasePath + _name + "/")
                    
    def _processContentNode(self, _content, _type, basePath):
        self._contentClass = _WoTClass[_type]
        self._contentNode = self._contentClass(_content, basePath).getNode()
        self._resourceModel.addNodes( self._contentNode )
        

    def serialize(self):
        return self._resourceModel.serialize()
 def __init__(self, model=None):
     self._model = model
     self._resourceModel = ResourceModel()
     self._processModelNode(model[v._resource], d._index, "/")