Permalink
Browse files

various bugfixes, test improvements

   - migrated from test:unit to rspec
   - many bugfixes, optimizations, test enhancements
   - rdoc / gem improvements
   - new bin/gen_ruby_definitions.rb utility to generate ruby class
     definition files in specified dir from provided xsd schema
  • Loading branch information...
1 parent f00dce3 commit 40ce50a00ef23793a951c380e68f0f0a80ec3697 @movitto committed Mar 18, 2010
Showing with 1,618 additions and 685 deletions.
  1. +0 −19 README
  2. +56 −0 README.rdoc
  3. +35 −18 Rakefile
  4. +3 −9 TODO
  5. +37 −0 bin/gen_ruby_definitions.rb
  6. +3 −10 bin/rxsd-test.rb
  7. +1 −1 lib/rxsd.rb
  8. +11 −8 lib/rxsd/builder.rb
  9. +2 −2 lib/rxsd/builders/ruby_class.rb
  10. +1 −1 lib/rxsd/builders/ruby_definition.rb
  11. +1 −1 lib/rxsd/builders/ruby_object.rb
  12. +32 −9 lib/rxsd/builtin_types.rb
  13. +2 −1 lib/rxsd/common.rb
  14. +1 −1 lib/rxsd/exceptions.rb
  15. +61 −24 lib/rxsd/libxml_adapter.rb
  16. +1 −1 lib/rxsd/loader.rb
  17. +8 −8 lib/rxsd/parser.rb
  18. +2 −2 lib/rxsd/resolver.rb
  19. +12 −12 lib/rxsd/translator.rb
  20. +31 −18 lib/rxsd/xml.rb
  21. +1 −1 lib/rxsd/xsd/attribute.rb
  22. +1 −1 lib/rxsd/xsd/attribute_group.rb
  23. +1 −1 lib/rxsd/xsd/choice.rb
  24. +1 −1 lib/rxsd/xsd/complex_content.rb
  25. +3 −2 lib/rxsd/xsd/complex_type.rb
  26. +5 −5 lib/rxsd/xsd/element.rb
  27. +1 −1 lib/rxsd/xsd/extension.rb
  28. +1 −1 lib/rxsd/xsd/group.rb
  29. +1 −1 lib/rxsd/xsd/list.rb
  30. +1 −1 lib/rxsd/xsd/restriction.rb
  31. +3 −2 lib/rxsd/xsd/schema.rb
  32. +1 −1 lib/rxsd/xsd/sequence.rb
  33. +1 −1 lib/rxsd/xsd/simple_content.rb
  34. +1 −1 lib/rxsd/xsd/simple_type.rb
  35. +0 −36 rxsd.gemspec
  36. +108 −43 test/builder_test.rb → spec/builder_spec.rb
  37. +8 −10 test/loader_test.rb → spec/loader_spec.rb
  38. +216 −189 test/parser_test.rb → spec/parser_spec.rb
  39. +609 −0 spec/resolver_spec.rb
  40. +14 −0 spec/spec_helper.rb
  41. +105 −0 spec/translator_spec.rb
  42. +47 −0 spec/types_spec.rb
  43. +189 −0 spec/xml_spec.rb
  44. +0 −20 test/all_tests.rb
  45. +0 −69 test/resolver_test.rb
  46. +0 −103 test/translator_test.rb
  47. +0 −50 test/types_test.rb
View
19 README
@@ -1,19 +0,0 @@
-RXSD - XSD / Ruby Translator
-Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
-See COPYING for the License of this software
-
-RXSD is a library that translates XSD XML Schema Definitions into Ruby Classes
-on the fly. It is able to read XSD resources and use them to define Ruby
-classes in memory or string class definitions to be written to the filesystem
-
-RXSD implements a full XSD parser that not only defines the various xsd schema
-classes, parsing them out of a XSD file, but translates them into a
-meta-class heirarchy, for use in subsequent transformations. The builder interface
-can easily be extended to output any format one could want including classes
-in other languages (Python, C++, Java, etc), other XML formats, etc.
-
-RXSD also parses XML conforming to a XSD schema, and instantiates objects
-corresponding to the XSD classes created. Furthermore, RXSD will work with
-existing class definitions resulting in a quick way to map XSD to Ruby constructs,
-letting you define the schema features that you need, and autogenerting handlers
-to the others.
View
@@ -0,0 +1,56 @@
+== RXSD - XSD / Ruby Translator
+
+Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
+
+RXSD is made available under the GNU LESSER GENERAL PUBLIC LICENSE
+as published by the Free Software Foundation, either version 3
+of the License, or (at your option) any later version.
+
+== Info
+RXSD is a library that translates XSD XML Schema Definitions into Ruby Classes
+on the fly. It is able to read XSD resources and use them to define Ruby
+classes in memory or string class definitions to be written to the filesystem
+
+RXSD implements a full XSD parser that not only defines the various xsd schema
+classes, parsing them out of a XSD file, but translates them into a
+meta-class heirarchy, for use in subsequent transformations. The builder interface
+can easily be extended to output any format one could want including classes
+in other languages (Python, C++, Java, etc), other XML formats, etc.
+
+RXSD also parses XML conforming to a XSD schema, and instantiates objects
+corresponding to the XSD classes created. Furthermore, RXSD will work with
+existing class definitions resulting in a quick way to map XSD to Ruby constructs,
+letting you define the schema features that you need, and autogenerting handlers
+to the others.
+
+== Installation
+
+To install rxsd simply run:
+ gem install rxsd
+
+Source code is available via:
+ git clone http://github.com/movitto/rxsd
+
+== Usage
+
+ require 'lib/rxsd'
+
+ xsd_uri = "file:///home/user/schema.xsd"
+ xml_uri = "file:///home/user/data.xml"
+
+ schema = RXSD::Parser.parse_xsd :uri => xsd_uri
+
+ puts "=======Classes======="
+ classes = schema.to :ruby_classes
+ puts classes.collect{ |cl| !cl.nil? ? (cl.to_s + " < " + cl.superclass.to_s) : ""}.sort.join("\n")
+
+ puts "=======Tags======="
+ puts schema.tags.collect { |n,cb| n + ": " + cb.to_s + ": " + (cb.nil? ? "ncb" : cb.klass_name.to_s + "-" + cb.klass.to_s) }.sort.join("\n")
+
+ puts "=======Objects======="
+ data = RXSD::Parser.parse_xml :uri => xml_uri
+ objs = data.to :ruby_objects, :schema => schema
+ objs.each { |obj|
+ puts "#{obj}"
+ }
+
View
@@ -1,29 +1,46 @@
# rxsd project Rakefile
#
-# Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
-# See COPYING for the License of this software
+# Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
+# Licensed under the LGPLv3+ http://www.gnu.org/licenses/lgpl.txt
-#task :default => :test
+require 'rake/rdoctask'
+require 'spec/rake/spectask'
+require 'rake/gempackagetask'
-task(:test) do
- desc "Run tests"
- require 'test/all_tests'
+
+GEM_NAME="rxsd"
+PKG_VERSION='0.3'
+
+desc "Run all specs"
+Spec::Rake::SpecTask.new('spec') do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
end
-task :rdoc do
- desc "Create RDoc documentation"
- system "rdoc --title 'rxsd documentation' lib/"
+Rake::RDocTask.new do |rd|
+ rd.main = "README.rdoc"
+ rd.rdoc_dir = "doc/site/api"
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
end
-task :create_gem do
- desc "Create a new gem"
- system "gem build rxsd.gemspec"
+PKG_FILES = FileList['bin/**/*', 'lib/**/*.rb', 'COPYING', 'LICENSE', 'Rakefile', 'README.rdoc', 'spec/**/*.rb' ]
+
+SPEC = Gem::Specification.new do |s|
+ s.name = GEM_NAME
+ s.version = PKG_VERSION
+ s.files = PKG_FILES
+
+ s.required_ruby_version = '>= 1.8.1'
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.3")
+
+ s.author = "Mohammed Morsi"
+ s.email = "movitto@yahoo.com"
+ s.date = %q{2010-03-18}
+ s.description = %q{A library to translate xsd schemas and xml implementations into ruby classes/objects}
+ s.summary = %q{A library to translate xsd schemas and xml implementations into ruby classes/objects}
+ s.homepage = %q{http://morsi.org/projects/RXSD}
end
-task :dist do
- desc "Create a source tarball"
- system "mkdir ruby-rxsd-0.2.0 && \
- cp -R conf/ bin/ db/ lib/ test/ ruby-rxsd-0.2.0/ && \
- tar czvf rxsd.tgz ruby-rxsd-0.2.0 && \
- rm -rf ruby-rxsd-0.2.0"
+Rake::GemPackageTask.new(SPEC) do |pkg|
+ pkg.need_tar = true
+ pkg.need_zip = true
end
View
12 TODO
@@ -1,16 +1,10 @@
-RXSD is a work in progress and is not current stable.
+Task list
-Various features left to be implemented
-
- * simple binary to generate file ruby definitions
- * ruby gem / pkg spec
- * readme / simple howto (run bin, import lib, add builder/xml-backend)
- * bug fixing (expanding the test suite in the process)
- * Support for missing XSD constructs:
+ * more tests, bugfixes, enhancements
+ * Support for missing XSD constructs (complete w/ tests):
- all / annotation / any / anyAttribute / appInfo / documentation / field /
import / include / key / keyref / notation / redefine / selector / union / unique
- add remote uri support to Loader, use in conjunction w/ import/include
* Additional builtin / native type support
* Additional builder support
* Support for ruby class/obj -> xsd/xml
- * C/C++ rewrite (?)
@@ -0,0 +1,37 @@
+#!/usr/bin/ruby
+# Simple rxsd test utility
+#
+# Usage rxsd-test.rb uri-to-schema uri-to-xml-instance
+#
+# Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
+# See COPYING for the License of this software
+
+require 'fileutils'
+require 'lib/rxsd'
+
+if ARGV.size < 2
+ puts "missing required arguments"
+ puts "usage: gen_ruby_definitions xsd_uri output_dir"
+ exit
+end
+
+xsd_uri = ARGV[0]
+output_dir = ARGV[1]
+
+if File.exists?(output_dir) && ! File.directory?(output_dir)
+ puts "#{output_dir} is not a dir, exiting"
+ exit
+end
+
+if !File.exists?(output_dir)
+ FileUtils.mkdir(output_dir)
+end
+
+schema = RXSD::Parser.parse_xsd :uri => xsd_uri
+definitions = schema.to :ruby_definitions
+
+definitions.each { |d|
+ d =~ /^.*class\s*([A-Za-z]*).*$/ # XXX Hacky way to get class name
+ cl = $1
+ File.write(output_dir + "/" + $1 + ".rb", d)
+}
View
13 bin/rxsd-test.rb 100644 → 100755
@@ -1,30 +1,23 @@
+#!/usr/bin/ruby
# Simple rxsd test utility
#
# Usage rxsd-test.rb uri-to-schema uri-to-xml-instance
#
-# Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
+# Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
# See COPYING for the License of this software
require 'lib/rxsd'
if ARGV.size < 2
puts "missing required arguments"
+ puts "usage: rxsd-test xsd_uri xml_uri"
exit
end
xsd_uri = ARGV[0]
xml_uri = ARGV[1]
schema = RXSD::Parser.parse_xsd :uri => xsd_uri
-#def disp_child(obj)
-# if obj.respond_to? 'children'
-# puts "#{obj}"
-# obj.children.each { |c|
-# disp_child c
-# }
-# end
-#end
-#disp_child(schema)
puts "=======Classes======="
classes = schema.to :ruby_classes
View
@@ -1,6 +1,6 @@
# include all rxsd modules
#
-# Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
+# Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
# See COPYING for the License of this software
lib = File.dirname(__FILE__)
View
@@ -2,12 +2,12 @@
#
# responsible for providing interface to build any output format from XSD metadata
#
-# Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
+# Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
# See COPYING for the License of this software
module RXSD
-# base interface and helper methods to build classes in various formats from specified parameters
+# Base interface and helper methods to build classes in various formats from xsd schemas
class ClassBuilder
# actual class built
attr_accessor :klass
@@ -27,8 +27,10 @@ class ClassBuilder
# name of the attribute which this class represents, for use in accessor construction
attr_accessor :attribute_name
- # create a new class builder w/ specified args
+ # Create a new class builder w/ specified args.
def initialize(args = {})
+ @klass = @klass_name = @attribute_name = @associated_builder = @base_builder = nil
+
if args.has_key? :builder
@klass = args[:builder].klass
@klass_name = args[:builder].klass_name
@@ -52,12 +54,13 @@ def initialize(args = {})
end
end
- # helper method
+ # Set base builder
def base=(base)
@base_builder = ClassBuilder.new :klass => base
end
- # perform a deep copy of builder, takes optional recursive guard
+ # Perform a deep copy of builder.
+ # cloned param is used internally and should not be set by invoker.
def clone(cloned = {})
return cloned[self] if cloned.has_key? self
@@ -74,7 +77,7 @@ def clone(cloned = {})
return cb
end
- # helper method to get all associated class builders
+ # Helper method to get all associated class builders
def associated(builders = [])
unless @base_builder.nil? || builders.include?(@base_builder)
builders.push @base_builder
@@ -102,7 +105,7 @@ def associated(builders = [])
end # class ClassBuilder
-# base interface and helper methods to build objects in various formats from specified parameters
+# Base interface and helper methods to build objects in various formats from specified parameters
class ObjectBuilder
# name of class instance to build
attr_accessor :tag_name
@@ -124,7 +127,7 @@ class ObjectBuilder
# parent object builder, optionally set
attr_accessor :parent
- # create a new class builder w/ specified args
+ # Create a new class builder w/ specified args
def initialize(args = {})
if args.has_key? :builder
@tag_name = args[:builder].tag_name
@@ -1,11 +1,11 @@
# RXSD Ruby Class builder
#
-# Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
+# Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
# See COPYING for the License of this software
module RXSD
-# Implements the RXSD::ClassBuilder interface to build Ruby Classes from xsd
+# Implements the RXSD::ClassBuilder interface to build Ruby Classes from a xsd schema
class RubyClassBuilder < ClassBuilder
@@ -1,6 +1,6 @@
# RXSD Ruby Definition builder
#
-# Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
+# Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
# See COPYING for the License of this software
module RXSD
@@ -1,6 +1,6 @@
# RXSD Ruby Object builder
#
-# Copyright (C) 2009 Mohammed Morsi <movitto@yahoo.com>
+# Copyright (C) 2010 Mohammed Morsi <movitto@yahoo.com>
# See COPYING for the License of this software
module RXSD
Oops, something went wrong.

0 comments on commit 40ce50a

Please sign in to comment.