Class: ResoTransport::MetadataParser
- Inherits:
-
Object
- Object
- ResoTransport::MetadataParser
- Includes:
- REXML::StreamListener
- Defined in:
- lib/reso_transport/metadata_parser.rb
Instance Attribute Summary collapse
-
#entity_sets ⇒ Object
readonly
Returns the value of attribute entity_sets.
-
#enumerations ⇒ Object
readonly
Returns the value of attribute enumerations.
-
#schemas ⇒ Object
readonly
Returns the value of attribute schemas.
Instance Method Summary collapse
- #datasystem? ⇒ Boolean
- #finalize ⇒ Object
-
#initialize ⇒ MetadataParser
constructor
A new instance of MetadataParser.
- #parse(doc) ⇒ Object
- #tag_end(name) ⇒ Object
-
#tag_start(name, args) ⇒ Object
Schema -> EnumType -> Members -> Annotation EntityType -> Key Properties -> enumerations.
Constructor Details
#initialize ⇒ MetadataParser
Returns a new instance of MetadataParser.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/reso_transport/metadata_parser.rb', line 7 def initialize @schemas = [] @entity_sets = [] @entity_types = [] @enumerations = [] @current_entity_type = nil @current_complex_type = nil @current_enum_type = nil @current_member = nil @datasystem = nil end |
Instance Attribute Details
#entity_sets ⇒ Object (readonly)
Returns the value of attribute entity_sets.
5 6 7 |
# File 'lib/reso_transport/metadata_parser.rb', line 5 def entity_sets @entity_sets end |
#enumerations ⇒ Object (readonly)
Returns the value of attribute enumerations.
5 6 7 |
# File 'lib/reso_transport/metadata_parser.rb', line 5 def enumerations @enumerations end |
#schemas ⇒ Object (readonly)
Returns the value of attribute schemas.
5 6 7 |
# File 'lib/reso_transport/metadata_parser.rb', line 5 def schemas @schemas end |
Instance Method Details
#datasystem? ⇒ Boolean
111 112 113 114 115 |
# File 'lib/reso_transport/metadata_parser.rb', line 111 def datasystem? return @datasystem unless @datasystem.nil? @datasystem = @schemas.any? { |s| s.entity_types.any? { |t| t.name == 'DataSystem' } } end |
#finalize ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/reso_transport/metadata_parser.rb', line 27 def finalize schemas.each do |s| s.entity_types.each do |et| et.properties.each do |p| p.finalize_type(self) end et..each do |p| p.finalize_type(self) end end s.complex_types.each do |et| et.properties.each do |p| p.finalize_type(self) end end end end |
#parse(doc) ⇒ Object
21 22 23 24 25 |
# File 'lib/reso_transport/metadata_parser.rb', line 21 def parse(doc) REXML::Document.parse_stream(doc, self) finalize self end |
#tag_end(name) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/reso_transport/metadata_parser.rb', line 94 def tag_end(name) case name when 'EntityType' @current_entity_type.schema = @schemas.last.namespace @schemas.last.entity_types << @current_entity_type when 'ComplexType' @current_complex_type.schema = @schemas.last.namespace @schemas.last.complex_types << @current_complex_type when 'EnumType' @enumerations << @current_enum_type @current_enum_type = nil when 'Member' @current_enum_type.members << @current_member @current_member = nil end end |
#tag_start(name, args) ⇒ Object
Schema ->
EnumType ->
Members ->
Annotation
EntityType ->
Key
Properties ->
enumerations
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/reso_transport/metadata_parser.rb', line 57 def tag_start(name, args) case name when 'Schema' @schemas << ResoTransport::Schema.from_stream(args) when 'EntitySet' @entity_sets << ResoTransport::EntitySet.from_stream(args) when 'EntityType' @current_entity_type = ResoTransport::EntityType.from_stream(args) when 'ComplexType' @current_complex_type = ResoTransport::EntityType.from_stream(args) when 'PropertyRef' @current_entity_type.primary_key = args['Name'] when 'Property' if @current_entity_type @current_entity_type.properties << ResoTransport::Property.from_stream(args.merge(schema: @schemas.last)) end if @current_complex_type @current_complex_type.properties << ResoTransport::Property.from_stream(args.merge(schema: @schemas.last)) end when 'NavigationProperty' @current_entity_type. << ResoTransport::Property.from_stream(args) when 'EnumType' @current_enum_type = ResoTransport::Enum.from_stream(args.merge(schema: @schemas.last)) when 'Member' @current_member = ResoTransport::Member.from_stream(args) when 'Annotation' if @current_enum_type && @current_member @current_member.annotation = args['String'] elsif @current_entity_type || @current_complex_type # raise args.inspect end end rescue StandardError => e puts e.inspect puts "Error processing Tag: #{[name, args].inspect}" end |