mappum 0.2.2 → 0.2.3

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/lib/mappum/dsl.rb CHANGED
@@ -7,6 +7,23 @@ class Object
7
7
  end
8
8
  module Mappum
9
9
  module DSL
10
+ def self.get_src_ref
11
+ caller_arr = caller(2)
12
+ file = nil
13
+ begin
14
+ caller_line = caller_arr.shift
15
+ file = parse_caller(caller_line).first
16
+ end while file == __FILE__ and not caller_arr.empty?
17
+ return caller_line
18
+ end
19
+ def self.parse_caller(at)
20
+ if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
21
+ file = Regexp.last_match[1]
22
+ line = Regexp.last_match[2].to_i
23
+ method = Regexp.last_match[3]
24
+ [file, line, method]
25
+ end
26
+ end
10
27
  class Map
11
28
  attr_accessor :def
12
29
  def initialize
@@ -15,7 +32,7 @@ module Mappum
15
32
  def map(*attr, &block)
16
33
  mapa = FieldMap.new(attr)
17
34
  mapa.def.source = @def.source
18
-
35
+ mapa.def.src_ref = DSL.get_src_ref
19
36
  mapa.def.desc = @comment
20
37
  @comment = nil
21
38
 
@@ -223,7 +240,7 @@ module Mappum
223
240
  end
224
241
 
225
242
  class Field < Mappet
226
- def initialize(parent, name, clazz, placeholder = false)
243
+ def initialize(parent, name, clazz, placeholder = false, src_ref = nil)
227
244
  @def = Mappum::Field.new
228
245
  @def.parent = parent
229
246
  @def.name = name
@@ -232,6 +249,7 @@ module Mappum
232
249
  @def.is_root = false
233
250
  @def.is_root = false
234
251
  @def.is_placeholder = placeholder
252
+ @def.src_ref = src_ref
235
253
  end
236
254
 
237
255
  def to_s
@@ -255,7 +273,7 @@ module Mappum
255
273
  if(symbol == :self)
256
274
  return Field.new(@def, nil, args[0], true)
257
275
  end
258
- return Field.new(@def, symbol, args[0])
276
+ return Field.new(@def, symbol, args[0], false, DSL.get_src_ref)
259
277
  end
260
278
 
261
279
  if symbol == :[]
data/lib/mappum/map.rb CHANGED
@@ -2,7 +2,7 @@ module Mappum
2
2
  # Base Map class representing mapping betwean two or more types, properties etc.
3
3
  class Map
4
4
 
5
- attr_accessor :maps, :bidi_maps, :strip_empty, :source
5
+ attr_accessor :maps, :bidi_maps, :strip_empty, :source, :src_ref
6
6
 
7
7
  def initialize
8
8
  @maps = []
@@ -163,7 +163,7 @@ module Mappum
163
163
  return Field.new(@parent, symbol, args[0])
164
164
  end
165
165
  end
166
- class Field < Struct.new(:name, :clazz, :parent, :func, :block, :is_root, :is_placeholder)
166
+ class Field < Struct.new(:name, :clazz, :parent, :func, :block, :is_root, :is_placeholder, :src_ref)
167
167
  #define is_array separetly to exclude it from equals
168
168
  attr_accessor :is_array
169
169
  def array?
@@ -0,0 +1,38 @@
1
+ module Mappum
2
+ class MappumException < RuntimeError
3
+ attr_accessor :from_name, :to_name, :from, :to, :from_root, :to_root, :mappum_backtrace
4
+ def wrap(map, from, to)
5
+
6
+ if map != nil and map != @map #don't store same maps twice
7
+ @map = map
8
+ from_suffix, to_suffix = "",""
9
+
10
+ add_to_mappum_backtrace(map)
11
+ from_suffix = "[]" if map.from.is_array
12
+ add_from_name(map.from.name, from_suffix)
13
+ to_suffix = "[]" if map.to.is_array
14
+ add_to_name(map.to.name, to_suffix)
15
+ end
16
+ @to = to if @to.nil?
17
+ @from = from if @from.nil?
18
+ @to_root = to
19
+ @from_root = from
20
+
21
+ end
22
+ private
23
+ def add_from_name(name,sfx)
24
+ @from_name = ["/", name.to_s+sfx, @from_name].join("") unless name.nil?
25
+ end
26
+ def add_to_name(name,sfx)
27
+ @to_name = ["/", name.to_s+sfx, @to_name].join("") unless name.nil?
28
+ end
29
+ def add_to_mappum_backtrace(map)
30
+ if @mappum_backtrace.nil?
31
+ @mappum_backtrace = []
32
+ @mappum_backtrace << map.from.src_ref
33
+ @mappum_backtrace << map.to.src_ref
34
+ end
35
+ @mappum_backtrace << map.src_ref
36
+ end
37
+ end
38
+ end
@@ -12,17 +12,20 @@ module Mappum
12
12
  class Mapserver < Sinatra::Default
13
13
  set :views => File.join(File.dirname(__FILE__), 'views')
14
14
  set :public => File.join(File.dirname(__FILE__), 'public')
15
+ set :show_exceptions => false
16
+ set :raise_errors => false
15
17
  configure do
16
18
  set :schema_dir => 'schema', :map_dir => 'map', :tmp_dir => nil
17
19
  set :catalogue => nil
18
20
  set :port => 9292
19
21
 
20
- # FIXME make configurable
21
- #wl = Mappum::WorkdirLoader.new(options.schema_dir, options.tmp_dir, options.map_dir)
22
+
22
23
  @wl = Mappum::WorkdirLoader.new('schema', 'map')
23
24
  @wl.generate_and_require
24
25
  end
25
26
  helpers do
27
+ alias_method :h, :escape_html
28
+
26
29
  def explain_func(element)
27
30
  name = element.name.to_s
28
31
  name ||= "self"
@@ -196,6 +199,12 @@ module Mappum
196
199
  @maps_name_source = Mappum.catalogue(@catalogue).list_map_names.collect{|mn| [mn, Mappum.catalogue(@catalogue)[mn].source]}
197
200
  [200, {"Content-Type" => "text/html"}, [erb(:main)]]
198
201
  end
202
+ error do
203
+ @xml_convertor = Syntax::Convertors::HTML.for_syntax "xml"
204
+ @exception = request.env['sinatra.error']
205
+ erb(:error)
206
+ end
207
+
199
208
  def self.parseopt
200
209
  require 'optparse'
201
210
  OptionParser.new { |op|
@@ -0,0 +1,61 @@
1
+ <html>
2
+ <head>
3
+ <style type='text/css'>
4
+ .normal {font-size: 14; font-family: 'Lucida Grande', 'Lucida Sans Unicode', 'Garuda'; }
5
+ .namespace { color: #B66; font-weight: bold;}
6
+ .tag { color: #660066; font-weight: bold;}
7
+ .comment { color: #005; font-style: italic; }
8
+ .punct { color: #000; font-weight: bold; }
9
+ .string { color: #0033ff; }
10
+ .number { color: #F99; }
11
+ .attribute { color: #000; font-weight: bold; }
12
+ </style>
13
+ </head>
14
+ <body>
15
+ <%begin%>
16
+ <%if @exception.kind_of?(Mappum::MappumException)%>
17
+ When mapping
18
+ <h3>From: <%=h @exception.from_name%></h3>
19
+ <h3>To: <%=h @exception.to_name%></h3>
20
+
21
+ Exception was thrown:
22
+ <h3<strong><%=h @exception.class %></strong></h3>
23
+ <h4><strong><%=h @exception.message %></strong></h4>
24
+ Mapping from (for nil parent is displayed):<br/>
25
+ <span class="normal">
26
+ <%= @xml_convertor.convert(@exception.from) %><br/>
27
+ </span>
28
+ Mapping to (for nil parent is displayed):<br/>
29
+ <span class="normal">
30
+ <%= @xml_convertor.convert(@exception.to) %><br/>
31
+ </span>
32
+ <br/>
33
+ Mappum backtrace:<br/>
34
+ <%= @exception.mappum_backtrace.join "<br/>" unless @exception.mappum_backtrace.nil? %><br/>
35
+ <br/>
36
+ Mapping from root:<br/>
37
+ <span class="normal">
38
+ <%= @xml_convertor.convert(@exception.from_root) %><br/>
39
+ </span>
40
+ Mapping to root:<br/>
41
+ <span class="normal">
42
+ <%= @xml_convertor.convert(@exception.to_root) %><br/>
43
+ </span>
44
+ <br/>
45
+ <%end%>
46
+ <%=h @exception.class %> <br/>
47
+ <%=h @exception.message %> <br/>
48
+ <%= @exception.backtrace.join "<br/>" %>
49
+ <%rescue => err%>
50
+ <br/>
51
+ Error when rendering this page:<br/>
52
+ <%=h err.message unless err.nil?%>
53
+ <%= err.backtrace.join("<br/>") unless err.nil? or err.backtrace.nil?%>
54
+ <br/>
55
+ Orginal error:<br/>
56
+ <%= sinatra_error = request.env['sinatra.error'] %>
57
+ <%=h sinatra_error.message unless sinatra_error.nil?%>
58
+ <%= sinatra_error.backtrace.join("<br/>") unless sinatra_error.nil? or sinatra_error.backtrace.nil?%>
59
+ <%end%>
60
+ </body>
61
+ <html>
@@ -3,6 +3,7 @@ require 'set'
3
3
  require 'mappum'
4
4
  require 'ostruct'
5
5
  require 'mappum/autoconv_catalogue'
6
+ require 'mappum/mappum_exception'
6
7
 
7
8
  module Mappum
8
9
  #
@@ -24,7 +25,7 @@ module Mappum
24
25
  # Method for transforming from object using map to "to" object.
25
26
  #
26
27
  def transform(from, map=nil, to=nil)
27
-
28
+ begin
28
29
  raise RuntimeError.new("Map catalogue is empty!") if @map_catalogue.nil?
29
30
 
30
31
  map ||= @map_catalogue[from.class]
@@ -38,6 +39,7 @@ module Mappum
38
39
 
39
40
  all_nils = true
40
41
  map.maps.each do |sm|
42
+ begin
41
43
  from_value, to_value = nil, nil
42
44
 
43
45
  from_value = get(from, sm.from, map.from)
@@ -165,12 +167,21 @@ module Mappum
165
167
  to.send("#{sm.to.name}=", convert_to(to_value, sm.to)) unless to_value.nil?
166
168
  end
167
169
  end
168
-
170
+ rescue Exception => e
171
+ e = MappumException.new(e) unless e.kind_of?(MappumException)
172
+ e.wrap(sm, from_value, to_value)
173
+ raise e
174
+ end
169
175
  end
170
176
  if all_nils and map.strip_empty?
171
177
  return nil
172
178
  end
173
- return to
179
+ return to
180
+ rescue Exception => e
181
+ e = MappumException.new(e) unless e.kind_of?(MappumException)
182
+ e.wrap(map, from, to)
183
+ raise e
184
+ end
174
185
  end
175
186
 
176
187
  protected
@@ -230,7 +241,7 @@ module Mappum
230
241
  method_missing(:id, *attr)
231
242
  end
232
243
  end
233
- class MapMissingException < RuntimeError
244
+ class MapMissingException < MappumException
234
245
  attr_accessor :from
235
246
  def initialize(from, msg=nil)
236
247
  msg ||= "Map for class \"#{from.class}\" not found!"
@@ -148,11 +148,24 @@ module Mappum
148
148
  if e.from == parsed
149
149
  raise MapMissingException.new(e.from,"Map for element \"#{from_qname}\" not found!")
150
150
  else
151
+ e.from = to_xml_string(e.from)
152
+ e.to = to_xml_string(e.to)
153
+ e.from_root = to_xml_string(e.from_root)
154
+ e.to_root = to_xml_string(e.to_root)
151
155
  raise e
152
156
  end
157
+ rescue MappumException => e
158
+ e.from = to_xml_string(e.from)
159
+ e.to = to_xml_string(e.to)
160
+ e.from_root = to_xml_string(e.from_root)
161
+ e.to_root = to_xml_string(e.to_root)
162
+ raise e
153
163
  end
154
164
 
155
- to_mapper = XSD::Mapping::Mapper.find_mapper_for_class(transformed.class)
165
+ return to_xml_string(transformed, map, to_qname, soap)
166
+ end
167
+ def to_xml_string(transformed, map=nil, to_qname=nil, soap=false)
168
+ to_mapper = XSD::Mapping::Mapper.find_mapper_for_class(transformed.class)
156
169
  if to_mapper.nil?
157
170
  to_mapper = @default_mapper
158
171
  end
@@ -170,8 +183,7 @@ module Mappum
170
183
  to_preparsed = SOAP::SOAPEnvelope.new(SOAP::SOAPHeader.new, SOAP::SOAPBody.new(to_preparsed))
171
184
  end
172
185
  generator = SOAP::Generator.new(XSD::Mapping::Mapper::MAPPING_OPT)
173
- to_xml = generator.generate(to_preparsed, nil)
174
- return to_xml
186
+ return generator.generate(to_preparsed, nil)
175
187
  end
176
188
  end
177
189
  class RubyXmlTransform < RubyTransform
data/mappum.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mappum}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jan Topi\305\204ski"]
12
- s.date = %q{2009-11-13}
12
+ s.date = %q{2009-11-16}
13
13
  s.default_executable = %q{mapserver.rb}
14
14
  s.description = %q{}
15
15
  s.email = %q{jtopinski@chatka.org}
@@ -39,10 +39,12 @@ Gem::Specification.new do |s|
39
39
  "lib/mappum/dsl.rb",
40
40
  "lib/mappum/java_transform.rb",
41
41
  "lib/mappum/map.rb",
42
+ "lib/mappum/mappum_exception.rb",
42
43
  "lib/mappum/mapserver/mapgraph.rb",
43
44
  "lib/mappum/mapserver/mapserver.rb",
44
45
  "lib/mappum/mapserver/maptable.rb",
45
46
  "lib/mappum/mapserver/views/doc.erb",
47
+ "lib/mappum/mapserver/views/error.erb",
46
48
  "lib/mappum/mapserver/views/main.erb",
47
49
  "lib/mappum/mapserver/views/maptable.erb",
48
50
  "lib/mappum/mapserver/views/rubysource.erb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mappum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jan Topi\xC5\x84ski"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-13 00:00:00 +01:00
12
+ date: 2009-11-16 00:00:00 +01:00
13
13
  default_executable: mapserver.rb
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -92,10 +92,12 @@ files:
92
92
  - lib/mappum/dsl.rb
93
93
  - lib/mappum/java_transform.rb
94
94
  - lib/mappum/map.rb
95
+ - lib/mappum/mappum_exception.rb
95
96
  - lib/mappum/mapserver/mapgraph.rb
96
97
  - lib/mappum/mapserver/mapserver.rb
97
98
  - lib/mappum/mapserver/maptable.rb
98
99
  - lib/mappum/mapserver/views/doc.erb
100
+ - lib/mappum/mapserver/views/error.erb
99
101
  - lib/mappum/mapserver/views/main.erb
100
102
  - lib/mappum/mapserver/views/maptable.erb
101
103
  - lib/mappum/mapserver/views/rubysource.erb