emf_jruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ $serialization_ids = {}
2
+ $next_serialization_id = 1
3
+
4
+ def serialization_id(obj)
5
+ unless $serialization_ids[obj]
6
+ $serialization_ids[obj] = $next_serialization_id
7
+ $next_serialization_id += 1
8
+ end
9
+ $serialization_ids[obj]
10
+ end
@@ -0,0 +1,65 @@
1
+ require 'ast_serialization'
2
+
3
+ def qname(e_object)
4
+ e_class = e_object.eClass
5
+ e_package = e_class.ePackage
6
+ "#{e_package.nsURI}##{e_class.name}"
7
+ end
8
+
9
+ def jsonize_attr_value(map,e_object,e_attr)
10
+ value = e_object.eGet e_attr
11
+ if e_attr.upperBound==1
12
+ map["attr_#{e_attr.name}"] = value
13
+ else
14
+ l = []
15
+ (0..(value.size-1)).each do |i|
16
+ l << value.get(i)
17
+ end
18
+ map["attr_#{e_attr.name}"] = l
19
+ end
20
+ end
21
+
22
+ def jsonize_ref_single_el(single_value,containment,adapters)
23
+ if containment
24
+ jsonize_obj(single_value,adapters)
25
+ else
26
+ serialization_id(single_value)
27
+ end
28
+ end
29
+
30
+ def jsonize_ref_value(map,e_object,e_ref,adapters)
31
+ value = e_object.eGet e_ref
32
+
33
+ propname = "relcont_#{e_ref.name}" if e_ref.containment
34
+ propname = "relnoncont_#{e_ref.name}" if not e_ref.containment
35
+
36
+ if e_ref.upperBound==1
37
+ map[propname] = jsonize_ref_single_el(value,e_ref.containment,adapters)
38
+ else
39
+ l = []
40
+ (0..(value.size-1)).each do |i|
41
+ l << jsonize_ref_single_el(value.get(i),e_ref.containment,adapters)
42
+ end
43
+ map[propname] = l
44
+ end
45
+ end
46
+
47
+ def jsonize_obj(e_object, adapters={})
48
+ if not e_object
49
+ nil
50
+ else
51
+ map = { 'type' => qname(e_object), 'id' => serialization_id(e_object) }
52
+ e_class = e_object.eClass
53
+ e_class.eAllAttributes.each do |a|
54
+ jsonize_attr_value(map,e_object,a)
55
+ end
56
+ e_class.eAllReferences.each do |r|
57
+ #puts "ref #{r.name} #{r.containment}"
58
+ jsonize_ref_value(map,e_object,r,adapters)
59
+ end
60
+ if adapters.has_key? qname(e_object)
61
+ adapters[qname(e_object)].adapt(e_object,map)
62
+ end
63
+ map
64
+ end
65
+ end
data/lib/emf_jruby.rb ADDED
@@ -0,0 +1,5 @@
1
+ emf_libs = $:.select{|e| e.gsub('emf_jruby').count>0}
2
+ raise "One lib containing 'emf_jruby' expected, found: #{emf_libs}" unless emf_libs.count==1
3
+
4
+ Dir[emf_libs[0]+"/jars/*.jar"].each do |jar|
5
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emf_jruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Federico Tomassetti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: EMF support for JRuby. Support for loading and saving models in JSon.
15
+ email: f.tomassetti@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/emf_jruby.rb
21
+ - lib/emf/emf_to_json.rb
22
+ - lib/emf/ast_serialization.rb
23
+ - lib/jars/org.antlr.runtime_3.0.0.v200803061811.jar
24
+ - lib/jars/org.eclipse.emf.common_2.8.0.v20130125-0546.jar
25
+ - lib/jars/org.eclipse.emf.ecore.xmi_2.8.1.v20130125-0546.jar
26
+ - lib/jars/org.eclipse.emf.ecore_2.8.3.v20130125-0546.jar
27
+ - lib/jars/org.eclipse.m2m.atl.common_3.3.1.v201209061455.jar
28
+ - lib/jars/org.eclipse.m2m.atl.core.emf_3.3.1.v201209061455.jar
29
+ - lib/jars/org.eclipse.m2m.atl.core_3.3.1.v201209061455.jar
30
+ - lib/jars/org.eclipse.m2m.atl.dsls_3.3.1.v201209061455.jar
31
+ - lib/jars/org.eclipse.m2m.atl.engine_3.3.1.v201209061455.jar
32
+ homepage: http://federico-tomassetti.it
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ none: false
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.24
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: EMF support for JRuby
56
+ test_files: []