module Domgen
  module Generator
    def self.define_jpa_templates
      template_dir = "#{File.dirname(__FILE__)}/templates"
      java_class_prefix = 'java/#{object_type.java.fully_qualified_name.gsub(".","/")}'
      java_package_prefix = 'java/#{schema.java.package.gsub(".","/")}'
      [
        Template.new(:object_type, "#{template_dir}/model.erb", "#{java_class_prefix}.java", [Domgen::Jpa::Helper]),
        Template.new(:object_type, "#{template_dir}/dao.erb", "#{java_class_prefix}DAO.java"),
        Template.new(:schema, "#{template_dir}/entity_manager.erb", "#{java_package_prefix}/SchemaEntityManager.java"),
        Template.new(:schema_set, "#{template_dir}/persistence.erb", 'resources/META-INF/persistence.xml'),
      ]
    end
  end
end

module Domgen
  module Generator
    module Jpa
      TEMPLATE_DIRECTORY = "#{File.dirname(__FILE__)}/templates"
      JAVA_CLASS_PREFIX = 'java/#{object_type.java.fully_qualified_name.gsub(".","/")}'
      JAVA_PACKAGE_PREFIX = 'java/#{schema.java.package.gsub(".","/")}'
    end

    def self.define_jpa_model_templates
      [Template.new(:object_type,
                    "#{Jpa::TEMPLATE_DIRECTORY}/model.erb",
                    "#{Jpa::JAVA_CLASS_PREFIX}.java",
                    [Domgen::Jpa::Helper])]
    end

    def self.define_jpa_ejb_templates
      [Template.new(:object_type, "#{Jpa::TEMPLATE_DIRECTORY}/ejb.erb", "#{Jpa::JAVA_CLASS_PREFIX}EJB.java"),]
    end

    def self.define_jpa_dao_templates
      [
        Template.new(:object_type, "#{Jpa::TEMPLATE_DIRECTORY}/dao.erb", "#{Jpa::JAVA_CLASS_PREFIX}DAO.java"),
        Template.new(:schema, "#{Jpa::TEMPLATE_DIRECTORY}/entity_manager.erb", "#{Jpa::JAVA_PACKAGE_PREFIX}/SchemaEntityManager.java"),
      ]
    end

    def self.define_jpa_jta_persistence_templates
      [Template.new(:schema_set, "#{Jpa::TEMPLATE_DIRECTORY}/persistence.erb", 'resources/META-INF/persistence.xml')]
    end
  end
end

Refactor so can selectively generate different jpa elements
Refactor so can selectively generate different jpa elements
