Module: Muml_Classifier

Includes:
Mjava_Annotation
Defined in:
lib/ontomde-uml2-java/java.rb,
lib/ontomde-uml2-java/java.rb,
lib/ontomde-uml2-java/equals.rb,
lib/ontomde-uml2-java/javadoc.rb,
lib/ontomde-uml2-java/accessorCode.rb,
lib/ontomde-uml2-java/enumAssignable.rb,
lib/ontomde-uml2-java/operationAsClass.rb,
lib/ontomde-uml2-java/operationAsClass.rb,
lib/ontomde-uml2-java/accessorSignature.rb,
lib/ontomde-uml2-java/accessorSignature.rb,
lib/ontomde-uml2-java/enumCompatibilityLayer.rb

Constant Summary collapse

JAVA_IMPORT_COMPUTED_DEPENDENCIES =

if true, generator will compute depencies and add imports NOTE !!

This feature was added for derived generators.
It's use is **not** recommended  for **java**.
Problems will occur if model manipulate classes
such as java.sql.Date and java.lang.Date simultaneously.
false
JAVA_DEFAULT_IMPORTS =

default java imports

[  ]
JAVA_MAGIC_DOT_STRING =

String used to replace dot in enum literals

'_dot_'
STRUTS_APPLY_TO_PARAM =
"applyTo"
STRUTS_APPLY_TO_PROP =
"ApplyTo"
STRUTS_RESULT_PARAM_NAME =

Creates a class for every business method holding every parameters and

"_result"

Instance Method Summary collapse

Methods included from Mjava_Annotation

#java_writeAnnotation

Instance Method Details

#getterParameterName(oa) ⇒ Object



91
92
93
94
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 91

def getterParameterName(oa)
	return "i#{oa.java_NameProperty}"

end

#java_addAccessors!Object



25
26
27
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 25

def java_addAccessors!
	java_transform!
end

#java_addAccessorsFor!(oa) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 30

def java_addAccessorsFor!(oa)
	#log.debug { "-------java.transform:Accessor for #{self.uml_name}.#{oa.uml_name}" }
	return unless context[:java_transform,true]
	return if oa.java_noAccessors?

               oa.uml_visibility=Cuml_VisibilityKind::Private

	#prevent multiple accessor addition.
	#useful when a transformation has manually launch
	#java_addAccessorFor! (ex: to set a custom getter code)
	return unless oa.java_getter_property_inv.empty?
	java_addGlobalGetter!(oa)
	java_addGlobalSetter!(oa)
	java_addQualifiedPutter!(oa)
	java_addQualifiedGetter!(oa)
	java_addAppender!(oa)
	java_addCreateAndAppender!(oa)
	java_addWithIndexAppender!(oa)
	java_addAppenderQualifier!(oa)
	java_addRemover!(oa)
	java_addSuggester!(oa)
	java_addSuggesterType!(oa)
	java_addCreater!(oa)
end

#java_addAppender!(oa) ⇒ Object

Adds an appender for parameter oa using a model transformation.

NOTE:

  • A new operation is added to the UML model. The operation then generated using standard operation generator.

  • operation is only generated for multi-valued property

  • If property is part of a bidirectional association, code is generated to update automaticaly the other side of the association.



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 308

def java_addAppender!(oa)
	return unless context[:java_addAppender,true]
	return if oa.umlx_upperValueIsOne?
	return unless oa.uml_qualifier.empty?
	return if oa.java_isSuggester?
	#return if oa.umlx_isComposite?
	return if oa.uml_isReadOnly?
	add=java_createAndAddMethodFromProperty(oa,"add",true)

	ip=Cuml_Parameter.new(rdf_model,add.rdf_uri+"_in")
	ip.uml_name=getterParameterName(oa)
	ip.uml_direction=Cuml_ParameterDirectionKind::In
	ip.uml_upperValue=umlx_literal(1);
	ip.uml_lowerValue=umlx_literal(1);
	ip.uml_type=oa.uml_type
	add.uml_ownedParameter_add(ip)
	oe=oa.umlx_otherEnd

	if oa.uml_isDerived?
		# no code generated
	elsif (oe.nil? || !oe.umlx_isNavigable?) && !oa.java_use_Arrays?
		add.java_code=<<END
/* TPL:0009b */
if(#{getterParameterName(oa)}==null) { return; }
#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)});
END
	elsif (oe.nil? || !oe.umlx_isNavigable?) && oa.java_use_Arrays?
		add.java_code=<<END
/* TPL:0009a */
if(#{getterParameterName(oa)}==null) { return; }
#{oa.uml_type_one.java_qualifiedName}[] newArray=null;
if (#{java_this(oa)}#{oa.java_NameProperty}==null) {
	newArray=new String[1];
	newArray[0]=#{getterParameterName(oa)};
} else {
	newArray=new String[1+#{java_this(oa)}#{oa.java_NameProperty}.length];
	System.arraycopy(#{java_this(oa)}#{oa.java_NameProperty}, 0, newArray,0, #{java_this(oa)}#{oa.java_NameProperty}.length);
	newArray[#{java_this(oa)}#{oa.java_NameProperty}.length]=#{getterParameterName(oa)};
}
#{java_this(oa)}#{oa.java_NameProperty}=newArray;
END


	elsif oe.umlx_upperValueIsOne?
		#*-1
		add.java_code=<<END
/* TPL:0010 */
if(#{getterParameterName(oa)}==null) { return; }
if(#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)})){
	#{getterParameterName(oa)}.set#{oe.java_NameBean}(this);
	}
END
	else
		#*-*
		# second test avoids loop
		add.java_code=<<END
/* TPL:0011 */
if(#{getterParameterName(oa)}==null) { return; }
if(#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)})) {
	#{getterParameterName(oa)}.add#{oe.java_NameBean}(this);
	}
END
	end

end

#java_addAppenderQualifier!(oa) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 147

def java_addAppenderQualifier!(oa)
	return unless context[:java_addAppenderQualifier,true]
	return if oa.umlx_upperValueIsOne?
	return if oa.uml_qualifier.empty?
	return if oa.umlx_isComposite?
	return if oa.uml_isReadOnly?
	add=java_createAndAddMethodFromProperty(oa,"add",true)

	ip=Cuml_Parameter.new(rdf_model,add.rdf_uri+"_in")
	ip.uml_name=getterParameterName(oa)
	ip.uml_direction=Cuml_ParameterDirectionKind::In
	ip.uml_upperValue=umlx_literal(1);
	ip.uml_lowerValue=umlx_literal(1);
	ip.uml_type=oa.uml_type
	add.uml_ownedParameter_add(ip)
	oe=oa.umlx_otherEnd

	qualCall=".get(#{oa.uml_qualifier_one.java_Name})"
	qualInit="//#{java_this(oa)}#{oa.java_NameProperty}.put(#{oa.uml_qualifier_one.java_Name},new java.util.HashSet<#{oa.uml_qualifier_one.uml_type_one}>);"

	if oa.uml_isDerived?
		# no code when derived
	elsif true #TODO:remetre le test oe.nil? || !oe.umlx_isNavigable?
		add.java_code=<<END
/* TPL:0006 */
//TODO:
if(#{ip.java_Name}==null) { return; }
#{qualInit}
#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name});
END
	elsif oe.umlx_upperValueIsOne?
		#*-1
		add.java_code=<<END
/* TPL:0007 */
if(#{ip.java_Name}==null) { return; }
if(#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name})){
	#{ip.java_Name}.set#{oe.java_NameBean}(this);
	}
END
	else
		#*-*
		add.java_code=<<END
/* TPL:0008 */
if(#{ip.java_Name}==null) { return; }
if(#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name})) {
	#{ip.java_Name}.remove#{oe.java_NameBean}(this);
	}
END
	end
end

#java_addCreateAndAppender!(oa) ⇒ Object

Adds a createAndAdd method for parameter oa using a model transformation.

NOTE:

  • A new operation is added to the UML model. The operation then generated using standard operation generator.

  • operation is only generated for multi-valued property

  • operation is only generated for a composite association end.



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 237

def java_addCreateAndAppender!(oa)
	#method cannot be generated if required enum assignable is not on.
	return unless context[:withEnumAssignable]
	return unless context[:java_addAppender,true]
	#return if oa.umlx_upperValueIsOne?
	return unless oa.uml_qualifier.empty?
	return unless oa.umlx_isComposite?
	return if oa.java_isSuggester?

	add=umlx_createAndAddOperation(rdf_uri+"_createAndAdd#{oa.java_NameBean}","createAndAdd#{oa.java_NameBean}")

	rp=add.umlx_createAndAddReturnParameter(add.rdf_uri+"_ret")
	rp.uml_upperValue=umlx_literal(1);
	rp.uml_lowerValue=umlx_literal(1);
	rp.uml_type=oa.uml_type

	#ip=add.umlx_createAndAddParameter(add.rdf_uri+"_type")
	#ip.uml_name="type"
	#ip.uml_upperValue=umlx_literal(1);
	#ip.uml_lowerValue=umlx_literal(1);
	#ip.uml_type=oa.uml_type


	tp=add.umlx_createAndAddParameter(oa.rdf_uri+"_reqType","requestedType")
	tp.uml_type=oa.uml_type_one.java_enumAssignableDataType_one

	#if  oa.uml_type_one.uml_isAbstract?
	# ******************************
	# TODO: implement type selector
	# ******************************
	# no java code generated

               #TODO: factorize in helper class
	add.java_code=%{ /* TPL:0020b */
	if (requestedType==null) {
		return null;
	}
	String qname=requestedType.name().replaceAll("#{JAVA_MAGIC_DOT_STRING}",".");
	try {
		// c=#{java_this(oa)}getClass().getClassLoader().loadClass(requestedType.name());
		Class<?> t = Class.forName(qname);
		Class<?>[] p = new Class[0];
		Object[]initArgs =new Object[0];
		java.lang.reflect.Constructor<?>  c=t.getConstructor(p);
		#{oa.uml_type_one.java_qualifiedName} ret=(#{oa.uml_type_one.java_qualifiedName})c.newInstance(initArgs);
		#{oa.umlx_upperValueIsOne? ? "set" : "add"}#{oa.java_NameBean}(ret);
		return ret;
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
		throw new RuntimeException("Missing type "+qname,e);
	} catch (NoSuchMethodException e) {
		e.printStackTrace();
		throw new RuntimeException("Missing default constructor for"+qname,e);
	} catch (IllegalAccessException e) {
		e.printStackTrace();
		throw new RuntimeException("Illegal access Exception on "+qname,e);
	} catch (InstantiationException e) {
		e.printStackTrace();
		throw new RuntimeException("Instantiation exception on "+qname,e);
	} catch (java.lang.reflect.InvocationTargetException e) {
		e.printStackTrace();
		throw new RuntimeException("Invocation Target Exception on "+qname,e);
	}}
end

#java_addCreater!(oa) ⇒ Object

Adds a creater for parameter oa using a model transformation.

NOTE:

  • A new operation is added to the UML model. The operation then generated using standard operation generator.

– TODO: implementer methodes



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 204

def java_addCreater!(oa)
	return unless context[:java_addCreater,true]
	return if oa.umlx_upperValueIsOne?
	#return unless oa.uml_qualifier.empty?
	return unless oa.umlx_isComposite?
	get=java_createAndAddMethodFromProperty(oa,"create",false)

	rp=Cuml_Parameter.new(rdf_model,get.rdf_uri+"_p1")
	rp.uml_name="return"
	rp.uml_direction=Cuml_ParameterDirectionKind::Return
	rp.uml_upperValue=oa.uml_upperValue
	rp.uml_lowerValue=oa.uml_lowerValue
	rp.uml_type=oa.uml_type
	rp.uml_qualifier=oa.uml_qualifier
	get.uml_ownedParameter_add(rp)
	if oa.umlx_upperValueIsOne?  || !oa.uml_qualifier.empty?
		j="{ new return #{oa.java_NameProperty}"
		sep_next=".get("
		sep_end=""
		j=j+sep_end  +";}"
		#get.java_code=j
	else
		#on ne peut pas permetre la modification de la liste en direct
		#get.java_code="{ return new java.util.HashSet<#{oa.uml_type_one.java_qualifiedName}>(#{oa.java_NameProperty}); }"
	end
end

#java_addEnumAssignable!Object

add an enum assignable to this model element



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ontomde-uml2-java/enumAssignable.rb', line 36

def java_addEnumAssignable!
	#log.debug { "java_addEnumAssignable! for #{self}::#{self.class.name}" }
	p=umlx_owner_one
	p=p.umlx_getOrCreatePackage(context[:enumAssignableSubPackage,"enumCreate"],p)

	ret=p.umlx_createAndAddEnumeration(self.rdf_uri+"_enumAssignable","#{uml_name} Assignable")
	ret.umlx_createAndAddImplementation(java_getJavaEnumInterface)
	self.java_enumAssignableDataType=ret

	umlx_assignableClassifier.each { |c|
		next if c.uml_isAbstract?
		ret.umlx_createAndAddLiteral(c.java_qualifiedName.to_s.gsub(/\./,JAVA_MAGIC_DOT_STRING));
	}

	return ret
end

#java_addEqualsAndHashOperations(callSuperEquals) ⇒ Object

adds a equals and a hash method to the current class. Signature is computed from attributes stereoptyped EqualsValue NOTE: method is not generated if there is no attribute stereotyped EqualsValue



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ontomde-uml2-java/equals.rb', line 7

def java_addEqualsAndHashOperations(callSuperEquals)
  ret=Set.new
  uml_ownedAttribute.each {|biz|
    ret << biz if biz.umlx_hasStereotype?("EqualsValue")
  }
  if !ret.empty?
    puts "generate hash and equals for #{self.java_Name}"
    java_addEqualsOperation!(ret, callSuperEquals)
    java_addHashCodeOperation!(ret)
  end
  return nil
end

#java_addEqualsOperation!(attributesInSignature, callSuperEquals) ⇒ Object

adds a equals method



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ontomde-uml2-java/equals.rb', line 21

def java_addEqualsOperation!(attributesInSignature, callSuperEquals)
    me=self.umlx_createAndAddOperation(self.rdf_uri+"_equals")
    me.uml_name="equals"
    #      me.uml_class=self
    me.uml_visibility=Cuml_VisibilityKind::Public
    rme=me.umlx_createAndAddReturnParameter("#{me.rdf_uri}_ret")
    rme.uml_type=umlx_getOrCreateDataType("boolean")
    rpe=me.umlx_createAndAddParameter("#{me.rdf_uri}_par", "o")
    rpe.uml_type=umlx_getOrCreateClass("Object")
    me.java_annotation_add("@Override")
    meCode = <<CODE
  if(this == o) {
      return true;
  }
  if(o==null || !(o instanceof #{self.java_Name})) {
      return false;
  }
CODE
    if callSuperEquals
    meCode << <<CODE
  if !super.equals(o) {
      return false;  
  }
CODE
  else
    meCode << "// do not use super.equals()\n"
  end
  meCode << <<CODE
  final #{self.java_Name} _o = (#{self.java_Name}) o;
CODE
  attributesInSignature.each { |a|
    meCode << <<CODE
  if (#{a.java_Name} != null ?
        !#{a.java_Name}.equals(_o.#{a.java_Name}) :
        _o.#{a.java_Name} != null) {
        return false;
  }
CODE
  }
  meCode << <<CODE
  return true;
CODE
  me.java_code = meCode
  return me
end

#java_addGlobalGetter!(oa) ⇒ Object

Adds a getter for parameter oa using a model transformation.

NOTE:

  • A new operation is added to the UML model. The operation then generated using standard operation generator.

  • If property is part of a bidirectional association, code is generated to update automaticaly the other side of the association.

  • If property is multivalued, the operation returns a set.



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 211

def java_addGlobalGetter!(oa)
	return unless context[:java_addGlobalGetter,true]
	#return if oa.uml_isDerived?
	#return unless oa.uml_isReadOnly?
	return unless oa.java_AttributeGlobalGetter.empty?
	get=java_createAndAddMethodFromProperty(oa,"get",false)
	get.java_getter_property=oa
	oa.java_AttributeGlobalGetter=get

	rp=get.umlx_createAndAddParameter(get.rdf_uri+"_p1")
	rp.java_use_Arrays=oa.java_use_Arrays
	oa.umlx_copyToAttributeProperty(rp)
	rp.uml_name="return"
	rp.uml_direction=Cuml_ParameterDirectionKind::Return
	rp.uml_qualifier=oa.uml_qualifier
	get.java_code=mtk_stss {java_writeGlobalGetterBody(oa) }
	return get
end

#java_addGlobalSetter!(oa) ⇒ Object

Adds a setter for parameter oa using a model transformation.

NOTE:

  • A new operation is added to the UML model. The operation then generated using standard operation generator.

  • If property is part of a bidirectional association, code is generated to update automaticaly the other side of the association.

  • If property is multivalued, the operation takes a set as an argument. For single value access use appender and remover.



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 236

def java_addGlobalSetter!(oa)
	return unless context[:java_addGlobalSetter,true]
	return unless oa.java_AttributeGlobalSetter.empty?
	# a setter is generated for derived attribute as it may be implemented.
	#return unless !oa.uml_isDerived?
	set=java_createAndAddMethodFromProperty(oa,"set",false)
	set.java_setter_property=oa
	oa.java_AttributeGlobalSetter=set

	ip=set.umlx_createAndAddParameter(set.rdf_uri+"_in")
	ip.java_use_Arrays=oa.java_use_Arrays
	oa.umlx_copyToAttributeProperty(ip)
	ip.uml_name=getterParameterName(oa)
	ip.uml_direction=Cuml_ParameterDirectionKind::In
	ip.uml_qualifier=oa.uml_qualifier
	oe=oa.umlx_otherEnd
	set.java_code=mtk_stss{java_writeGlobalSetterBody(oa)}
	return set
end

#java_addHashCodeOperation!(attributesInSignature) ⇒ Object

adds a hash method



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ontomde-uml2-java/equals.rb', line 68

def java_addHashCodeOperation!(attributesInSignature)
  me=self.umlx_createAndAddOperation(self.rdf_uri+"_hash")
  me.uml_name="hashCode"
  me.uml_class=self
  me.uml_visibility=Cuml_VisibilityKind::Public
  rme=me.umlx_createAndAddReturnParameter("#{me.rdf_uri}_ret")
  rme.uml_type=umlx_getOrCreateDataType("int")
  me.java_annotation_add("@Override")
  meCode = <<CODE
  final int prime = 31;
  int result = 1;
CODE
  attributesInSignature.each { |a|
    meCode << <<CODE
  result = prime * result + ((#{a.java_Name} == null) ? 0 : #{a.java_Name}.hashCode());
CODE
  }
  meCode << <<CODE
  return result;
CODE
  me.java_code = meCode
  return me 
end

#java_addQualifiedAppender!(oa) ⇒ Object



121
122
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 121

def java_addQualifiedAppender!(oa)
end

#java_addQualifiedGetter!(oa) ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 256

def java_addQualifiedGetter!(oa)
	return unless context[:java_addQualifiedGetter,true]
	return if oa.uml_qualifier.empty?
	return unless !oa.uml_isDerived?

	getter=java_createAndAddMethodFromProperty(oa,"get",true)

	rp=getter.umlx_createAndAddParameter(getter.rdf_uri+"_p1")
	rp.java_use_Arrays=oa.java_use_Arrays
	oa.umlx_copyToAttributeProperty(rp)
	rp.uml_name="return"
	rp.uml_direction=Cuml_ParameterDirectionKind::Return

	getter.java_code=mtk_stss{java_writeQualifiedGetterBody(oa)}
	return getter
end

#java_addQualifiedPutter!(oa) ⇒ Object

Adds a putter for parameter oa using a model transformation. (manages addition to a hastable):

NOTE:

  • This code is generated when a qualifier is defined in model.

  • Languages do not not handled multiple key Hastable.

  • A new operation is puttered to the UML model. The operation then generated using standard operation generator.

  • operation is only generated for multi-valued property

*WARNING: bi-directional cannot be handled with qualifier because association key is not known.

  • a TODO note is added in the code in case model is bi-directional so developper knows something has to be done.

EXAMPLE 1: (uml_upperValue==1)

Class3 putRoleClass3(String key) {
...
}

EXAMPLE 2 (uml_upperValue==*):

Set<Class3> putRoleClass3(String key) {
...
}


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 115

def java_addQualifiedPutter!(oa)
	return unless context[:java_addQualifiedPutter,true]
	return if oa.uml_qualifier.empty?
	return unless !oa.uml_isDerived?

	putter=java_createAndAddMethodFromProperty(oa,"put",true)
	ip=putter.umlx_createAndAddParameter(putter.rdf_uri+"_in")
	ip.java_use_Arrays=oa.java_use_Arrays
	oa.umlx_copyToAttributeProperty(ip)
	ip.uml_name=getterParameterName(oa)
	ip.uml_direction=Cuml_ParameterDirectionKind::In
	oe=oa.umlx_otherEnd
	putter.java_code= mtk_stss { java_writeQualifiedPutterBody(oa) }
	return putter
end

#java_addQualifiedRemover!(oa) ⇒ Object



118
119
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 118

def java_addQualifiedRemover!(oa)
end

#java_addRemover!(oa) ⇒ Object

Adds a remover for parameter oa using a model transformation.

NOTE:

  • A new operation is added to the UML model. The operation then generated using standard operation generator.

  • Remover is only generated for multi-valued property

  • If property is part of a bidirectional association, code is generated to update automaticaly the other side of the association.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 47

def java_addRemover!(oa)
	return unless context[:java_addRemover,true]
	return if oa.umlx_upperValueIsOne?
	return if oa.java_isSuggester?
	return if oa.uml_isReadOnly?
	set=java_createAndAddMethodFromProperty(oa,"remove",true)

	if oa.uml_qualifier.empty?
		qualCall=""
		qualInit=""
		qualCheckRemove=""
	else
		qualCall=".get(#{oa.uml_qualifier_one.java_Name})"
		qualInit="//#{java_this(oa)}#{oa.java_NameProperty}.put(#{oa.uml_qualifier_one.java_Name},new java.util.HashSet<#{oa.uml_qualifier_one.uml_type_one}>);"
		qualCheckRemove="==null"
	end

	ip=Cuml_Parameter.new(rdf_model,set.rdf_uri+"_in")
	ip.uml_name=getterParameterName(oa)
	ip.uml_direction=Cuml_ParameterDirectionKind::In
	ip.uml_upperValue=umlx_literal(1)
	ip.uml_lowerValue=umlx_literal(1)
	ip.uml_type=oa.uml_type
	set.uml_ownedParameter_add(ip)
	oe=oa.umlx_otherEnd
	if oa.uml_isDerived?
		#no code when derived
	elsif oe.nil? || !oe.umlx_isNavigable?
		set.java_code=<<END
/* TPL:0003 */
#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)});
END
	elsif oe.umlx_upperValueIsOne?
		set.java_code=<<END
/* TPL:0004 */
 #{qualInit}
 if(#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)})#{qualCheckRemove}) {
	#{getterParameterName(oa)}#{qualCall}.set#{oe.java_NameBean}(null);
}
END
	else
		set.java_code=<<END
/* TPL:0005 */
if(#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)})) {
	#{getterParameterName(oa)}#{qualCall}.remove#{oe.java_NameBean}(this);
}
END
	end

	if set.java_use_Arrays?
		set.java_code=nil # TODO: implement
	end

end

#java_addSuggester!(oa) ⇒ Object

Adds a suggester for parameter oa using a model transformation.

NOTE:

  • A new operation is added to the UML model. The operation then generated using standard operation generator.

  • A suggester returns a set of possible value for the parameter.

  • Suggester is not generated for datatypes (string, int, …)

  • A default suggester is generated for enum that return every enum values

  • A default non functional suggester is generated for objects.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 139

def java_addSuggester!(oa)
	return if oa.java_isSuggester?
	return if oa.uml_isReadOnly?
	#log.debug { "add suggester (#{oa}) self=#{self}" }
	return unless context[:java_addSuggester,true]
	return if oa.uml_type_one.kind_of?(Muml_DataType) && !oa.uml_type_one.kind_of?(Muml_Enumeration)

	#sug=umlx_createAndAddProperty("#{oa.rdf_uri}_sugP","#{oa.uml_name}Sug2")
	#sug2.uml_type=oa.uml_type
	#sug2.uml_upperValue=umlx_literal(-1)
	#sug2.uml_lowerValue=umlx_literal(0)
	#sug2.uml_isOrdered=RDF_TRUE
	#sug2.uml_isDerived=RDF_TRUE
	#sug2.java_isSuggester=RDF_TRUE


	sug=java_createAndAddMethodFromProperty(oa,"sug",false)
	#suggester is a defined as a bean property so it can be used with tools such as struts.
	sug.uml_name="get#{oa.java_NameBean}Sug"
	#java_createAndAddMethodParameterFromProperty(oa,true)

	rp=sug.umlx_createAndAddParameter(sug.rdf_uri+"_p1")
	#rp.java_use_Arrays=oa.java_use_Arrays
	oa.umlx_copyToAttributeProperty(rp)
	rp.uml_name="return"
	rp.uml_direction=Cuml_ParameterDirectionKind::Return
	rp.uml_upperValue=umlx_literal(-1)
	rp.uml_lowerValue=umlx_literal(0)
	rp.uml_isOrdered=RDF_TRUE

	if(oa.uml_type_one.kind_of?(Muml_Enumeration))
		sug.java_code=mtk_stss{ java_writeSuggesterBodyEnum(oa) }
	else
		sug.java_code=mtk_stss{ java_writeSuggesterBody(oa) }
	end
	return sug
end

#java_addSuggesterType!(oa) ⇒ Object

adds a suggester for creator. Returns an enum of possible types.



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 179

def java_addSuggesterType!(oa)
	#log.debug { "add suggester (#{oa}) self=#{self}" }
	return if oa.uml_isReadOnly?
	return unless context[:withEnumAssignable]
	return unless context[:java_addSuggester,true]
	return if oa.uml_type_one.kind_of?(Muml_DataType) && !oa.uml_type_one.kind_of?(Muml_Enumeration)
	return unless oa.umlx_isComposite?
	sug=java_createAndAddMethodFromProperty(oa,"createAndAddSug",false)
	#suggester is a defined as a bean property so it can be used with tools such as struts.
	sug.uml_name="getCreateAndAdd#{oa.java_NameBean}Sug"
	rp=sug.umlx_createAndAddParameter(sug.rdf_uri+"_p1")
	#rp.java_use_Arrays=oa.java_use_Arrays
	oa.umlx_copyToAttributeProperty(rp)
	rp.uml_type=oa.uml_type_one.java_enumAssignableDataType
	rp.uml_name="return"
	rp.uml_direction=Cuml_ParameterDirectionKind::Return
	rp.uml_upperValue=umlx_literal(-1)
	rp.uml_lowerValue=umlx_literal(0)
	rp.uml_isOrdered=RDF_TRUE

	isCreateAndAdd=true
	sug.java_code=mtk_stss{ java_writeSuggesterTypeBodyEnum(oa,isCreateAndAdd) }
	oa.java_createAndAddSuggester=sug
	return sug
end

#java_addWithIndexAppender!(oa) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 273

def java_addWithIndexAppender!(oa)
	return unless context[:java_addAppender,true]
	return if oa.umlx_upperValueIsOne?
	#return unless oa.uml_qualifier.empty?
	return unless oa.uml_isOrdered?
	return if oa.java_isSuggester?
	return if oa.uml_isReadOnly?
	#return if oa.umlx_isComposite?
	add=java_createAndAddMethodFromProperty(oa,"add",true,"wi")

	ip2=Cuml_Parameter.new(rdf_model,add.rdf_uri+"_in")
	ip2.uml_name="_index"
	ip2.uml_direction=Cuml_ParameterDirectionKind::In
	ip2.uml_upperValue=umlx_literal(1);
	ip2.uml_lowerValue=umlx_literal(1);
	ip2.uml_type=umlx_dataType_integer
	add.uml_ownedParameter_add(ip2)
	oe=oa.umlx_otherEnd

	ip=Cuml_Parameter.new(rdf_model,add.rdf_uri+"_in")
	ip.uml_name=getterParameterName(oa)
	ip.uml_direction=Cuml_ParameterDirectionKind::In
	ip.uml_upperValue=umlx_literal(1);
	ip.uml_lowerValue=umlx_literal(1);
	ip.uml_type=oa.uml_type
	add.uml_ownedParameter_add(ip)

	add.java_code = mtk_stss{java_addWithIndexAppenderBody(oa,oe,ip,ip2)}
	return add
end

#java_addWithIndexAppenderBody(oa, oe, ip, ip2) ⇒ Object



375
376
377
378
379
380
381
382
383
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 375

def java_addWithIndexAppenderBody(oa,oe,ip,ip2)
		if oe.nil? || !oe.umlx_isNavigable?
			write <<END
/* TPL:0019 */
if(#{getterParameterName(oa)}==null) { return; }
#{oa.java_NameProperty}.add(#{ip2.java_Name}, #{ip.java_Name});
END
		end
end

#java_createAndAddMethodFromProperty(oa, mName, withQualifier, uri_suffix = "") ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 58

def java_createAndAddMethodFromProperty(oa,mName,withQualifier,uri_suffix="")
	m=umlx_createAndAddOperation(oa.rdf_uri+"_#{mName}"+uri_suffix)
	m.uml_name="#{mName}#{oa.java_NameBean}"
	m.uml_class=self
	m.uml_visibility=Cuml_VisibilityKind::Public
	m.uml_isStatic=oa.uml_isStatic
	m.java_use_Arrays=oa.java_use_Arrays
	#puts "java_use_Arrays(#{oa})=#{m.java_use_Arrays}"


	if withQualifier
		oa.uml_qualifier.each { |qual|
			ip_qual=m.umlx_createAndAddParameter(m.rdf_uri+qual.rdf_uri)
			ip_qual.java_use_Arrays=oa.java_use_Arrays
			qual.umlx_copyToAttributeProperty(ip_qual)
			ip_qual.uml_name=qual.uml_name
			ip_qual.uml_direction=Cuml_ParameterDirectionKind::In
			}
		oe=oa.umlx_otherEnd
		if((!oe.nil?) && oe.umlx_isNavigable?)
			oe.uml_qualifier.each { |qual|
				ip_qual=m.umlx_createAndAddParameter(m.rdf_uri+qual.rdf_uri)
				ip_qual.java_use_Arrays=oa.java_use_Arrays
				qual.umlx_copyToAttributeProperty(ip_qual)
				ip_qual.uml_name=qual.uml_name
				ip_qual.uml_direction=Cuml_ParameterDirectionKind::In
				}
		end
	end
	return m
end

#java_FileNameObject

Returns the full java file name for this element (Uses: Java_FilePath and java_Name.) Example:

  • build/package1/package2/NomDeLaClasse.java



549
550
551
# File 'lib/ontomde-uml2-java/java.rb', line 549

def java_FileName
  return "#{java_FilePath}#{java_Name}.java"
end

#java_generateObject

opens java file for writing with java_openOutStream and calls java_write



595
596
597
598
599
600
601
602
603
604
605
606
607
608
# File 'lib/ontomde-uml2-java/java.rb', line 595

def java_generate
  return if @java_already_generated
  return if java_ignoreMe?

  return unless self.umlx_owner_one.kind_of?(Muml_Package)
  @java_already_generated=true

  java_openOutStream {
    mtk_context(:innerClass=> false,
      :java_interface => kind_of?(Muml_Interface)) {
      java_write
    }
  }
end

#java_getJavaEnumInterfaceObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ontomde-uml2-java/enumAssignable.rb', line 52

def java_getJavaEnumInterface
	ret=umlx_getOrCreateInterface(JAVA_ENUM_INTERFACE_QNAME)
	if ret.uml_ownedOperation.empty?
		ret.umlx_external="false"
		op=ret.umlx_createAndAddOperation("#{ret.rdf_uri}_name}","name")
		r=op.umlx_createAndAddReturnParameter("#{op.rdf_uri}_ret","return")
		r.uml_type=umlx_dataType_string
                       op.umlx_businessMethod=RDF_FALSE
	end
	return ret
end

#java_isEnumStringMapping?(oa) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ontomde-uml2-java/enumCompatibilityLayer.rb', line 25

def java_isEnumStringMapping?(oa)
	return !oa.umlx_stringMappingForEnum.empty?
end

#java_openOutStream(&block) ⇒ Object

Opens java_FileName for writing

Example usage: java_openOutStream { write (“this text goes in java file”) }



559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
# File 'lib/ontomde-uml2-java/java.rb', line 559

def java_openOutStream(&block)
  mtk_writeSession(java_FileName) {
    yield
    if (context[:protectedReverse].protectedMode?)
      write <<NOTICE
\/\/**********************************************************************
\/\/** This file is in REVERSE MODE. Text between tags will be saved
\/\/** upon next generation if reverse="yes"
\/\/** Element between tags are not stored in model, so this file should
\/\/** manage in a version management tool.#{%{
      /\/\**
      /\/\** This file was generated with option --skipNoReverseMarker
      \/\/** Please set --no-skipNoReverseMarker if you wish to add a
      \/\/** reverse="yes" section.} if context[:skipNoReverseMarker] }
      \/\/**********************************************************************
      \/\/** Generated with ontoMDE (ORANGE-FT/RD/BIZZ/CIL/SAM 2006-2007)
      \/\/**********************************************************************
NOTICE


    else
      write <<NOTICE
\/\/**********************************************************************
\/\/** This file is in NOREVERSE MODE and was totaly generated from
/\/\** model informations.
/\/\** It is not mandatory to use a
/\/\** version management tool for this file
\/\/**********************************************************************
\/\/** Generated with ontoMDE (ORANGE-FT/RD/BIZZ/CIL/SAM 2006-2007
\/\/**********************************************************************
NOTICE
    end
  }
end

#java_qualifierNavigabilityWarning(oa) ⇒ Object

return a warning text to be included in java method if incorrect model is found.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 103

def java_qualifierNavigabilityWarning(oa)
	oe=oa.umlx_otherEnd
	return "" if oe.nil?
	return "" if oe.umlx_isNavigable?
	return <<END
/*TODO: association other end is navigable (#{oe.uml_name}).
 Because extrinsic qualifier key is not computable, there is no way a computer program can guess it.
 Check your model !
 If your key is intrisic, you should reconsider your model as it is a redundant functional qualifier.
 You should take appropriate action or your data model could be corrupted
 as association other end will not be updated.
*/
END
end

#java_this(oa) ⇒ Object

java_this(oa)=“#java_this(oa)”



3
4
5
6
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 3

def java_this(oa)
 return "" if oa.uml_isStatic?
 return "this."
end

#java_transform!Object

Performs a model transformation to add

  • attribute getter

  • attribute setter

  • attribute remover

  • attribute appender

  • attribute suggester

NOTE:

  • java_transform! is skipped if context is false (default=true)



20
21
22
23
24
# File 'lib/ontomde-uml2-java/accessorSignature.rb', line 20

def java_transform!
		uml_ownedAttribute.each { |oa|
			java_addAccessorsFor!(oa)
		}
end

#java_writeObject

write java code for class.

(Uses java_writeClassHeader, java_writeClassBody)

NOTE

  • also used for inner classes



614
615
616
617
618
# File 'lib/ontomde-uml2-java/java.rb', line 614

def java_write
  java_writeClassHeader {
    java_writeClassBody
  }
end

#java_writeAttributesObject

iterate java_write on attributes

NOTE

  • no attribute is generated for an interface

  • getter/setter// are not handled here (see java_transform!).



819
820
821
822
823
824
# File 'lib/ontomde-uml2-java/java.rb', line 819

def java_writeAttributes
  return if kind_of?(Muml_Interface)
  #sort has been added because ownedAttribute order is random
  #which is cause false change detection on versionned file
  uml_ownedAttribute.sort { |a,b| a.java_Name.to_s <=> b.java_Name.to_s }.each { |o| o.java_write}
end

#java_writeClassBodyObject

write class body.

(Uses java_writeClassComment, java_writeClassModifiers, java_writeMetaClassName, java_writeExtends, java_writeImplements, java_writeDeclarationSpecificOnBegin, java_writeAttributes, java_writeConstructors, java_writeOperations, java_writeDeclarationSpecificOnEnd)


639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
# File 'lib/ontomde-uml2-java/java.rb', line 639

def java_writeClassBody
  java_writeClassComment
  java_writeJavadoc
  java_writeAnnotation
  java_writeClassModifiers
  java_writeMetaClassName
  java_writeExtends
  java_writeImplements # class seulement
  write("{\n")
  java_writeCustomCode
  
  java_writeDeclarationSpecificOnBegin
  java_writeAttributes
  write("\n\n")
  #java_writeConstructors
  write("\n\n")
  java_writeOperations
  java_writeDeclarationSpecificOnEnd

  mtk_context(:innerClass=>true) {
    uml_nestedClassifier.each { |c|
      c.java_write
    }
  }
  write("}\n")
end

#java_writeClassCommentObject

Does nothing.



682
683
# File 'lib/ontomde-uml2-java/java.rb', line 682

def java_writeClassComment
end

#java_writeClassHeader(&block) ⇒ Object

write java header.

(Uses java_writePackageDeclaration, java_writeImports)

Exemple:

package pack1;
import xyz;


625
626
627
628
629
630
631
# File 'lib/ontomde-uml2-java/java.rb', line 625

def java_writeClassHeader(&block)
  return if context[:innerClass]
  java_writePackageDeclaration {
    java_writeImports
    yield
  }
end

#java_writeConstructorsObject

Does nothing.



694
695
# File 'lib/ontomde-uml2-java/java.rb', line 694

def java_writeConstructors
end

#java_writeCustomCodeObject

add add a custom code zone that is usefull for out of model code.



668
669
670
671
672
673
674
675
676
677
678
679
# File 'lib/ontomde-uml2-java/java.rb', line 668

def java_writeCustomCode
  mtk_protected(Mrdf_Resource::NOREVERSE,"custom_code") {
    write !java_customCode.empty? ? java_customCode : <<END
// ***********************************************
// This area is provided to insert special code
// that cannot be handled by generator.
// Please, don't use custom method to avoid
// keeping source models up to date.
// ***********************************************
END
  }
end

#java_writeDeclarationSpecificOnBeginObject

Does nothing.



686
687
# File 'lib/ontomde-uml2-java/java.rb', line 686

def java_writeDeclarationSpecificOnBegin
end

#java_writeDeclarationSpecificOnEndObject

Does nothing.



690
691
# File 'lib/ontomde-uml2-java/java.rb', line 690

def java_writeDeclarationSpecificOnEnd
end

#java_writeEnumStringMappingGetterCode(oa) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ontomde-uml2-java/enumCompatibilityLayer.rb', line 29

def java_writeEnumStringMappingGetterCode(oa)
	# getter for compatibility layer (enum visible as string)
	enum_oa=oa.umlx_stringMappingForEnum_one
	if  oa.umlx_upperValueIsOne?
		write "/* TPL:0012b */ return (#{enum_oa.java_NameProperty}==null) ? null : (#{enum_oa.java_NameProperty}.name());  "

	else
		write %{ /*TPL:0012c */
java.util.Set<java.lang.String>  ret=new java.util.HashSet<java.lang.String>();
for ( java.util.Iterator<#{enum_oa.uml_type_one.java_qualifiedName}>  iter = #{enum_oa.java_NameProperty}.iterator(); iter.hasNext();) {
	ret.add(iter.next().name());
}
return ret;\n}
	end
end

#java_writeEnumStringMappingSetterCode(oa) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/ontomde-uml2-java/enumCompatibilityLayer.rb', line 44

def java_writeEnumStringMappingSetterCode(oa)
	oa_enum=oa.umlx_stringMappingForEnum_one
	#Note: throws a runtime exception if enum is not found
	#Note: valueOf throws null pointer exception
	if  oa.umlx_upperValueIsOne?
		write "#{oa_enum.java_NameProperty}= #{getterParameterName(oa)}==null ? null : Enum.valueOf(#{oa_enum.uml_type_one.java_qualifiedName}.class,#{getterParameterName(oa)}); /* TPL:0014c*/"
	else
		# TODO: provide java implementation
	end
end

#java_writeExtendsObject

write java extends instructions is necessary (Uses java_qualifiedName)

Example:

extends Class2,Class3


719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
# File 'lib/ontomde-uml2-java/java.rb', line 719

def java_writeExtends
  ext=Set.new
  nbrInterface=0;

  uml_generalization.each { |g|
    nbrInterface+=1
    if (nbrInterface>1) && !kind_of?(Muml_Interface)
      write("\n/*TODO: UML model defines multiple inheritance (#{g.uml_general_one.java_qualifiedName})*/")
    else
      ext.add(g.uml_general_one.java_qualifiedName)
    end
  }
  java_extends.each { |g|
    nbrInterface+=1
    if nbrInterface>1
      write("\n/*TODO: UML model defines multiple inheritance (#{g})*/")
    else
      ext.add(g)
    end
  }
  sep="\nextends "
  ext.sort{ |a,b| a <=> b}.each { |g|
    write(sep)
    write(g)
    sep=","
  }

end

#java_writeGlobalGetterBody(oa) ⇒ Object



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 385

def java_writeGlobalGetterBody(oa)
	return if oa.uml_isDerived?  && oa.umlx_stringMappingForEnum.empty?

	if java_isEnumStringMapping?(oa)
		java_writeEnumStringMappingGetterCode(oa)

	elsif oa.umlx_upperValueIsOne?  || !oa.uml_qualifier.empty?
		j="/* TPL:0012 */ return #{oa.java_NameProperty}"
		sep_next=".get("
		sep_end=""
		#oa.uml_qualifier.each { |key|
		#	j=j+sep_next+key.uml_name_one
		#	sep_next=","
		#	sep_end=")"
		#}
		j=j+sep_end  +";"
		write j
	else
		#on ne peut pas permettre la modification de la liste en direct
		write %{
if(#{oa.java_NameProperty}!=null){ /* TPL:0013 */
	return #{oa.java_NameProperty};
} else {
	return #{oa.java_getCollectionMapping.addNew(oa.uml_type_one.java_qualifiedName)};
}}
	end
end

#java_writeGlobalSetterBody(oa) ⇒ Object



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 413

def java_writeGlobalSetterBody(oa)
	return if oa.uml_isDerived?  && oa.umlx_stringMappingForEnum.empty?

	oe=oa.umlx_otherEnd
	if java_isEnumStringMapping?(oa)
		java_writeEnumStringMappingSetterCode(oa)
	elsif  !oa.uml_qualifier.empty? || (!oe.nil? && oe.umlx_isNavigable? && !oe.uml_qualifier.empty?)
		#TODO: gerer bi-nav et qualifier
		write "/* TPL:0014 */ //TODO: bi-navigability\n #{oa.java_NameProperty}=#{getterParameterName(oa)};"
	elsif (oe.nil?) ||  (!oe.umlx_isNavigable?)
		# Autre extr�mit� non navigable.
		#begin
		#if oa.uml_qualifier.empty?
		write "#{java_this(oa)}#{oa.java_NameProperty}=#{getterParameterName(oa)}; /* TPL:0014d*/"
		#else
		#	j="{ #{oa.java_NameProperty}.put("
		#	sep=""
		#	oa.uml_qualifier.each { |qual|
		#		j=j+sep+qual.java_NameProperty
		#		sep=","
		#		}
		#	j=j+sep+"#{ip.uml_name});}"
		#	set.java_code=j
		#end
		#end
	elsif oa.umlx_upperValueIsOne? && oe.umlx_upperValueIsOne?
		# 1<->1
		#Ne pas enlver le =null (bloque la recursion)
		write <<END
/* TPL:0015 */
		if(#{java_this(oa)}#{oa.java_NameProperty}==#{getterParameterName(oa)}) { return ;}
		#{oa.uml_type_one.java_qualifiedName} previous=#{java_this(oa)}#{oa.java_NameProperty};

		#{java_this(oa)}#{oa.java_NameProperty}=null;
		if(previous!=null) { previous.set#{oe.java_NameBean}(null); }

		#{java_this(oa)}#{oa.java_NameProperty}=#{getterParameterName(oa)};
		if(#{getterParameterName(oa)}!=null) { #{getterParameterName(oa)}.set#{oe.java_NameBean}(this); }
END

	elsif oa.umlx_upperValueIsOne? && (!oe.umlx_upperValueIsOne?)
		# 1<->*
		write <<END
/* TPL:0016 */
		if(#{oa.java_NameProperty}!=null && #{oa.java_NameProperty}.equals(#{getterParameterName(oa)})) { return ;}
		#{oa.uml_type_one.java_qualifiedName} previous=#{oa.java_NameProperty};
		
		#{oa.java_NameProperty}=null;
		if(previous!=null) { previous.remove#{oe.java_NameBean}(this); }

		#{java_this(oa)}#{oa.java_NameProperty}=#{getterParameterName(oa)};
		if(#{getterParameterName(oa)}!=null) { #{getterParameterName(oa)}.add#{oe.java_NameBean}(this); }
END
	else # *<->1 and *<->*
		write <<END
/* TPL:0017 */
		#{oa.java_propertyAssociationType} toBeRemoved=new #{oa.java_propertyAssociationConcreteType}();
		for(#{oa.uml_type_one.java_qualifiedName} item:#{oa.java_NameProperty}) {
			if(#{getterParameterName(oa)}!=null && #{getterParameterName(oa)}.contains(item)) { continue;}
			toBeRemoved.add(item);
		}
		for(#{oa.uml_type_one.java_qualifiedName} item:toBeRemoved) {
			#{java_this(oa)}remove#{oa.java_NameBean}(item);
		}
		if(#{getterParameterName(oa)}==null) { return ; }
		for(#{oa.uml_type_one.java_qualifiedName} item:#{getterParameterName(oa)}) {
			#{java_this(oa)}add#{oa.java_NameBean}(item);
		}
END
	end
end

#java_writeImportsObject

write import instructions

NOTE:

The generator always uses qualified names, thus imports are not used by the generator.
Using short names leads to name clash. (different Date class, ...)

Letting eclipse handle imports is a the best solution.

Eclipse offers a highly convenient organize imports feature.
Developer should generate java code squeleton and fill it with their code eventually
using ECLIPSE organize import features.


767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
# File 'lib/ontomde-uml2-java/java.rb', line 767

def java_writeImports
  setOfImport=Set.new
  java_import.each { |imp|
    setOfImport<< imp
  }
  JAVA_DEFAULT_IMPORTS.each { |c|
    setOfImport<< c
  }
  if(JAVA_IMPORT_COMPUTED_DEPENDENCIES)
    umlx_computeDirectDepencies().each { |c|
      m=c.java_qualifiedName
      #Concrete type may come from a datatype mapping definition and be either a class or a language datatype.
      next unless m.index(".")
      setOfImport<< m
    }
  end

  if (setOfImport.empty?)
    # adds a useless import so eclipse
    # will place imports in the right area (between ontomde reverse marquers)
    # when using "organize import" eclipse feature.
    if umlx_owner_one.kind_of?(Muml_Model)
      #import of class in root package is invalid
      setOfImport<<"java.lang.Object"
    else
      #we import something
      setOfImport<< self.java_qualifiedName;
    end
  end

  mtk_protected(Mrdf_Resource::NOREVERSE,"imports") {
    setOfImport.sort { |a,b| a <=> b}.each {|imp|
      write("import #{imp};\n");
    }
  }
end

#java_writeJavadocObject

write classifier javadoc comment.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ontomde-uml2-java/javadoc.rb', line 20

def java_writeJavadoc
  return unless context[:javadoc]
  c=""
  sep=""
  uml_ownedComment.each { |comment|
    c="#{c}#{sep}#{comment.uml_body_one}"
    sep="\n"
  }
  write("    /**\n");
  c.java_writeJavadoc(self)
  #Note: RSM exports adds an extraneous http://
  #Note: TODO: This code is RSM 6 specific
  %{@see <a href="#{context[:rsm6WebDocURI]}#{UriNamespace.instance.unalias(rdf_uri).gsub(/http:\/\/kb#/,"")}-content.html">UML documentation.</a>}.java_writeJavadoc(self) unless context[:rsm6WebDocURI].empty?

  write("    */\n")
end

#java_writeOperationsObject

iterate java_write on operations



808
809
810
811
812
# File 'lib/ontomde-uml2-java/java.rb', line 808

def java_writeOperations
  #sort has been added because ownedOperation order is random
  #which is cause false change detection on versionned file
  uml_ownedOperation.sort { |a,b| a.java_Name.to_s <=> b.java_Name.to_s }.each { |o| o.java_write}
end

#java_writePackageDeclaration(&block) ⇒ Object

write java package declaration (Uses java_qualifiedName)

Example:

  • package aPackage;

  • package aPackage.aPackage2;

  • //package –none–



704
705
706
707
708
709
710
711
712
# File 'lib/ontomde-uml2-java/java.rb', line 704

def java_writePackageDeclaration(&block)
  p = umlx_package
  if p.nil?
    write("//package --none--;\n")
  else
    write("package #{p.java_qualifiedName};\n")
  end
  yield
end

#java_writeQualifiedGetterBody(oa) ⇒ Object



485
486
487
488
489
490
491
492
493
494
495
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 485

def java_writeQualifiedGetterBody(oa)
	write("/* TPL:0018 */\n")
	write("return   #{oa.java_NameProperty}.get(")
	sep=""
	oa.uml_qualifier.each { |key|
			write(sep)
			sep=","
			write(key.java_Name)
		}
	write(");\n")
end

#java_writeQualifiedPutterBody(oa) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 126

def java_writeQualifiedPutterBody(oa)
	j=""
	sep=""
	oa.uml_qualifier.each { |key|
		j=j+sep+key.java_Name
		sep=","
	}
	write <<END
{
#{java_qualifierNavigabilityWarning(oa)}
if(#{getterParameterName(oa)}==null) {
   #{java_this(oa)}#{oa.java_NameProperty}.remove(#{j});
 } else {
   #{java_this(oa)}#{oa.java_NameProperty}.put(#{j},#{getterParameterName(oa)});
 }
}
END
end

#java_writeSuggesterBody(oa) ⇒ Object



7
8
9
10
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 7

def java_writeSuggesterBody(oa)
	#TODO: recherche du composite commun
	write("/* TPL:0001 */ return null;\n")
end

#java_writeSuggesterBodyEnum(oa) ⇒ Object

Write code for a suggester for a parameter enum



18
19
20
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 18

def java_writeSuggesterBodyEnum(oa)
	java_writeSuggesterBodyEnumWithType(oa,oa.uml_type_one)
end

#java_writeSuggesterBodyEnumWithType(oa, enum, isCreateAndAddSuggester = false) ⇒ Object

Write code for a suggester returning enum given has parameter if lowerValue is zero, null is also added (except if createAndAdd)



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 23

def java_writeSuggesterBodyEnumWithType(oa,enum,isCreateAndAddSuggester=false)
	write <<END
/* TPL:0002 */
java.util.ArrayList<#{enum.java_qualifiedName}> ret=new java.util.ArrayList<#{enum.java_qualifiedName}>();
#{ (oa.umlx_lowerValueIsZero? && (!isCreateAndAddSuggester))  ? %{ret.add(null);} : %{} } /* TPL:0002i */
for(int i=java.lang.reflect.Array.getLength(#{enum.java_qualifiedName}.values())-1; i>=0 ; i--){
	ret.add(#{enum.java_qualifiedName}.values()[i]);
	}
return ret;
END
end

#java_writeSuggesterTypeBodyEnum(oa, isCreateAndAdd = false) ⇒ Object

Write code for a composition createAndAdd suggester



13
14
15
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 13

def java_writeSuggesterTypeBodyEnum(oa,isCreateAndAdd=false)
	java_writeSuggesterBodyEnumWithType(oa,oa.uml_type_one.java_enumAssignableDataType_one,isCreateAndAdd)
end

#struts_addAllOperationAggregateParameterClass!(biz) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ontomde-uml2-java/operationAsClass.rb', line 68

def struts_addAllOperationAggregateParameterClass!(biz)
	mpc=self
	mpc.struts_bizOperation=biz
	biz.struts_bizOperationReverse_add(mpc)
	#biz.struts_bizForm=mpc
	mpc.uml_name="#{biz.umlx_owner_one.java_Name}#{biz.java_Name}MPC"
	(biz.uml_ownedParameter+biz.uml_returnResult).each { |param|
		#next if param.uml_direction_one.isReturn?
		mpcp=mpc.umlx_createAndAddProperty(mpc.rdf_uri+"_mpc3")
		param.umlx_copyToAttributeProperty(mpcp)
		mpcp.uml_name= param.uml_direction_one.isReturn? ? STRUTS_RESULT_PARAM_NAME : param.uml_name
	}
	mpc.struts_addApplyToParameter!(biz)
	mpc.struts_addProceed!(biz)
	#mpc.apaCom_addLogger!
end

#struts_addApplyToParameter!(biz) ⇒ Object



85
86
87
88
89
90
# File 'lib/ontomde-uml2-java/operationAsClass.rb', line 85

def struts_addApplyToParameter!(biz)
	mpc=self
	m,m1,m2=mpc.umlx_createAndAddAssociation(mpc.rdf_uri+"_apply",biz.umlx_owner_one)
	m1.uml_name=STRUTS_APPLY_TO_PARAM
	m2.uml_name="#{STRUTS_APPLY_TO_PARAM}_inv"
end

#struts_addProceed!(biz) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ontomde-uml2-java/operationAsClass.rb', line 92

def struts_addProceed!(biz)
	mpc=self
	cpt=mpc.umlx_createAndAddOperation(mpc.rdf_uri+"_proceed","proceed")
	params=""; sep=""
	hasRP=false
	(biz.uml_ownedParameter+biz.uml_returnResult).each { |param|
		if param.uml_direction_one.isReturn?
			hasRP=true
			next
		end
		params="#{params}#{sep}#{param.java_Name}"
		sep=","
		}
	if(biz.uml_raisedException.empty?)
	cpt.java_code=%{
		#{hasRP ? "#{STRUTS_RESULT_PARAM_NAME}=" : ""} #{STRUTS_APPLY_TO_PARAM}.#{biz.java_Name}(#{params});
	}
	else
	cpt.java_code=%{
	try {
		//log.error("before biz method");
		//log.error("applyTo="+#{STRUTS_APPLY_TO_PARAM});
		#{hasRP ? "#{STRUTS_RESULT_PARAM_NAME}=" : ""} #{STRUTS_APPLY_TO_PARAM}.#{biz.java_Name}(#{params});
		//log.error("after biz method");
		//log.error("result="+#{hasRP ? STRUTS_RESULT_PARAM_NAME : %{"-none-"}});
	} catch(Exception e) {
		//TODO: implement proper exception handling
		throw new java.lang.RuntimeException(e);
	}
	}
	end

end

#umlx_literal(val) ⇒ Object



35
36
37
38
39
# File 'lib/ontomde-uml2-java/accessorCode.rb', line 35

def umlx_literal(val)
	r=Cuml_LiteralInteger.new(rdf_model,nil)
	r.uml_value=val
	return r
end