Module: Saxon::Loader

Defined in:
lib/saxon/loader.rb

Defined Under Namespace

Classes: MissingJarError, NoJarsError

Constant Summary collapse

LOAD_SEMAPHORE =
Mutex.new

Class Method Summary collapse

Class Method Details

.load!(saxon_home = File.expand_path('../../../vendor/saxonica', __FILE__)) ⇒ true, false

Returns true if Saxon had not been loaded and is now, and false if Saxon was already loaded

Parameters:

  • saxon_home (String, Pathname) (defaults to: File.expand_path('../../../vendor/saxonica', __FILE__))

    the path to the dir containing Saxon’s .jars. Defaults to the vendored Saxon HE

Returns:

  • (true, false)

    Returns true if Saxon had not been loaded and is now, and false if Saxon was already loaded



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/saxon/loader.rb', line 40

def self.load!(saxon_home = File.expand_path('../../../vendor/saxonica', __FILE__))
  return false if @saxon_loaded
  LOAD_SEMAPHORE.synchronize do
    if Saxon::S9API.const_defined?(:Processor)
      false
    else
      if jars_not_on_classpath?
        saxon_home = Pathname.new(saxon_home)
        raise NoJarsError, saxon_home unless saxon_home.directory?
        jars = [main_jar(saxon_home)].compact
        raise MissingJarError if jars.empty?
        jars += extra_jars(saxon_home)

        add_jars_to_classpath!(saxon_home, jars)
      end
      import_classes_to_namespace!

      @saxon_loaded = true
      true
    end
  end
end