Method: Muml_Classifier#java_addCreateAndAppender!
- Defined in:
- lib/ontomde-uml2-java/accessorCode.rb
#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 |