Commit cd93c7ad authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Ability to detect and store version of the cadbiom namespace => versioning of the models

parent 6c322f57
......@@ -79,8 +79,15 @@ class ChartModel(object):
Model of a chart - implements the observer pattern as subject
observers must have an update method
"""
def __init__(self, name):
def __init__(self, name, xml_namespace="http://cadbiom.genouest.org/"):
"""
:param name: Name of the model (ex: concat of graphs uris).
:param xml_namespace: Global namespace: Model version.
ex: http://cadbiom.genouest.org/ (v1),
or http://cadbiom.genouest.org/v2/ (v2)
"""
self.name = name
self.xml_namespace = xml_namespace # Version of cadbiom model
self.simple_node_dict = dict() # for quick finding - name -> node
self.node_dict = dict()
self.transition_list = [] # idem
......
......@@ -186,13 +186,19 @@ class XmlVisitor:
return [tag, attrname, attr]
def visit_ctop_node(self, tnode):
"""
interative build of xml tree for model saving
"""Interative build of xml tree for model saving
.. note:: namespace seems to be useless regarding nsmap here,
because we use the default namespace without prefix...
See http://lxml.de/tutorial.html#namespaces.
"""
header = objectify.ElementMaker(
annotate=False,
namespace="http://cadbiom.genouest.org/",
nsmap={None : "http://cadbiom.genouest.org/"}
#namespace="http://cadbiom.genouest.org/",
#nsmap={None: "http://cadbiom.genouest.org/"}
namespace=self.model.xml_namespace,
# the default namespace (no prefix)
nsmap={None: self.model.xml_namespace}
)
xmodel = header.model(name=self.model_name)
self.current_element = xmodel
......@@ -396,9 +402,13 @@ class MakeHandler(ContentHandler):
self.in_constraints = True
self.constraints = ""
elif name == "model":
elif name == 'model':
if not self.model:
self.model = ChartModel(att.get('name',''))
# Init CharModel: get name and namespace (default v1)
self.model = ChartModel(
att.get('name', ''),
att.get('xmlns', 'http://cadbiom.genouest.org/')
)
# Root is a virtual macronode on top of the hierarchy.
# A model can be a list of hierarchy grouped under this node.
root = self.model.get_root()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment