Module: Mxsd_Schema

Included in:
Cxsd_Schema
Defined in:
lib/ontomde-java/java/xsd.rb

Constant Summary collapse

XSD_HEADER =
<<END
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
END
<<END
</xsd:schema>
END

Instance Method Summary collapse

Instance Method Details

#xsd_computeDependencies!(defaultXSD) ⇒ Object

compute xsd dependencies from file



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ontomde-java/java/xsd.rb', line 39

def xsd_computeDependencies!(defaultXSD)
  deps=Set.new 
  xsd_getSetOfTypeUsedByAttributes.each { |clazz|
    clazz.xsd_types_inv.each {|i|
      next if i==self
      deps.add(i)	  
    }
  }
  deps.each {|d|
    xsd_dependencies_add(d)
  }
  return 
end

#xsd_generateSchemaObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ontomde-java/java/xsd.rb', line 62

def xsd_generateSchema
  xsd_openOutStream {
    write(XSD_HEADER)
    xsd_writeImports
    xsd_types.each { |clazz|
      #        puts "--> #{clazz}"
      clazz.xsd_writeType
    }
    write(XSD_FOOTER)
  }
end

#xsd_getSetOfTypeUsedByAttributesObject

return set of types used by attributes of classes in current xsd file.



17
18
19
20
21
22
23
24
25
26
# File 'lib/ontomde-java/java/xsd.rb', line 17

def xsd_getSetOfTypeUsedByAttributes
  types=Set.new
  xsd_types.each { |clazz|
    clazz.uml_ownedAttribute.each { |param|
	next if param.xsd_ignoreMe?
      types.merge(param.uml_type)
    }
  }
  return types
end

#xsd_openOutStream(&block) ⇒ Object

Opens xsd_SchemaName for writing

Example usage: xsd_openOutStream { write (“this text goes in java file”) }



88
89
90
91
92
# File 'lib/ontomde-java/java/xsd.rb', line 88

def xsd_openOutStream(&block)
  mtk_writeSession(xsd_SchemaName) {
    yield
  }
end

#xsd_SchemaNameObject



74
75
76
77
78
79
80
# File 'lib/ontomde-java/java/xsd.rb', line 74

def xsd_SchemaName
  if xsd_baseName.empty?
    return "global.xsd"
  else
    return xsd_baseName_one.xsd_SchemaName
  end
end

#xsd_writeImportsObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/ontomde-java/java/xsd.rb', line 28

def xsd_writeImports
  empty=true
  xsd_dependencies.each {|dep|
    empty=false
    base=Pathname.new(File.dirname(self.xsd_SchemaName))
    target=Pathname.new(dep.xsd_SchemaName)
    write(%{  <xsd:include schemaLocation="#{target.relative_path_from(base)}"/>\n})
  }
  write("\n") unless empty 
end