Module: Muml_Class

Defined in:
lib/ontomde-uml2-java/java.rb,
lib/ontomde-uml2-java/java.rb,
lib/ontomde-uml2-java/security.rb,
lib/ontomde-uml2-java/enumCompatibilityLayer.rb

Constant Summary collapse

JAVA_GETSTATIC_ROLE_COMMENT =

method comment that will be generated as javadoc

<<ENDHELP 
This method returns a set of "static roles" that *may* *be* granted to the user based on database informations. 

When a "security role" (defined at runtime) is bounded(linked) to a "static role" (defined at compile time), 
users must 
- be granted the security role 
- and the bounded "static role" must be included in the set of role returned by this method.
ENDHEL
JAVA_GETSTATIC_ROLE_CODE =

method default implementation

<<ENDROLECODE
//return empty list (every static role are denied)
return new java.util.HashSet<#{Mrdf_Model::JAVA_GLOBAL_ACCESS_CONTROL_ENUM}>();
ENDROLECODE

Instance Method Summary collapse

Instance Method Details

#java_addEnumPostDeserialiseUpdate!Object



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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/ontomde-uml2-java/enumCompatibilityLayer.rb', line 87

def java_addEnumPostDeserialiseUpdate!
	#TODO optimize
	#return unless java_hasEnumDirectProperties?

	#rr=umlx_createAndAddOperation(self.rdf_uri+"_"+"readResolve","readResolve")
	#rr.uml_raisedException_add(umlx_getOrCreateClass("java.io.ObjectStreamException"))
	#rr.uml_visibility=::Cuml_VisibilityKind::Private
	#rr.java_code="updateEnumFromEnumAsString();\nreturn this;\n"

	#rp=rr.umlx_createAndAddReturnParameter(rr.rdf_uri+"_ret")
	#rp.uml_type=umlx_getOrCreateClass("java.lang.Object")


	#u=umlx_createAndAddOperation(self.rdf_uri+"_"+"upd_Enum","updateEnumFromEnumAsString")


	#code=%{Sy stem.out.println("readResolve #{java_qualifiedName}");\n}
	#code=code+(uml_generalization.empty? ? "//" : "")+"super.#{u.java_Name}();\n"

	uml_ownedAttribute.each { |a|
		next unless a.uml_type_one.kind_of?(Muml_Enumeration)
		a.java_setter_property_inv.each { |g|
			g.java_code=g.java_code_one+<<END
			\n#{a.umlx_stringMappingForEnum_one.java_Name}=#{a.java_Name}.name();
END
		}
		a.umlx_stringMappingForEnum_one.java_getter_property_inv.each { |g|
			#asString is not updated when loaded from base
			g.java_code=%{#{a.umlx_stringMappingForEnum_one.java_Name}= #{a.java_Name}==null ? null : #{a.java_Name}.name();\n}+g.java_code_one
		}
		a.umlx_stringMappingForEnum_one.java_setter_property_inv.each { |g|
			g.java_code=g.java_code_one+<<END
			\n#{a.java_Name}=Enum.valueOf(#{a.uml_type_one.java_qualifiedName}.class,#{a.umlx_stringMappingForEnum_one.java_Name});
END
		}

		#code=code+<<END
		#if(#{a.umlx_stringMappingForEnum_one.java_Name}!=null) {
		#	#{a.java_Name}=Enum.valueOf(#{a.uml_type_one.java_qualifiedName}.class,#{a.umlx_stringMappingForEnum_one.java_Name});
		#} else {
		#	#{a.java_Name}=null;
		#}
	 #END
	}
	#u.java_code=code;

	return
end

#java_hasEnumDirectProperties?Boolean

returns true if class has at least one enum property Inherited properties are not taken into account.

Returns:

  • (Boolean)


80
81
82
83
84
85
# File 'lib/ontomde-uml2-java/enumCompatibilityLayer.rb', line 80

def java_hasEnumDirectProperties?
	uml_ownedAttribute.each { |a|
		return true if a.uml_type_one.kind_of?(Muml_Enumeration)
	}
	return false
end

#java_makeSerializable!Object

Mark this java class as serializable.

  • adds implements java.io.Serializable

  • adds serialVersionUID variable

Example:

private static final long serialVersionUID = 1L;


1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
# File 'lib/ontomde-uml2-java/java.rb', line 1238

def java_makeSerializable!
  #java_implements_add("java.io.Serializable");
  s=umlx_getOrCreateClass("java.io.Serializable")
  umlx_createAndAddImplementation(s)

  p=umlx_createAndAddProperty(rdf_uri+"_serialVersionUID","serialVersionUID");
  p.uml_visibility=::Cuml_VisibilityKind::Private
  p.uml_isStatic=RDF_TRUE
  p.java_isFinal=RDF_TRUE
  p.java_isTransient=RDF_TRUE
  p.uml_type=umlx_dataType_long
  p.java_code="1L"
  p.java_noAccessors=RDF_TRUE
end

#java_writeConstructorsObject

Adds a constructor with paramter

NOTE:

  • EXPERIMENTAL

TODO: associations, et filtrer attributs static



509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/ontomde-uml2-java/java.rb', line 509

def java_writeConstructors
  write("  public #{java_Name}() {\n")
  write("  }\n")
  #TODO: associations ??, filtrer static
  if (!uml_ownedAttribute.empty?)
    parameters = ""
    uml_ownedAttribute.each { |o|
      if o.umlx_isAttribute?
        parameters << ", "
        parameters << o.java_propertyRoleType.to_s
        parameters << " "
        parameters << o.java_NameProperty
      end
    }
    if (!parameters.empty?)
      write("\n")
      parameters = parameters.slice(1, parameters.length)
      write("  public #{java_Name}(#{parameters}) {\n")
      uml_ownedAttribute.each { |o|
        if o.umlx_isAttribute?
          write("    set#{o.java_NameBean}(#{o.java_NameProperty});\n")
        end
      }
      write("  }\n")
    end
  end
end

#java_writeImplementsObject

write java implements declaration clause if needed.

Example:

  • implements interface1, interface2



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/ontomde-uml2-java/java.rb', line 486

def java_writeImplements
  imp=Set.new
  uml_implementation.each { |g|
    imp.add(g.uml_supplier_one.java_qualifiedName)
  }
  java_implements.each { |g|
    imp.add(g)
  }

  sep="\nimplements "
  imp.sort{ |a,b| a <=> b}.each { |g|
    write(sep)
    write(g)
    sep=","
  }
end

#java_writeMetaClassNameObject

write java class keyword and class name

Example:

  • classe Class1



478
479
480
# File 'lib/ontomde-uml2-java/java.rb', line 478

def java_writeMetaClassName
  write(" class #{java_Name}")
end

#umlx_addGetStaticRoleOperation!Object

public List<SecurityRole> getStaticRoles(org.acegi.security.UserDetails userName



239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/ontomde-uml2-java/security.rb', line 239

def umlx_addGetStaticRoleOperation!
  m=self.umlx_createAndAddOperation("#{rdf_uri}_getComputedAccessControlGrant","getComputedAccessControlGrant")

  r=m.umlx_createAndAddReturnParameter("#{m.rdf_uri}_return")
  r.uml_type=umlx_reserved_model.umlx_getOrCreateEnumeration(Mrdf_Model::JAVA_GLOBAL_ACCESS_CONTROL_ENUM,Muml_Classifier::UMLX_SEARCH_EVERY_MODEL)
  r.uml_upperValue=umlx_literal(-1)
  r.umlx_createAndAddComment("#{r.rdf_uri}_c1",JAVA_GETSTATIC_ROLE_COMMENT)
 
  p=m.umlx_createAndAddParameter("#{m.rdf_uri}_p1","user")
  p.uml_type=umlx_reserved_model.umlx_getOrCreateEnumeration("org.acegisecurity.userdetails.UserDetails",Muml_Classifier::UMLX_SEARCH_EVERY_MODEL)
  
  m.java_code=JAVA_GETSTATIC_ROLE_CODE
end