Module: Xampl::XamplObject

Defined Under Namespace

Modules: XamplRubyDefinition

Constant Summary collapse

@@preferred_ns_prefix =
{ "http://xampl.com/" => "xampl",
"http://xampl.com/generator" => "xampl-gen",
"http://www.w3.org/XML/1998/namespace" => "xml" }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#is_changedObject

Returns the value of attribute is_changed.



5
6
7
# File 'lib/xamplr/xampl-object.rb', line 5

def is_changed
  @is_changed
end

#parentsObject

Returns the value of attribute parents.



5
6
7
# File 'lib/xamplr/xampl-object.rb', line 5

def parents
  @parents
end

Class Method Details

.from_ruby(ruby_string, target = nil) ⇒ Object



175
176
177
178
179
# File 'lib/xamplr/xampl-object.rb', line 175

def XamplObject.from_ruby(ruby_string, target=nil)
  eval(ruby_string, nil, "ruby_definition", 0)
  target.load_needed = false if target
  xampl = XamplRubyDefinition.build(target)
end

.from_string(string, target = nil) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/xamplr/xampl-object.rb', line 158

def XamplObject.from_string(string, target=nil)
  return FromXML.new.parse_string(string, true, false, target)

  #       if '<' == string[0] then
  #         puts "XO.from_string XML ------------------------------------------------------"
  #         return FromXML.new.parse_string(string, true, false, target)
  #       else
  #         puts "XO.from_string RUBY ------------------------------------------------------"
  #         return XamplObject.from_ruby(string, target)
  #       end
end

.from_xml_file(file_name, tokenise = true) ⇒ Object



195
196
197
# File 'lib/xamplr/xampl-object.rb', line 195

def XamplObject.from_xml_file(file_name, tokenise=true)
  return FromXML.new.parse(file_name, tokenise)
end

.from_xml_string(xml_string, tokenise = true) ⇒ Object



191
192
193
# File 'lib/xamplr/xampl-object.rb', line 191

def XamplObject.from_xml_string(xml_string, tokenise=true)
  return FromXML.new.parse_string(xml_string, tokenise)
end

.lookup_preferred_ns_prefix(ns) ⇒ Object



23
24
25
# File 'lib/xamplr/xampl-object.rb', line 23

def XamplObject.lookup_preferred_ns_prefix(ns)
  @@preferred_ns_prefix[ns]
end

.ns_preferred_prefix(ns, prefix) ⇒ Object



19
20
21
# File 'lib/xamplr/xampl-object.rb', line 19

def XamplObject.ns_preferred_prefix(ns, prefix)
  @@preferred_ns_prefix[ns] = prefix unless @@preferred_ns_prefix.has_key?(ns)
end

.realise_from_xml_string(xml_string, target = nil, tokenise = true) ⇒ Object



186
187
188
189
# File 'lib/xamplr/xampl-object.rb', line 186

def XamplObject.realise_from_xml_string(xml_string, target=nil, tokenise=true)
  xampl = FromXML.new.realise_string(xml_string, tokenise, target)
  return xampl
end

.recover_from_string(string) ⇒ Object



170
171
172
173
# File 'lib/xamplr/xampl-object.rb', line 170

def XamplObject.recover_from_string(string)
  #       return FromXML.new.realise_string(string)
  return FromXML.new(true).parse_string(string, true, false, nil)
end

Instance Method Details

#===(other) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/xamplr/xampl-object.rb', line 110

def ===(other)
  accessed
  other.accessed if other
  return false unless self.class == other.class
  return false unless self.children.size == other.children.size
  self.children.zip(other.children).each do |c1, c2|
    return false unless c1.class == c2.class
    if c1.kind_of? String then
      return false unless c1 == c2
    else
      return false unless c1 === c2
    end
  end
  if (defined? self._content) and (defined? other._content) then
    return false unless self._content == other._content
  else
    return false if (defined? self._content) or (defined? other._content)
  end
  return true
end

#accessedObject

Raises:



59
60
61
# File 'lib/xamplr/xampl-object.rb', line 59

def accessed
  raise XamplIsInvalid.new(self) if invalid
end

#add_parent(xampl) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/xamplr/xampl-object.rb', line 63

def add_parent(xampl)
  @parents = [] if (not defined? @parents) or (nil == @parents)
  @parents << xampl
  if Xampl.persister and self.persist_required and (nil == self.persister) then
    Xampl.introduce_to_persister(self)
  end
end

#changedObject



49
50
51
52
53
54
55
56
57
# File 'lib/xamplr/xampl-object.rb', line 49

def changed
  unless Xampl.persister then
    raise UnmanagedChange.new(self)
  end
  unless @is_changed then
    @is_changed = true
    @parents.each{ | parent | parent.changed } if nil != @parents
  end
end

#changes_acceptedObject



45
46
47
# File 'lib/xamplr/xampl-object.rb', line 45

def changes_accepted
  ResetIsChanged.new.start(self)
end

#compare_xampl(other) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/xamplr/xampl-object.rb', line 89

def compare_xampl(other)
  accessed
  other.accessed if other
  return false unless self.class == other.class
  return false unless self.children.size == other.children.size
  self.children.zip(other.children).each do |c1, c2|
    return false unless c1.class == c2.class
    if c1.kind_of? String then
      return false unless c1 == c2
    else
      return false unless c1.compare_xampl(c2)
    end
  end
  if (defined? self._content) and (defined? other._content) then
    return false unless self._content == other._content
  else
    return false if (defined? self._content) or (defined? other._content)
  end
  return true
end

#copy_xampl(root, translate_pids = {}) ⇒ Object



563
564
565
# File 'lib/xamplr/visitors.rb', line 563

def copy_xampl(root, translate_pids={})
  CopyXML.copy(root, translate_pids)
end

#ignore_when_no_indexObject



31
32
33
# File 'lib/xamplr/xampl-object.rb', line 31

def ignore_when_no_index
  return false
end

#init_attributes(attr_name, attr_namespace, attr_value) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/xamplr/xampl-object.rb', line 71

def init_attributes(attr_name, attr_namespace, attr_value)
  return unless attr_name

  attr_name.each_index do |i|
    self.attributes.each do |attr_spec|
      if (2 == attr_spec.size) then
        if (attr_spec[1] == attr_name[i]) then
          self.instance_variable_set(attr_spec[0], attr_value[i])
        end
      else
        if ((attr_spec[1] == attr_name[i]) and (attr_spec[2] == attr_namespace[i])) then
          self.instance_variable_set(attr_spec[0], attr_value[i])
        end
      end
    end
  end
end

#init_hookObject



16
17
# File 'lib/xamplr/xampl-object.rb', line 16

def init_hook
end

#init_xampl_objectObject



11
12
13
14
# File 'lib/xamplr/xampl-object.rb', line 11

def init_xampl_object
  @parents = nil if not defined? @parents
  @is_changed = false if not defined? @is_changed
end

#invalidObject



41
42
43
# File 'lib/xamplr/xampl-object.rb', line 41

def invalid
  return kind_of?(InvalidXampl)
end

#invalidateObject



35
36
37
38
39
# File 'lib/xamplr/xampl-object.rb', line 35

def invalidate
  self.note_invalidate
  self.persister.uncache(self) if self.persister
  self.extend InvalidXampl
end

#mark_changed_deepObject



567
568
569
# File 'lib/xamplr/visitors.rb', line 567

def mark_changed_deep
  MarkChangedDeep.new.start(self)
end

#note_add_child(child, realising) ⇒ Object

about to be added to a parent



37
38
39
# File 'lib/xamplr/notifications.rb', line 37

def note_add_child(child, realising)
  return child
end

#note_add_to_parent(parent, realising) ⇒ Object

about to be added to a parent



31
32
33
# File 'lib/xamplr/notifications.rb', line 31

def note_add_to_parent(parent, realising)
  return self
end

#note_adding_text_content(xml_text, realising) ⇒ Object

add text (while loading from XML)

xml_text -- the text
realising -- true when loading from a persister


9
10
11
# File 'lib/xamplr/notifications.rb', line 9

def note_adding_text_content(xml_text, realising)
  return xml_text
end

#note_attributes_initialised(realising) ⇒ Object

attributes are setup up (while loading from XML)



21
22
# File 'lib/xamplr/notifications.rb', line 21

def note_attributes_initialised(realising)
end

#note_closed(realising) ⇒ Object

this element has been completed



43
44
45
# File 'lib/xamplr/notifications.rb', line 43

def note_closed(realising)
  return self
end

#note_created(realising) ⇒ Object

just created



26
27
# File 'lib/xamplr/notifications.rb', line 26

def note_created(realising)
end

#note_initialise_attributes_with(names, namespaces, values, realising) ⇒ Object

these are the arrays of attribute information about to be used to initialise the attributes



16
17
# File 'lib/xamplr/notifications.rb', line 16

def note_initialise_attributes_with(names, namespaces, values, realising)
end

#note_invalidateObject

about to be invalidated



54
55
# File 'lib/xamplr/notifications.rb', line 54

def note_invalidate
end

#note_replacing(original) ⇒ Object

replacing the original



49
50
# File 'lib/xamplr/notifications.rb', line 49

def note_replacing(original)
end

#persist(out = "", mentions = nil, rules = nil) ⇒ Object



181
182
183
184
# File 'lib/xamplr/xampl-object.rb', line 181

def persist(out="", mentions=nil, rules=nil)
  persist_xml_new = PersistXML.new(out, mentions)
  return persist_xml_new.start(self).done
end

#persist_requiredObject



27
28
29
# File 'lib/xamplr/xampl-object.rb', line 27

def persist_required
  return false
end

#pp_xml(out = "", skip = []) ⇒ Object



559
560
561
# File 'lib/xamplr/visitors.rb', line 559

def pp_xml(out="", skip=[])
  PrettyXML.new(out, skip).start(self).done
end

#to_ruby(mentions = nil) ⇒ Object



131
132
133
134
# File 'lib/xamplr/xampl-object.rb', line 131

def to_ruby(mentions=nil)
  accessed
  return RubyPrinter.new(mentions).to_ruby(self)
end

#to_xml(out = "", skip = []) ⇒ Object



243
244
245
# File 'lib/xamplr/persist-to-xml.rb', line 243

def to_xml(out="", skip=[])
  PersistXML.new(out).start(self).done
end