Module: Muml_Classifier

Includes:
Mjava_Annotation, Mxsd_Annotation
Defined in:
lib/ontomde-java/jpa/jpa.rb,
lib/ontomde-java/jpa/jpa.rb,
lib/ontomde-java/java/xsd.rb,
lib/ontomde-java/flex/main.rb,
lib/ontomde-java/java/java.rb,
lib/ontomde-java/java/equals.rb,
lib/ontomde-java/java/tenant.rb,
lib/ontomde-java/jpa/locking.rb,
lib/ontomde-java/struts/form.rb,
lib/ontomde-java/struts/form.rb,
lib/ontomde-java/crank/equals.rb,
lib/ontomde-java/crank/helper.rb,
lib/ontomde-java/java/javadoc.rb,
lib/ontomde-java/java/refactor.rb,
lib/ontomde-java/struts/action.rb,
lib/ontomde-java/crank/facelets.rb,
lib/ontomde-java/java/component.rb,
lib/ontomde-java/struts/jsp_edit.rb,
lib/ontomde-java/crank/validation.rb,
lib/ontomde-java/java/accessorCode.rb,
lib/ontomde-java/java/contextualize.rb,
lib/ontomde-java/java/enumAssignable.rb,
lib/ontomde-java/struts/localeAction.rb,
lib/ontomde-java/struts/localeAction.rb,
lib/ontomde-java/java/operationAsClass.rb,
lib/ontomde-java/java/operationAsClass.rb,
lib/ontomde-java/java/accessorSignature.rb,
lib/ontomde-java/java/accessorSignature.rb,
lib/ontomde-java/java/annotationOntoMDE.rb,
lib/ontomde-java/java/enumCompatibilityLayer.rb

Constant Summary collapse

ACTIONSCRIPT_IMPORT_COMPUTED_DEPENDENCIES =
true
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

[  ]
TENANT_FIELD_NAME =
"tenantOwner"
TENANT_FIELD_BEAN_NAME =
"TenantOwner"
DB_OBJECT_VERSION_FIELD =
"objectVersion"
STRUTS_REQUESTED_CREATION_TYPE_FIELD_NAME =
"reqType"
STRUTS_REQUESTED_CREATION_TYPE_FIELD_PROP =
"ReqType"
STRUTS_DISPATCH_FIELD_NAME =
"doWhat"
STRUTS_DISPATCH_FIELD_METH =
"DoWhat"
STRUTS_REQUESTED_TAB =
"reqtab"
STRUTS_FORM_INTERFACE =
"xmda.struts.Form"
STRUTS_ACCEPT_NULL_FIELD_IN_FORMS =
true
STRUTS_NEW_ACTION =
"newa"
STRUTS_CREATE_ACTION =
"sgbd_create"
STRUTS_UPDATE_ACTION =
"sgbd_update"
STRUTS_READ_ACTION =
"sgbd_read"
STRUTS_DELETE_ACTION =
"sgbd_delete"
STRUTS_PROCEED_ACTION =
"biz_proceed"
STRUTS_INPUT_FWD =
"inputfw"
STRUTS_RESULTS_FWD =

TODO

"retour"
STRUTS_RETURN_ACTION =

terminate local treatment and return control to calling controller.

"returnTo"
STRUTS_RESUME_ACTION =

Resume local treatment avect geting control back from another controler.

"resumeAct"
STRUTS_REFRESH_ACTION =
"executeRefresh"
STRUTS_SGBD_STATE =
"sgbd_state"
STRUTS_SGBD_STATE_PROP =
"Sgbd_state"
STRUTS_ACTION_MAPPING =

STRUTS_RETURN_TO_FIELD=“jsp_return_to” STRUTS_RETURN_TO_PROP=“Jsp_return_to”

"org.apache.struts.action.ActionMapping"
STRUTS_ACTION_FORWARD =
"org.apache.struts.action.ActionForward"
STRUTS_ACTION_STARTEDIT =
"startEditAction"
STRUTS_SESSION_KEY_EditAction =
"objToEdit"
JUMP_TO_PROCEED =
<<ENDSKIP
			if (form.getReference().get#{STRUTS_APPLY_TO_PROP}()!=null) {
  				//form contains only #{STRUTS_APPLY_TO_PROP} field and it is not null
				//skip input screen and jump to #{STRUTS_PROCEED_ACTION}
				return #{STRUTS_PROCEED_ACTION}(mapping, abstractForm, request, response);
			}
ENDSKIP
PROCEED_ACTION_CODE =
<<ENDTPL
String msg="unexpected value for #{STRUTS_SGBD_STATE_PROP} in #{STRUTS_PROCEED_ACTION}";
log.error(msg);
org.apache.struts.action.ActionErrors ae=new org.apache.struts.action.ActionErrors();
ae.add("Error processing request",new  org.apache.struts.action.ActionMessage("errors.ioException",msg));
saveErrors(request, ae);
return mapping.findForward("#{STRUTS_INPUT_FWD}");
ENDTPL
STRUTS_SETSKIN_ACTION =
"setSkin"
STRUTS_SETTIMEZONE_ACTION =
"setTimeZone"
STRUTS_SETLOCALE_ACTION =
"setLocale"
USE_PAGINATION =
false
USE_HELPER_FOR_ACCESSORS =

generate add/… using helper instead of inlining

true
STRUTS_SETSKIN_FIELD =
"skin"
STRUTS_SETTIMEZONE_FIELD =
"struts_tz"
STRUTS_SETTIMEZONE_BEAN =
"Struts_tz"
STRUTS_SETLOCALE_LANGUAGE_FIELD =
"strutsLanguage"
STRUTS_SETCOUNTRY_FIELD =
'strutsCountry'
STRUTS_APPLY_TO_PARAM =

name of property which stores the object whose business method will be invoked.

"applyTo"
STRUTS_APPLY_TO_PROP =

name of bean property which stores the object whose business method will be invoked.

"ApplyTo"
STRUTS_RESULT_PARAM_NAME =
"_result"

Instance Method Summary collapse

Methods included from Mjava_Annotation

#java_writeAnnotation, #java_writeMdatkAnno, #java_writeParamAnnotation

Methods included from Mxsd_Annotation

#xsd_writeAnnotation

Instance Method Details

#as_destinationNameObject



76
77
78
# File 'lib/ontomde-java/flex/main.rb', line 76

def  as_destinationName
	return "dst-#{as_qualifiedName}"
end

#as_FDS_writeConfigurationObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ontomde-java/flex/main.rb', line 44

def as_FDS_writeConfiguration
	write %{
<destination id="#{as_destinationName}">
<adapter ref="#{Mrdf_Repository::ACTIONSCRIPT_JAVA_ADAPTER_ID}"/>
<properties>
 <source>#{java_qualifiedName}Assembler</source>
 <scope>application</scope>
 <metadata>
   <identity property="id"></identity>
#{mtk_stss{()}}
 </metadata>
 <server>
<fill-method>
	<name>load</name>
</fill-method>
<fill-method>
	<name>load</name>
	<params>java.lang.String</params>
</fill-method>
<sync-method>
	<name>sync</name>
</sync-method>
 </server>
</properties>
</destination>
}
end

#as_FileNameObject



26
27
28
# File 'lib/ontomde-java/flex/main.rb', line 26

def as_FileName
	return "#{as_FilePath}#{as_Name}.as"
end

#as_write_metadataObject



71
72
73
74
75
# File 'lib/ontomde-java/flex/main.rb', line 71

def 
	uml_ownedAttribute.each { |a|
		a.
	}
end

#as_writePackageDeclaration(&block) ⇒ Object



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

def as_writePackageDeclaration(&block)
	p = umlx_package
	if p.nil?
		write("package {\n")
	else
		write("package #{p.as_qualifiedName} {\n")
	end
	yield
	if p.nil?
		write("//end of package *unnamed*\n")
	else
		write("} // end of package #{p.as_qualifiedName};\n")
	end
end

#crank_crud_relationshipObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ontomde-java/crank/facelets.rb', line 115

def crank_crud_relationship
  rel = ""
  rels = eachCrankBeanRelations
  rels.each { |a|
     if !a.umlx_isComposite? && !a.java_isManyAssociation?
        rel << crank_simpleRelationHelper(a)
     end
  }
  bManyAsociation = false
  rels.each { |a|
     if !a.umlx_isComposite? && a.java_isManyAssociation?
        if !bManyAsociation
          rel << "<rich:tabPanel width=\"100%\">\n"
          bManyAsociation = true
        end
        rel << "   <rich:tab label=\"${crud:createLabel('#{a.java_Name}')}\">\n"
        rel << crank_simpleRelationHelper(a)
        rel << "   </rich:tab>\n"
     end
  }   
  if bManyAsociation
     rel << "</rich:tabPanel>\n"
  end
  bManyAsociation = false
  rels.each { |a|
     if a.crank_isMasterFromMasterDetail?
        if !bManyAsociation
          rel << "<rich:tabPanel width=\"100%\">\n"
          bManyAsociation = true
        end
        rel << "   <rich:tab label=\"${crud:createLabel('#{a.java_Name}')}\">\n"
        rel << crank_masterDetailRelationHelper(a)
        rel << "   </rich:tab>\n"
     end
  }
  if bManyAsociation
     rel << "</rich:tabPanel>\n"
  end
  return rel
end

#crank_editSimplePropertiesObject



239
240
241
# File 'lib/ontomde-java/crank/facelets.rb', line 239

def crank_editSimpleProperties
  return crank_listingProperties
end

#crank_generate_formObject



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
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ontomde-java/crank/facelets.rb', line 70

def crank_generate_form
  mtk_writeSession("#{context[:webContentDir]}/pages/crud/#{self.java_Name}/Form.xhtml") {
    write <<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
xmlns:rich="http://richfaces.ajax4jsf.org/rich"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:crank="http://www.googlecode.com/crank"
xmlns:validation="http://code.google.com/p/krank/validation"
>

<ui:composition template="/templates/layout.xhtml">
<ui:define name="content">

  <c:set var="adapter" value="${#{self.java_Name.downcase}Crud}" />
  <c:set var="crud" value="${adapter.controller}" />
  
  <span class="pageTitle">#{self.java_Name} Entry Form</span>

  <a4j:region renderRegionOnly="false"> 
    <a4j:form
      id="#{self.java_Name.downcase}Form">
      
      <crank:form
        crud="${crud}" 
        parentForm="#{self.java_Name.downcase}Form"
        propertyNames="#{self.crank_editSimpleProperties}"
        readOnlyProperties="#{self.crank_readOnlyProperties}">
        #{crank_crud_relationship}
      </crank:form>
    </a4j:form>
  </a4j:region>

</ui:define>
</ui:composition>
</html>
END
  }
end

#crank_generate_listingObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
66
67
# File 'lib/ontomde-java/crank/facelets.rb', line 5

def crank_generate_listing
  mtk_writeSession("#{context[:webContentDir]}/pages/crud/#{self.java_Name}/Listing.xhtml") {
    write <<END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
xmlns:rich="http://richfaces.ajax4jsf.org/rich"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:crank="http://www.googlecode.com/crank"
>
<ui:composition template="/templates/layout.xhtml">
<ui:define name="javascript">
  <script type="text/javascript" src="${request.contextPath}/js/jquery.js"/>
  <script type="text/javascript" src="${request.contextPath}/js/messages.js"/>
  <script type="text/javascript" src="${request.contextPath}/js/details.js"/>
</ui:define>
<ui:define name="content">

  <h:outputText value="#{self.java_Name}s" styleClass="pageTitle"/>

  <a4j:region renderRegionOnly="false"> 
    <a4j:form id="${daoName}ListForm">
      <crank:listing 
        paginator="${paginators['#{self.java_Name}']}" 
        jsfCrudAdapter="${cruds['#{self.java_Name}']}" 
        propertyNames="#{self.crank_listingProperties}"
        pageTitle="${daoName}"
        parentForm="${daoName}ListForm"
        reRender="${daoName}ListForm"
        crud="${cruds['#{self.java_Name}'].controller}"         
END
    if crank_hasCrankBeanChild?
        write <<END

        clazzs="
END
        isFirstSubclazz = true
        crank_subCrankBean.each{|c|
           if isFirstSubclazz
             isFirstSubclazz = false
           elsif
             write ","
           end
           write "#{c.java_Name}"
        }
        write "\""
    end
    
    write <<END
 />
    </a4j:form>
  </a4j:region>
      
  
</ui:define>
</ui:composition>
</html>
END
  }
end

#crank_generate_validationObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ontomde-java/crank/validation.rb', line 5

def crank_generate_validation    
  uml_ownedAttribute.each { |a|    
    #next if a.umlx_isComposite? 
    #next unless a.umlx_isAttribute?
    
    if a.umlx_hasStereotype?('Required')
        a.java_annotation_add("@org.crank.annotations.validation.Required")
    end
    if a.uml_type_one.kind_of?(Muml_DataType) && !a.uml_type_one.crank_validation_annotation.nil?
      a.java_annotation_add(a.uml_type_one.crank_validation_annotation)
    end
  }
end

#crank_hasCrankBeanChild?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/ontomde-java/crank/helper.rb', line 25

def crank_hasCrankBeanChild?
  uml_general_inv.each { |g|
    return true
  }
  return false
end

#crank_isTopCrankBeanObject



17
18
19
20
21
22
23
# File 'lib/ontomde-java/crank/helper.rb', line 17

def crank_isTopCrankBean
  uml_generalization.each { |g|
    next if g.kind_of?(Muml_Interface)      
    return false if !g.uml_general_one.db_isTransient?
  }
  return true;
end

#crank_listingPropertiesObject



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/ontomde-java/crank/facelets.rb', line 195

def crank_listingProperties
  attributes = nil
  umlx_ownedAndInheritedAttribute.each { |a|    
    next if a.umlx_isComposite? 
    next unless a.umlx_isAttribute?
    #next if a.uml_type_one.db_isTransient?
    next if a.uml_isStatic?
    next if a.uml_isReadOnly?
    next if "id" == "#{a.java_Name}" #TODO Faire mieux
    next if "objectVersion" == "#{a.java_Name}" #TODO Faire mieux
    if attributes.nil?
      attributes = "#{a.java_Name}"
    else
      attributes << ",#{a.java_Name}"
    end
  }
  if (attributes.nil?)
    attributes = ""
  end
  return attributes
end

#crank_masterDetailRelationHelper(a) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/ontomde-java/crank/facelets.rb', line 173

def crank_masterDetailRelationHelper(a)
  rel=<<CODE
   <crank:detailListingExtended detailController="${#{a.java_Name.downcase}From#{java_Name}To#{a.uml_type_one.java_Name}Controller}"
                                      propertyNames="#{a.uml_type_one.crank_listingProperties}" editRelation="${true}"
CODE
    if a.uml_type_one.crank_hasCrankBeanChild?
        rel << " clazzs=\""
        isFirstSubclazz = true
        a.uml_type_one.crank_subCrankBean.each{|c|
           if isFirstSubclazz
             isFirstSubclazz = false
           elsif
             rel <<  ","
           end
           rel <<  "#{c.java_Name}"
        }
        rel <<  "\""
    end
  rel << " />\n"
  return rel    
end

#crank_readOnlyPropertiesObject



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/ontomde-java/crank/facelets.rb', line 217

def crank_readOnlyProperties
  attributes = nil
  umlx_ownedAndInheritedAttribute.each { |a|    
    next if a.umlx_isComposite? 
    next unless a.umlx_isAttribute?
    #next if a.uml_type_one.db_isTransient?
    next if a.uml_isStatic?
    next if !a.uml_isReadOnly?
    next if "id" == "#{a.java_Name}" #TODO Faire mieux
    next if "objectVersion" == "#{a.java_Name}" #TODO Faire mieux
    if attributes.nil?
      attributes = "#{a.java_Name}"
    else
      attributes << ",#{a.java_Name}"
    end      
  }
  if (attributes.nil?)
    attributes = ""
  end
  return attributes
end

#crank_simpleRelationHelper(a) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/ontomde-java/crank/facelets.rb', line 156

def crank_simpleRelationHelper(a)
  rel=""
  if a.java_isManyAssociation?
    rel += "      <crank:selectManyExtended jsfSelectManyController="
  elsif
    rel += "      <crank:selectOneListing jsfSelectOneController="
  end
  rel +=<<CODE
 "${#{a.java_Name.downcase}From#{java_Name}To#{a.uml_type_one.java_Name}Controller}"
          propertyNames="#{a.uml_type_one.crank_listingProperties}"
          parentForm="#{self.java_Name.downcase}Form" editRelation="${true}"
          />
          
CODE
  return rel    
end

#crank_subCrankBean(ret = Set.new, abstractIncluded = false) ⇒ Object

Include the class too



33
34
35
36
37
38
# File 'lib/ontomde-java/crank/helper.rb', line 33

def crank_subCrankBean(ret=Set.new, abstractIncluded=false)
  umlx_assignableClassifier().sort{ |a,b| a <=> b}.each{ |c|
     ret.add(c) if abstractIncluded || !c.uml_isAbstract?
  }
  return ret
end

#getterParameterName(oa) ⇒ Object

returns a string containing the name of getter parameter relative to a uml parameter.



159
160
161
162
# File 'lib/ontomde-java/java/accessorSignature.rb', line 159

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

end

#java_addAccessors!Object

Adds accessors when needed for UML properties.

Reference: #java_transform!



73
74
75
# File 'lib/ontomde-java/java/accessorSignature.rb', line 73

def java_addAccessors!
  java_transform!
end

#java_addAccessorsFor!(oa) ⇒ Object

Adds accessors for uml property oa passed as parameter.

Reference:

  • java_addGlobalGetter!

  • java_addGlobalSetter!

  • java_addQualifiedPutter!

  • java_addQualifiedGetter!

  • java_addAppender!

  • java_addCreateAndAppender!

  • java_addWithIndexAppender!

  • java_addAppenderQualifier!

  • java_addRemover!

  • java_addSuggester!

  • java_addSuggesterType!

  • java_addCreater!



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
# File 'lib/ontomde-java/java/accessorSignature.rb', line 92

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?
  #static and final interface parameter are indeed consts
  return if oa.umlx_owner_one.kind_of?(Muml_Interface) && (oa.java_isFinal?||oa.uml_isStatic?)

  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.



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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/ontomde-java/java/accessorCode.rb', line 439

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_Repository,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
\t\txmda.crud.Helper.genericAddIgnoreNull(#{java_this(oa)}#{oa.java_NameProperty},#{getterParameterName(oa)} ); 
END
#      add.java_code=<<END
#\t\tif (#{getterParameterName(oa)} == null) {
#\t\t\treturn;
#\t\t}
#\t\t#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)});
#END
  elsif (oe.nil? || !oe.umlx_isNavigable?) && oa.java_use_Arrays?
    add.java_code=<<END
\t\tif (#{getterParameterName(oa)} == null) {
\t\t\treturn;
\t\t}
\t\t#{oa.uml_type_one.java_qualifiedName}[] newArray = null;
\t\tif (#{java_this(oa)}#{oa.java_NameProperty} == null) {
\t\t\tnewArray = new #{oa.uml_type_one.java_qualifiedName}[1];
\t\t\tnewArray[0] = #{getterParameterName(oa)};
\t\t} else {
\t\t\tnewArray = new #{oa.uml_type_one.java_qualifiedName}[1+#{java_this(oa)}#{oa.java_NameProperty}.length];
\t\t\tSystem.arraycopy(#{java_this(oa)}#{oa.java_NameProperty}, 0, newArray,0, #{java_this(oa)}#{oa.java_NameProperty}.length);
\t\t\tnewArray[#{java_this(oa)}#{oa.java_NameProperty}.length] = #{getterParameterName(oa)};
\t\t}
\t\t#{java_this(oa)}#{oa.java_NameProperty} = newArray;
END


  elsif oe.umlx_upperValueIsOne?
    #*-1
    add.java_code=<<END
\t\tif (xmda.crud.Helper.genericAddIgnoreNull(#{java_this(oa)}#{oa.java_NameProperty},#{getterParameterName(oa)} )) {
\t\t\t#{getterParameterName(oa)}.set#{oe.java_NameBean}(this);
\t\t}
END

#      add.java_code= <<END
#\t\tif (#{getterParameterName(oa)} == null) {
#\t\t\treturn;
#\t\t}
#\t\tif (#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)})){
#\t\t\t#{getterParameterName(oa)}.set#{oe.java_NameBean}(this);
#\t\t}
#END
  else
    #*-*
    # second test avoids loop
    add.java_code=<<END
\t\tif (#{getterParameterName(oa)} == null) {
\t\t\treturn;
\t\t}
\t\tif (#{java_this(oa)}#{oa.java_NameProperty}.add(#{getterParameterName(oa)})) {
\t\t\t#{getterParameterName(oa)}.add#{oe.java_NameBean}(this);
\t\t}
END
  end

end

#java_addAppenderQualifier!(oa) ⇒ Object



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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/ontomde-java/java/accessorCode.rb', line 163

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_Repository,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
	//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
\t\tif (#{ip.java_Name} == null) {
\t\t\treturn; 
\t\t}
\t\tif (#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name})) {
\t\t\t#{ip.java_Name}.set#{oe.java_NameBean}(this);
\t\t}
END
  else
    #*-*
    add.java_code=<<END
\t\tif (#{ip.java_Name} == null) {
\t\t\treturn; 
\t\t}
\t\tif (#{java_this(oa)}#{oa.java_NameProperty}#{qualCall}.add(#{ip.java_Name})) {
\t\t\t#{ip.java_Name}.remove#{oe.java_NameBean}(this);
\t\t}
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.



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/ontomde-java/java/accessorCode.rb', line 388

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=%{\t\t#{oa.uml_type_one.java_qualifiedName} ret = (#{oa.uml_type_one.java_qualifiedName})#{java_getCrudHelperClass!.java_qualifiedName}.createFromEnum(requestedType);#{%{
\t\tret.setTenantOwner(getTenantOwner());} if context[:multiTenant]}
\t\t#{oa.umlx_upperValueIsOne? ? "set" : "add"}#{oa.java_NameBean}(ret);
\t\treturn ret;}
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



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/ontomde-java/java/accessorCode.rb', line 221

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)

  tenantClause=""
  if context[:multiTenant]
    #call constructor with tenant
    tenantClause="(get#{TENANT_FIELD_BEAN_NAME}())"
  end
  
  rp=Cuml_Parameter.new(rdf_Repository,get.rdf_uri+"_p1")
  rp.uml_name="\t\treturn"
  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}#{tenantClause}"
    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_addDeleter!Object

add a deleter that support dangling links deleted objects are mark deleted and should be processed by a purging script in database.



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
66
67
68
# File 'lib/ontomde-java/java/accessorSignature.rb', line 34

def java_addDeleter!
  return if kind_of?(Muml_Enumeration) || kind_of?(Muml_Interface) || kind_of?(Muml_Component)
  return unless umlx_businessMethod?
  return if db_isTransient?
  m=umlx_createAndAddOperation(self.rdf_uri+"_delete")
  m.uml_name="logicalDelete"
  m.uml_class=self
  m.uml_visibility=Cuml_VisibilityKind::Public
  m.uml_isStatic=RDF_FALSE

  code2=""
  m.umlx_createAndAddComment(m.rdf_uri+"_comment","Mark object as being logicaly deleted.\nUse this method when object cannot be physically deleted because it might be\nreferenced by some other objects in memory or database.\nNote that referencer of this objects will have dangling links.\nObject fields are reseted.\nDepending on requirements, it may be\nnecessary to implement a database purge.")

  self.uml_ownedAttribute.sort{ |a,b| a.java_Name.to_s <=> b.java_Name.to_s}.each {|a|
   v=DatatypeMapping.instance.getMapping(a.uml_type_one)
   c=(a.uml_isReadOnly? ) ? "// " : ""
   if(a.umlx_upperValueIsOne?)
    code2+=%{\t\t#{c}this.set#{a.java_NameBean}(#{v.java_getUndefinedValue});\n}
   else
    code2+=%{\t\t#{c}this.set#{a.java_NameBean}(null);\n}
     	    end 
  }

  code1=""
  if self.uml_generalization.empty? || self.uml_generalization_one.uml_general_one.java_ignoreMe?(true)
	p=umlx_createAndAddProperty(self.rdf_uri+"_deletable")
	p.uml_type=umlx_dataType_boolean
	p.uml_name="isLogicallyDeleted"
  	code1+="\t\tthis.set#{p.java_NameBean}(true);\n" 
  elsif !self.uml_generalization.empty?
	code1+="\t\tsuper.logicalDelete();\n" 
  end
  m.java_code=code1+code2
	
end

#java_addEnumAssignable!Object

add an enum assignable for this model element



43
44
45
46
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
# File 'lib/ontomde-java/java/enumAssignable.rb', line 43

def java_addEnumAssignable!
	return if self.java_qualifiedName.to_s==java_getJavaEnumInterface.java_qualifiedName.to_s
	#log.debug { "java_addEnumAssignable! for #{self}::#{self.class.name}" }
	p=nil
	#if self.kind_of?(Muml_Interface)
	#then
	#	p=umlx_owner_one
	#	p=p.umlx_getOrCreatePackage(context[:enumAssignableSubPackage,"enumCreate"],p)
	#else
		p=self
	#end
	ret=p.umlx_createAndAddEnumeration(self.rdf_uri+"_enumAssignable","#{uml_name} Assignable")
	ret.umlx_createAndAddImplementation(java_getJavaEnumInterface)
	ret.umlx_createAndAddImplementation(java_getJavaEnumAssignInterface)
	self.java_enumAssignableDataType=ret
	ret.java_customCode= <<END
\t\tClass<?> type;

\t\tpublic Class<?> getType() {
\t\t\treturn type;
\t\t}

\t\t#{ret.java_Name}(Class<?> _type) {
\t\t\tthis.type = _type;
\t\t}

\t\t#{ret.java_Name}() {
\t\t\tthis.type = null;
\t\t}
END

	umlx_assignableClassifier.each { |c|
		next if c.uml_isAbstract?
		#lit=ret.umlx_createAndAddLiteral(c.java_qualifiedName.to_s.gsub(/\./,JAVA_MAGIC_DOT_STRING));
		lit=ret.umlx_createAndAddLiteral(c.java_Name)
		lit.java_initParameterValue_add("#{c.java_qualifiedName}.class")
	}

	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-java/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-java/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.



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/ontomde-java/java/accessorSignature.rb', line 289

def java_addGlobalGetter!(oa)
  return nil unless context[:java_addGlobalGetter,true]
  #return if oa.uml_isDerived?
  #return unless oa.uml_isReadOnly?
  return oa.java_AttributeGlobalGetter_one 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.

Reference:

  • #java_writeGlobalSetterBody



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/ontomde-java/java/accessorSignature.rb', line 317

def java_addGlobalSetter!(oa)
  return nil unless context[:java_addGlobalSetter,true]
  return if oa.uml_isReadOnly?
  return oa.java_AttributeGlobalSetter_one 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-java/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



137
138
# File 'lib/ontomde-java/java/accessorCode.rb', line 137

def java_addQualifiedAppender!(oa)
end

#java_addQualifiedGetter!(oa) ⇒ Object

adds a qualified getter for uml property oa.

Reference:

  • #java_writeQualifiedGetterBody



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/ontomde-java/java/accessorSignature.rb', line 342

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,'_qual')

  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) {
...
}


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/ontomde-java/java/accessorSignature.rb', line 185

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,'_qual')
  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



134
135
# File 'lib/ontomde-java/java/accessorCode.rb', line 134

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.



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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ontomde-java/java/accessorCode.rb', line 66

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_Repository,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
\t\t#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)});
END
  elsif oe.umlx_upperValueIsOne?
    set.java_code=<<END
\t\t#{qualInit}
\tif(#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)})#{qualCheckRemove}) {
\t\t\t#{getterParameterName(oa)}#{qualCall}.set#{oe.java_NameBean}(null);
	}
END
  else
    set.java_code=<<END
\t\tif(#{java_this(oa)}#{oa.java_NameProperty}.remove(#{getterParameterName(oa)})) {
\t\t\t#{getterParameterName(oa)}#{qualCall}.remove#{oe.java_NameBean}(this);
\t\t}
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.



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/ontomde-java/java/accessorSignature.rb', line 209

def java_addSuggester!(oa)
  return if oa.java_isSuggester?
  return if oa.java_noSuggester?
  return if oa.uml_isReadOnly?
  return if oa.umlx_owner_one.umlx_hasStereotype?('DTO')
  return if oa.umlx_owner_one.kind_of?(Muml_Interface)
  #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.

Reference:

  • #java_writeSuggesterTypeBodyEnum

  • #java_createAndAddMethodFromProperty

  • #umlx_createAndAddParameter



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
# File 'lib/ontomde-java/java/accessorSignature.rb', line 257

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_addTenantField!(tenantClass = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/ontomde-java/java/tenant.rb', line 55

def java_addTenantField!(tenantClass=nil)
  return unless context[:multiTenant]
  tenantClass=rdf_Repository.java_getTenantClass if tenantClass.nil?
 # return if tenantClass==self
 #Tenant itself has a tenant field for homogenity
 #
  tf=umlx_createAndAddProperty("#{self.rdf_uri}_tenant",TENANT_FIELD_NAME)
  tf.uml_type=tenantClass
end

#java_addWithIndexAppender!(oa) ⇒ Object

adds a indexed appender method for uml property oa.

Example:

  • void addYourProperty( keyType key, valueObject)

Reference:

  • #java_addWithIndexAppenderBody



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/ontomde-java/java/accessorSignature.rb', line 366

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_Repository,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_Repository,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



519
520
521
522
523
524
525
526
# File 'lib/ontomde-java/java/accessorCode.rb', line 519

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

#java_contextualizeMyStaticProperties!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ontomde-java/java/contextualize.rb', line 15

def java_contextualizeMyStaticProperties!
  o=umlx_getCompositeRec
  return if o.nil?
  
  uml_ownedAttribute.each {|att|
    next unless att.uml_isStatic?
    oe=o.umlx_otherEnd
    puts "compositeRec   #{oe} #{o.class.name} #{o} <X>--> #{self}"
    att.uml_isStatic=RDF_FALSE
    att.uml_isDerived=RDF_TRUE
    att.uml_isReadOnly=RDF_TRUE
    self.java_addAccessorsFor!(att)
    att.java_AttributeGlobalGetter_one.java_code="return get#{oe.java_NameBean}().get#{att.java_NameBean}();"
    
#      owner.
#      att.
    
  }
  
#    next unless uml_isStatic?
#    ow=false
#    uml_ownedElement.each { |elt|
#      next unless elt.uml_isStatic?
#      if(ow)
#      
#    }
  
end

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

Helper method for creating an accessor method related to a property.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ontomde-java/java/accessorSignature.rb', line 124

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

  # propagate deprecated stereotype
  deprec=oa.umlx_returnStereotypeIfHas("deprecated")
  m.uml_appliedStereotype_add(deprec) unless deprec.nil?

  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



679
680
681
# File 'lib/ontomde-java/java/java.rb', line 679

def java_FileName
  return Pathname.new("#{java_FilePath}#{java_Name}.java").cleanpath.to_s
end

#java_generate_equalsAndHashObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/ontomde-java/crank/equals.rb', line 3

def java_generate_equalsAndHash
  ret=Set.new
  uml_ownedAttribute.each {|biz|
    ret << biz if biz.umlx_hasStereotype?("EqualsValue")
  }
  if !ret.empty?
    java_generateEquals(ret, !crank_isTopCrankBean)
    java_generateHashCode(ret)
  end
end

#java_generateClassifierObject

opens java file for writing with java_openOutStream and calls java_write



732
733
734
735
736
737
738
739
740
741
742
743
744
745
# File 'lib/ontomde-java/java/java.rb', line 732

def java_generateClassifier
  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_generateEquals(ret, callSuperEquals) ⇒ Object



15
16
17
18
19
20
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
# File 'lib/ontomde-java/crank/equals.rb', line 15

def java_generateEquals(ret, 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
  end
  meCode << <<CODE
final #{self.java_Name} _o = (#{self.java_Name}) o;
CODE
  ret.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
end

#java_generateHashCode(ret) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ontomde-java/crank/equals.rb', line 59

def java_generateHashCode(ret)
    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
  ret.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
 
end

#java_getCrudHelperClass!Object



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
301
302
303
304
305
306
307
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
373
374
375
376
377
378
379
380
# File 'lib/ontomde-java/java/accessorCode.rb', line 254

def java_getCrudHelperClass!
	helper=umlx_getOrCreateClass('xmda.crud.Helper')
	return helper unless helper.uml_ownedOperation.empty?
	helper.db_isTransient=RDF_TRUE
	helper.umlx_external=RDF_FALSE
	helper.java_customCode=<<END

public static Object createFromEnum(#{java_getJavaEnumAssignInterface.java_qualifiedName} requestedType) {
	if (requestedType == null) {
return null;
	}

	Class<?> t = requestedType.getType();
	try {
Class<?>[] p = new Class[0];
Object[]initArgs =new Object[0];
java.lang.reflect.Constructor<?>  c=t.getConstructor(p);
Object ret=c.newInstance(initArgs);
return ret;
	} catch (NoSuchMethodException e) {
e.printStackTrace();
throw new RuntimeException("Missing default constructor for"+t.getName(),e);
	} catch (IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException("Illegal access Exception on "+t.getName(),e);
	} catch (InstantiationException e) {
e.printStackTrace();
throw new RuntimeException("Instantiation exception on "+t.getName(),e);
	} catch (java.lang.reflect.InvocationTargetException e) {
e.printStackTrace();
throw new RuntimeException("Invocation Target Exception on "+t.getName(),e);
	}
}

	/*
* Helper for compacting code in add operations
*/
	@SuppressWarnings("unchecked")
	public static <T> T[] genericUnidirAdd(final T t, T[] oldVal) {
T[] newArray = null;
if (oldVal == null) {
	newArray = (T[]) new Object[1];
	newArray[0] = t;
} else {
	newArray = (T[]) new Object[1 + oldVal.length];
	System.arraycopy(oldVal, 0, newArray, 0, oldVal.length);
	newArray[oldVal.length] = t;
}
return newArray;
	}

	public static <T> java.util.List<T> arrayToList(T[] t) {
java.util.List<T> ret = null;
if (t == null) {
	ret=new java.util.ArrayList<T>();
} else {
	ret=java.util.Arrays.asList(t);
	//if RW: ret=new java.util.ArrayList<T>(ret);
}
return ret;
	}

	public static <T> java.util.List<T> arrayToListPlusNull(T[] t) {
java.util.List<T> ret = null;
if (t == null) {
	ret=new java.util.ArrayList<T>();
} else {
	ret=java.util.Arrays.asList(t);
	ret=new java.util.ArrayList<T>(ret);
}
ret.add(0,null);
return ret;
	}

	public static <T> boolean genericAddIgnoreNull(java.util.Collection<T> lst,
	T elt) {
if (elt != null) {
	return lst.add(elt);
}
return false; // no change
	}

	/** 
	* replace null Long by 0 Long
	* Method used by jpa module.
	*/
	public static Long longObjZeroForNull(Long id) {
if (id == null) {
	return Long.valueOf(0);
} else {
	return id;
}
	}

	/* method to be used by jpa */
	public static<T> java.util.List<T> addMissingItems(java.util.List<T> lstInOut,java.util.Collection<T> missings) {
for (java.util.Iterator<T> iterator = missings.iterator(); iterator.hasNext();) {
	T item = (T) iterator.next();
	if (!lstInOut.contains(item)) {
		lstInOut.add(item);
	}
}
return lstInOut;
	}

	/* returns lst if no null, or a newly created set otherwise */
	public static <T> java.util.Set<T> emptyNewCollectionIfNull(java.util.Set<T> lst) {
if (lst != null) {
	return lst;
} else {
	return new java.util.HashSet<T>();
}
	}

	/* returns lst if no null, or a newly created List otherwise */
	public static <T> java.util.List<T> emptyNewCollectionIfNull(java.util.List<T> lst) {
if (lst != null) {
	return lst;
} else {
	return new java.util.ArrayList<T>();
}
	}

END
	
	return helper
end

#java_getJavaAnnotationOntoMDEObject



20
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
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
# File 'lib/ontomde-java/java/annotationOntoMDE.rb', line 20

def java_getJavaAnnotationOntoMDE
  anno=umlx_getOrCreateClass(JAVA_ANNO_ONTOMDE_QNAME)
  if(anno.java_customCode.empty?)
    anno.umlx_createAndAddComment(anno.rdf_uri+"comment", %{
 Annotation used to specify which code sections should be overridden or preserved by OntoMDE MDA code generator.<p/>
 <p/>For example, &nbsp;@OntoMDE(reverse = { imports,javadoc } , uri="..." ) tells OntoMDE to preserve import and javadoc sections. Sections <b>not</b> listed in reverse list are <b>overwritten</b> by generator. 
 <p/>Annotation may be used on class,interface, enum inner-class, methods and attributes.
 <p/>Reverse zones types are: <b>imports</b> for class imports, <b>javadoc</b>, <b>annotations</b> and <b>code</b> for function code body.
 <p/>Please note that uri contains a unique key used by generator to identify the element that should never be modified.
 })
    anno.umlx_external=RDF_FALSE
    anno.uml_appliedStereotype_add(anno.umlx_getOrCreateStereotype("JavaAnnotation"))
    anno.java_customCode= <<ENDCODE
	public enum ZoneCode {
/**
 * Erase and replace this section with OntoMDE generated code.<br>
 *  
 */
nothing,

/**
 * Preserve imports related to this section when OntoMDE code generator is invoked.
 *   
 * Other elements (javadoc,annotations, ...) will not be preserved unless explicitely requested.<br>
 */
imports,

/**
 * Preserve javadoc related to this section when OntoMDE code generator is invoked.
 * Other elements (imports,annotations, ...) will not be preserved unless explicitely requested.<br>
 */
javadoc,

/**
 * Preserve annotations related to this section when OntoMDE code generator is invoked.
 * Other elements (imports,javadoc, ...) will not be preserved unless explicitely requested.<br>
 */
annotations,

/**
 * Preserve annotations related to this method's parameters when OntoMDE code generator is invoked.
 * Other elements (imports,javadoc,annotations, ...) will not be preserved unless explicitely requested.<br>
 */
anno_param,

/**
 * Preserve code body related to this method when OntoMDE code generator is invoked.
 * Other elements (imports,javadoc,annotations, ...) will not be preserved unless explicitely requested.<br>
 */
code,

/**
 * Preserve non-generated code (named custom code) included 
 * in this class/interface/enum when OntoMDE code generator is invoked.
 * This feature allows any utility methods/attributes to be added in a class.
 * Other elements (imports,javadoc,annotations, ...) will not be preserved unless explicitely requested. 
 */
custom

	}

	/**
* List of code section type that ontoMDE code will preserve on next
* generation. If empty, no element will be preserved. In other word, if
* empty, every element will be overwritten.<br>
*
*/
	ZoneCode[] reverse();

	/**
* URI used to identify uniquely model element related to this java
* construct.
*/
	String uri();
ENDCODE

  end
  return anno;
end

#java_getJavaEnumAssignInterfaceObject

return enum interface for this model element. (creates it if necessary).



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ontomde-java/java/enumAssignable.rb', line 97

def java_getJavaEnumAssignInterface
	ret=umlx_getOrCreateInterface(JAVA_ENUM_ASSIGN_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

		op=ret.umlx_createAndAddOperation("#{ret.rdf_uri}_getType}","getType")
		r=op.umlx_createAndAddReturnParameter("#{op.rdf_uri}_ret","return")
		r.uml_type=umlx_getOrCreateGeneric("java.lang.Class","?")
	end
	return ret
end

#java_getJavaEnumInterfaceObject

return enum interface for this model element. (creates it if necessary).



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/ontomde-java/java/enumAssignable.rb', line 85

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)


32
33
34
# File 'lib/ontomde-java/java/enumCompatibilityLayer.rb', line 32

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”) }



689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
# File 'lib/ontomde-java/java/java.rb', line 689

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.
    #NOTICE
    #        if context[:skipNoReverseMarker] 
    #        write <<NOTICE2
    #\/\/**
    #\/\/** This file was generated with option --skipNoReverseMarker
    #\/\/** Please set --no-skipNoReverseMarker if you wish to add a
    #\/\/** reverse="yes" section.}  
    #NOTICE2
    #      end
    #        
    #      write <<NOTICE3
    #\/\/**********************************************************************
    #\/\/** Generated with ontoMDE (ORANGE-FT/RD/BIZZ/CIL/SAM 2006-2008)
    #\/\/**********************************************************************
    #NOTICE3
    #
    #
    #    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_ownedOperationObject



974
975
976
977
978
979
980
981
# File 'lib/ontomde-java/java/java.rb', line 974

def java_ownedOperation 
  #sort has been added because ownedOperation order is random
  #which is cause false change detection on versionned file
  #
  # uri has been added because of method overloading
  # ' ' is added to preserve natural order (ex: xxx, xxxSug)
 return uml_ownedOperation.sort { |a,b| (a.java_Name.to_s+' '+a.rdf_uri) <=> (b.java_Name.to_s+' '+b.rdf_uri) }
end

#java_qualifierNavigabilityWarning(oa) ⇒ Object

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



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ontomde-java/java/accessorCode.rb', line 119

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

returns access method access to current element (empty if static context, this otherwise)



5
6
7
8
# File 'lib/ontomde-java/java/accessorCode.rb', line 5

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)



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

def java_transform!
  java_addDeleter!
  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



751
752
753
754
755
# File 'lib/ontomde-java/java/java.rb', line 751

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!).



993
994
995
996
997
998
# File 'lib/ontomde-java/java/java.rb', line 993

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)


799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# File 'lib/ontomde-java/java/java.rb', line 799

def java_writeClassBody
  java_writeClassComment
  java_writeJavadoc
  java_writeAnnotation
  java_writeMdatkAnno(['imports','javadoc','annotations','custom_code']) if context[:hasGlobalReverse]
  java_writeClassModifiers
  java_writeMetaClassName
  java_writeTemplateParameter
  java_writeExtends
  java_writeImplements # class seulement
  write("{\n")
  
  java_writeDeclarationSpecificOnBegin
  java_writeAttributes
  write("\n\n")
  #java_writeConstructors
  write("\n\n")
  java_writeOperations
  java_writeDeclarationSpecificOnEnd

  mtk_context(:innerClass=>true) {
    uml_nestedClassifier.each { |c|
      next unless c.kind_of?(Muml_Class) || c.kind_of?(Muml_Enumeration)
      #filter out Collaboration 
      c.java_write
    }
  }
  java_writeCustomCode
  write("}\n")
end

#java_writeClassCommentObject

Does nothing.



841
842
# File 'lib/ontomde-java/java/java.rb', line 841

def java_writeClassComment
end

#java_writeClassHeader(&block) ⇒ Object

write java header.

(Uses java_writePackageDeclaration, java_writeImports)

Exemple:

package pack1;
import xyz;


762
763
764
765
766
767
768
769
770
771
772
# File 'lib/ontomde-java/java/java.rb', line 762

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

#java_writeConstructorsObject

Does nothing.



853
854
# File 'lib/ontomde-java/java/java.rb', line 853

def java_writeConstructors
end

#java_writeCustomCodeObject

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



832
833
834
835
836
837
838
# File 'lib/ontomde-java/java/java.rb', line 832

def java_writeCustomCode
  mtk_protected(Mrdf_Resource::NOREVERSE,'custom_code',true) {
    write !java_customCode.empty? ? java_customCode : <<END
END
  }
  write("\n\n")
end

#java_writeDeclarationSpecificOnBeginObject

Does nothing.



845
846
# File 'lib/ontomde-java/java/java.rb', line 845

def java_writeDeclarationSpecificOnBegin
end

#java_writeDeclarationSpecificOnEndObject

Does nothing.



849
850
# File 'lib/ontomde-java/java/java.rb', line 849

def java_writeDeclarationSpecificOnEnd
end

#java_writeEnumStringMappingGetterCode(oa) ⇒ Object



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

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

  else
    write %{
	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



51
52
53
54
55
56
57
58
59
60
# File 'lib/ontomde-java/java/enumCompatibilityLayer.rb', line 51

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)});"
  else
    # TODO: provide java implementation
  end
end

#java_writeExtends(isTemplateParameter = false) ⇒ Object

write java extends instructions is necessary (Uses java_qualifiedName)

Example:

extends Class2,Class3


878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# File 'lib/ontomde-java/java/java.rb', line 878

def java_writeExtends(isTemplateParameter=false)
  #HACK for handling of faulty EA models
  if (!uml_name.to_s.index('FIX_UML_MODEL_unknown_exception',0).nil?)
	java_extends_add('java.lang.Exception')
  end

  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=isTemplateParameter ? " extends " : "\nextends "
  ext.sort{ |a,b| a <=> b}.each { |g|
    write(sep)
    write(g)
    sep=","
  }

end

#java_writeGlobalGetterBody(oa) ⇒ Object

writes to current output global getter body which return the variable directly (not a subset).

Example:

return myVariable;

Reference:

  • #getterParameterName

  • #java_isEnumStringMapping

  • #java_writeEnumStringMappingGetterCode

  • #java_getCollectionMapping



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# File 'lib/ontomde-java/java/accessorCode.rb', line 537

def java_writeGlobalGetterBody(oa)
  if oa.uml_isDerived?  && oa.umlx_stringMappingForEnum.empty?
    # provide an implementation because a getter
    # should never throw an exception.
    write ("\t\t//TODO: implement this derived attribute\n")
    if oa.umlx_oneSide?
            v=DatatypeMapping.instance.getMapping(oa.uml_type_one)
     write ("\t\treturn #{v.java_getUndefinedValue};");
    else
     cm=oa.java_getCollectionMapping
     write ("\t\treturn #{cm.addNew(oa.uml_type_one.java_qualifiedName)};");
    end
  elsif java_isEnumStringMapping?(oa)
    java_writeEnumStringMappingGetterCode(oa)

  elsif oa.umlx_upperValueIsOne?  || !oa.uml_qualifier.empty?
    j="\t\treturn #{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
  elsif ! oa.java_use_Arrays?
    #on ne peut pas permettre la modification de la liste en direct
    write %{
       return xmda.crud.Helper.emptyNewCollectionIfNull(#{oa.java_NameProperty});
}
     else
      # code same as above bu could not get it to work with generic Array
    write %{
if(#{oa.java_NameProperty}!=null){
	return #{oa.java_NameProperty};
} else {
	return #{oa.java_getCollectionMapping.addNew(oa.uml_type_one.java_qualifiedName)};
}}

  end
end

#java_writeGlobalSetterBody(oa) ⇒ Object

writes to current output global setter body which return the variable directly (not a subset).

Example:

return myVariable;

Reference:

  • #getterParameterName

  • #java_isEnumStringMapping

  • #java_writeEnumStringMappingSetterCode

  • #java_getCollectionMapping



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# File 'lib/ontomde-java/java/accessorCode.rb', line 589

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 "//TODO: bi-navigability\n #{oa.java_NameProperty}=#{getterParameterName(oa)};"
  elsif (oe.nil?) ||  (!oe.umlx_isNavigable?)
    # other end is non navigable.
    #begin
    #if oa.uml_qualifier.empty?
    write "\t\t#{java_this(oa)}#{oa.java_NameProperty} = #{getterParameterName(oa)};"
    #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
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
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
#{oa.java_propertyAssociationType} toBeRemoved=new #{oa.java_propertyAssociationConcreteType}();
for(#{oa.uml_type_one.java_qualifiedName} item:this.#{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.


931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
# File 'lib/ontomde-java/java/java.rb', line 931

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?) && !context[:hasGlobalReverse]
    # 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.umlx_isARootNamespace?
      #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',context[:hasGlobalReverse]) {
    setOfImport.sort { |a,b| a <=> b}.each {|imp|
      write("import #{imp};\n");
    }
    if context[:hasGlobalReverse]
      write("import xmda.annotationOntoMDE.OntoMDE;\nimport static xmda.annotationOntoMDE.OntoMDE.ZoneCode.*;\n")
    end
  }
end

#java_writeJavadocObject

write classifier javadoc comment.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ontomde-java/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"
  }
  mtk_protected(Mrdf_Resource::NOREVERSE,"javadoc",context[:hasGlobalReverse]||context[:hideJavadocReverseTag]) {
    write("\t/**\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("\t */\n")
  }
end

#java_writeOperationsObject

iterate java_write on operations



984
985
986
# File 'lib/ontomde-java/java/java.rb', line 984

def java_writeOperations
   java_ownedOperation.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–



863
864
865
866
867
868
869
870
871
# File 'lib/ontomde-java/java/java.rb', line 863

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

#java_writeQualifiedGetterBody(oa) ⇒ Object

writes to current output getter body when a qualifier (~hashtable) is used. Qualifier parameters are used as parameter.

Example:

return myVariable;

Reference:

  • #getterParameterName

  • #java_isEnumStringMapping

  • #java_writeEnumStringMappingSetterCode

  • #java_getCollectionMapping



674
675
676
677
678
679
680
681
682
683
# File 'lib/ontomde-java/java/accessorCode.rb', line 674

def java_writeQualifiedGetterBody(oa)
  write("\t\treturn   #{oa.java_NameProperty}.get(")
  sep=""
  oa.uml_qualifier.each { |key|
    write(sep)
    sep=","
    write(key.java_Name)
  }
  write(");\n")
end

#java_writeQualifiedPutterBody(oa) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ontomde-java/java/accessorCode.rb', line 142

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_writeRefactorDataObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ontomde-java/java/refactor.rb', line 83

def java_writeRefactorData
	write(%{<#{self.class}\n})
	write(%{  uri=\"#{rdf_uri}"\n})
	#write(%{  class="#{self.class}"\n})
	write(%{  package="#{umlx_owner_one.rdf_uri}"\n})
	write(%{  name="#{java_Name.mtk_xml}"\n})
	write(%{>\n})
	uml_ownedAttribute.sort {|a,b| a.rdf_uri<=>b.rdf_uri}.each {|a|
		write(%{  <attribute\n})
		write(%{    uri=\"#{a.rdf_uri}"\n})
		# uri is used for type because we track here a change
		# of parameter type, not a change of type itself.
		#write(%{    type="#{a.uml_type_one.rdf_uri}"\n})
		write(%{    name="#{a.java_Name.mtk_xml}"\n})
		write(%{  />\n})
	}
	uml_ownedOperation.sort {|a,b| a.rdf_uri<=>b.rdf_uri}.each {|a|
		write(%{  <operation\n})
		write(%{    uri=\"#{a.rdf_uri}"\n})
		write(%{    name="#{a.java_Name.mtk_xml}"\n})
		#write(%{    returnType="#{a.umlx_returnResult_one0.rdf_uri}"\n}) unless a.umlx_returnResult_one0.nil?
		write(%{  />\n})
	}
	write(%{</#{self.class}>\n})
end

#java_writeSuggesterBody(oa) ⇒ Object

returns default suggester body code. (this method is often overwritten, especially by persistence module).



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

def java_writeSuggesterBody(oa)
  #TODO: recherche du composite commun
  write("\t\treturn null;\n")
end

#java_writeSuggesterBodyEnum(oa) ⇒ Object

Write code for a suggester for a parameter enum see: #java_writeSuggesterBodyEnumWithType



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

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 Note: if lowerValue is zero, null is also added (except if createAndAdd)



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ontomde-java/java/accessorCode.rb', line 31

def java_writeSuggesterBodyEnumWithType(oa,enum,isCreateAndAddSuggester=false)
  if(true)
  write <<END
 return xmda.crud.Helper.arrayToList#{%{PlusNull} if (oa.umlx_lowerValueIsZero? && (!isCreateAndAddSuggester))}(#{enum.java_qualifiedName}\n\t\t\t\t\t\t.values());
END
  else
  write <<END
ret=new java.util.ArrayList<#{enum.java_qualifiedName}>();
#{ (oa.umlx_lowerValueIsZero? && (!isCreateAndAddSuggester))  ? %{ret.add(null);} : %{} }
for (int i = java.lang.reflect.Array
		.getLength(#{enum.java_qualifiedName}\n\t\t\t\t\t\t.values()) - 1; i >= 0; i--) {
	ret.add(#{enum.java_qualifiedName}\n\t\t\t\t\t.values()[i]);
}
return ret;
END
  end
end

#java_writeSuggesterTypeBodyEnum(oa, isCreateAndAdd = false) ⇒ Object

Write code for a composition createAndAdd suggester see: #java_writeSuggesterBodyEnumWithType



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

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

#java_writeTemplateParameterObject

write java5 generic parameters



775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
# File 'lib/ontomde-java/java/java.rb', line 775

def  java_writeTemplateParameter
  return if uml_ownedTemplateSignature.empty?
  write("<")
  sep=""
  uml_ownedTemplateSignature.each {|ts|
    #Muml_TemplateSignature
    ts.uml_ownedParameter.each { |tp|
      #Muml_TemplateParameter
      write(sep)
      sep=","
      c=tp.uml_ownedParameteredElement_one
      write(c.java_Name)
      c.java_writeExtends(true)
    }
  }
  write(">")
end

#jpa_addOptimisticLockingAnnotation!(p) ⇒ Object



3
4
5
6
7
# File 'lib/ontomde-java/jpa/locking.rb', line 3

def jpa_addOptimisticLockingAnnotation!(p)
  p.java_annotation_add("@Version")
  p.umlx_owner_one.java_import_add("javax.persistence.Version")
  p.java_annotation_add(%{@SuppressWarnings("unused")})
end

#jpa_addOptimisticLockingVar!Object



10
11
12
13
14
15
16
17
# File 'lib/ontomde-java/jpa/locking.rb', line 10

def jpa_addOptimisticLockingVar!
  return unless jpa_hasPersistenceId?
  p=umlx_createAndAddProperty(rdf_uri+"_auto_version",DB_OBJECT_VERSION_FIELD)
  jpa_addOptimisticLockingAnnotation!(p)
  p.uml_type=umlx_dataType_long
  p.uml_visibility=::Cuml_VisibilityKind::Private
  #java_addAccessorsFor!(p)
end

#jpa_addPersistenceId!Object



497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/ontomde-java/jpa/jpa.rb', line 497

def jpa_addPersistenceId!
  #return unless uml_generalization.empty?
  return unless context[:db_useOptimisticLocking,true]
  return unless jpa_hasPersistenceId?

  p=umlx_createAndAddProperty(rdf_uri+"_auto_id","id")
  jpa_addPersistenceIdAnnnotation!(p)
  #p.uml_type=umlx_dataType_long
  p.uml_type=umlx_getOrCreateDataType("Long")
  p.uml_visibility=::Cuml_VisibilityKind::Private
  java_addAccessorsFor!(p)

  #TODO Surcharge le getter : A enlever une fois avoir corrig� incompatibilit� avec couche Struts
  gettter = p.java_AttributeGlobalGetter
  #removed ? : operator to make checkstyle happy.
  gettter[0].java_code = %{\t\treturn xmda.crud.Helper.longObjZeroForNull (#{p.java_Name});}
  
  stereo = umlx_package.umlx_createAndAddStereotype(rdf_uri+"Equals", "EqualsValue")
  p.uml_appliedStereotype = stereo
  
end

#jpa_processDTOObject



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/ontomde-java/jpa/jpa.rb', line 462

def jpa_processDTO
  return unless self.umlx_hasStereotype?('DTO')
  
  puts "DTO Found : #{java_Name}"
  
  self.java_import_add("java.io.Serializable")
  io=umlx_getOrCreateClass("java.io.Serializable")
  self.umlx_createAndAddImplementation(io)
  
  # Add a method to<UML_Name> to the main class linked to the DTO by a dependency
  self.uml_clientDependency.each{|dep|
    next unless dep.kind_of?(Cuml_Dependency)
    relatedObject = dep.uml_supplier_one
    
    relatedObject.java_import_add(self.java_qualifiedName)
    relatedObject.java_import_add("org.apache.commons.beanutils.PropertyUtils")
    me=relatedObject.umlx_createAndAddOperation(self.rdf_uri+"_to#{self.java_Name}")
    me.uml_name="to#{self.java_Name}"
    me.uml_visibility=Cuml_VisibilityKind::Public
    rme=me.umlx_createAndAddReturnParameter("#{me.rdf_uri}_ret")
    rme.uml_type=self
    me.java_code = <<CODE
  #{self.java_Name} dto = new #{self.java_Name}();
  try {
     PropertyUtils.copyProperties(dto, this);
  } catch (Exception e) {
     throw new RuntimeException(e);
  }
  return dto;
CODE

  }
  
end

#struts_addAction!Object



67
68
69
70
71
72
73
74
# File 'lib/ontomde-java/struts/action.rb', line 67

def struts_addAction!
  #log.debug { "struts_addAction! #{self}::#{self.class.name}" }
  if struts_bizOperation.empty?
    struts_addActionCRUD!
  else
    struts_addActionBiz!
  end
end

#struts_addActionBiz!Object



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
101
102
103
# File 'lib/ontomde-java/struts/action.rb', line 76

def struts_addActionBiz!
  action=struts_createAndAddActionBase!
  struts_addStartEditActionBiz!(action)

  struts_addsetTimeZoneAction!(action)
  struts_addsetSkinAction!(action)
  struts_addsetLocaleAction!(action)
  struts_addRefreshAction!(action)
  struts_addNewBizAction!(action)
  struts_addProceedBizAction!(action)
  struts_addTabsBiz!(action)
  struts_addSwitchToFlexAction!(action)

  struts_addReturnAction!(action)
  #struts_addProceedAction!(action)
  struts_addResumeAction!(action)
  #struts_addNewAction!(action)
  #struts_addCreateAction!(action)
  struts_addReadAction!(action)
  #struts_addUpdateAction!(action)
  #struts_addDeleteAction!(action)
  #struts_addBusinessMethods!(action)
  struts_addCreateAndAddActions!(action)
  struts_addRemoveAndDeleteActions!(action)

  struts_addFieldMethods!(action)

end

#struts_addActionCRUD!Object



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/ontomde-java/struts/action.rb', line 194

def struts_addActionCRUD!
  action=struts_createAndAddActionBase!

  struts_addStartEditAction!(action)
  struts_addsetTimeZoneAction!(action)
  struts_addsetSkinAction!(action)
  struts_addsetLocaleAction!(action)
  struts_addReturnAction!(action)
  struts_addProceedAction!(action)
  struts_addResumeAction!(action)
  struts_addRefreshAction!(action)
  struts_addNewAction!(action)
  struts_addCreateAction!(action)
  struts_addReadAction!(action)
  struts_addUpdateAction!(action)
  struts_addDeleteAction!(action)

  struts_addCreateAndAddActions!(action)
  struts_addRemoveAndDeleteActions!(action)
  struts_addTabs!(action)
  struts_addSwitchToFlexAction!(action)

  struts_addFieldMethods!(action)

  return if db_isTransient?
  struts_addBusinessMethods!(action)
end

#struts_addActionForm!Object

Creates and add an action form corresponding to this class.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ontomde-java/struts/form.rb', line 105

def struts_addActionForm!
	#log.debug { "struts_addActionForm! for #{self}:#{self.class}" }
	p=umlx_owner_one
	p=p.umlx_getOrCreatePackage(context[:strutsFormPackage,context[:strutsActionFormPackage,"struts"]],p)

	form=p.umlx_createAndAddClass(rdf_uri+"_ActionFormClass")

	form.umlx_createAndAddImplementation(struts_getFormInterface)
	form.struts_addInitAndCopyToReference!

	form.struts_isForm=RDF_TRUE
	form.db_isTransient=RDF_TRUE

	form.struts_actionFormSrc=self
	self.struts_actionForm=form

	form.uml_name="#{uml_name}StrutsForm"
	#af=umlx_getOrCreateClass("org.apache.struts.action.ActionForm")
	#if (uml_generalization.empty?)
	#NOTE: Forms inheritance DO NOT follow class inheritance.
	#      (to allow exact typing in redefined methods)

	af=umlx_getOrCreateClass("org.apache.struts.validator.ValidatorForm")
	form.umlx_createAndAddGeneralization(af)

	form.java_makeSerializable!
	#ag=umlx_getOrCreateClass("java.io.Serializable")
	#form.umlx_createAndAddImplementation(ag)
	#TODO ajouter implements interface

	struts_addActionFormAttribute!(form)
	struts_create_getXMLFormOperations!(form)

	struts_addInitFrom!
	struts_addCopyTo!
	struts_addReset!

	ref=form.umlx_createAndAddProperty(form.rdf_uri+"__ref","reference")
	ref.uml_type=self
               ref.java_noSuggester=RDF_TRUE

	[STRUTS_DISPATCH_FIELD_NAME,STRUTS_SGBD_STATE,STRUTS_REQUESTED_CREATION_TYPE_FIELD_NAME].each {|p|
		act=form.umlx_createAndAddProperty(form.rdf_uri+p)
		act.uml_name=p
		act.uml_type=umlx_dataType_string
	}

	form.struts_addActionLocaleFormFields!

	form.java_addAccessors!  #ajouter getter/setter
	form.apaCom_addLogger!
end

#struts_addActionFormAttribute!(form) ⇒ Object



182
183
184
185
186
187
# File 'lib/ontomde-java/struts/form.rb', line 182

def struts_addActionFormAttribute!(form)
	struts_formAttribute.each { |a|
		a.struts_addActionFormAttribute!(form)
	}
	#struts_addDateFormater!(form)
end

#struts_addActionLocaleFormFields!Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ontomde-java/struts/localeAction.rb', line 75

def struts_addActionLocaleFormFields!
  form=self
  [STRUTS_SETSKIN_FIELD,STRUTS_SETTIMEZONE_FIELD,STRUTS_SETLOCALE_LANGUAGE_FIELD,STRUTS_SETCOUNTRY_FIELD].each { |an|
    ems=form.umlx_createAndAddProperty(form.rdf_uri+an,an);
    ems.uml_type=form.umlx_dataType_string
    ems.uml_upperValue=form.umlx_literal(1)
    ems.uml_lowerValue=form.umlx_literal(0)
    #ems.uml_isStatic=RDF_TRUE
    ems.db_isTransient=RDF_TRUE
    ems.uml_visibility=::Cuml_VisibilityKind::Public
    #form.java_addGlobalSetter!(ems)
    #g=form.java_addGlobalGetter!(ems)
  }
end

#struts_addAllOperationAggregateParameterClass!(biz) ⇒ Object

Creates a class for every business method holding every parameters



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ontomde-java/java/operationAsClass.rb', line 93

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

generates an apply to parameter



111
112
113
114
115
116
# File 'lib/ontomde-java/java/operationAsClass.rb', line 111

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_addBusinessMethods!(action) ⇒ Object



432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/ontomde-java/struts/action.rb', line 432

def struts_addBusinessMethods!(action)
  umlx_ownedAndInheritedOperation.each { |op|
    # private and protected methods are not published
    next if op.uml_visibility_one.isPrivate?
    next if op.uml_isAbstract?
    next if op.uml_visibility_one.isProtected?
    next unless op.umlx_businessMethod?
    next if op.struts_bizOperationReverse.empty?

    biz=action.struts_createAndAddExecuteOperation("#{op.java_Name}")
    biz.java_code=<<ENDCODE
	#{struts_formCastJavaCode}
	form.copyToReference();
	form.setReference(form.getReference().merge());
	#{op.struts_bizOperationReverse_one.java_qualifiedName} newElt=new #{op.struts_bizOperationReverse_one.java_qualifiedName}();
	newElt.set#{STRUTS_APPLY_TO_PROP}(form.getReference());
	return #{struts_getActionHelper.java_qualifiedName}.transferToStartEditAction(mapping,request,newElt,"#{self.java_Name}");
ENDCODE
  }
end

#struts_addCopyTo!Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/ontomde-java/struts/form.rb', line 159

def struts_addCopyTo!
	#log.debug{ "addCopyTo #{self}" }
	form=struts_actionForm_one
	cpt=form.umlx_createAndAddOperation(form.rdf_uri+"_copyTo","copyTo")
	#cpt.java_annotation_add(%{@SuppressWarnings("unused")})
	pcpt=cpt.umlx_createAndAddParameter(cpt.rdf_uri+"_to","_to")
	pcpt.uml_direction=Cuml_ParameterDirectionKind::Inout
	pcpt.uml_type=self
	code="java.util.TimeZone currentTimeZone = java.util.TimeZone.getTimeZone(get#{STRUTS_SETTIMEZONE_BEAN}());"
	code=code+"if(currentTimeZone==null) {}\n" # quick hack to avoid unused/not unused warning
	struts_formAttribute.each { |a|
		if(a.uml_isReadOnly?) 
			code=code+"\t\/\/ a.java_NameBean (read-only)\n"
		else
				code=code+"if(this.get#{a.java_NameBean}()!=null) {\n  " if(STRUTS_ACCEPT_NULL_FIELD_IN_FORMS)
			code=code+"#{DatatypeMapping.instance.getMapping(a.uml_type_one).getFormCopyTo(a)}"
			code=code+"  }//test !=null\n" if(STRUTS_ACCEPT_NULL_FIELD_IN_FORMS)
		end
	}

	cpt.java_code=code
end

#struts_addCreateAction!(action) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/ontomde-java/struts/action.rb', line 366

def struts_addCreateAction!(action)
  create=action.struts_createAndAddExecuteOperation(STRUTS_CREATE_ACTION)
  #note: persist must be before copyTo
  create.java_code=<<ENDMETH
	#{struts_formCastJavaCode}
	form.copyToReference();
	form.setReference(form.getReference().merge());
	form.initFromReference();
	form.set#{STRUTS_SGBD_STATE_PROP}("#{STRUTS_UPDATE_ACTION}");
	return #{STRUTS_RETURN_ACTION}(mapping,form,request,response);
ENDMETH
end

#struts_addCreateAndAddActions!(action) ⇒ Object



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
# File 'lib/ontomde-java/struts/action.rb', line 453

def struts_addCreateAndAddActions!(action)
  struts_formAttribute.each { |a|
    next unless a.umlx_isComposite?
    if a.umlx_oneSide?
      struts_addCreateAndAddOneAction!(action,a)
    else
      struts_addCreateAndAddManyAction!(action,a)
    end
  }
  struts_formAttribute.each { |a|
    next if a.umlx_isAttribute?
    if a.umlx_oneSide?
      struts_addEditOneAction!(action,a)
    else
      struts_addEditManyAction!(action,a)
    end
  }
end

#struts_addCreateAndAddManyAction!(action, a) ⇒ Object



475
476
477
# File 'lib/ontomde-java/struts/action.rb', line 475

def struts_addCreateAndAddManyAction!(action,a)
  struts_addCreateAndAddOneOrManyAction!(action,a,true)
end

#struts_addCreateAndAddOneAction!(action, a) ⇒ Object



472
473
474
# File 'lib/ontomde-java/struts/action.rb', line 472

def struts_addCreateAndAddOneAction!(action,a)
  struts_addCreateAndAddOneOrManyAction!(action,a,false)
end

#struts_addCreateAndAddOneOrManyAction!(action, a, isMany) ⇒ Object



479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/ontomde-java/struts/action.rb', line 479

def struts_addCreateAndAddOneOrManyAction!(action,a,isMany)
  cr=action.struts_createAndAddExecuteOperation("createAndAdd#{a.java_NameBean}")
  cr.java_code=<<ENDCODE
	#{struts_formCastJavaCode}
	#{db_tx_none(%{
  form.copyToReference();
#{a.uml_type_one.java_enumAssignableDataType_one.java_qualifiedName} reqType=Enum.valueOf(#{a.uml_type_one.java_enumAssignableDataType_one.java_qualifiedName}.class,form.get#{STRUTS_REQUESTED_CREATION_TYPE_FIELD_PROP}());
form.setReference(form.getReference().merge());
#{a.uml_type_one.java_qualifiedName} newElt=form.getReference().createAndAdd#{a.java_NameBean}(reqType);
form.getReference().persist();
return #{struts_getActionHelper.java_qualifiedName}.transferToStartEditAction(mapping,request,newElt,"#{self.java_Name}");
})}
ENDCODE
end

#struts_addDeleteAction!(action) ⇒ Object



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/ontomde-java/struts/action.rb', line 415

def struts_addDeleteAction!(action)
  update=action.struts_createAndAddExecuteOperation(STRUTS_DELETE_ACTION)
  if false #java_DAOClass.empty?
    update.java_code=<<ENDMETH
throw new RuntimeException("method #{update.java_Name} is only available for persistent elements");
ENDMETH
  else
    update.java_code= <<ENDCODE
	#{struts_formCastJavaCode}
	form.copyToReference();
	form.set#{STRUTS_SGBD_STATE_PROP}("#{STRUTS_NEW_ACTION}");
	form.initFromReference();
	return #{STRUTS_RETURN_ACTION}(mapping,form,request,response);
ENDCODE
  end
end

#struts_addEditManyAction!(action, a) ⇒ Object



494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/ontomde-java/struts/action.rb', line 494

def struts_addEditManyAction!(action,a)
  cr=action.struts_createAndAddExecuteOperation("edit#{a.java_NameBean}")
  e=struts_getFunctionalException
  cr.java_code= <<ENDCODE
	#{struts_formCastJavaCode}
	#{%{
  long referenceId = form.getReference().getId();
	#{self.java_qualifiedName} reference = #{self.java_qualifiedName}.find(referenceId);
	form.setReference(reference);
	} unless java_DAOClass.empty? }

	form.copyToReference();
	String sid=request.getParameter("#{STRUTS_REQUESTED_TAB}");
	long id=Long.parseLong(sid);

	#{a.uml_type_one.java_qualifiedName} elt=null;

	{
java.util.Iterator<?> iter=form.getReference().get#{a.java_NameBean}().iterator();
while(iter.hasNext()) {
	elt=(#{a.uml_type_one.java_qualifiedName})iter.next();
	if (elt.getId()!=id) continue;
	break;
	}
	#{e.java_qualifiedName} exceptionToFire = new #{e.java_qualifiedName}("/pages/#{java_InternalFilePath}form/#{java_Name}all.jsp","Internal error. #{cr.java_qualifiedName} called on null element");
	#{struts_getActionHelper.java_qualifiedName}.checkNotNull(elt,exceptionToFire);

	}
	return #{struts_getActionHelper.java_qualifiedName}.transferToStartEditAction(mapping,request,elt,"#{self.java_Name}");
ENDCODE
end

#struts_addEditOneAction!(action, a) ⇒ Object



526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/ontomde-java/struts/action.rb', line 526

def struts_addEditOneAction!(action,a)
  cr=action.struts_createAndAddExecuteOperation("edit#{a.java_NameBean}")
  e=struts_getFunctionalException
  cr.java_code= <<ENDCODE
	#{struts_formCastJavaCode}
	#{%{
  long referenceId = form.getReference().getId();
	#{self.java_qualifiedName} reference = #{self.java_qualifiedName}.find(referenceId);
	form.setReference(reference);
	} unless java_DAOClass.empty?}

	form.copyToReference();
	//form.setReference(form.getReference().merge());

	#{a.uml_type_one.java_qualifiedName} elt=form.getReference().get#{a.java_NameBean}();

	#{e.java_qualifiedName} exceptionToFire = new #{e.java_qualifiedName}("/pages/#{java_InternalFilePath}form/#{java_Name}all.jsp","Internal error. #{cr.java_qualifiedName} called on null element");
	#{struts_getActionHelper.java_qualifiedName}.checkNotNull(elt,exceptionToFire);

	return #{struts_getActionHelper.java_qualifiedName}.transferToStartEditAction(mapping,request,elt,"#{self.java_Name}");
ENDCODE
end

#struts_addFieldMethods!(action) ⇒ Object



688
689
690
691
692
693
694
# File 'lib/ontomde-java/struts/action.rb', line 688

def struts_addFieldMethods!(action)
  form=struts_actionForm_one
  struts_formAttribute.each {|a|
    tpl=DatatypeMapping.instance.getMapping(a.uml_type_one)
    tpl.addActionFieldMethod!(a,action,form)
  }
end

#struts_addInitAndCopyToReference!Object



96
97
98
99
100
101
102
# File 'lib/ontomde-java/struts/form.rb', line 96

def struts_addInitAndCopyToReference!
	i=umlx_createAndAddOperation(rdf_uri+"initFromReference","initFromReference");
	i.java_code="initFrom(getReference());"

	c=umlx_createAndAddOperation(rdf_uri+"copyToReference","copyToReference");
	c.java_code="copyTo(getReference());"
end

#struts_addInitFrom!Object



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/ontomde-java/struts/form.rb', line 200

def struts_addInitFrom!
	form=struts_actionForm_one
	inf=form.umlx_createAndAddOperation(form.rdf_uri+"_initFrom","initFrom")
	#inf.java_annotation_add(%{@SuppressWarnings("unused")})
	pinf=inf.umlx_createAndAddParameter(inf.rdf_uri+"_from","_from")
	pinf.uml_type=self
	pinf.uml_direction=Cuml_ParameterDirectionKind::In

	code="java.util.TimeZone currentTimeZone = java.util.TimeZone.getTimeZone(get#{STRUTS_SETTIMEZONE_BEAN}());\n"
	struts_formAttribute.each { |a|
		code=code+"#{DatatypeMapping.instance.getMapping(a.uml_type_one).getFormInitFrom(a)}"

	}
	inf.java_code=code
end

#struts_addNewAction!(action) ⇒ Object



334
335
336
337
338
339
340
# File 'lib/ontomde-java/struts/action.rb', line 334

def struts_addNewAction!(action)
  if uml_isAbstract? || kind_of?(Muml_Interface)
    struts_addNewActionNotAvailable!(action)
  else
    struts_addNewActionAvailable!(action)
  end
end

#struts_addNewActionAvailable!(action) ⇒ Object



350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/ontomde-java/struts/action.rb', line 350

def struts_addNewActionAvailable!(action)
  create=action.struts_createAndAddExecuteOperation(STRUTS_NEW_ACTION)
  create.java_code= <<ENDMETH
	// Creates a new transient object instance and forwards to an edit page.
	#{struts_formCastJavaCode}
	form.setReference(new #{java_qualifiedName}());
	#{%{ form.getReference().initData();\nform.getReference().persist(); } if self.java_isATestFile? }
	form.initFromReference();
	//form.getReference().persist();
	form.set#{STRUTS_SGBD_STATE_PROP}("#{STRUTS_CREATE_ACTION}");
	#{java_debug(%{"STATE="+form.get#{STRUTS_SGBD_STATE_PROP}()})}
	return mapping.findForward("#{STRUTS_INPUT_FWD}");
ENDMETH
end

#struts_addNewActionNotAvailable!(action) ⇒ Object



342
343
344
345
346
347
# File 'lib/ontomde-java/struts/action.rb', line 342

def struts_addNewActionNotAvailable!(action)
  create=action.struts_createAndAddExecuteOperation(STRUTS_NEW_ACTION)
  create.java_code=%{
	throw new java.lang.RuntimeException("new not available for abstract class #{self.java_qualifiedName}");
  }
end

#struts_addNewBizAction!(action) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/ontomde-java/struts/action.rb', line 105

def struts_addNewBizAction!(action)
  create=action.struts_createAndAddExecuteOperation(STRUTS_NEW_ACTION)
  create.java_code=<<ENDMETH
	#{struts_formCastJavaCode}
	form.setReference(new #{java_qualifiedName}());
	form.initFromReference();
	form.set#{STRUTS_DISPATCH_FIELD_METH}("#{STRUTS_CREATE_ACTION}");
	return mapping.findForward("#{STRUTS_INPUT_FWD}");
ENDMETH
end

#struts_addOneOrManyAction!(action, a) ⇒ Object



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
# File 'lib/ontomde-java/struts/action.rb', line 563

def struts_addOneOrManyAction!(action,a)
  return if a.uml_isReadOnly?
  meth=action.struts_createAndAddExecuteOperation("add#{a.java_NameBean}")
  if false #java_DAOClass.empty?
    meth.java_code=<<ENDMETH
	throw new RuntimeException("method #{meth.java_Name} is only available for persistent elements");
ENDMETH
  else
    meth.java_code= <<ENDMETH
	#{struts_formCastJavaCode}
	String sid=request.getParameter("#{STRUTS_REQUESTED_TAB}");
	long id=Long.parseLong(sid);

	form.copyToReference();
	form.setReference(form.getReference().merge());
	#{struts_findElt(a,true)}
	if(elt!=null) {
form.getReference().#{a.umlx_oneSide? ? "set":"add"}#{a.java_NameBean}(elt);
//TODO: delete element
}
	form.initFromReference();
	return mapping.findForward("#{STRUTS_INPUT_FWD}");
ENDMETH
  end
end

#struts_addProceed!(biz) ⇒ Object

generates a proceed operation.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ontomde-java/java/operationAsClass.rb', line 119

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

#struts_addProceedAction!(action) ⇒ Object



285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/ontomde-java/struts/action.rb', line 285

def struts_addProceedAction!(action)
  proca=action.struts_createAndAddExecuteOperation(STRUTS_PROCEED_ACTION)
  j=%{
#{struts_formCastJavaCode}
String s=form.get#{STRUTS_SGBD_STATE_PROP}();
  }

  [STRUTS_NEW_ACTION,STRUTS_CREATE_ACTION,STRUTS_UPDATE_ACTION,STRUTS_READ_ACTION,STRUTS_DELETE_ACTION].each {|m|
    j=j+%{if(s.compareTo("#{m}")==0) { return #{m}(mapping,form,request,response); }\n}
  }
  j=j+PROCEED_ACTION_CODE
  proca.java_code=j
end

#struts_addProceedBizAction!(action) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/ontomde-java/struts/action.rb', line 116

def struts_addProceedBizAction!(action)
  # form contains a parameter generated from an operation return parameter
  # if true, proceed has no return to display. Thus, return screen is skipped
  hasMethodToClassReturn=false;
  struts_formAttribute.each { |a|
	hasMethodToClassReturn=a.java_isMethodToClassReturn?
	break if hasMethodToClassReturn
  }

  proceed=action.struts_createAndAddExecuteOperation(STRUTS_PROCEED_ACTION)
  proceed.java_code=<<ENDMETH
	#{struts_formCastJavaCode}
	form.copyToReference();
	form.getReference().proceed();
	form.initFromReference();
	form.set#{STRUTS_DISPATCH_FIELD_METH}("#{STRUTS_CREATE_ACTION}");
      #{!hasMethodToClassReturn ? "return returnTo(mapping, abstractForm, request, response);": %{return new org.apache.struts.action.ActionForward("/pages/#{java_InternalFilePath}form/#{java_Name}#{STRUTS_RESULTS_FWD}.jsp",false);}}
ENDMETH
end

#struts_addReadAction!(action) ⇒ Object



379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/ontomde-java/struts/action.rb', line 379

def struts_addReadAction!(action)
  update=action.struts_createAndAddExecuteOperation(STRUTS_READ_ACTION)
  if java_DAOClass.empty?
    update.java_code=<<ENDMETH
throw new RuntimeException("method #{update.java_Name} is only available for persistent elements");
ENDMETH
  else
    update.java_code=<<ENDMETH
	//loads object from database using id and forwards to edit page
	#{struts_formCastJavaCode}
	form.setReference(#{java_DAOClass_one.java_qualifiedName}.find(Long.parseLong(form.getId())));
	form.initFromReference();
	form.set#{STRUTS_SGBD_STATE_PROP}("#{STRUTS_UPDATE_ACTION}");
	return mapping.findForward("#{STRUTS_INPUT_FWD}");
ENDMETH
  end
end

#struts_addRefreshAction!(action) ⇒ Object



673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'lib/ontomde-java/struts/action.rb', line 673

def struts_addRefreshAction!(action)
  meth=action.struts_createAndAddExecuteOperation(STRUTS_REFRESH_ACTION)
  meth.java_code=<<ENDMETH
	#{struts_formCastJavaCode}
	String z=request.getParameter("#{STRUTS_REQUESTED_TAB}");
	#{STRUTS_ACTION_FORWARD} am=mapping.findForward(z);
	form.copyToReference();
	form.setReference(form.getReference().merge());
	if(am==null) {
#{java_error(%{"ActionMapping not found for '"+z+"'"})}
return mapping.findForward("#{STRUTS_INPUT_FWD}");
}
	return am;
ENDMETH
end

#struts_addRemoveAndDeleteActions!(action) ⇒ Object



549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/ontomde-java/struts/action.rb', line 549

def struts_addRemoveAndDeleteActions!(action)
  struts_formAttribute.each { |a|
    #next unless a.umlx_isComposite?
    #next unless a.umlx_isAssociation?
    next if a.umlx_isAttribute?
    if a.umlx_oneSide?
      struts_addRemoveAndDeleteOneAction!(action,a)
    else
      struts_addRemoveAndDeleteManyAction!(action,a)
    end
    struts_addOneOrManyAction!(action,a)
  }
end

#struts_addRemoveAndDeleteManyAction!(action, a) ⇒ Object



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# File 'lib/ontomde-java/struts/action.rb', line 629

def struts_addRemoveAndDeleteManyAction!(action,a)
  return if a.uml_isReadOnly?
  del=action.struts_createAndAddExecuteOperation("removeAndDelete#{a.java_NameBean}")
  del.java_code= <<ENDJCODE
	#{struts_formCastJavaCode}
	#{db_tx_none(%{
  String sid=request.getParameter("#{STRUTS_REQUESTED_TAB}");
	long id=Long.parseLong(sid);

	form.copyToReference();
	form.setReference(form.getReference().merge());
	#{struts_findElt(a)}
	if(elt!=null) {
form.getReference().remove#{a.java_NameBean}(elt);
//TODO: delete element
}
	form.initFromReference();

	})}
	return mapping.findForward("#{STRUTS_INPUT_FWD}");
ENDJCODE
end

#struts_addRemoveAndDeleteOneAction!(action, a) ⇒ Object



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# File 'lib/ontomde-java/struts/action.rb', line 589

def struts_addRemoveAndDeleteOneAction!(action,a)
  return if a.uml_isReadOnly?
  del=action.struts_createAndAddExecuteOperation("removeAndDelete#{a.java_NameBean}")
  del.java_code= <<END_DEL_CODE
	#{struts_formCastJavaCode}
	#{db_tx_none(%{
  //String sid=request.getParameter("#{STRUTS_REQUESTED_TAB}");
	//long id=Long.parseLong(sid);
	//#{a.uml_type_one.java_qualifiedName} elt=null;
	form.copyToReference();
	form.setReference(form.getReference().merge());
	form.getReference().set#{a.java_NameBean}(null);
	//TODO: delete element
	form.initFromReference();
	})}
	return mapping.findForward("#{STRUTS_INPUT_FWD}");
END_DEL_CODE
end

#struts_addReset!Object



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/ontomde-java/struts/form.rb', line 217

def struts_addReset!
	form=struts_actionForm_one
	o=form.umlx_createAndAddOperation(form.rdf_uri+"_reset","reset")
	o.java_annotation_add("@Override")
	o.java_code= <<END
// if the time zone is not set yet in the session
// we set the default value ("Europe/Paris") else
// we get the timezone saved in the user session.
this.set#{Muml_Classifier::STRUTS_SETTIMEZONE_BEAN}(xmda.tags.helpers.XMDARequestUtils.getUserTimeZone(request, null).getID());
END
	p=o.umlx_createAndAddParameter(o.rdf_uri+"_mapping","mapping")
	p.uml_type=o.umlx_getOrCreateClass("org.apache.struts.action.ActionMapping")
	p=o.umlx_createAndAddParameter(o.rdf_uri+"_request","request")
	p.uml_type=o.umlx_getOrCreateClass("javax.servlet.http.HttpServletRequest")
end

#struts_addResumeAction!(action) ⇒ Object



319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/ontomde-java/struts/action.rb', line 319

def struts_addResumeAction!(action)
  resume=action.struts_createAndAddExecuteOperation(STRUTS_RESUME_ACTION)
  resume.java_code=<<ENDRESCODE
	#{struts_formCastJavaCode}
	#{%{
  long referenceId = form.getReference().getId();
	#{self.java_qualifiedName} reference = #{self.java_qualifiedName}.find(referenceId);
	form.setReference(reference);
	} unless java_DAOClass.empty? }
	form.setSgbd_state("#{STRUTS_UPDATE_ACTION}");
	form.initFromReference();
	return mapping.findForward("#{STRUTS_INPUT_FWD}");
ENDRESCODE
end

#struts_addReturnAction!(action) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/ontomde-java/struts/action.rb', line 299

def struts_addReturnAction!(action)
  reta=action.struts_createAndAddExecuteOperation(STRUTS_RETURN_ACTION)
  reta.java_code=%{
#{struts_formCastJavaCode}
javax.servlet.http.HttpSession session=request.getSession();
String key=form.getReference().getClass().getName()+"_returnTo";
String url=(String)session.getAttribute(key);
session.removeAttribute(key);
if(url==null) {
	// loop on self when reach top of returnTo stack.
	return mapping.findForward("#{STRUTS_INPUT_FWD}");
}

//external redirect is not supported nor desired when FLEX.
// FLEX: redirect = false , not FLEX: redirected= true
boolean redirect = request.getParameter("FLEX")==null ;
return new org.apache.struts.action.ActionForward(url,redirect);
  }
end

#struts_addsetLocaleAction!(action) ⇒ Object

TODO cpt.java_code=



716
717
718
719
720
721
722
723
724
# File 'lib/ontomde-java/struts/action.rb', line 716

def struts_addsetLocaleAction!(action)
  mpc=self
  cpt=action.struts_createAndAddExecuteOperation(STRUTS_SETLOCALE_ACTION)
  cpt.java_code=%{
	#{struts_formCastJavaCode}
	form.copyToReference();
	return #{struts_getActionHelper.java_qualifiedName}.changeLocaleAction(mapping,getLocale(request),request,form.getStrutsLanguage(),form.getStrutsCountry());
  }
end

#struts_addsetSkinAction!(action) ⇒ Object



711
712
713
714
715
# File 'lib/ontomde-java/struts/action.rb', line 711

def struts_addsetSkinAction!(action)
  mpc=self
  cpt=action.struts_createAndAddExecuteOperation(STRUTS_SETSKIN_ACTION)
  #TODO cpt.java_code=
end

#struts_addsetTimeZoneAction!(action) ⇒ Object



699
700
701
702
703
704
705
706
707
708
709
710
# File 'lib/ontomde-java/struts/action.rb', line 699

def struts_addsetTimeZoneAction!(action)
  mpc=self
  cpt=action.struts_createAndAddExecuteOperation(STRUTS_SETTIMEZONE_ACTION)
  cpt.java_code=<<ENDCODE
	#{struts_formCastJavaCode}
	//form.copyToReference();
String newTimeZoneId = form.getStruts_tz();
	#{struts_getActionHelper.java_qualifiedName}.changeTimeZoneAction_s1(form,mapping,request, newTimeZoneId);
	form.setReference(form.getReference().merge());
	return #{struts_getActionHelper.java_qualifiedName}.changeTimeZoneAction_s2(form,mapping,request, newTimeZoneId);
ENDCODE
end

#struts_addStartEditAction!(action, optCode = "") ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/ontomde-java/struts/action.rb', line 153

def struts_addStartEditAction!(action,optCode="")
  edit=action.struts_createAndAddExecuteOperation(STRUTS_ACTION_STARTEDIT)
  edit.java_code= <<ENDCODE
	#{struts_formCastJavaCode}
	javax.servlet.http.HttpSession session=request.getSession();
	#{self.java_qualifiedName} obj=(#{self.java_qualifiedName}) session.getAttribute("#{STRUTS_SESSION_KEY_EditAction}");
	session.removeAttribute("#{STRUTS_SESSION_KEY_EditAction}");
	form.setReference(obj);
	form.initFromReference();
	form.setSgbd_state("#{STRUTS_UPDATE_ACTION}"); #{optCode}
	return mapping.findForward("#{STRUTS_INPUT_FWD}");
ENDCODE
end

#struts_addStartEditActionBiz!(action) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/ontomde-java/struts/action.rb', line 145

def struts_addStartEditActionBiz!(action)
	#puts "############# #{uml_name} #{struts_formAttribute.length}"
	# add code to skip input screen when no user input is necessary
	# (first attribute is applyTo)
	optCode= struts_formAttribute(false,true).length > 0 ? '' : JUMP_TO_PROCEED 
	return struts_addStartEditAction!(action,optCode)
end

#struts_addSwitchToFlexAction!(action) ⇒ Object



652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'lib/ontomde-java/struts/action.rb', line 652

def struts_addSwitchToFlexAction!(action)
  return unless context[:generateXMLStrutsForm]
  create=action.struts_createAndAddExecuteOperation(::Muml_Class::STRUTS_SWITH_TO_FLEX_ACTION)
  create.java_code= <<JCODE
	#{struts_formCastJavaCode}
	String z="#{Muml_Class::STRUTS_SWITCH_TO_FLEX_FORWARD}";
	#{STRUTS_ACTION_FORWARD} am=mapping.findForward(z);
	#{db_tx_none(%{
  form.copyToReference();
  form.setReference(form.getReference().merge());
  if(am==null) {
	#{java_error(%{"ActionMapping not found for '"+z+"'"})}
	return mapping.findForward("#{STRUTS_INPUT_FWD}");
	}
	})}
	request.getSession().setAttribute("flex_action",request.getRequestURI());
	request.getSession().setAttribute("flex_locale",getLocale(request).getLanguage());
	return am;
JCODE
end

#struts_addTabAll!(action) ⇒ Object

adds a tab with all attributes



260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/ontomde-java/struts/action.rb', line 260

def struts_addTabAll!(action)
  t=Cstruts_tab.new(rdf_Repository,self.rdf_uri+"_taball")
  t.java_Name="all"
  self.struts_ownedTab_add(t);
  cgi=umlx_classifier_generalization_indirect
  cgi.add(self)
  cgi.each { |c|
    c.uml_ownedAttribute.each { |a|
      next if a.struts_ignoreInForm?
      next if a.java_Name==STRUTS_RESULT_PARAM_NAME
      t.struts_ownedAttribute_add(a)
    }
  }
end

#struts_addTabFromInterface!(action) ⇒ Object



244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/ontomde-java/struts/action.rb', line 244

def struts_addTabFromInterface!(action)
  return if kind_of?(Muml_Interface)
  uml_implementation.each {|imp|
    ie=imp.uml_supplier_one
    next if ie.java_ignoreMe?
    t=Cstruts_tab.new(rdf_Repository,self.rdf_uri+"_tab_"+ie.rdf_uri)
    self.struts_ownedTab_add(t);
    t.java_Name=ie.java_Name
    ie.uml_ownedAttribute.each { |a|
      next if a.struts_ignoreInForm?
      t.struts_ownedAttribute_add(a)
    }
  }
end

#struts_addTabReturnParameter!(action) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/ontomde-java/struts/action.rb', line 231

def struts_addTabReturnParameter!(action)
  t=Cstruts_tab.new(rdf_Repository,self.rdf_uri+"_tab_return")
  self.struts_ownedTab_add(t);
  t.java_Name=STRUTS_RESULTS_FWD
  self.uml_ownedAttribute.each { |a|
    next if a.struts_ignoreInForm?
    next unless a.java_Name==STRUTS_RESULT_PARAM_NAME
    #next unless a.struts_sourceProperty_one.uml_direction_one.isReturn?
    t.struts_ownedAttribute_add(a);
    break # there can be only one return parameter
  }
end

#struts_addTabs!(action) ⇒ Object



221
222
223
224
# File 'lib/ontomde-java/struts/action.rb', line 221

def struts_addTabs!(action)
  struts_addTabFromInterface!(action)
  struts_addTabAll!(action)
end

#struts_addTabsBiz!(action) ⇒ Object



225
226
227
228
229
# File 'lib/ontomde-java/struts/action.rb', line 225

def struts_addTabsBiz!(action)
  struts_addTabFromInterface!(action)
  struts_addTabAll!(action)
  struts_addTabReturnParameter!(action)
end

#struts_addUpdateAction!(action) ⇒ Object



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/ontomde-java/struts/action.rb', line 397

def struts_addUpdateAction!(action)
  update=action.struts_createAndAddExecuteOperation(STRUTS_UPDATE_ACTION)
  if false #java_DAOClass.empty?
    update.java_code=<<ENDMETH
throw new RuntimeException("method #{update.java_Name} is only available for persistent elements");
ENDMETH
  else
    update.java_code=<<ENDMETH
	//update persistent object from html form.
	#{struts_formCastJavaCode}
	form.copyToReference();
	form.setReference(form.getReference().merge());
	form.set#{STRUTS_SGBD_STATE_PROP}("#{STRUTS_UPDATE_ACTION}");
	form.initFromReference();
	return #{STRUTS_RETURN_ACTION}(mapping,form,request,response);
ENDMETH
  end
end

#struts_createAndAddActionBase!Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/ontomde-java/struts/action.rb', line 167

def struts_createAndAddActionBase!
  p=umlx_owner_one
  p=p.umlx_getOrCreatePackage(context[:strutsActionPackage,context[:strutsActionFormPackage,"struts"]],p)
  action=p.umlx_createAndAddClass(rdf_uri+"_Action")
  action.db_isTransient=RDF_TRUE

  action.struts_actionSrc=self
  self.struts_action=action
  action.uml_name="#{uml_name}StrutsAction"
  #af=action.umlx_getOrCreateClass("org.apache.struts.action.Action")
  af=action.umlx_getOrCreateClass("org.apache.struts.actions.DispatchAction")
  action.umlx_createAndAddGeneralization(af)

  action.apaCom_addLogger!

  #all=action.umlx_createAndAddProperty("#{action.rdf_uri}FORWARD","FORWARD");
  #mtk_context(:struts_tab=> struts_defaultTabId ){
  #	all.java_code=%{"/#{struts_jsp_edit_path}"}
  #  }
  #		all.uml_isStatic=RDF_TRUE;
  #		all.uml_type=uml_type=umlx_dataType_string

  return action
end

#struts_createAndAddExecuteOperation(name) ⇒ Object

Creates an add a struts “execute” method of an action bean Names needs not be “execute” thanks to struts dispatch feature.



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

def struts_createAndAddExecuteOperation(name)
  action=self
  afo=action.umlx_createAndAddOperation(action.rdf_uri+"_"+name,name)
  p=afo.umlx_createAndAddParameter(afo.rdf_uri+"_to","mapping")
  p.uml_type=umlx_getOrCreateClass(STRUTS_ACTION_MAPPING)
  p=afo.umlx_createAndAddParameter(afo.rdf_uri+"_form","abstractForm")
  p.uml_type=umlx_getOrCreateClass("org.apache.struts.action.ActionForm")

  p=afo.umlx_createAndAddParameter(afo.rdf_uri+"_request","request")
  p.uml_type=umlx_getOrCreateClass("javax.servlet.http.HttpServletRequest")

  p=afo.umlx_createAndAddParameter(afo.rdf_uri+"_response","response")
  p.uml_type=umlx_getOrCreateClass("javax.servlet.http.HttpServletResponse")
  p=afo.umlx_createAndAddReturnParameter(afo.rdf_uri+"_return","return")
  p.uml_type=umlx_getOrCreateClass("org.apache.struts.action.ActionForward")

  return afo
end

#struts_eachFormAttribute_deprecObject



43
44
45
46
47
# File 'lib/ontomde-java/struts/form.rb', line 43

def struts_eachFormAttribute_deprec()
	struts_formAttribute.each { |a|
		yield(a)
	}
end

#struts_eachLabelField(field, withLabelOnly = true, &block) ⇒ Object



526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 526

def struts_eachLabelField(field,withLabelOnly=true,&block)
  emptySelection=true
  field.uml_type_one.struts_formAttribute.each { |a|
          #next if a.uml_name_one=="id"
          next if a.uml_name_one=="owner"
          next if a.uml_name_one=="isLogicallyDeleted"
          next if a.uml_type_one.kind_of?(Muml_Class)
          next if withLabelOnly && !(a.umlx_hasStereotype?("label"))
	  next if a.umlx_hasStereotype?("noLabel")
          emptySelection=false
	  yield(a)
        }
   struts_eachLabelField(field,false) { |a| yield(a) } if emptySelection && withLabelOnly
end

#struts_edit_writeField(field, owner) ⇒ Object



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 500

def struts_edit_writeField(field,owner)
  if field.nil?
    log.error { "nil field in #{self}" }
    return
  end
  os=field.umlx_oneSide?
  ic=field.umlx_isComposite?
  if os && !ic
    # OAS (Object Association Single)
    struts_edit_writeFieldOne(field,owner)
  elsif (!os) && (!ic)
    # OAM (Object Association Multiple)
    struts_edit_writeFieldMany(field,owner)
  elsif os && ic
    # OCS (Object Composition Single)
    struts_edit_writeFieldOneCompo(field,owner)
  elsif (!os) && ic
    # OCM (Object Composition Multiple)
    struts_edit_writeFieldManyCompo(field,owner)
  end
end

#struts_edit_writeFieldCompo(field, owner, isMany) ⇒ Object



567
568
569
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 567

def struts_edit_writeFieldCompo(field,owner,isMany)
  struts_edit_writeFieldGeneric(field,owner,isMany,true)
end

#struts_edit_writeFieldGeneric(field, owner, isMany, isCompo) ⇒ Object



662
663
664
665
666
667
668
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 662

def struts_edit_writeFieldGeneric(field,owner,isMany,isCompo)
  #adds create and add section
  struts_edit_writeFieldGenericIsCompo(field,owner,isMany,isCompo)

  #adds table displaying already selected elements
  struts_edit_writeFieldGeneric_DisplayTable(field,owner,isMany,isCompo)
end

#struts_edit_writeFieldGeneric_DisplayTable(field, owner, isMany, isCompo) ⇒ Object



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

def struts_edit_writeFieldGeneric_DisplayTable(field,owner,isMany,isCompo)
  elt="elt_#{field.java_Name}"
  struts_encloseWrite(%{<logic:notEmpty name="#{owner.java_Name}StrutsForm" property="reference.#{field.java_Name}">\n},'</logic:notEmpty>') {
    if field.context[:jspUseXmdaTaglib]
      struts_edit_writeFieldGeneric_DisplayTable_displayTag(field,owner,isMany,isCompo)
    else
      struts_edit_writeFieldGeneric_DisplayTable_strutsOnly(field,owner,isMany,isCompo)
    end
  }
end

#struts_edit_writeFieldGeneric_DisplayTable_displayTag(field, owner, isMany, isCompo) ⇒ Object



683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 683

def struts_edit_writeFieldGeneric_DisplayTable_displayTag(field,owner,isMany,isCompo)
  elt="elt_#{field.java_Name}"
  struts_encloseWrite(%{

<div class="blockScroll">
<%--
	You can specify the column to sort by adding sortable="true"
	By default this is the first column
--%>
	<display:table id="#{elt}" name="sessionScope.#{owner.java_Name}StrutsForm.reference.#{field.java_Name}" defaultorder="descending" defaultsort="1" class="CWTable">
  	<display:column class='action'>
		<a onclick='removeAndDelete#{field.java_NameBean}("<c:out value="${#{elt}.id}"/>");return false;' >
			<img src="#{css_path_model}/#{css_color_class}/image/btnDelete.gif" alt="" border="0" height="16" width="16"/>
		</a>
	</display:column>
  	<display:column class='action'>
		<a onclick='edit#{field.java_NameBean}("<c:out value="${#{elt}.id}"/>");return false;' >
			<img src="#{css_path_model}/#{css_color_class}/image/btnCreate.gif" alt="" border="0" height="16" width="16"/>
		</a>
	</display:column>
    },
    %{</display:table>\n 
     #{%{<html:text property="#{field.java_Name}_strutsPage" size="40%" maxlength="2" />\n} if isMany && USE_PAGINATION} 
</div>

    }) {
    struts_eachLabelField(field) { |a|
    #field.uml_type_one.struts_formAttribute.each { |a|
      next if a.uml_name_one=="id"
      next if a.uml_name_one=="owner"
      t=a.uml_type_one
      next unless a.uml_type_one.kind_of?(Muml_Enumeration) || a.uml_type_one.kind_of?(Muml_DataType)
      tpl=DatatypeMapping.instance.getMapping(t)
      tpl.struts_edit_writeFieldGeneric_DisplayTable_displayTag_column(a)
    }
  }
end

#struts_edit_writeFieldGeneric_DisplayTable_strutsOnly(field, owner, isMany, isCompo) ⇒ Object



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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 721

def struts_edit_writeFieldGeneric_DisplayTable_strutsOnly(field,owner,isMany,isCompo)
  struts_encloseWrite( %{
<table class="proprietes"><%-- T:1006 --%>
	<thead><tr>
	#{field.uml_isReadOnly? ? "" : "<th>&nbsp;</th>"}
	<th>&nbsp;</th>
    }, %{</table>\n}) {
    field.uml_type_one.struts_formAttribute.each { |a|
      next if a.uml_name_one=="id"
      next if a.uml_name_one=="owner"
      next unless a.uml_type_one.kind_of?(Muml_Enumeration) || a.uml_type_one.kind_of?(Muml_DataType)
      write(%{<th><b>#{struts_writeMsg("#{a.umlx_owner_one.java_qualifiedName}.#{a.java_Name}")}</b></th>\n})
    }
    write %{</tr></thead>\n}

    before=isMany ? %{<logic:iterate id="#{elt}" name="#{owner.java_Name}StrutsForm" property="reference.#{field.java_Name}" >\n} : %{<bean:define id="#{elt}" name="#{owner.java_Name}StrutsForm" property="reference.#{field.java_Name}" />\n}
    after=isMany ? '</logic:iterate>' : '</bean>'

    struts_encloseWrite(before,after) {
      write %{<tr>}
      write %{<td class='action'><a onclick='removeAndDelete#{field.java_NameBean}("<bean:write name="#{elt}" property="id"/>");return false;'/>#{isCompo ? "[D]" : "[R]"}</a></td>\n} unless field.uml_isReadOnly?
      write %{<td class='action'><a  onclick='edit#{field.java_NameBean}("<bean:write name="#{elt}" property="id"/>");return false;'/>[E]</a></td>\n}

      field.uml_type_one.struts_formAttribute.each { |a|
        next if a.uml_name_one=="id"
        next if a.uml_name_one=="owner"
        next unless a.uml_type_one.kind_of?(Muml_Enumeration) || a.uml_type_one.kind_of?(Muml_DataType)
        if(a.uml_type_one.kind_of?(Muml_Enumeration))
          write(%{
<td class='action'>
	<%-- enum:TODO localize (use ressource) --%>
	<bean:write name="#{elt}" property="#{a.java_Name}"/>
</td>
            })
        else
          write(%{
<td class='action'>
	<bean:write name="#{elt}" property="#{a.java_Name}"/>
</td>
            })
        end

      }
      write %{</tr>\n}
    }
  }
end

#struts_edit_writeFieldGenericIsCompo(field, owner, isMany, isCompo) ⇒ Object



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 571

def struts_edit_writeFieldGenericIsCompo(field,owner,isMany,isCompo)
  return unless isCompo
  before=''
  after=''
  beforeIsEmpty=''
  afterIsEmpty=''
  b=%{<logic:empty name="#{owner.java_Name}StrutsForm" property="reference.#{field.java_Name}">\n}
  a=%{</logic:empty>\n}
  if !isMany
    # only display creater if adding one more is ok.
    before,after=b,a
  else
	  # display no element to display, only when collection is empty
    beforeIsEmpty,afterIsEmpty=b,a
  end

  struts_encloseWrite( before,after) {
    if context[:jspUseXmdaTaglib]
      write <<END

<div style=' width:400px; overflow:left; display: none; ' class="dialog"  id="Popup#{field.java_NameBean}">
  <div class="alphacube_close"  onclick="javascript:show_sel('#{field.java_Name}_createAndAdd');document.getElementById('Popup#{field.java_NameBean}').style.display='none';document.getElementById('add#{field.java_NameBean}').style.display='block';"> </div>
   <table  class="top table_window">
     <tbody>
       <tr>
         <td class="alphacube_nw">&nbsp;</td>
         <td class="alphacube_n">
	<div class="alphacube_title title_window top_draggable">
#{struts_writeMsg("#{field.umlx_owner_one.java_qualifiedName}.#{field.java_Name}")}</div></td>
         <td class="alphacube_ne">&nbsp;</td>
       </tr>
     </tbody>
   </table>
   <table class="mid table_window">
     <tbody>
       <tr>
         <td class="alphacube_w"></td>
         <td   class="alphacube_content" valign="top">
	<div    class="alphacube_content">
        <center><br/>   
	<select name="#{field.java_Name}_createAndAdd" onchange="createAndAdd#{field.java_NameBean}(options[selectedIndex].value);return false;" id="#{field.java_Name}_createAndAdd">
	<xmda:i18noptionsCollection name="#{owner.java_Name}StrutsForm" property="createAndAdd#{field.java_NameBean}Sug" />
		</select>
		</center><br/>
           </div></td>
         <td class="alphacube_e"></td>
       </tr>
     </tbody>
   </table>
   <table  class="bot table_window">
     <tbody>
       <tr>
         <td class="alphacube_sw">&nbsp;</td>
         <td class="alphacube_s"><div  class="status_bar bottom_draggable">&nbsp;</div></td>
         <td class="alphacube_sizer" >&nbsp;</td>
       </tr>
     </tbody>
   </table>
</div>
	<div  style="color:#FF5400;background-color:#FAFCEB;" id='add#{field.java_NameBean}'>
<a  onClick="javascript:hide_sel('#{field.java_Name}_createAndAdd');document.getElementById('Popup#{field.java_NameBean}').style.display='block';document.getElementById('add#{field.java_NameBean}').style.display='none';" >
<img src="res//orange/image/plus.gif" alt="Add"  border="0" />
</a>
#{beforeIsEmpty} &nbsp;&nbsp;&nbsp;<bean:message key="label.helper.none"/>#{afterIsEmpty}
	</div>

END
    else
      write %{

<%-- begin TPL:1006 --%>
<select name="#{field.java_Name}_createAndAdd" onchange="createAndAdd#{field.java_NameBean}(options[selectedIndex].value);return false;">
<logic:iterate id="_#{field.java_Name}" name="#{owner.java_Name}StrutsForm" property="createAndAdd#{field.java_NameBean}Sug" >
<option value="<bean:write name="_#{field.java_Name}" property="value" />" >
<bean:define id="_id">
<bean:write name="_#{field.java_Name}" property="label" />
</bean:define>
<%-- TODO: eviter entrelacement balises XML --%>
<bean:message key="<%= _id %>"/>
</option>
</logic:iterate>
</select>
<SCRIPT> <%-- TODO : supprimer javascript --%>
document.forms[0].#{field.java_Name}_createAndAdd.value="#{::Muml_Property::NIL_LVB_KEY}";
</SCRIPT>
<%-- end TPL:1006 --%>
      }
    end
  }
end

#struts_edit_writeFieldMany(field, owner) ⇒ Object



521
522
523
524
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 521

def struts_edit_writeFieldMany(field,owner)
  struts_edit_writeFieldGeneric(field,owner,true,false)
  struts_edit_writeSelectAndAdd(field,owner)
end

#struts_edit_writeFieldManyCompo(field, owner) ⇒ Object



560
561
562
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 560

def struts_edit_writeFieldManyCompo(field,owner)
  struts_edit_writeFieldCompo(field,owner,true)
end

#struts_edit_writeFieldOne(field, owner) ⇒ Object



769
770
771
772
773
774
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 769

def struts_edit_writeFieldOne(field,owner)
  struts_edit_writeFieldGeneric(field,owner,false,false)
  write %{<logic:empty name="#{owner.java_Name}StrutsForm" property="reference.#{field.java_Name}">\n}
  struts_edit_writeSelectAndAdd(field,owner)
  write %{</logic:empty>\n}
end

#struts_edit_writeFieldOneCompo(field, owner) ⇒ Object



563
564
565
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 563

def struts_edit_writeFieldOneCompo(field,owner)
  struts_edit_writeFieldCompo(field,owner,false)
end

#struts_edit_writeSelectAndAdd(field, owner) ⇒ Object



550
551
552
553
554
555
556
557
558
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 550

def struts_edit_writeSelectAndAdd(field,owner)
  return if field.uml_isReadOnly?
  elt="#{field.java_Name}_add"
  struts_encloseWrite( %{<select name="#{field.java_Name}_add" onchange="add#{field.java_NameBean}(value);"> \n<option>--</option>\n} ,%{</select>\n}) {
    struts_encloseWrite( %{<logic:iterate id="#{elt}" name="#{owner.java_Name}StrutsForm" property="reference.#{field.java_Name}Sug" >\n} ,%{</logic:iterate>}) {
      struts_encloseWrite( %{ <option value="<bean:write name="#{elt}" property="id"/>">\n},%{ </option> \n}) {
        struts_editWriteSelectAndAddLabel(field,elt)
      }}}
end

#struts_editWriteSelectAndAddLabel(field, elt, withLabelOnly = true) ⇒ Object

add label use every property stereotpyed Label. if none found, use every field



544
545
546
547
548
# File 'lib/ontomde-java/struts/jsp_edit.rb', line 544

def struts_editWriteSelectAndAddLabel(field,elt,withLabelOnly=true)
	struts_eachLabelField(field,withLabelOnly) { |a|
          write %{<bean:write name="#{elt}" property="#{a.java_Name}"/>,  }
	}
end

#struts_findElt(a, findFromSug = false) ⇒ Object



608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'lib/ontomde-java/struts/action.rb', line 608

def struts_findElt(a,findFromSug=false)
  sug=findFromSug ? "Sug" : ""
  cr=a
  e=struts_getFunctionalException
  return <<ENDCODE
	#{a.uml_type_one.java_qualifiedName} elt=null;
	{
java.util.Iterator<?> iter=form.getReference().get#{a.java_NameBean}#{sug}().iterator();
while(iter.hasNext()) {
	elt=(#{a.uml_type_one.java_qualifiedName})iter.next();
	if(elt.getId()!=id) continue;
	break;
	}
	}
	#{e.java_qualifiedName} exceptionToFire = new #{e.java_qualifiedName}("/pages/#{java_InternalFilePath}form/#{java_Name}#{STRUTS_RESULTS_FWD}.jsp","Internal error. #{cr.java_qualifiedName} called on null element");
	#{struts_getActionHelper.java_qualifiedName}.checkNotNull(elt,exceptionToFire);
ENDCODE
end

#struts_formAttribute(ignoreDbId = false, ignoreApplyToOrReturn = false) ⇒ Object

every attribute meant to appear in the form.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ontomde-java/struts/form.rb', line 49

def struts_formAttribute(ignoreDbId=false,ignoreApplyToOrReturn=false)
	#tab=context[:struts_tab,nil]

	ret=Array.new
	cgi=umlx_classifier_generalization_indirect
	cgi.add(self)
	cgi.each { |c|
		c.uml_ownedAttribute.each { |a|
			next if a.struts_ignoreInForm?(ignoreDbId)
			next if ignoreApplyToOrReturn && a.java_isMethodToClassApplyToOrReturn?
			ret << a
			}
	}
	return ret
end

#struts_formCastJavaCode(action = nil) ⇒ Object

Return java code to be included at the begining of every action execute method. Example: EffectiveFormType form=<EffectiveFormType> abstractForm;



57
58
59
60
61
62
63
# File 'lib/ontomde-java/struts/action.rb', line 57

def struts_formCastJavaCode(action=nil)
  action=struts_actionForm_one if action.nil?
  return <<ENDMETH
	#{action.java_qualifiedName} form=(#{action.java_qualifiedName})abstractForm;
	form.set#{STRUTS_DISPATCH_FIELD_METH}("");
ENDMETH
end

#struts_formOperationObject

every method meant to appear in the form.



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

def struts_formOperation()
	ret=Array.new
	cgi=umlx_classifier_generalization_indirect
	cgi.add(self)
	cgi.each { |c|
		c.uml_ownedOperation.each { |a|
			#next if a.db_isTransient?
			next if a.uml_isStatic?
			#next if a.java_ignoreMe?
			ret << a
			}
	}
	return ret
end

#struts_getFormInterfaceObject



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ontomde-java/struts/form.rb', line 83

def struts_getFormInterface
	iform=umlx_getOrCreateInterface(STRUTS_FORM_INTERFACE)
	if(iform.uml_ownedOperation.empty?)
		iform.umlx_external=RDF_FALSE
		iform.struts_addActionLocaleFormFields!
		["initFromReference","copyToReference"].each {|m|
			iform.umlx_createAndAddOperation(iform.rdf_uri+m,m);
		}
		iform.java_addAccessors!  #ajouter getter/setter
	end
	return iform
end

#struts_typeIsUsed?(type) ⇒ Boolean

Returns:

  • (Boolean)


189
190
191
192
193
194
195
196
197
198
# File 'lib/ontomde-java/struts/form.rb', line 189

def struts_typeIsUsed?(type)
	type=type.downcase
	struts_formAttribute.each { |a|
		t=a.uml_type_one
		next unless t.kind_of?(Muml_Property)
		next unless t.uml_name_one.downcase==type
		return true
		}
	return false
end

#umlx_literal(val) ⇒ Object

Returns an UML LiteralInteger initialized with val value.

Example:

  • umlx_literal(45)

  • umlx_literal(“45”)



54
55
56
57
58
# File 'lib/ontomde-java/java/accessorCode.rb', line 54

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

#umlx_ownedAndInheritedAttribute(ret = Set.new) ⇒ Object

returns every type assignable to this classifier (this includes self and any class deriving from it)



6
7
8
9
10
11
12
13
14
15
# File 'lib/ontomde-java/crank/helper.rb', line 6

def umlx_ownedAndInheritedAttribute(ret=Set.new)
  uml_ownedAttribute.each {|biz|
    ret << biz
  }
  uml_generalization.each { |g|
    next if g.kind_of?(Muml_Interface)
    g.uml_general_one.umlx_ownedAndInheritedAttribute(ret)
  }
  return ret
end

#xsd_writeAttributesObject

iterate xsd_write on attributes

NOTE

  • no attribute is generated for an interface

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



954
955
956
957
958
959
960
961
# File 'lib/ontomde-java/java/xsd.rb', line 954

def xsd_writeAttributes
  return if kind_of?(Muml_Interface)
  #sort has been added because ownedAttribute order is random
  #which causes false change detection on versionned file
  write(%{    <xsd:sequence>\n})
  uml_ownedAttribute.sort { |a,b| a.xsd_Name.to_s <=> b.xsd_Name.to_s }.each { |o| o.xsd_writeProperty}
  write(%{    </xsd:sequence>\n})
end

#xsd_writeClassCommentObject

Does nothing.



825
826
# File 'lib/ontomde-java/java/xsd.rb', line 825

def xsd_writeClassComment
end

#xsd_writeClassHeader(&block) ⇒ Object

write java header.

(Uses xsd_writePackageDeclaration, xsd_writeImports)

Exemple:

package pack1;
import xyz;


763
764
765
766
767
768
769
770
771
# File 'lib/ontomde-java/java/xsd.rb', line 763

def xsd_writeClassHeader(&block)
  return if context[:innerClass]
  #xsd_writePackageDeclaration {
  write(XSD_HEADER)
  xsd_writeImports
  yield
  write(XSD_FOOTER)
  #}
end

#xsd_writeConstructorsObject

Does nothing.



837
838
# File 'lib/ontomde-java/java/xsd.rb', line 837

def xsd_writeConstructors
end

#xsd_writeCustomCodeObject

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



811
812
813
814
815
816
817
818
819
820
821
822
# File 'lib/ontomde-java/java/xsd.rb', line 811

def xsd_writeCustomCode
  mtk_protected(Mrdf_Resource::NOREVERSE,"custom_code") {
    write !xsd_customCode.empty? ? xsd_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

#xsd_writeDeclarationSpecificOnBeginObject

Does nothing.



829
830
# File 'lib/ontomde-java/java/xsd.rb', line 829

def xsd_writeDeclarationSpecificOnBegin
end

#xsd_writeDeclarationSpecificOnEndObject

Does nothing.



833
834
# File 'lib/ontomde-java/java/xsd.rb', line 833

def xsd_writeDeclarationSpecificOnEnd
end

#xsd_writeExtends(&block) ⇒ Object

write java extends instructions is necessary (Uses xsd_qualifiedName)

Example:

extends Class2,Class3


862
863
864
865
866
867
868
869
870
871
872
873
874
# File 'lib/ontomde-java/java/xsd.rb', line 862

def xsd_writeExtends(&block)
  pre=""
  post=""
  tab=""
  uml_generalization.each { |g|
    pre+=%{#{tab}<xsd:complexContent>\n#{tab}  <xsd:extension base="#{g.uml_general_one.xsd_qualifiedName}">\n}
    post+=%{#{tab}  </xsd:extension>\n#{tab}</xsd:complexContent>\n}
    tab=tab+"  "
  }
  write(pre)
  yield
  write(post)
end

#xsd_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.


895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
# File 'lib/ontomde-java/java/xsd.rb', line 895

def xsd_writeImports
  xsd_dependencies.each {|dep|
    puts(%{<xsd:include schemaLocation="#{dep}"/>})
  
  }



  setOfImport=Set.new
  xsd_import.each { |imp|
    setOfImport<< imp
  }
  JAVA_DEFAULT_IMPORTS.each { |c|
    setOfImport<< c
  }
  if(JAVA_IMPORT_COMPUTED_DEPENDENCIES)
    umlx_computeDirectDepencies().each { |c|
      m=c.xsd_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.umlx_isARootNamespace?
      #import of class in root package is invalid
      setOfImport<<"java.lang.Object"
    else
      #we import something
      setOfImport<< self.xsd_qualifiedName;
    end
  end

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

#xsd_writeMetaClassName(&block) ⇒ Object

write java class keyword and class name

Example:

  • classe Class1



751
752
753
754
755
# File 'lib/ontomde-java/java/xsd.rb', line 751

def xsd_writeMetaClassName(&block)
  write(%{  <xsd:complexType name="#{xsd_qualifiedName}">\n})
  yield
  write(%{  </xsd:complexType>\n})
end

#xsd_writeTypeObject

write class body.

(Uses xsd_writeClassComment, xsd_writeClassModifiers, xsd_writeMetaClassName, xsd_writeExtends, xsd_writeImplements, xsd_writeDeclarationSpecificOnBegin, xsd_writeAttributes, xsd_writeConstructors, xsd_writeOperations, xsd_writeDeclarationSpecificOnEnd)


779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
# File 'lib/ontomde-java/java/xsd.rb', line 779

def xsd_writeType
  xsd_writeMetaClassName {
    xsd_writeExtends {
      # #     xsd_writeClassComment
      #      xsd_writeJavadoc
      #      xsd_writeAnnotation
      #      xsd_writeClassModifiers
      #      xsd_writeExtends
      #      xsd_writeImplements # class seulement
      #      # write("{\n")
      #      xsd_writeCustomCode
      #    
      #      xsd_writeDeclarationSpecificOnBegin
      xsd_writeAttributes
      #write("\n\n")
      #xsd_writeConstructors
#        write("\n\n")
      #xsd_writeOperations
      xsd_writeDeclarationSpecificOnEnd

      mtk_context(:innerClass=>true) {
        uml_nestedClassifier.each { |c|
          puts "ignored nested classifier #{c} in #{self}"
          #c.xsd_writeType # !!
        }
      }
    }
  }
end