Module: RGen::MetamodelBuilder::BuilderRuntime

Includes:
Util::NameHelper
Included in:
MMBase
Defined in:
lib/rgen/metamodel_builder/builder_runtime.rb

Overview

This module is mixed into MetamodelBuilder::MMBase. The methods provided by this module are used by the methods generated by the class methods of MetamodelBuilder::BuilderExtensions

Instance Method Summary collapse

Methods included from Util::NameHelper

#camelize, #className, #firstToLower, #firstToUpper, #normalize, #saneClassName, #saneMethodName

Instance Method Details

#_add_contained_element(element) ⇒ Object



147
148
149
150
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 147

def _add_contained_element(element)
  @_contained_elements ||= []
  @_contained_elements << element
end

#_assignmentTypeError(target, value, expected) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 156

def _assignmentTypeError(target, value, expected)
	text = ""
	if target
		targetId = target.class.name
		targetId += "(" + target.name + ")" if target.respond_to?(:name) and target.name
		text += "In #{targetId} : "
	end
	valueId = value.class.name
	valueId += "(" + value.name + ")" if value.respond_to?(:name) and value.name
	valueId += "(:" + value.to_s + ")" if value.is_a?(Symbol)
	text += "Can not use a #{valueId} where a #{expected} is expected"
	StandardError.new(text)
end

#_remove_contained_element(element) ⇒ Object



152
153
154
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 152

def _remove_contained_element(element)
  @_contained_elements.delete(element) if @_contained_elements
end

#_set_container(container, containing_feature_name) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 131

def _set_container(container, containing_feature_name)
  # if a new container is set, make sure to disconnect from the old one.
  # note that _set_container will never be called for the container and the role
  # which are currently set because the accessor methods in BuilderExtensions
  # block setting/adding a value which is already present.
  # (it may be called for the same container with a different role, a different container
  # with the same role and a different container with a different role, though)
  # this ensures, that disconnecting for the current container doesn't break
  # a new connection which has just been set up in the accessor methods.
  disconnectContainer if container
  @_container._remove_contained_element(self) if @_container
  container._add_contained_element(self) if container
  @_container = container
  @_containing_feature_name = containing_feature_name
end

#addGeneric(role, value, index = -1)) ⇒ Object



21
22
23
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 21

def addGeneric(role, value, index=-1)
	send("add#{firstToUpper(role.to_s)}",value, index)
end

#disconnectContainerObject



127
128
129
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 127

def disconnectContainer
  eContainer.setNilOrRemoveGeneric(eContainingFeature, self) if eContainer
end

#eAllContents(&block) ⇒ Object

if a block is given, calls the block on every contained element in depth first order. if the block returns :prune, recursion will stop at this point.

if no block is given builds and returns a list of all contained elements.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 106

def eAllContents(&block)
  if block
    if @_contained_elements
      @_contained_elements.each do |e|
        res = block.call(e)
        e.eAllContents(&block) if res != :prune
      end
    end
    nil
  else
    result = []
    if @_contained_elements
      @_contained_elements.each do |e|
        result << e
        result.concat(e.eAllContents)
      end
    end
    result
  end
end

#eContainerObject



84
85
86
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 84

def eContainer
  @_container
end

#eContainingFeatureObject



88
89
90
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 88

def eContainingFeature
  @_containing_feature_name
end

#eContentsObject

returns the contained elements in no particular order



93
94
95
96
97
98
99
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 93

def eContents
  if @_contained_elements
    @_contained_elements.dup
  else
    []
  end
end

#eIsSet(role) ⇒ Object



71
72
73
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 71

def eIsSet(role)
  eval("defined? @#{role}") != nil
end

#eUnset(role) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 75

def eUnset(role)
  if respond_to?("add#{firstToUpper(role.to_s)}")
    setGeneric(role, [])
  else
    setGeneric(role, nil)
  end
  remove_instance_variable("@#{role}")
end

#getGeneric(role) ⇒ Object



61
62
63
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 61

def getGeneric(role)
	send("get#{firstToUpper(role.to_s)}")
end

#getGenericAsArray(role) ⇒ Object



65
66
67
68
69
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 65

def getGenericAsArray(role)
  result = getGeneric(role)
  result = [result].compact unless result.is_a?(Array)
  result
end

#hasManyMethods(role) ⇒ Object



33
34
35
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 33

def hasManyMethods(role)
  respond_to?("add#{firstToUpper(role.to_s)}")
end

#is_a?(c) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 16

def is_a?(c)
   return super unless c.const_defined?(:ClassModule)
   kind_of?(c::ClassModule)
end

#removeGeneric(role, value) ⇒ Object



25
26
27
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 25

def removeGeneric(role, value)
	send("remove#{firstToUpper(role.to_s)}",value)
end

#setGeneric(role, value) ⇒ Object



29
30
31
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 29

def setGeneric(role, value)
	send("set#{firstToUpper(role.to_s)}",value)
end

#setNilOrRemoveAllGeneric(role) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 53

def setNilOrRemoveAllGeneric(role)
  if hasManyMethods(role)
    setGeneric(role, [])
  else
    setGeneric(role, nil)
  end
end

#setNilOrRemoveGeneric(role, value) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 45

def setNilOrRemoveGeneric(role, value)
  if hasManyMethods(role)
    removeGeneric(role, value)
  else
    setGeneric(role, nil)
  end
end

#setOrAddGeneric(role, value) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/rgen/metamodel_builder/builder_runtime.rb', line 37

def setOrAddGeneric(role, value)
  if hasManyMethods(role)
    addGeneric(role, value)
  else
    setGeneric(role, value)
  end
end