sdl-ng 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sdl.rb +18 -7
- data/lib/sdl/base.rb +7 -6
- data/lib/sdl/base/fact.rb +7 -11
- data/lib/sdl/base/property.rb +22 -26
- data/lib/sdl/base/service.rb +8 -12
- data/lib/sdl/base/service_compendium.rb +97 -109
- data/lib/sdl/base/type.rb +62 -68
- data/lib/sdl/exporters.rb +13 -9
- data/lib/sdl/exporters/exporter.rb +10 -14
- data/lib/sdl/exporters/markdown_service_exporter.rb +0 -2
- data/lib/sdl/exporters/rdf_exporter.rb +17 -21
- data/lib/sdl/exporters/rdf_mapping.rb +0 -1
- data/lib/sdl/exporters/schema_exporter.rb +3 -7
- data/lib/sdl/exporters/service_exporter.rb +4 -8
- data/lib/sdl/exporters/xml_service_exporter.rb +22 -26
- data/lib/sdl/exporters/xsd_schema_exporter.rb +65 -70
- data/lib/sdl/ng/version.rb +1 -1
- data/lib/sdl/receivers.rb +7 -6
- data/lib/sdl/receivers/fact_receiver.rb +8 -12
- data/lib/sdl/receivers/service_receiver.rb +41 -47
- data/lib/sdl/receivers/type_instance_receiver.rb +67 -73
- data/lib/sdl/receivers/type_receiver.rb +72 -76
- data/lib/sdl/types.rb +15 -9
- data/lib/sdl/types/sdl_datetime.rb +4 -8
- data/lib/sdl/types/sdl_description.rb +6 -10
- data/lib/sdl/types/sdl_duration.rb +4 -8
- data/lib/sdl/types/sdl_number.rb +4 -8
- data/lib/sdl/types/sdl_simple_type.rb +13 -6
- data/lib/sdl/types/sdl_string.rb +4 -8
- data/lib/sdl/types/sdl_type.rb +20 -24
- data/lib/sdl/types/sdl_url.rb +9 -13
- data/lib/sdl/util.rb +1 -0
- metadata +2 -2
data/lib/sdl/exporters.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module SDL::Exporters
|
2
|
+
extend ActiveSupport::Autoload
|
3
|
+
|
4
|
+
autoload :Exporter
|
5
|
+
autoload :SchemaExporter
|
6
|
+
autoload :ServiceExporter
|
7
|
+
autoload :RDFExporter
|
8
|
+
autoload :RDFMapping
|
9
|
+
autoload :MarkdownServiceExporter
|
10
|
+
autoload :XMLMapping
|
11
|
+
autoload :XMLServiceExporter
|
12
|
+
autoload :XSDSchemaExporter
|
13
|
+
end
|
@@ -1,19 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
attr :compendium
|
5
|
-
attr :options
|
1
|
+
class SDL::Exporters::Exporter
|
2
|
+
attr :compendium
|
3
|
+
attr :options
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
def initialize(compendium, options = {})
|
6
|
+
@compendium = compendium
|
7
|
+
@options = options
|
8
|
+
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
10
|
+
def export_to_file(path, content)
|
11
|
+
File.open(path, 'w') do |f|
|
12
|
+
f.write(content)
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
@@ -1,33 +1,29 @@
|
|
1
1
|
require 'rdf'
|
2
2
|
require 'rdf/rdfxml'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
class RDFExporter < ServiceExporter
|
7
|
-
@@s = RDF::Vocabulary.new('http://www.open-service-compendium.org/')
|
4
|
+
class SDL::Exporters::RDFExporter < ServiceExporter
|
5
|
+
@@s = RDF::Vocabulary.new('http://www.open-service-compendium.org/')
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
def export_service(service)
|
8
|
+
graph = RDF::Graph.new
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
service.facts.each do |fact|
|
11
|
+
graph << [RDF::URI.new(service.uri), @@s["has_#{fact.class.local_name.underscore}"], RDF::URI.new(fact.uri)]
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
expand_properties(fact, graph)
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
16
|
+
graph.dump(:rdf)
|
17
|
+
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
def expand_properties(type_instance, graph)
|
20
|
+
type_instance.property_values.each do |property, value|
|
21
|
+
[value].flatten.each do |v|
|
22
|
+
graph << [RDF::URI.new(type_instance.uri), @@s["#{property.name.underscore}"], v.rdf_object] unless v.nil?
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
25
|
+
if property.type < SDL::Base::Type
|
26
|
+
[value].flatten.each do |v| expand_properties(v, graph) end
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
@@ -1,9 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
def export_schema_to_file(path)
|
5
|
-
export_to_file path, export_schema
|
6
|
-
end
|
7
|
-
end
|
1
|
+
class SDL::Exporters::SchemaExporter < Exporter
|
2
|
+
def export_schema_to_file(path)
|
3
|
+
export_to_file path, export_schema
|
8
4
|
end
|
9
5
|
end
|
@@ -1,9 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
def export_service_to_file(service, path)
|
5
|
-
export_to_file path, export_service(service)
|
6
|
-
end
|
7
|
-
end
|
1
|
+
class SDL::Exporters::ServiceExporter < Exporter
|
2
|
+
def export_service_to_file(service, path)
|
3
|
+
export_to_file path, export_service(service)
|
8
4
|
end
|
9
|
-
end
|
5
|
+
end
|
@@ -1,35 +1,31 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
xml.
|
7
|
-
|
8
|
-
xml.send(fact.class.xsd_element_name + '_') do
|
9
|
-
serialize_type_instance fact, xml
|
10
|
-
end
|
11
|
-
end
|
1
|
+
class SDL::Exporters::XMLServiceExporter < ServiceExporter
|
2
|
+
def export_service(service)
|
3
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
4
|
+
xml.service('xmlns' => 'http://www.open-service-compendium.org') do
|
5
|
+
service.facts.each do |fact|
|
6
|
+
xml.send(fact.class.xsd_element_name + '_') do
|
7
|
+
serialize_type_instance fact, xml
|
12
8
|
end
|
13
9
|
end
|
14
|
-
|
15
|
-
builder.to_xml
|
16
10
|
end
|
11
|
+
end
|
12
|
+
|
13
|
+
builder.to_xml
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
xml.documentation v.documentation if (!value.is_a?(Array) && value.identifier)
|
27
|
-
serialize_type_instance(v, xml)
|
28
|
-
end
|
29
|
-
else
|
30
|
-
xml.send(property.xsd_element_name + '_', v)
|
16
|
+
def serialize_type_instance(type_instance, xml)
|
17
|
+
type_instance.property_values.each do |property, value|
|
18
|
+
[value].flatten.each do |v|
|
19
|
+
if v.class < SDL::Base::Type
|
20
|
+
xml.send(property.xsd_element_name + '_', (!value.is_a?(Array) && value.identifier) ? {'identifier' => value.identifier.to_s} : {}) do
|
21
|
+
v.annotations.each do |annotation|
|
22
|
+
xml.annotation annotation
|
31
23
|
end
|
24
|
+
xml.documentation v.documentation if (!value.is_a?(Array) && value.identifier)
|
25
|
+
serialize_type_instance(v, xml)
|
32
26
|
end
|
27
|
+
else
|
28
|
+
xml.send(property.xsd_element_name + '_', v)
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
@@ -1,65 +1,60 @@
|
|
1
|
-
require 'active_support/inflector'
|
2
1
|
require 'nokogiri'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
export_schema_xml.to_xml
|
18
|
-
end
|
3
|
+
##
|
4
|
+
# The XSD schema exporter creates an XML Schema Definition for consuming service descriptions using the XML provided
|
5
|
+
# by the XMLServiceExporter.
|
6
|
+
#
|
7
|
+
# The schema consists of the following main components:
|
8
|
+
# - The definition of the root node, i.e., a service. The service contains an arbitrary number of elements of
|
9
|
+
# service fact types.
|
10
|
+
# - The definition of service fact classes and SDL types
|
11
|
+
# - The definition of a type base, containing annotations and documentation
|
12
|
+
class SDL::Exporters::XSDSchemaExporter < SchemaExporter
|
13
|
+
def export_schema
|
14
|
+
export_schema_xml.to_xml
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
17
|
+
def export_schema_xml
|
18
|
+
Nokogiri::XML::Builder.new do |xml|
|
19
|
+
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
|
20
|
+
xml['ns'].element :name => 'service' do
|
21
|
+
document(xml, I18n.t('sdl.xml.service_root'))
|
22
|
+
xml['ns'].complexType do
|
23
|
+
xml['ns'].choice :maxOccurs => 'unbounded' do
|
24
|
+
@compendium.fact_classes.each do |fact_class|
|
25
|
+
xml['ns'].element :name => fact_class.xsd_element_name, :type => fact_class.xsd_type_name do
|
26
|
+
document(xml, fact_class.documentation)
|
32
27
|
end
|
33
28
|
end
|
34
29
|
end
|
30
|
+
end
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
xml['ns'].attribute :name => 'identifier' do
|
47
|
-
document(xml, I18n.t('sdl.xml.identifier'))
|
48
|
-
end
|
33
|
+
xml['ns'].complexType :name => 'SDLTypeBase' do
|
34
|
+
document(xml, I18n.t('sdl.xml.typebase'))
|
35
|
+
xml['ns'].choice do
|
36
|
+
xml['ns'].element :name => 'documentation', :minOccurs => 0, :maxOccurs => 'unbounded', :type => 'ns:string' do
|
37
|
+
document(xml, I18n.t('sdl.xml.documentation'))
|
38
|
+
end
|
39
|
+
xml['ns'].element :name => 'annotation', :minOccurs => 0, :maxOccurs => 'unbounded', :type => 'ns:string' do
|
40
|
+
document(xml, I18n.t('sdl.xml.annotation'))
|
49
41
|
end
|
42
|
+
end
|
43
|
+
xml['ns'].attribute :name => 'identifier' do
|
44
|
+
document(xml, I18n.t('sdl.xml.identifier'))
|
45
|
+
end
|
46
|
+
end
|
50
47
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
48
|
+
(@compendium.fact_classes + @compendium.types).each do |fact_class|
|
49
|
+
xml['ns'].complexType :name => fact_class.xsd_type_name do
|
50
|
+
document(xml, fact_class.documentation)
|
51
|
+
xml['ns'].complexContent do
|
52
|
+
xml['ns'].extension :base => fact_class.is_sub? ? fact_class.superclass.xsd_type_name : 'SDLTypeBase' do
|
53
|
+
unless fact_class.properties.empty?
|
54
|
+
xml['ns'].sequence do
|
55
|
+
fact_class.properties.each do |property|
|
56
|
+
extend_property(property, xml) do
|
57
|
+
document(xml, property.documentation)
|
63
58
|
end
|
64
59
|
end
|
65
60
|
end
|
@@ -69,26 +64,26 @@ module SDL
|
|
69
64
|
end
|
70
65
|
end
|
71
66
|
end
|
67
|
+
end
|
68
|
+
end
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
else
|
80
|
-
xml['ns'].element :name => property.name, :type => property.type.xml_type, :minOccurs => 0 do
|
81
|
-
yield
|
82
|
-
end
|
83
|
-
end
|
70
|
+
# Creates an xml element corresponding to the SDL property
|
71
|
+
def extend_property(property, xml)
|
72
|
+
if property.multi?
|
73
|
+
xml['ns'].element :name => property.name.singularize, :type => property.type.xml_type, :minOccurs => 0, :maxOccurs => 'unbounded' do
|
74
|
+
yield
|
84
75
|
end
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
xml['ns'].annotation do
|
89
|
-
xml['ns'].documentation documentation
|
90
|
-
end
|
76
|
+
else
|
77
|
+
xml['ns'].element :name => property.name, :type => property.type.xml_type, :minOccurs => 0 do
|
78
|
+
yield
|
91
79
|
end
|
92
80
|
end
|
93
81
|
end
|
82
|
+
|
83
|
+
# Shortcut for adding an XSD documentation annotation
|
84
|
+
def document(xml, documentation)
|
85
|
+
xml['ns'].annotation do
|
86
|
+
xml['ns'].documentation documentation
|
87
|
+
end
|
88
|
+
end
|
94
89
|
end
|
data/lib/sdl/ng/version.rb
CHANGED
data/lib/sdl/receivers.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
require_relative 'receivers/type_instance_receiver'
|
2
|
-
require_relative 'receivers/type_receiver'
|
3
|
-
require_relative 'receivers/fact_receiver'
|
4
|
-
require_relative 'receivers/service_receiver'
|
5
|
-
|
6
|
-
|
7
1
|
module SDL
|
8
2
|
module Receivers
|
3
|
+
extend ActiveSupport::Autoload
|
4
|
+
|
5
|
+
autoload :FactReceiver
|
6
|
+
autoload :ServiceReceiver
|
7
|
+
autoload :TypeReceiver
|
8
|
+
autoload :TypeInstanceReceiver
|
9
|
+
|
9
10
|
#
|
10
11
|
def self.set_value(type_class, type_instance, *property_values, compendium)
|
11
12
|
property_values.zip(type_class.properties(true)).each do |value, property|
|
@@ -1,15 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
SDL::Base::Fact
|
6
|
-
end
|
7
|
-
|
8
|
-
def register_sdltype(type)
|
9
|
-
false
|
10
|
-
end
|
1
|
+
class SDL::Receivers::FactReceiver < SDL::Receivers::TypeReceiver
|
2
|
+
def base_class
|
3
|
+
SDL::Base::Fact
|
4
|
+
end
|
11
5
|
|
12
|
-
|
13
|
-
|
6
|
+
def register_sdltype(type)
|
7
|
+
false
|
14
8
|
end
|
9
|
+
|
10
|
+
alias :subfact :subtype
|
15
11
|
end
|
@@ -1,63 +1,57 @@
|
|
1
1
|
require 'verbs'
|
2
2
|
|
3
|
-
|
3
|
+
class SDL::Receivers::ServiceReceiver
|
4
|
+
include ActiveSupport::Inflector
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
class ServiceReceiver
|
8
|
-
include ActiveSupport::Inflector
|
6
|
+
attr :service
|
7
|
+
attr :compendium
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
def initialize(sym, compendium)
|
10
|
+
@service = SDL::Base::Service.new(sym.to_s)
|
11
|
+
@compendium = compendium
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
compendium.fact_classes.each do |fact_class|
|
18
|
-
define_singleton_method("is_#{fact_class.local_name.underscore.verb.conjugate(:tense => :past, :person => :third, :plurality => :singular, :aspect => :perfective)}") do |*args, &block|
|
19
|
-
add_fact fact_class, *args, &block
|
20
|
-
end
|
13
|
+
compendium.fact_classes.each do |fact_class|
|
14
|
+
define_singleton_method("is_#{fact_class.local_name.underscore.verb.conjugate(:tense => :past, :person => :third, :plurality => :singular, :aspect => :perfective)}") do |*args, &block|
|
15
|
+
add_fact fact_class, *args, &block
|
16
|
+
end
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
define_singleton_method("has_#{fact_class.local_name.underscore}") do |*args, &block|
|
19
|
+
add_fact fact_class, *args, &block
|
20
|
+
end
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
22
|
+
define_singleton_method("#{fact_class.local_name.underscore}") do |*args, &block|
|
23
|
+
add_fact fact_class, *args, &block
|
30
24
|
end
|
25
|
+
end
|
26
|
+
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
private
|
29
|
+
def add_fact(fact_class, *property_values, &block)
|
30
|
+
fact_instance = fact_class.new
|
31
|
+
fact_instance.service = @service
|
36
32
|
|
37
|
-
|
33
|
+
SDL::Receivers.set_value(fact_class, fact_instance, *property_values, @compendium)
|
38
34
|
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
if block_given?
|
36
|
+
SDL::Receivers::TypeInstanceReceiver.new(fact_instance, @compendium).instance_eval &block
|
37
|
+
end
|
42
38
|
|
43
|
-
|
44
|
-
|
39
|
+
@service.facts << fact_instance
|
40
|
+
end
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
else
|
58
|
-
raise Exception.new("I do not know what to do with '#{name}' in #{caller[0]}")
|
59
|
-
end
|
42
|
+
##
|
43
|
+
# Catches calls to methods named similarily to possible predefined type instances
|
44
|
+
def method_missing(name, *args)
|
45
|
+
possible_type_instances = @compendium.type_instances.map{|k, v| v[name]}.select{|v| v != nil}
|
46
|
+
|
47
|
+
unless possible_type_instances.nil? || possible_type_instances.empty?
|
48
|
+
if possible_type_instances.length > 1
|
49
|
+
raise Exception.new("Multiple possibilities for #{name} in #{caller[0]}")
|
50
|
+
else
|
51
|
+
possible_type_instances[0]
|
60
52
|
end
|
53
|
+
else
|
54
|
+
raise Exception.new("I do not know what to do with '#{name}' in #{caller[0]}")
|
55
|
+
end
|
61
56
|
end
|
62
|
-
end
|
63
57
|
end
|