module Mrdf_Repository end class Crdf_Resource #True if resource is a bootstrap resource. #A bootstrap resource is a resource existing prior to model creation (not loaded from external configuration file). #Loaded resources are built using bootstrap resouces as references. rdf_safe_attr_reader_many :ext_isBootstrap end #Class meant to store every element of a model. class Crdf_Repository #< Hash include Mrdf_Repository attr_reader :updateCount attr :typeIndex def delete(key) @resourceSet.delete(key) end def addTypeIndex(idxType) @typeIndex[idxType]=Set.new end def length @resourceSet.length end def empty? return @resourceSet.empty? end def to_s log.debug 'Model' end # Returns the ressource associated to the uri key. def [](key) return @resourceSet[key] end # Internal use def []=(key,res) if @resourceSet.include?(key) #puts "duplicate key: #{res == @resourceSet[key]} #{@@zzzz} #{key} --> #{res} #{@resourceSet[key]}" #raise Exception.new() if res.to_s.include?("string") #if res != @resourceSet[key] #&& key.include?("get_p1") end @typeIndex.each { |ti,idx| idx.add(res) if res.kind_of?(ti) } @resourceSet[key]=res end # Standard each iterator def each(&block_expr) @resourceSet.each &block_expr end # Standard find_all iterator def find_all(&block_expr) @resourceSet.find_all &block_expr end # Standard each_value iterator def each_value(&block_expr) @resourceSet.each_value &block_expr end # # Standard reject iterator def reject(&block_expr) @resourceSet.reject &block_expr end # Initialize model internal structures. def initialize super @resourceSet=Hash.new #@fileGenerated=Array.new @updateCount=0 @typeIndex=Hash.new #@@mtk_out=nil #bootstrap Crdf_Resource.new(self,'rdf_Resource'); Crdf_Resource.new(self,'rdfs_Resource'); # le p�re des h�ritages Crdf_Resource.new(self,'rdfs_Class'); Crdf_Resource.new(self,'rdf_Property'); Crdf_Resource.new(self,'rdfs_Literal'); #bootstrap pour module kb Crdf_Resource.new(self,'kb_UML_METACLASS'); Crdf_Resource.new(self,'kb_UML_SLOT'); self.each {|k,c| c.ext_isBootstrap='true'} end #returns ressource associated to uri stored in model def getRes(uri) raise Warning.new,'nil uri' if uri.nil? obj=self[uri] raise WarningURIundefined.new(uri),"--uri undefined \"#{uri}\" " if obj.nil? return obj end # internal use def parseNT(nt,modeData) if modeData # MODE_parseModelStream_POPULATE_FIELDS parseModeData(nt) else # MODE_parseModelStream_CREATE_INSTANCES parseModeResource(nt) end end # internal use @@RDF_type=['rdf_type'] # internal use def predicat_isRDFTYPE(predicat) return @@RDF_type.include?(predicat) end # internal use def dynNewInstance(value_res,about_uri) cmd=value_res.getRubyClassName+'.new(self,about_uri)' return eval(cmd) end # internal use def parseModeResource(nt) return if !predicat_isRDFTYPE(nt.predicat_uri) about_res=self[nt.about_uri] if about_res about_res.forceReset!() else value_res=self.getRes(nt.value_uri) begin about_res=dynNewInstance(value_res,nt.about_uri) about_res.rdf_type=value_res #about_res.set(rubyIdentifier(predicat_uri),value_res) # ref rescue => e log.debug "e-->#{e}" #TODO: cause probable raise WarningRubyTypeUndefined.new(nt.about_uri,value_res),"Ruby Type #{value_res.getRubyClassName} Undefined (cause probable!)" end return end end # internal use def parseModeData(nt) return if predicat_isRDFTYPE(nt.predicat_uri) subject=self.getRes(nt.about_uri) if nt.valueIsReference? subject.set(rubyIdentifier(nt.predicat_uri),self.getRes(nt.value_uri)) else subject.set(rubyIdentifier(nt.predicat_uri),nt.value_litteral) end end # internal use def rubyIdentifier(str) return str.tr('^a-zA-Z0-9','_') end # internal use def generateClassesFromMetamodel(outRubyModelFileName) #log.debug("ecriture du metamodele dans: #{outRubyModelFileName}") mtk_default_context(:logFileWrite => false) { mtk_writeSession(outRubyModelFileName) { mtk_addTempFileToDelete(outRubyModelFileName) f=self f.write < #{x} #{x.class}" #createRubyClassMinimal(model) cmd=x.createRubyClass(self) f.write(cmd) } f.write("# End of file #{outRubyModelFileName}\n") }} end end