Module: EMF

Defined in:
lib/emf/exceptions.rb,
lib/emf/xmi.rb,
lib/emf/emf_utils.rb,
lib/emf/rgen_to_emf.rb

Overview

Various exceptions used in the lib

Defined Under Namespace

Modules: XmiConversion Classes: ConversionContext, LessThanExpectedFound, MoreThanExpectedFound, SingleAttributeRequired, UnexistingFeature

Constant Summary collapse

EcoreLiterals =
JavaUtilities.get_proxy_class('org.eclipse.emf.ecore.EcorePackage$Literals')

Class Method Summary collapse

Class Method Details

.create_eattribute(name, datatype) ⇒ Object



20
21
22
23
24
25
# File 'lib/emf/emf_utils.rb', line 20

def self.create_eattribute(name, datatype)
	a = EcoreFactory.eINSTANCE.createEAttribute
	a.name = name
	a.etype = datatype
	a
end

.create_eattribute_str(name) ⇒ Object



27
28
29
# File 'lib/emf/emf_utils.rb', line 27

def self.create_eattribute_str(name)
	create_eattribute(name,EcoreLiterals::ESTRING)
end

.create_eclass(p = nil) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/emf/emf_utils.rb', line 11

def self.create_eclass(p=nil)
	if p
		c = p.createEClass p.next_id
		c
	else
		EcoreFactory.eINSTANCE.createEClass
	end
end

.create_eobject(eclass) ⇒ Object



45
46
47
48
49
# File 'lib/emf/emf_utils.rb', line 45

def self.create_eobject(eclass)
	eo = EcoreFactory.eINSTANCE.createEObject
	eo.eSetClass eclass
	eo
end

.create_epackage(name, uri) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/emf/emf_utils.rb', line 51

def self.create_epackage(name, uri)
	p = EcoreFactory.eINSTANCE.createEPackage
	class << p
		def next_id
			@next_id = 0 unless @next_id
			@next_id += 1
			@next_id
		end
	end
	p.setName name
	p.setNsURI uri
	p
end

.create_ereference(type = nil, name = nil, params = []) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/emf/emf_utils.rb', line 31

def self.create_ereference(type=nil, name=nil, params=[])
	r = EcoreFactory.eINSTANCE.createEReference #(type, type.ePackage.next_id)
	r.set_etype(type) 
	r.name = name
	raise 'Cannot be both single and many' if params.include? :many and params.include? :single
	raise 'Cannot be both containment and not containment' if params.include? :containment and params.include? :not_containment
	containment = params.include? :containment
	many = params.include? :many
	r.containment = containment
	r.set_upper_bound(-1) if many
	r.set_upper_bound(1) unless many
	r
end

.rgen_to_eclass(rgen_class, context = ConversionContext.new) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/emf/rgen_to_emf.rb', line 35

def self.rgen_to_eclass(rgen_class,context=ConversionContext.new)
	if rgen_class.respond_to? :ecore
		ecore = rgen_class.ecore
	else
		ecore = rgen_class
	end
	emf_eclass = create_eclass
	ecore.getEAttributes.each do |a|			
		emf_a = create_eattribute(a.name,rgen_to_edatatype(a.eType))
		emf_eclass.getEStructuralFeatures.add emf_a
	end
	ecore.getEReferences.each do |r|
		#puts "Ref #{r} #{r.name}"
		emf_r = create_ereference
		emf_r.name = r.name
		emf_r.containment = r.containment
		#emf_r.resolve_proxies = r.getResolveProxies
		#emf_r.setEType(context.convert r.getEType)
		emf_eclass.getEStructuralFeatures.add emf_r
	end
	emf_eclass
end

.rgen_to_edatatype(rgen_datatype) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/emf/rgen_to_emf.rb', line 27

def self.rgen_to_edatatype(rgen_datatype)
	if rgen_datatype.name=='EString'
		return EcoreLiterals.ESTRING
	else
		raise "I don't know how to deal with datatype #{rgen_datatype} (name=#{rgen_datatype.name})"
	end
end

.rgen_to_eobject(rgen_obj, context = ConversionContext.new) ⇒ Object



24
25
# File 'lib/emf/rgen_to_emf.rb', line 24

def self.rgen_to_eobject(rgen_obj,context=ConversionContext.new)
end