class Rubernate::Bytecode::ProxyClass

Representation of the generated class

Attributes

class_file[RW]
clazz[RW]
const_pool[RW]
ct_class[RW]
frozen[RW]

Public Class Methods

new(ct_class) click to toggle source
# File lib/rubernate/bytecode.rb, line 49
def initialize(ct_class)
  self.ct_class = ct_class
  self.frozen = false
            
  java_import 'javassist.bytecode.ClassFile'
  java_import 'javassist.bytecode.AnnotationsAttribute'
  java_import 'javassist.bytecode.annotation.Annotation'
  java_import 'javassist.bytecode.annotation.StringMemberValue'
  
  self.class_file = self.ct_class.getClassFile
  self.const_pool = self.class_file.getConstPool
  
  ann_attr = AnnotationsAttribute.new(self.const_pool, AnnotationsAttribute.visibleTag)
  ann = Annotation.new("javax.persistence.Entity",self.const_pool)
  ann.add_member_value "name", StringMemberValue.new(self.ct_class.name,self.const_pool)
  

  ann_attr.set_annotation ann          
  self.class_file.addAttribute(ann_attr)                    
end

Public Instance Methods

add_annotation(field,name) click to toggle source

adds full qulified java annotation to a field @param javassist field @param field name

# File lib/rubernate/bytecode.rb, line 73
def add_annotation(field,name)
  ann_attr = AnnotationsAttribute.new(self.const_pool, AnnotationsAttribute.visibleTag)
  ann = Annotation.new(name,self.const_pool)
  
  ann_attr.set_annotation ann
  field.getFieldInfo.addAttribute ann_attr
end
add_parameter(type,name) click to toggle source

This wild add a parammeter to given class and generates te setter

@param java type @Param name of the field @return Generated field

# File lib/rubernate/bytecode.rb, line 93
def add_parameter(type,name)
   java_import 'javassist.CtField'
   java_import 'javassist.CtMethod'           
   java_import 'javassist.Modifier'
   java_import 'javax.persistence.Basic'
         
   field = CtField.make("private #{type} #{name};",self.ct_class)
   self.ct_class.add_field(field)      
   
   get = CtMethod.make(" public #{type} get#{name.capitalize}(){ return #{name}; }",self.ct_class)
   set = CtMethod.make(" public void set#{name.capitalize}(#{type} #{name}){ this.#{name} = #{name}; }",self.ct_class)          
   self.ct_class.add_method(get)
   self.ct_class.add_method(set)
   
   return field
end
add_simple(type,name) click to toggle source

add simple parameter to a field (see add_parameter)

# File lib/rubernate/bytecode.rb, line 83
def add_simple(type,name)
  add_parameter(Rubernate::Bytecode.mapped_types[type],name)
end
to_class() click to toggle source

@return java byte code generated class

# File lib/rubernate/bytecode.rb, line 111
def to_class          
  self.ct_class.to_class
end