Class: SDL::Exporters::XSDSchemaExporter
- Inherits:
-
SchemaExporter
- Object
- Exporter
- SchemaExporter
- SDL::Exporters::XSDSchemaExporter
- Defined in:
- lib/sdl/exporters/xsd_schema_exporter.rb
Overview
The XSD schema exporter creates an XML Schema Definition for consuming service descriptions using the XML provided by the XMLServiceExporter.
The schema consists of the following main components:
- The definition of the root node, i.e., a service. The service contains an arbitrary number of elements of
service fact types.
- The definition of service fact classes and SDL types
- The definition of a type base, containing annotations and documentation
Instance Attribute Summary
Attributes inherited from Exporter
Instance Method Summary collapse
-
#document(xml, documentation) ⇒ Object
Shortcut for adding an XSD documentation annotation.
- #export_schema ⇒ Object
- #export_schema_xml ⇒ Object
-
#extend_property(property, xml) ⇒ Object
Creates an xml element corresponding to the SDL property.
Methods inherited from SchemaExporter
Methods inherited from Exporter
Constructor Details
This class inherits a constructor from SDL::Exporters::Exporter
Instance Method Details
#document(xml, documentation) ⇒ Object
Shortcut for adding an XSD documentation annotation
97 98 99 100 101 |
# File 'lib/sdl/exporters/xsd_schema_exporter.rb', line 97 def document(xml, documentation) xml['ns'].annotation do xml['ns'].documentation documentation end end |
#export_schema ⇒ Object
13 14 15 |
# File 'lib/sdl/exporters/xsd_schema_exporter.rb', line 13 def export_schema export_schema_xml.to_xml end |
#export_schema_xml ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 |
# File 'lib/sdl/exporters/xsd_schema_exporter.rb', line 17 def export_schema_xml Nokogiri::XML::Builder.new do |xml| xml['ns'].schema('xmlns' => 'http://www.open-service-compendium.org', 'targetNamespace' => 'http://www.open-service-compendium.org', 'xmlns:ns' => 'http://www.w3.org/2001/XMLSchema', 'elementFormDefault' => 'qualified') do xml['ns'].element :name => 'services' do document(xml, I18n.t('sdl.xml.services_root')) xml['ns'].complexType do xml['ns'].sequence do xml['ns'].element :name=> 'service', :type => 'Service', :minOccurs => 0, :maxOccurs => :unbounded end end end xml['ns'].element :name => 'service', :type => 'Service' do document(xml, I18n.t('sdl.xml.service_root')) end xml['ns'].complexType :name => 'Service' do document(xml, I18n.t('sdl.xml.service_class')) xml['ns'].sequence do xml['ns'].choice :maxOccurs => :unbounded do @compendium.fact_classes.each do |fact_class| xml['ns'].element :name => fact_class.xsd_element_name, :type => fact_class.xsd_type_name do document(xml, fact_class.documentation) end end end end end xml['ns'].complexType :name => 'SDLTypeBase' do document(xml, I18n.t('sdl.xml.typebase')) xml['ns'].choice do xml['ns'].element :name => 'documentation', :minOccurs => 0, :maxOccurs => 'unbounded', :type => 'ns:string' do document(xml, I18n.t('sdl.xml.documentation')) end xml['ns'].element :name => 'annotation', :minOccurs => 0, :maxOccurs => 'unbounded', :type => 'ns:string' do document(xml, I18n.t('sdl.xml.annotation')) end end xml['ns'].attribute :name => 'identifier' do document(xml, I18n.t('sdl.xml.identifier')) end end (@compendium.fact_classes + @compendium.types).each do |fact_class| xml['ns'].complexType :name => fact_class.xsd_type_name do document(xml, fact_class.documentation) xml['ns'].complexContent do xml['ns'].extension :base => fact_class.is_sub? ? fact_class.superclass.xsd_type_name : 'SDLTypeBase' do unless fact_class.properties.empty? xml['ns'].sequence do fact_class.properties.each do |property| extend_property(property, xml) do document(xml, property.documentation) end end end end end end end end end end end |
#extend_property(property, xml) ⇒ Object
Creates an xml element corresponding to the SDL property
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sdl/exporters/xsd_schema_exporter.rb', line 84 def extend_property(property, xml) if property.multi? xml['ns'].element :name => property.name.singularize, :type => property.type.xml_type, :minOccurs => 0, :maxOccurs => 'unbounded' do yield end else xml['ns'].element :name => property.name, :type => property.type.xml_type, :minOccurs => 0 do yield end end end |