saxon 0.1.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +20 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/net/sf/saxon/Saxon-HE/9.9.1-2/Saxon-HE-9.9.1-2.jar +0 -0
- data/lib/saxon.rb +6 -0
- data/lib/saxon/axis_iterator.rb +32 -0
- data/lib/saxon/configuration.rb +116 -0
- data/lib/saxon/document_builder.rb +28 -0
- data/lib/saxon/item_type.rb +200 -0
- data/lib/saxon/jaxp.rb +8 -0
- data/lib/saxon/loader.rb +103 -0
- data/lib/saxon/occurrence_indicator.rb +33 -0
- data/lib/saxon/parse_options.rb +127 -0
- data/lib/saxon/processor.rb +102 -0
- data/lib/saxon/qname.rb +97 -0
- data/lib/saxon/s9api.rb +16 -0
- data/lib/saxon/serializer.rb +143 -0
- data/lib/saxon/source.rb +187 -0
- data/lib/saxon/version.rb +3 -0
- data/lib/saxon/xdm_atomic_value.rb +48 -0
- data/lib/saxon/xdm_node.rb +65 -0
- data/lib/saxon/xdm_value.rb +129 -0
- data/lib/saxon/xpath.rb +8 -0
- data/lib/saxon/xpath/compiler.rb +69 -0
- data/lib/saxon/xpath/executable.rb +59 -0
- data/lib/saxon/xpath/static_context.rb +204 -0
- data/lib/saxon/xpath/variable_declaration.rb +68 -0
- data/lib/saxon/xslt.rb +8 -0
- data/lib/saxon/xslt/compiler.rb +61 -0
- data/lib/saxon/xslt/executable.rb +127 -0
- data/lib/saxon/xslt/static_context.rb +69 -0
- data/lib/saxon_jars.rb +10 -0
- data/saxon.gemspec +38 -0
- metadata +215 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19f0e9fb8c21c339568c774ffc0c3020f39d45f896c1bf009c9d1052bed65412
|
4
|
+
data.tar.gz: 92ec755ab385c2ab0509db7a4e5846f22979be58a12cc1fe7fefcc8f1350899f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8154c57826865c13c48347ab517f9c9fa8c0499f0ee1693c063a381571d8401275c0c8718a25f3fcb4e37910423c1b7ca670b9cd490464d8bbd396e66a74379
|
7
|
+
data.tar.gz: 63a5ca988ee42631bf7f02158c8ce377015269716a54c194e8756a4c158e602a00c67965538cf59136517f0785de226155b05b7e56b8699a58009d76a0e19d1c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-9.2.6.0
|
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
dist: trusty
|
2
|
+
sudo: false
|
3
|
+
language: ruby
|
4
|
+
rvm:
|
5
|
+
- jruby-9.1.17.0
|
6
|
+
- jruby-1.7.27
|
7
|
+
jdk:
|
8
|
+
- oraclejdk8
|
9
|
+
- openjdk7
|
10
|
+
before_install: gem install bundler -v 1.16.1
|
11
|
+
cache: bundler
|
12
|
+
env:
|
13
|
+
JDK_VERSION_FOR_CODECLIMATE: oraclejdk8
|
14
|
+
JRUBY_OPTS: "--debug"
|
15
|
+
before_script:
|
16
|
+
- if [ "$TRAVIS_JDK_VERSION" = "$JDK_VERSION_FOR_CODECLIMATE" ]; then curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter; chmod +x ./cc-test-reporter; ./cc-test-reporter before-build; fi
|
17
|
+
script:
|
18
|
+
- bundle exec rspec
|
19
|
+
- if [[ "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_JDK_VERSION" = "$JDK_VERSION_FOR_CODECLIMATE" ]]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
|
20
|
+
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at matt@reprocessed.org. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Matt Patterson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Saxon
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/saxon`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'saxon'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install saxon
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/saxon. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Saxon project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/saxon/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "saxon"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
Binary file
|
data/lib/saxon.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'saxon/s9api'
|
2
|
+
require 'saxon/xdm_node'
|
3
|
+
|
4
|
+
module Saxon
|
5
|
+
# An XPath Data Model Node object, representing an XML document, or an element or one of the other node chunks in the XDM.
|
6
|
+
class AxisIterator
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
attr_reader :s9_xdm_node, :s9_axis
|
10
|
+
private :s9_xdm_node, :s9_axis
|
11
|
+
|
12
|
+
def initialize(xdm_node, axis)
|
13
|
+
@s9_xdm_node = xdm_node.to_java
|
14
|
+
@s9_axis = Saxon::S9API::Axis.const_get(axis.to_s.upcase.to_sym)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Saxon::S9API::XdmSequenceIterator] A new Saxon Java XDM sequence iterator.
|
18
|
+
def to_java
|
19
|
+
s9_sequence_iterator
|
20
|
+
end
|
21
|
+
|
22
|
+
def each(&block)
|
23
|
+
s9_sequence_iterator.lazy.map { |s9_xdm_node| Saxon::XdmNode.new(s9_xdm_node) }.each(&block)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def s9_sequence_iterator
|
29
|
+
s9_xdm_node.axisIterator(s9_axis)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'saxon/s9api'
|
2
|
+
require 'saxon/parse_options'
|
3
|
+
|
4
|
+
module Saxon
|
5
|
+
# Wraps the <tt>net.saxon.Configuration</tt> class. See
|
6
|
+
# http://saxonica.com/documentation9.5/javadoc/net/sf/saxon/Configuration.html
|
7
|
+
# for details of what configuration options are available and what values
|
8
|
+
# they accept. See
|
9
|
+
# http://saxonica.com/documentation9.5/javadoc/net/sf/saxon/lib/FeatureKeys.html
|
10
|
+
# for details of the constant names used to access the values
|
11
|
+
class Configuration
|
12
|
+
DEFAULT_SEMAPHORE = Mutex.new
|
13
|
+
|
14
|
+
# Provides a processor with default configuration. Essentially a singleton
|
15
|
+
# instance
|
16
|
+
# @return [Saxon::Configuration]
|
17
|
+
def self.default
|
18
|
+
DEFAULT_SEMAPHORE.synchronize do
|
19
|
+
@config ||= create
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param processor [Saxon::Processor] a Saxon::Processor instance
|
24
|
+
# @return [Saxon::Configuration]
|
25
|
+
def self.create(processor = nil)
|
26
|
+
Saxon::Loader.load!
|
27
|
+
if processor
|
28
|
+
config = processor.to_java.underlying_configuration
|
29
|
+
else
|
30
|
+
config = Saxon::S9API::Configuration.new
|
31
|
+
end
|
32
|
+
new(config)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param license_path [String] the absolute path to a Saxon PE or EE
|
36
|
+
# license file
|
37
|
+
# @return [Saxon::Configuration]
|
38
|
+
def self.create_licensed(license_path)
|
39
|
+
Saxon::Loader.load!
|
40
|
+
java_config = Saxon::S9API::Configuration.makeLicensedConfiguration(nil, nil)
|
41
|
+
config = new(java_config)
|
42
|
+
config[:LICENSE_FILE_LOCATION] = license_path
|
43
|
+
config
|
44
|
+
end
|
45
|
+
|
46
|
+
# Set a already-created Licensed Configuration object as the default
|
47
|
+
# configuration
|
48
|
+
def self.set_licensed_default!(licensed_configuration)
|
49
|
+
DEFAULT_SEMAPHORE.synchronize do
|
50
|
+
@config = licensed_configuration
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# @api private
|
55
|
+
# @param config [net.sf.saxon.Configuration] The Saxon Configuration
|
56
|
+
# instance to wrap
|
57
|
+
def initialize(config)
|
58
|
+
@config = config
|
59
|
+
end
|
60
|
+
|
61
|
+
# Get a configuration option value
|
62
|
+
# See https://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/lib/FeatureKeys.html
|
63
|
+
# for details of the available options. Use the constant name as a string
|
64
|
+
# or symbol as the option
|
65
|
+
#
|
66
|
+
# @param option [String, Symbol]
|
67
|
+
# @return [Object] the value of the configuration option
|
68
|
+
# @raise [NameError] if the option name does not exist
|
69
|
+
def [](option)
|
70
|
+
@config.getConfigurationProperty(option_url(option))
|
71
|
+
end
|
72
|
+
|
73
|
+
# Get a configuration option value
|
74
|
+
# See http://saxonica.com/documentation9.5/javadoc/net/sf/saxon/lib/FeatureKeys.html
|
75
|
+
# for details of the available options. Use the constant name as a string
|
76
|
+
# or symbol as the option
|
77
|
+
#
|
78
|
+
# @param option [String, Symbol]
|
79
|
+
# @param value [Object] the value of the configuration option
|
80
|
+
# @return [Object] the value you passed in
|
81
|
+
# @raise [NameError] if the option name does not exist
|
82
|
+
def []=(option, value)
|
83
|
+
url = option_url(option)
|
84
|
+
@config.setConfigurationProperty(url, value)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Return the current ParseOptions object
|
88
|
+
# See https://www.saxonica.com/documentation/index.html#!javadoc/net.sf.saxon.lib/ParseOptions
|
89
|
+
# for details. This allows you to set JAXP features and properties to be
|
90
|
+
# passed to the parser
|
91
|
+
#
|
92
|
+
# @return [Saxon::ParseOptions] the ParseOptions object
|
93
|
+
def parse_options
|
94
|
+
ParseOptions.new(@config.getParseOptions)
|
95
|
+
end
|
96
|
+
|
97
|
+
# @return [net.sf.saxon.Configuration] The underlying Saxon Configuration
|
98
|
+
def to_java
|
99
|
+
@config
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def feature_keys
|
105
|
+
@feature_keys ||= Saxon::S9API::FeatureKeys.java_class
|
106
|
+
end
|
107
|
+
|
108
|
+
def option_url(option)
|
109
|
+
feature_keys.field(normalize_option_name(option)).static_value
|
110
|
+
end
|
111
|
+
|
112
|
+
def normalize_option_name(option)
|
113
|
+
option.to_s.upcase
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'saxon/xdm_node'
|
2
|
+
|
3
|
+
module Saxon
|
4
|
+
# Builds XDM objects from XML sources, for use in XSLT or for query and
|
5
|
+
# access
|
6
|
+
class DocumentBuilder
|
7
|
+
# @api private
|
8
|
+
# @param [net.sf.saxon.s9api.DocumentBuilder] s9_document_builder The
|
9
|
+
# Saxon DocumentBuilder instance to wrap
|
10
|
+
def initialize(s9_document_builder)
|
11
|
+
@s9_document_builder = s9_document_builder
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param [Saxon::Source] source The Saxon::Source containing the source
|
15
|
+
# IO/string
|
16
|
+
# @return [Saxon::XdmNode] The Saxon::XdmNode representing the root of the
|
17
|
+
# document tree
|
18
|
+
def build(source)
|
19
|
+
XdmNode.new(@s9_document_builder.build(source.to_java))
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [net.sf.saxon.s9api.DocumentBuilder] The underlying Java Saxon
|
23
|
+
# DocumentBuilder instance
|
24
|
+
def to_java
|
25
|
+
@s9_document_builder
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
require_relative 's9api'
|
2
|
+
|
3
|
+
module Saxon
|
4
|
+
# Represent XDM types abstractly
|
5
|
+
class ItemType
|
6
|
+
# A mapping of Ruby types to XDM type constants
|
7
|
+
TYPE_MAPPING = {
|
8
|
+
'String' => :STRING,
|
9
|
+
'Array' => :ANY_ARRAY,
|
10
|
+
'Hash' => :ANY_MAP,
|
11
|
+
'TrueClass' => :BOOLEAN,
|
12
|
+
'FalseClass' => :BOOLEAN,
|
13
|
+
'Date' => :DATE,
|
14
|
+
'DateTime' => :DATE_TIME,
|
15
|
+
'Time' => :DATE_TIME,
|
16
|
+
'BigDecimal' => :DECIMAL,
|
17
|
+
'Integer' => :INTEGER,
|
18
|
+
'Float' => :FLOAT,
|
19
|
+
'Numeric' => :NUMERIC
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
# A mapping of type names/QNames to XDM type constants
|
23
|
+
STR_MAPPING = {
|
24
|
+
'array(*)' => :ANY_ARRAY,
|
25
|
+
'xs:anyAtomicType' => :ANY_ATOMIC_VALUE,
|
26
|
+
'item()' => :ANY_ITEM,
|
27
|
+
'map(*)' => :ANY_MAP,
|
28
|
+
'node()' => :ANY_NODE,
|
29
|
+
'xs:anyURI' => :ANY_URI,
|
30
|
+
'xs:base64Binary' => :BASE64_BINARY,
|
31
|
+
'xs:boolean' => :BOOLEAN,
|
32
|
+
'xs:byte' => :BYTE,
|
33
|
+
'xs:date' => :DATE,
|
34
|
+
'xs:dateTime' => :DATE_TIME,
|
35
|
+
'xs:dateTimeStamp' => :DATE_TIME_STAMP,
|
36
|
+
'xs:dayTimeDuration' => :DAY_TIME_DURATION,
|
37
|
+
'xs:decimal' => :DECIMAL,
|
38
|
+
'xs:double' => :DOUBLE,
|
39
|
+
'xs:duration' => :DURATION,
|
40
|
+
'xs:ENTITY' => :ENTITY,
|
41
|
+
'xs:float' => :FLOAT,
|
42
|
+
'xs:gDay' => :G_DAY,
|
43
|
+
'xs:gMonth' => :G_MONTH,
|
44
|
+
'xs:gMonthDay' => :G_MONTH_DAY,
|
45
|
+
'xs:gYear' => :G_YEAR,
|
46
|
+
'xs:gYearMonth' => :G_YEAR_MONTH,
|
47
|
+
'xs:hexBinary' => :HEX_BINARY,
|
48
|
+
'xs:ID' => :ID,
|
49
|
+
'xs:IDREF' => :IDREF,
|
50
|
+
'xs:int' => :INT,
|
51
|
+
'xs:integer' => :INTEGER,
|
52
|
+
'xs:language' => :LANGUAGE,
|
53
|
+
'xs:long' => :LONG,
|
54
|
+
'xs:Name' => :NAME,
|
55
|
+
'xs:NCName' => :NCNAME,
|
56
|
+
'xs:negativeInteger' => :NEGATIVE_INTEGER,
|
57
|
+
'xs:NMTOKEN' => :NMTOKEN,
|
58
|
+
'xs:nonNegativeInteger' => :NON_NEGATIVE_INTEGER,
|
59
|
+
'xs:nonPositiveInteger' => :NON_POSITIVE_INTEGER,
|
60
|
+
'xs:normalizedString' => :NORMALIZED_STRING,
|
61
|
+
'xs:NOTATION' => :NOTATION,
|
62
|
+
'xs:numeric' => :NUMERIC,
|
63
|
+
'xs:positiveInteger' => :POSITIVE_INTEGER,
|
64
|
+
'xs:QName' => :QNAME,
|
65
|
+
'xs:short' => :SHORT,
|
66
|
+
'xs:string' => :STRING,
|
67
|
+
'xs:time' => :TIME,
|
68
|
+
'xs:token' => :TOKEN,
|
69
|
+
'xs:unsignedByte' => :UNSIGNED_BYTE,
|
70
|
+
'xs:unsignedInt' => :UNSIGNED_INT,
|
71
|
+
'xs:unsignedLong' => :UNSIGNED_LONG,
|
72
|
+
'xs:unsignedShort' => :UNSIGNED_SHORT,
|
73
|
+
'xs:untypedAtomic' => :UNTYPED_ATOMIC,
|
74
|
+
'xs:yearMonthDuration' => :YEAR_MONTH_DURATION
|
75
|
+
}.freeze
|
76
|
+
|
77
|
+
class << self
|
78
|
+
# Get an appropriate {ItemType} for a Ruby type or given a type name as a
|
79
|
+
# string
|
80
|
+
#
|
81
|
+
# @return [Saxon::ItemType]
|
82
|
+
# @overload get_type(ruby_class)
|
83
|
+
# Get an appropriate {ItemType} for object of a given Ruby class
|
84
|
+
# @param ruby_class [Class] The Ruby class to get a type for
|
85
|
+
# @overload get_type(type_name)
|
86
|
+
# Get the {ItemType} for the name
|
87
|
+
# @param type_name [String] name of the built-in {ItemType} to fetch
|
88
|
+
def get_type(arg)
|
89
|
+
new(get_s9_type(arg))
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def get_s9_type(arg)
|
95
|
+
case arg
|
96
|
+
when Class
|
97
|
+
get_s9_class_mapped_type(arg)
|
98
|
+
when String
|
99
|
+
get_s9_str_mapped_type(arg)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def get_s9_class_mapped_type(klass)
|
104
|
+
class_name = klass.name
|
105
|
+
if mapped_type = TYPE_MAPPING.fetch(class_name, false)
|
106
|
+
S9API::ItemType.const_get(mapped_type)
|
107
|
+
else
|
108
|
+
raise UnmappedRubyTypeError, class_name
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_s9_str_mapped_type(type_str)
|
113
|
+
if mapped_type = STR_MAPPING.fetch(type_str, false)
|
114
|
+
# ANY_ITEM is a method, not a constant, for reasons not entirely
|
115
|
+
# clear to me
|
116
|
+
return S9API::ItemType.ANY_ITEM if mapped_type == :ANY_ITEM
|
117
|
+
S9API::ItemType.const_get(mapped_type)
|
118
|
+
else
|
119
|
+
raise UnmappedXSDTypeNameError, type_str
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
attr_reader :s9_item_type
|
125
|
+
private :s9_item_type
|
126
|
+
|
127
|
+
# @api private
|
128
|
+
def initialize(s9_item_type)
|
129
|
+
@s9_item_type = s9_item_type
|
130
|
+
end
|
131
|
+
|
132
|
+
# Return the {QName} which represents this type
|
133
|
+
#
|
134
|
+
# @return [Saxon::QName] the {QName} of the type
|
135
|
+
def type_name
|
136
|
+
@type_name ||= Saxon::QName.new(s9_item_type.getTypeName)
|
137
|
+
end
|
138
|
+
|
139
|
+
# @return [Saxon::S9API::ItemType] The underlying Saxon Java ItemType object
|
140
|
+
def to_java
|
141
|
+
s9_item_type
|
142
|
+
end
|
143
|
+
|
144
|
+
# compares two {ItemType}s using the underlying Saxon and XDM comparision rules
|
145
|
+
# @param other [Saxon::ItemType]
|
146
|
+
# @return [Boolean]
|
147
|
+
def ==(other)
|
148
|
+
return false unless other.is_a?(ItemType)
|
149
|
+
s9_item_type.equals(other.to_java)
|
150
|
+
end
|
151
|
+
|
152
|
+
alias_method :eql?, :==
|
153
|
+
|
154
|
+
def hash
|
155
|
+
@hash ||= s9_item_type.hashCode
|
156
|
+
end
|
157
|
+
|
158
|
+
# Error raised when a Ruby class has no equivalent XDM type to be converted
|
159
|
+
# into
|
160
|
+
class UnmappedRubyTypeError < StandardError
|
161
|
+
def initialize(class_name)
|
162
|
+
@class_name = class_name
|
163
|
+
end
|
164
|
+
|
165
|
+
def to_s
|
166
|
+
"Ruby class <#{@class_name}> has no XDM type equivalent"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Error raise when an attempt to reify an <tt>xs:*</tt> type string is
|
171
|
+
# made, but the type string doesn't match any of the built-in <tt>xs:*</tt>
|
172
|
+
# types
|
173
|
+
class UnmappedXSDTypeNameError < StandardError
|
174
|
+
def initialize(type_str)
|
175
|
+
@type_str = type_str
|
176
|
+
end
|
177
|
+
|
178
|
+
def to_s
|
179
|
+
"'#{@type_str}' is not recognised as an XSD built-in type"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
class Factory
|
184
|
+
DEFAULT_SEMAPHORE = Mutex.new
|
185
|
+
|
186
|
+
attr_reader :processor
|
187
|
+
|
188
|
+
def initialize(processor)
|
189
|
+
@processor = processor
|
190
|
+
end
|
191
|
+
|
192
|
+
def s9_factory
|
193
|
+
return @s9_factory if instance_variable_defined?(:@s9_factory)
|
194
|
+
DEFAULT_SEMAPHORE.synchronize do
|
195
|
+
@s9_factory = S9API::ItemTypeFactory.new(processor.to_java)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|