MMCT TEAM
Server IP : 111.118.215.189  /  Your IP : 3.145.133.121
Web Server : Apache
System : Linux md-in-83.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : a1673wkz ( 2475)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/share/ruby/vendor_ruby/puppet/vendor/rgen/lib/rgen/serializer/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/share/ruby/vendor_ruby/puppet/vendor/rgen/lib/rgen/serializer/xml_serializer.rb
module RGen

module Serializer

class XMLSerializer

  INDENT_SPACE = 2
  
	def initialize(file)
    @indent = 0
    @lastStartTag = nil
    @textContent = false
    @file = file
	end
	
	def serialize(rootElement)
		raise "Abstract class, overwrite method in subclass!"
	end
  
  def startTag(tag, attributes={})
    @textContent = false
    handleLastStartTag(false, true)
    if attributes.is_a?(Hash)
      attrString = attributes.keys.collect{|k| "#{k}=\"#{attributes[k]}\""}.join(" ")
    else
      attrString = attributes.collect{|pair| "#{pair[0]}=\"#{pair[1]}\""}.join(" ")
    end
    @lastStartTag = " "*@indent*INDENT_SPACE + "<#{tag} "+attrString
    @indent += 1
  end
  
  def endTag(tag)
    @indent -= 1
    unless handleLastStartTag(true, true)
      output " "*@indent*INDENT_SPACE unless @textContent
      output "</#{tag}>\n"
    end
    @textContent = false
  end

  def writeText(text)
    handleLastStartTag(false, false)
    output "#{text}"
    @textContent = true
  end  
	
	protected

  def eAllReferences(element)
    @eAllReferences ||= {}
    @eAllReferences[element.class] ||= element.class.ecore.eAllReferences
  end

  def eAllAttributes(element)
    @eAllAttributes ||= {}
    @eAllAttributes[element.class] ||= element.class.ecore.eAllAttributes
  end
    
  def eAllStructuralFeatures(element)
    @eAllStructuralFeatures ||= {}
    @eAllStructuralFeatures[element.class] ||= element.class.ecore.eAllStructuralFeatures
  end

	def eachReferencedElement(element, refs, &block)
		refs.each do |r|
			targetElements = element.getGeneric(r.name)
			targetElements = [targetElements] unless targetElements.is_a?(Array)
			targetElements.each do |te|
				yield(r,te)
			end
		end			
	end  

  def containmentReferences(element)
    @containmentReferences ||= {}
    @containmentReferences[element.class] ||= eAllReferences(element).select{|r| r.containment}
  end
  
  private
  
  def handleLastStartTag(close, newline)
    return false unless @lastStartTag
    output @lastStartTag
    output close ? "/>" : ">"
    output "\n" if newline
    @lastStartTag = nil
    true
  end
  
  def output(text)
    @file.write(text)
  end
  
end

end

end

MMCT - 2023