emf_jruby 0.1.1-java

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 'emf/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,9 @@
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
+ require jar
6
+ end
7
+
8
+ require 'emf/ast_serialization'
9
+ require 'emf/emf_to_json'
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emf_jruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.1
6
+ platform: java
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
+ homepage: http://federico-tomassetti.it
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ none: false
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ none: false
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 1.8.24
48
+ signing_key:
49
+ specification_version: 3
50
+ summary: EMF support for JRuby
51
+ test_files: []