Class: ClassBuilder
- Inherits:
-
Object
- Object
- ClassBuilder
- Defined in:
- lib/kody/builder/class_builder.rb
Instance Attribute Summary collapse
-
#business_package ⇒ Object
readonly
Returns the value of attribute business_package.
-
#enum_type ⇒ Object
readonly
Returns the value of attribute enum_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#persistence_package ⇒ Object
readonly
Returns the value of attribute persistence_package.
-
#stereotype ⇒ Object
readonly
Returns the value of attribute stereotype.
Instance Method Summary collapse
-
#initialize(clazz, engine) ⇒ ClassBuilder
constructor
A new instance of ClassBuilder.
- #relations ⇒ Object
- #sequence_name ⇒ Object
- #table_name ⇒ Object
- #to_liquid ⇒ Object
Constructor Details
#initialize(clazz, engine) ⇒ ClassBuilder
Returns a new instance of ClassBuilder.
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 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/kody/builder/class_builder.rb', line 15 def initialize(clazz, engine) @clazz = clazz @engine = engine @name = @clazz.name.strip @package = @clazz.package.full_name @table_name = nil @extends = @clazz.parent.full_name if !@clazz.parent.nil? @annotations = Array.new @imports = Array.new @persistence_package = engine.properties["project.persistence.package"]; raise "Property 'project.persistence.package' does not exists in #{App.specification.name}.properties." if @persistence_package.nil? @business_package = engine.properties["project.business.package"] raise "Property 'project.business.package' does not exists in #{App.specification.name}.properties." if @business_package.nil? @enum_type = "String" @attributes = Array.new @clazz.attributes.each do |a| att = AttributeBuilder.new(a, self, engine) @attributes << att @imports = @imports + att.imports @enum_type = att.type end inheritance = nil @clazz.tagged_values.each do |t| if "@andromda.persistence.table" == t.name @table_name = t.value.downcase[0, 30] elsif "@andromda.hibernate.inheritance" == t.name # "org.andromda.profile::persistence::HibernateInheritanceStrategy::subclass" inheritance = "JOINED" if t.value == "org.andromda.profile::persistence::HibernateInheritanceStrategy::class" inheritance = "SINGLE_TABLE" @annotations << "@DiscriminatorColumn(name=\"class\", discriminatorType=DiscriminatorType.STRING)" @imports << "javax.persistence.DiscriminatorColumn" @imports << "javax.persistence.DiscriminatorType" end elsif "@andromda.hibernate.generator.class" == t.name else puts "tagged value desconhecida: #{clazz.name} - #{t.name}: #{t.value}" end end # Verifica se esta classe possui filhas. # Caso positipo irá tratar a estratégia de herança "JOINED" if inheritance.nil? && !@clazz.children.nil? && @clazz.children.size > 0 inheritance = "JOINED" end # Verifica se este classe é filha e se a classe pai possui a tagged value @andromda.persistence.inheritance if inheritance.nil? && !@clazz.parent.nil? puts "Possui heranca #{@name }- #{@clazz.parent}" @clazz.parent.tagged_values.each do |t| puts "Tags '#{t.name}' = '#{t.value}'" if "@andromda.persistence.inheritance".eql?(t.name) puts 'Chegou aqui' if t.value == "org.andromda.profile::persistence::HibernateInheritanceStrategy::class" puts 'Chegou aqui 2' @annotations << "@DiscriminatorValue(\"#{@clazz.parent.name.strip}\")" end break end end end if !inheritance.nil? @annotations << "@Inheritance(strategy=InheritanceType.#{inheritance})" @imports << "javax.persistence.Inheritance" @imports << "javax.persistence.InheritanceType" end @clazz.stereotypes.each do |s| case s.name when "org.andromda.profile::persistence::Entity", "UML Standard Profile::entity", "Entity" @stereotype = :entity when "org.andromda.profile::persistence::WebServiceData" @stereotype = :web_service_data when "org.andromda.profile::ApplicationException" @stereotype = :application_exception when "org.andromda.profile::Enumeration" @stereotype = :enumeration when "org.andromda.profile::presentation::FrontEndSessionObject" @stereotype = :front_end_session_object when "org.andromda.profile::ValueObject" @stereotype = :value_object else App.logger.warn "Stereotype desconhecido: '#{s.name}', classe: #{clazz.name}" end end @imports = @imports.uniq.sort end |
Instance Attribute Details
#business_package ⇒ Object (readonly)
Returns the value of attribute business_package.
12 13 14 |
# File 'lib/kody/builder/class_builder.rb', line 12 def business_package @business_package end |
#enum_type ⇒ Object (readonly)
Returns the value of attribute enum_type.
13 14 15 |
# File 'lib/kody/builder/class_builder.rb', line 13 def enum_type @enum_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/kody/builder/class_builder.rb', line 9 def name @name end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
10 11 12 |
# File 'lib/kody/builder/class_builder.rb', line 10 def package @package end |
#persistence_package ⇒ Object (readonly)
Returns the value of attribute persistence_package.
11 12 13 |
# File 'lib/kody/builder/class_builder.rb', line 11 def persistence_package @persistence_package end |
#stereotype ⇒ Object (readonly)
Returns the value of attribute stereotype.
8 9 10 |
# File 'lib/kody/builder/class_builder.rb', line 8 def stereotype @stereotype end |
Instance Method Details
#relations ⇒ Object
135 136 137 |
# File 'lib/kody/builder/class_builder.rb', line 135 def relations Array.new end |
#sequence_name ⇒ Object
155 156 157 |
# File 'lib/kody/builder/class_builder.rb', line 155 def sequence_name "#{table_name}_seq" end |
#table_name ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/kody/builder/class_builder.rb', line 139 def table_name return @table_name unless @table_name.nil? @table_name = @clazz.name.underscore App.abbreviations.each do |k, v| @table_name.gsub!(/^#{k}_/, "#{v}_") @table_name.gsub!(/_#{k}_/, "_#{v}_") @table_name.gsub!(/_#{k}$/, "_#{v}") @table_name.gsub!(/^#{k}$/, "#{v}") #puts "#{k} -> #{v} = #{@table_name}" end @table_name = @table_name[0, 30] @table_name end |
#to_liquid ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/kody/builder/class_builder.rb', line 118 def to_liquid { 'annotations' => @annotations, 'attributes' => @attributes, 'business_package' => @business_package, 'extends' => @extends, 'enum_type' => @enum_type, 'name'=> @name, 'imports' => @imports, 'package' => @package, 'persistence_package' => @persistence_package, 'relations' => relations, 'table_name' => table_name, 'sequence_name' => sequence_name } end |