xamplr 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/CHANGES.txt +13 -0
  2. data/LICENSE +3 -0
  3. data/README.rdoc +26 -0
  4. data/README.rdoc.orig +118 -0
  5. data/Rakefile +85 -0
  6. data/VERSION.yml +4 -0
  7. data/examples/random-people-shared-addresses/Makefile +16 -0
  8. data/examples/random-people-shared-addresses/batch-load-users.rb +83 -0
  9. data/examples/random-people-shared-addresses/find-mentions.rb +47 -0
  10. data/examples/random-people-shared-addresses/find-people-by-address.rb +104 -0
  11. data/examples/random-people-shared-addresses/optimise.rb +16 -0
  12. data/examples/random-people-shared-addresses/people.rb +35 -0
  13. data/examples/random-people-shared-addresses/query.rb +75 -0
  14. data/examples/random-people-shared-addresses/query2.rb +73 -0
  15. data/examples/random-people-shared-addresses/random-names.csv +10000 -0
  16. data/examples/random-people-shared-addresses/settings.rb +3 -0
  17. data/examples/random-people-shared-addresses/what-to-query-on.rb +82 -0
  18. data/examples/random-people-shared-addresses/xampl-gen.rb +36 -0
  19. data/examples/random-people-shared-addresses/xml/people.xml +14 -0
  20. data/examples/random-people/Makefile +16 -0
  21. data/examples/random-people/batch-load-users.rb +61 -0
  22. data/examples/random-people/optimise.rb +16 -0
  23. data/examples/random-people/people.rb +22 -0
  24. data/examples/random-people/query.rb +73 -0
  25. data/examples/random-people/query2.rb +73 -0
  26. data/examples/random-people/random-names.csv +10000 -0
  27. data/examples/random-people/rawtc.rb +91 -0
  28. data/examples/random-people/settings.rb +3 -0
  29. data/examples/random-people/what-to-query-on.rb +80 -0
  30. data/examples/random-people/xampl-gen.rb +36 -0
  31. data/examples/random-people/xml/people.xml +11 -0
  32. data/examples/read-testing/Makefile +10 -0
  33. data/examples/read-testing/load.rb +65 -0
  34. data/examples/read-testing/read.rb +51 -0
  35. data/examples/read-testing/rrr.rb +87 -0
  36. data/examples/read-testing/settings.rb +2 -0
  37. data/examples/read-testing/xampl-gen.rb +36 -0
  38. data/examples/read-testing/xml/text.xml +8 -0
  39. data/examples/tokyo-cabinet-experimental/expt-query.rb +42 -0
  40. data/examples/tokyo-cabinet-experimental/expt-query2.rb +42 -0
  41. data/examples/tokyo-cabinet-experimental/expt-query3.rb +41 -0
  42. data/examples/tokyo-cabinet-experimental/expt-reader.rb +32 -0
  43. data/examples/tokyo-cabinet-experimental/expt.rb +61 -0
  44. data/examples/tokyo-cabinet-experimental/xampl-gen.rb +36 -0
  45. data/examples/tokyo-cabinet-experimental/xml/tcx.xml +6 -0
  46. data/lib/xampl-generator.rb +3 -0
  47. data/lib/xampl.rb +3 -0
  48. data/lib/xamplr-generator.rb +10 -0
  49. data/lib/xamplr.rb +37 -0
  50. data/lib/xamplr/README-POSSIBLE-PROBLEMS +5 -0
  51. data/lib/xamplr/TODO +1 -0
  52. data/lib/xamplr/exceptions.rb +97 -0
  53. data/lib/xamplr/from-xml-orig.rb +350 -0
  54. data/lib/xamplr/from-xml.rb +439 -0
  55. data/lib/xamplr/gen-elements.xml +6230 -0
  56. data/lib/xamplr/gen.elements.xml +108 -0
  57. data/lib/xamplr/generate-elements.rb +15 -0
  58. data/lib/xamplr/generator.rb +5 -0
  59. data/lib/xamplr/graphml-out.rb +470 -0
  60. data/lib/xamplr/handwritten/example.rb +698 -0
  61. data/lib/xamplr/handwritten/hand-example.rb +533 -0
  62. data/lib/xamplr/handwritten/test-handwritten.rb +873 -0
  63. data/lib/xamplr/indexed-array.rb +115 -0
  64. data/lib/xamplr/mixins.rb +397 -0
  65. data/lib/xamplr/my.gen.elements.xml +461 -0
  66. data/lib/xamplr/notifications.rb +57 -0
  67. data/lib/xamplr/obsolete/fsdb.rb +62 -0
  68. data/lib/xamplr/persist-to-xml.rb +249 -0
  69. data/lib/xamplr/persistence.rb +522 -0
  70. data/lib/xamplr/persistence.rb.more_thread_safe +771 -0
  71. data/lib/xamplr/persistence.rb.partially_thread_safe +763 -0
  72. data/lib/xamplr/persister.rb +310 -0
  73. data/lib/xamplr/persisters/caches.rb +186 -0
  74. data/lib/xamplr/persisters/caching.rb +172 -0
  75. data/lib/xamplr/persisters/filesystem.rb +60 -0
  76. data/lib/xamplr/persisters/in-memory.rb +180 -0
  77. data/lib/xamplr/persisters/simple.rb +59 -0
  78. data/lib/xamplr/persisters/tokyo-cabinet.rb +641 -0
  79. data/lib/xamplr/simpleTemplate/danger.rx +4 -0
  80. data/lib/xamplr/simpleTemplate/obsolete/input-c.r4 +35 -0
  81. data/lib/xamplr/simpleTemplate/obsolete/play.r6.txt +12 -0
  82. data/lib/xamplr/simpleTemplate/obsolete/play_more.r6.txt +20 -0
  83. data/lib/xamplr/simpleTemplate/obsolete/test001.r5 +8 -0
  84. data/lib/xamplr/simpleTemplate/obsolete/test002.r5 +13 -0
  85. data/lib/xamplr/simpleTemplate/obsolete/test003.r5 +37 -0
  86. data/lib/xamplr/simpleTemplate/old/r6.000.rb +122 -0
  87. data/lib/xamplr/simpleTemplate/old/r6.001.rb +145 -0
  88. data/lib/xamplr/simpleTemplate/play.r6 +12 -0
  89. data/lib/xamplr/simpleTemplate/play_more.r6 +20 -0
  90. data/lib/xamplr/simpleTemplate/play_noblanks.r6 +21 -0
  91. data/lib/xamplr/simpleTemplate/playq.r6 +16 -0
  92. data/lib/xamplr/simpleTemplate/r6.rb +87 -0
  93. data/lib/xamplr/simpleTemplate/simple-template.rb +75 -0
  94. data/lib/xamplr/templates/child.template +47 -0
  95. data/lib/xamplr/templates/child_indexed.template +89 -0
  96. data/lib/xamplr/templates/child_modules.template +5 -0
  97. data/lib/xamplr/templates/element_classes.template +11 -0
  98. data/lib/xamplr/templates/element_data.template +282 -0
  99. data/lib/xamplr/templates/element_empty.template +285 -0
  100. data/lib/xamplr/templates/element_mixed.template +277 -0
  101. data/lib/xamplr/templates/element_simple.template +276 -0
  102. data/lib/xamplr/templates/package.template +26 -0
  103. data/lib/xamplr/test-support/Makefile +47 -0
  104. data/lib/xamplr/test-support/bench-cache.rb +80 -0
  105. data/lib/xamplr/test-support/bench-script.rb +21 -0
  106. data/lib/xamplr/test-support/bench.rb +116 -0
  107. data/lib/xamplr/test-support/bench2.rb +132 -0
  108. data/lib/xamplr/test-support/test-cache.rb +147 -0
  109. data/lib/xamplr/test-support/test-data/binding.xml +7 -0
  110. data/lib/xamplr/test-support/test-data/example.xml +14 -0
  111. data/lib/xamplr/test-support/test-data/internationalization-utf8.txt +1 -0
  112. data/lib/xamplr/test-support/test-data/labels.xml +37 -0
  113. data/lib/xamplr/test-support/test-data/labels001.xml +38 -0
  114. data/lib/xamplr/test-support/test-deep-change.rb +135 -0
  115. data/lib/xamplr/test-support/test-elements.rb +109 -0
  116. data/lib/xamplr/test-support/test-indexed-array.rb +169 -0
  117. data/lib/xamplr/test-support/test-misc.rb +73 -0
  118. data/lib/xamplr/test-support/test-names.rb +67 -0
  119. data/lib/xamplr/test-support/test-rollback.rb +106 -0
  120. data/lib/xamplr/test-support/test.rb +1504 -0
  121. data/lib/xamplr/to-ruby.rb +220 -0
  122. data/lib/xamplr/to-xml.rb +158 -0
  123. data/lib/xamplr/version.rb +67 -0
  124. data/lib/xamplr/visitor.rb +140 -0
  125. data/lib/xamplr/visitors.rb +573 -0
  126. data/lib/xamplr/xampl-generator.rb +533 -0
  127. data/lib/xamplr/xampl-hand-generated.rb +1535 -0
  128. data/lib/xamplr/xampl-module.rb +36 -0
  129. data/lib/xamplr/xampl-object-internals.rb +6 -0
  130. data/lib/xamplr/xampl-object.rb +202 -0
  131. data/lib/xamplr/xampl-persisted-object.rb +122 -0
  132. data/lib/xamplr/xml-text.rb +117 -0
  133. data/lib/xamplr/xml/document.xml +7 -0
  134. data/lib/xamplr/xml/elements.xml +101 -0
  135. data/lib/xamplr/xml/elements000.xml +73 -0
  136. data/lib/xamplr/xml/example.xml +23 -0
  137. data/lib/xamplr/xml/options.xml +12 -0
  138. data/lib/xamplr/xml/uche.xml +38 -0
  139. data/lib/xamplr/yEd-sample.graphml +300 -0
  140. data/test/test_helper.rb +10 -0
  141. data/test/xamplr_test.rb +7 -0
  142. metadata +245 -0
@@ -0,0 +1,21 @@
1
+ [1]
2
+ |
3
+ | some_number = 42
4
+ |# def gen_some_number
5
+ |# 42 + rand
6
+ |# end
7
+ |
8
+ [2]
9
+ [3]Hello there(play_noblanks)! #{@message}
10
+ [4]
11
+ |
12
+ | another_number = 99
13
+ | result << sprintf("execute gen: %d\n", gen_some_number)
14
+ |
15
+ [5]
16
+ [6] some number: [[[#{some_number}]]]
17
+ [7]gen some number: [[[#{gen_some_number}]]]
18
+ [8] another number: [[[#{another_number}]]]
19
+ [9]
20
+ [10]play_noblanks _____________________________________________________
21
+ [11]
@@ -0,0 +1,16 @@
1
+ |
2
+ | some_number = 42
3
+ | def gen_some_number
4
+ | 42 + rand
5
+ | end
6
+ |
7
+
8
+ Hello there (play)! #{@message}
9
+
10
+ one: 'one #{gen_some_number}'
11
+ two: "two #{gen_some_number}"
12
+
13
+ some number: [[[#{some_number}]]]
14
+ gen some number: [[[#{gen_some_number}]]]
15
+ play __________________________________________________________
16
+
@@ -0,0 +1,87 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "xamplr/simpleTemplate/simple-template"
4
+
5
+ ###
6
+ ### and this is how it can be used...
7
+ ###
8
+
9
+ # Define a class to hold the template methods. Any attributes defined by this
10
+ # class will be available to be used by the templates when they are 'run'.
11
+ # These are expected to be set up by the template-invoking program. This
12
+ # class defines a single attribute 'message'
13
+
14
+ class R6_Template
15
+ include TemplateEngine
16
+ attr_accessor :message
17
+ end
18
+
19
+ # Now we need to get some templates into place. We are providing a list of
20
+ # files here, but it is possible to imagine using ARGS to get filenames from
21
+ # the command line. Simply pass the list to the compile_script method.
22
+
23
+ files = [ "play.r6", "play_more.r6", "playq.r6", "play_noblanks.r6"];
24
+
25
+ engine = R6_Template.new
26
+ engine.compile_scripts(files)
27
+
28
+ # For illustrative purposes, go over the file arguments and execute
29
+ # the corresponding method defined above. The file names are used by the
30
+ # Template Engine to create a method that, when called, will 'execute' the
31
+ # template. The method name will be chosen by removing the filename extension.
32
+
33
+ files.each { | script_name |
34
+ method_name = File::basename(script_name, ".*")
35
+
36
+ # just a silly message that identifies the script that is running
37
+ engine.message = sprintf("this is script '%s'", method_name)
38
+
39
+ puts "#{method_name}*******************"
40
+ what = engine.send(method_name);
41
+ puts "{{{#{what}}}}*******************"
42
+ }
43
+
44
+ # This time call the play method directly. There must be a template
45
+ # called 'play' for this to work.
46
+
47
+ engine.message = "this is script 'play' -- called explicitly"
48
+ puts "!!play!!*******************"
49
+ what = engine.play()
50
+ puts "{{{#{what}}}}*******************"
51
+
52
+ # Now do the same thing as the illustrative loop above but writing to a file
53
+ # with the script name and a ".out" extension.
54
+
55
+ files.each { | script_name |
56
+ method_name = File::basename(script_name, ".*")
57
+ engine.message = sprintf("this is script '%s'", method_name)
58
+ File.open(sprintf("%s.out", method_name), "w") { | file |
59
+ engine.send(method_name, file);
60
+ }
61
+ }
62
+
63
+ # Write to a file called "play-x.out", again, there must be a play template
64
+ # defined.
65
+
66
+ engine.message = "this is script 'play' -- called explicitly"
67
+ File.open("play-x.out", "w") { | file |
68
+ engine.play(file)
69
+ }
70
+
71
+ # Build up a single string by applying all the templates
72
+ long_string = ""
73
+ files.each { | script_name |
74
+ method_name = File::basename(script_name, ".*")
75
+ engine.message = sprintf("this is script '%s'", method_name)
76
+ what = engine.send(method_name, long_string);
77
+ }
78
+ puts "!!{{{#{long_string}}}}!!*******************"
79
+
80
+ # This will fail, because the template methods are only defined on the
81
+ # instance of the engine that compiled them.
82
+ #
83
+ #engine2 = R6_Template.new
84
+ #engine2.message = "this is script 'play' -- called explicitly"
85
+ #File.open("play-x.out", "w") { | file |
86
+ # engine2.play(file)
87
+ #}
@@ -0,0 +1,75 @@
1
+ module TemplateEngine
2
+ attr_accessor :method_to_file_name, :file_name_to_method
3
+
4
+ def initialize
5
+ @method_to_file_name = Hash.new()
6
+ @file_name_to_method = Hash.new()
7
+ end
8
+
9
+ # def macro(name, &block)
10
+ # Kernel.send(:define_method, name) { |*args|
11
+ # puts block.call(args)
12
+ # }
13
+ # end
14
+
15
+ def build_script(template_file_name, method_name)
16
+
17
+ # Build the definition of a method (called 'method_name') that
18
+ # will execute the template (in the file 'template_file_name'). There will
19
+ # be an optional argument that defaults to the empty string (and so this
20
+ # method will, by default, build a new string representing the result). If
21
+ # the argument is supplied, it must respond to the "<<" (append) method.
22
+ #
23
+ # The result variable is available in the template. To write to the result
24
+ # from Ruby code, result << sprintf("hello %s", "world") in the template
25
+ # will get its output where expected.
26
+
27
+ found_template_file_name = nil
28
+ $LOAD_PATH.each{ | directory |
29
+ possible_template_file_name = File.join(directory, template_file_name)
30
+ if File.exists?(possible_template_file_name)
31
+ found_template_file_name = possible_template_file_name
32
+ end
33
+ }
34
+ return unless found_template_file_name
35
+ File.open(found_template_file_name) do | file |
36
+ tmp = ""
37
+ r = "
38
+ def #{method_name}(result=\"\")
39
+ result << \"\"
40
+ "
41
+ while line = file.gets
42
+ if line[0] == ?|
43
+ if (0 < tmp.length)
44
+ r << " result << \"#{tmp.gsub("\"", "\\\"")}\""
45
+ tmp = ""
46
+ end
47
+ r << " #{line[1..-1]}"
48
+ else
49
+ #tmp << line.chomp << "\n"
50
+ tmp << line
51
+ end
52
+ end
53
+ r << " result << \"#{tmp.gsub("\"", "\\\"")}\""
54
+ r << "
55
+ result
56
+ end
57
+ "
58
+ end
59
+ end
60
+
61
+ def compile_scripts(files)
62
+ files.each { | script_name |
63
+ method_name = File::basename(script_name, ".*")
64
+ #puts "COMPILE: [[#{method_name}]]"
65
+
66
+ @method_to_file_name[method_name] = script_name;
67
+ @file_name_to_method[script_name] = method_name;
68
+
69
+ the_script = build_script(script_name, method_name)
70
+ #puts the_script
71
+ instance_eval(the_script, "SCRIPT:#{script_name}", 1)
72
+ }
73
+ end
74
+ end
75
+
@@ -0,0 +1,47 @@
1
+
2
+ module #{element.class_name}AsChild
3
+ def #{element.attribute_name}_child
4
+ accessed
5
+ @#{element.attribute_name}_child
6
+ end
7
+
8
+ def #{element.attribute_name}_child=(v)
9
+ accessed
10
+ @#{element.attribute_name}_child = v
11
+ end
12
+
13
+ alias #{element.attribute_name} #{element.attribute_name}_child
14
+ alias #{element.attribute_name}= #{element.attribute_name}_child=
15
+
16
+ def init_#{element.attribute_name}_as_child
17
+ @#{element.attribute_name}_child = []
18
+ end
19
+
20
+ def add_#{element.attribute_name}(#{element.attribute_name})
21
+ accessed
22
+ @children << #{element.attribute_name}
23
+ @#{element.attribute_name}_child << #{element.attribute_name}
24
+ #{element.attribute_name}.add_parent(self)
25
+ changed
26
+ return #{element.attribute_name}
27
+ end
28
+
29
+ def new_#{element.attribute_name}
30
+ accessed
31
+ #{element.attribute_name} = #{element.class_name}.new
32
+ yield(#{element.attribute_name}) if block_given?
33
+ return add_#{element.attribute_name}(#{element.attribute_name})
34
+ end
35
+
36
+ def ensure_#{element.attribute_name}
37
+ accessed
38
+ new_#{element.attribute_name} if 0 == #{element.attribute_name}.size
39
+ end
40
+
41
+ def remove_#{element.attribute_name}(#{element.attribute_name})
42
+ accessed
43
+ changed
44
+ @#{element.attribute_name}_child.delete(#{element.attribute_name})
45
+ @children.delete(#{element.attribute_name})
46
+ end
47
+ end
@@ -0,0 +1,89 @@
1
+
2
+ module #{element.class_name}AsChild
3
+ require "xamplr/indexed-array"
4
+
5
+ def #{element.attribute_name}_child
6
+ accessed
7
+ @#{element.attribute_name}_child
8
+ end
9
+
10
+ def #{element.attribute_name}_child=(v)
11
+ accessed
12
+ @#{element.attribute_name}_child = v
13
+ end
14
+
15
+ alias #{element.attribute_name} #{element.attribute_name}_child
16
+ alias #{element.attribute_name}= #{element.attribute_name}_child=
17
+
18
+ def init_#{element.attribute_name}_as_child
19
+ @#{element.attribute_name}_child = IndexedArray.new
20
+ end
21
+
22
+ def add_#{element.attribute_name}(#{element.attribute_name})
23
+ accessed
24
+ index = #{element.attribute_name}.get_the_index
25
+ if(nil == index) then
26
+ raise Xampl::XamplException.new("no value for the index '#{element.indexed_by_attr}' of #{element.attribute_name} defined in : " << #{element.attribute_name}.pp_xml)
27
+ end
28
+
29
+ existing = @#{element.attribute_name}_child[index]
30
+
31
+ return existing if existing == #{element.attribute_name}
32
+
33
+ self.remove_#{element.attribute_name}(index) if existing
34
+
35
+ @children << #{element.attribute_name}
36
+ @#{element.attribute_name}_child[index] = #{element.attribute_name}
37
+
38
+ #{element.attribute_name}.add_parent(self)
39
+
40
+ changed
41
+ return #{element.attribute_name}
42
+ end
43
+
44
+ def new_#{element.attribute_name}(index)
45
+ accessed
46
+
47
+ #{element.attribute_name} = nil
48
+ |
49
+ |if @element.persisted then
50
+ |
51
+ #{element.attribute_name} = #{element.class_name}.lookup(index) if Xampl.persister and Xampl.persister.automatic
52
+ |
53
+ |end
54
+ |
55
+ #{element.attribute_name} = #{element.class_name}.new(index) unless #{element.attribute_name}
56
+
57
+ yield(#{element.attribute_name}) if block_given?
58
+ return add_#{element.attribute_name}(#{element.attribute_name})
59
+ end
60
+
61
+ def ensure_#{element.attribute_name}(index)
62
+ accessed
63
+
64
+ #{element.attribute_name} = @#{element.attribute_name}_child[index]
65
+ return #{element.attribute_name} if #{element.attribute_name}
66
+
67
+ |
68
+ |if @element.persisted then
69
+ |
70
+ #{element.attribute_name} = #{element.class_name}.lookup(index) if Xampl.persister and Xampl.persister.automatic
71
+ |
72
+ |end
73
+ |
74
+ #{element.attribute_name} = #{element.class_name}.new(index) unless #{element.attribute_name}
75
+
76
+ yield(#{element.attribute_name}) if block_given?
77
+ return add_#{element.attribute_name}(#{element.attribute_name})
78
+ end
79
+
80
+ def remove_#{element.attribute_name}(index)
81
+ accessed
82
+ changed
83
+ unless String === index or Symbol === index then
84
+ index = index.get_the_index
85
+ end
86
+ #{element.attribute_name} = @#{element.attribute_name}_child.delete(index) if index
87
+ @children.delete(#{element.attribute_name})
88
+ end
89
+ end
@@ -0,0 +1,5 @@
1
+ | if @element.indexed_by_attr then
2
+ | child_indexed(result)
3
+ | else
4
+ | child(result)
5
+ | end
@@ -0,0 +1,11 @@
1
+ | if "empty" == @element.kind then
2
+ | element_empty(result)
3
+ | elsif "simple" == @element.kind then
4
+ | element_simple(result)
5
+ | elsif "data" == @element.kind then
6
+ | element_data(result)
7
+ | elsif "mixed" == @element.kind then
8
+ | element_mixed(result)
9
+ | else
10
+ | raise Xampl::XamplException.new(:unkown_kind_of_element, "unknown element kind: '#{@element.kind}'")
11
+ | end
@@ -0,0 +1,282 @@
1
+
2
+ |
3
+ class #{@element.class_name}
4
+ |
5
+ |if @element.persisted then
6
+ |
7
+ include Xampl::XamplPersistedObject
8
+
9
+ @@default_persister_format = nil
10
+
11
+ def default_persister_format
12
+ @@default_persister_format
13
+ end
14
+ def #{@element.class_name}.default_persister_format
15
+ @@default_persister_format
16
+ end
17
+ def #{@element.class_name}.set_default_persister_format(format)
18
+ @@default_persister_format = format
19
+ end
20
+
21
+ def #{@element.class_name}.find_by_query
22
+ things = Xampl.find_xampl do | q |
23
+ q.add_condition('class', :equals, self.name)
24
+ yield(q)
25
+ end
26
+ end
27
+
28
+
29
+ |
30
+ |else
31
+ |
32
+ include Xampl::XamplObject
33
+ |
34
+ |end
35
+ |
36
+ include Xampl::XamplWithDataContent
37
+
38
+ @@tag = "#{@element.name}"
39
+ @@ns = "#{@element.namespace}"
40
+ @@ns_tag = "{#{@element.namespace}}#{@element.name}"
41
+ @@module_name = "#{@package_name}"
42
+ @@safe_name = "#{@package_name}_#{@element.attribute_name}"
43
+ @@attributes = [
44
+ |
45
+ |@element.attribute_child.each{ | attribute |
46
+ | if attribute.namespace then
47
+ |
48
+ [ :@#{attribute.name}, "#{attribute.tag_name}", "#{attribute.namespace}" ],
49
+ |
50
+ | else
51
+ |
52
+ [ :@#{attribute.name}, "#{attribute.tag_name}" ],
53
+ |
54
+ | end
55
+ |}
56
+ |
57
+ ]
58
+ |
59
+ |@element.child_element_child.each{ | child_element |
60
+ | element_class_name = @lookup_element[child_element.name].class_name
61
+ | element_package = @lookup_element[child_element.name].package
62
+ |
63
+ include #{element_package}::#{element_class_name}AsChild
64
+ |
65
+ |}
66
+ |
67
+ |
68
+
69
+ |
70
+ |if @element.persisted then
71
+ |
72
+
73
+ def #{@element.class_name}.lookup(pid)
74
+ Xampl.lookup(#{@element.class_name}, pid)
75
+ end
76
+
77
+ def #{@element.class_name}.[](pid)
78
+ Xampl.lookup(#{@element.class_name}, pid)
79
+ end
80
+ |
81
+ |end
82
+ |
83
+ |@element.attribute_child.each{ | attribute |
84
+ | if attribute.name == @element.indexed_by_attr and @element.persisted then
85
+ |
86
+
87
+ def #{attribute.name}
88
+ @#{attribute.name}
89
+ end
90
+
91
+ def #{attribute.name}=(v)
92
+ accessed
93
+ # This is kind of optimistic, I think you are in trouble if you do this
94
+ Xampl.auto_uncache(self) if @#{attribute.name}
95
+ @#{attribute.name} = v
96
+ changed
97
+ Xampl.auto_cache(self) if v
98
+ end
99
+ |
100
+ | else
101
+ |
102
+
103
+ def #{attribute.name}
104
+ accessed
105
+ @#{attribute.name}
106
+ end
107
+
108
+ def #{attribute.name}=(v)
109
+ accessed
110
+ changed
111
+ @#{attribute.name} = v
112
+ end
113
+ |
114
+ | end
115
+ |}
116
+ |
117
+ | if @element.indexed_by_attr then
118
+ |
119
+
120
+ def initialize(index=nil)
121
+ @#{@element.indexed_by_attr} = index if index
122
+ super()
123
+ |
124
+ | else
125
+ |
126
+
127
+ def initialize
128
+ super
129
+ |
130
+ |end
131
+ |
132
+ |if 0 < @element.attribute_child.size then
133
+ |
134
+
135
+ |
136
+ |end
137
+ |
138
+ |@element.attribute_child.each{ | attribute |
139
+ |
140
+ @#{attribute.name} = nil if not defined? @#{attribute.name}
141
+ |
142
+ |}
143
+ |
144
+
145
+ init_xampl_object
146
+ init_data_content
147
+ |
148
+ |@element.child_element_child.each{ | child_element |
149
+ | element_attribute_name = @lookup_element[child_element.name].attribute_name
150
+ |
151
+ init_#{element_attribute_name}_as_child
152
+ |
153
+ |}
154
+ |
155
+
156
+ yield(self) if block_given?
157
+ init_hook
158
+
159
+ changed
160
+ end
161
+
162
+ def clear_non_persistent_index_attributes
163
+ |
164
+ |@element.attribute_child.each{ | attribute |
165
+ | unless attribute.name == @element.indexed_by_attr and @element.persisted then
166
+ |
167
+ @#{attribute.name} = nil
168
+ |
169
+ | end
170
+ |}
171
+ |
172
+ end
173
+
174
+ def append_to(other)
175
+ other.add_#{@element.attribute_name}(self)
176
+ end
177
+
178
+ |
179
+ |if @element.persisted then
180
+ |
181
+ def #{@element.class_name}.persisted?
182
+ return :#{@element.indexed_by_attr}
183
+ end
184
+
185
+ def persisted?
186
+ return :#{@element.indexed_by_attr}
187
+ end
188
+
189
+ |
190
+ |else
191
+ |
192
+ def #{@element.class_name}.persisted?
193
+ return nil
194
+ end
195
+
196
+ def persisted?
197
+ return nil
198
+ end
199
+
200
+ |
201
+ |end
202
+ |
203
+ def #{@element.class_name}.tag
204
+ @@tag
205
+ end
206
+
207
+ def #{@element.class_name}.ns
208
+ @@ns
209
+ end
210
+
211
+ def #{@element.class_name}.ns_tag
212
+ @@ns_tag
213
+ end
214
+
215
+ def #{@element.class_name}.safe_name
216
+ @@safe_name
217
+ end
218
+
219
+ def #{@element.class_name}.module_name
220
+ @@module_name
221
+ end
222
+
223
+ def tag
224
+ @@tag
225
+ end
226
+
227
+ def ns
228
+ @@ns
229
+ end
230
+
231
+ def ns_tag
232
+ @@ns_tag
233
+ end
234
+
235
+ def safe_name
236
+ @@safe_name
237
+ end
238
+
239
+ def module_name
240
+ @@module_name
241
+ end
242
+
243
+ def attributes
244
+ @@attributes
245
+ end
246
+ |
247
+ |if @element.indexed_by_attr
248
+ |
249
+
250
+ def indexed_by
251
+ :#{@element.indexed_by_attr}
252
+ end
253
+
254
+ def get_the_index
255
+ @#{@element.indexed_by_attr}
256
+ end
257
+
258
+ def set_the_index(index)
259
+ @#{@element.indexed_by_attr} = index
260
+ end
261
+ |
262
+ |end
263
+ |
264
+
265
+ def substitute_in_visit(visitor)
266
+ return visitor.substitute_in_visit_#{@element.attribute_name}(self) || self
267
+ end
268
+
269
+ def before_visit(visitor)
270
+ visitor.before_visit_#{@element.attribute_name}(self)
271
+ end
272
+
273
+ def visit(visitor)
274
+ visitor.visit_#{@element.attribute_name}(self)
275
+ end
276
+
277
+ def after_visit(visitor)
278
+ visitor.after_visit_#{@element.attribute_name}(self)
279
+ end
280
+
281
+ Xampl::FromXML::register(#{@element.class_name}::tag, #{@element.class_name}::ns_tag, #{@element.class_name})
282
+ end