Class: Enterprisifier::Schema::Elements::SchemaElement

Inherits:
BaseElement
  • Object
show all
Defined in:
lib/enterprisifier/schema/elements/schema.rb

Constant Summary collapse

RegisterableElements =
%w[simpleType complexType group attributeGroup element attribute]

Instance Attribute Summary collapse

Attributes inherited from BaseElement

#attributes, #children, #default_namespace, #namespaces, #parent, #text

Instance Method Summary collapse

Methods inherited from BaseElement

#add_child, #add_text, #annotation, #base, #documentation, #each_child, #has_child?, #has_children?, map_attribute, #name, #read_attribute, #ref, register, #registered_as, #root, #rootable?

Constructor Details

#initialize(*args) ⇒ SchemaElement

Returns a new instance of SchemaElement.



14
15
16
17
18
19
# File 'lib/enterprisifier/schema/elements/schema.rb', line 14

def initialize(*args)
  super
  @registries = {}
  set_default_namespace
  add_observer(self)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/enterprisifier/schema/elements/schema.rb', line 8

def path
  @path
end

#registriesObject (readonly)

Returns the value of attribute registries.



9
10
11
# File 'lib/enterprisifier/schema/elements/schema.rb', line 9

def registries
  @registries
end

Instance Method Details

#default_registryObject



39
40
41
# File 'lib/enterprisifier/schema/elements/schema.rb', line 39

def default_registry
  registry_for(default_namespace)
end

#merge_schemas(other_schema, namespace = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/enterprisifier/schema/elements/schema.rb', line 27

def merge_schemas(other_schema, namespace = nil)
  if namespace
    ns_def = @namespaces.rassoc(namespace)
    raise ArgumentError, "Namespace #{namespace} is not defined in this schema document." unless ns_def
  end
  other_schema.each_child { |child| add_child(child) }
  namespaces.concat(other_schema.namespaces).uniq!
  other_schema.registries.each do |ns,values|
    values.each { |key,elements| registry_for(ns)[key].reverse_merge!(elements) }
  end
end

#update(element, state) ⇒ Object



21
22
23
24
25
# File 'lib/enterprisifier/schema/elements/schema.rb', line 21

def update(element, state)
  return nil if element.default_namespace != default_namespace
  return nil unless state == :child_added && default_registry.has_key?(element.registered_as)
  register_element(element)
end

#xsd_namespace?(namespace_ref) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/enterprisifier/schema/elements/schema.rb', line 43

def xsd_namespace?(namespace_ref)
  namespaces.any? do |ref,url|
    ref == namespace_ref && url == XMLSchemaNameSpaceURI
  end
end