module ActiveFedora

def self.fedora

def self.fedora
  Fedora::Repository.instance
end

def self.init( config_path=nil )

def self.init( config_path=nil )
  
  config_env = defined?(RAILS_ENV) ? RAILS_ENV : "development"
  
  if config_path.nil? 
    if defined?(RAILS_ROOT)
      config_path = "#{RAILS_ROOT}/config/fedora.yml"
    else
      raise "Don't know where to look for fedora.yml.  You should either set RAILS_ROOT or pass the path to fedora.yml as an argument to ActiveFedora.init"
    end
  end
  
  logger.info("FEDORA: loading ActiveFedora config from #{File.expand_path(config_path)}")
  
  fedora_config = YAML::load(File.open(config_path))
  raise "The #{config_env} environment settings were not found in the fedora.yml config.  If you already have a fedora.yml file defined, make sure it defines settings for the #{config_env} environment" unless fedora_config[config_env]
  
  ActiveFedora.solr_config[:url] = fedora_config[config_env]['solr']['url']
  
  # Register Solr
  logger.info("FEDORA: initializing ActiveFedora::SolrService with solr_config: #{ActiveFedora.solr_config.inspect}")
  
  ActiveFedora::SolrService.register(ActiveFedora.solr_config[:url])
  logger.info("FEDORA: initialized Solr with ActiveFedora.solr_config: #{ActiveFedora::SolrService.instance.inspect}")
      
  ActiveFedora.fedora_config[:url] = fedora_config[config_env]['fedora']['url']
  logger.info("FEDORA: initializing Fedora with fedora_config: #{ActiveFedora.fedora_config.inspect}")
  
  Fedora::Repository.register(ActiveFedora.fedora_config[:url])
  logger.info("FEDORA: initialized Fedora as: #{Fedora::Repository.instance.inspect}")    
  
end

def self.logger

def self.logger      
  @logger ||= defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new(STDOUT)
end

def self.solr

def self.solr
  ActiveFedora::SolrService.instance
end