(function() {
    angular
        .module("templateStoreService", [])
        .factory("TemplateStore", TemplateStore);

    function TemplateStore() {
        var service, _resourceToFirstClassMap, _resourceTemplates, _resourceTypes, _typeMap, _idToTemplate, _profiles;

        service = {
            addResourceFirstClass: addResourceFirstClass,
            getResourceFirstClass: getResourceFirstClass,
            addResourceTemplate: addResourceTemplate,
            hasTemplateByClassID: hasTemplateByClassID,
            getTemplateByClassID: getTemplateByClassID,
            hasTemplateByID: hasTemplateByID,
            getTemplateByID: getTemplateByID,
            getTemplateIDHash: getTemplateIDHash,
            addResourceType: addResourceType,
            getReferenceResourceType: getReferenceResourceType,
            getTypeProperties: getTypeProperties,
            addProfile: addProfile,
            getProfiles: getProfiles
        };

        _resourceToFirstClassMap = {};
        _resourceTemplates = {};
        _resourceTypes = {};
        _typeMap = {};
        _idToTemplate = {};
        _profiles = [];

        return service;

        function addResourceFirstClass(res, fc) {
            _resourceToFirstClassMap[res] = fc;
        }

        function getResourceFirstClass(res) {
            return _resourceToFirstClassMap[res];
        }

        function addResourceTemplate(template) {
            _resourceTemplates[template.getClassID()] = template;
        }

        function hasTemplateByClassID(id) {
            return typeof _resourceTemplates[id] !== "undefined";
        }

        function getTemplateByClassID(id) {
            return _resourceTemplates[id];
        }

        function hasTemplateByID(id) {
            return typeof _idToTemplate[id] !== "undefined";
        }

        function getTemplateByID(id) {
            return _idToTemplate[id];
        }

        function getTemplateIDHash() {
            return _idToTemplate;
        }

        function getReferenceResourceType(ref) {
            if (hasTemplateByID(ref)) {
                return _resourceTypes[_idToTemplate[ref].getClassID()];
            } else {
                return null;
            }
        }

        function addResourceType(uri, type) {
            if (typeof type === "string") {
                _resourceTypes[uri] = type;
            } else {
                _resourceTypes[uri] = type.type;
                _typeMap[type.type] = type.propertyMap;
            }
        }

        function getTypeProperties(type) {
            return _typeMap[type];
        }

        function addProfile(profile) {
            _profiles.push(profile);
        }

        function getProfiles() {
            return _profiles;
        }
    }
    
})();

@@ -671,27 +671,27 @@
         
-get
+add
 Template
 IDHash: 
@@ -686,33 +686,81 @@
 late
-IDHash: getTemplateIDHash
+: addTemplate,%0A            identifiersFromClassID: identifiersFromClassID
 ,%0A  
@@ -1150,24 +1150,51 @@
 plate = %7B%7D;%0A
+        _classIDToID = %7B%7D;%0A
         _pro
@@ -2012,63 +2012,479 @@
 ion 
-getTemplateIDHash() %7B%0A            return _idToTemplate;
+addTemplate(id, cid, tmpl) %7B%0A            _idToTemplate%5Bid%5D = tmpl;%0A            if (typeof _classIDToID%5Bcid%5D !== %22undefined%22) %7B%0A                _classIDToID%5Bcid%5D.push(id);%0A            %7D else %7B%0A                _classIDToID%5Bcid%5D = %5Bid%5D;%0A            %7D%0A        %7D%0A%0A        function identifiersFromClassID(cid) %7B%0A            if (typeof _classIDToID%5Bcid%5D !== %22undefined%22) %7B%0A                return _classIDToID%5Bcid%5D;%0A            %7D else %7B%0A                return null;%0A            %7D
 %0A   

add mapping from URI to profile ID, get rid of direct access to hash, and add a callback method to assist with profile registration