summaryrefslogtreecommitdiff
path: root/cpp/managementgen/schema.py
diff options
context:
space:
mode:
authorCarl C. Trieloff <cctrieloff@apache.org>2008-02-28 18:55:21 +0000
committerCarl C. Trieloff <cctrieloff@apache.org>2008-02-28 18:55:21 +0000
commitac3f850123c903f00c163d6d2dbad22d98aec7a2 (patch)
tree2e622a3e9349a9062454d16bf4bca83a5a3e9d90 /cpp/managementgen/schema.py
parent1820dd421a096ed184a08deee9512e809312fed2 (diff)
downloadqpid-python-ac3f850123c903f00c163d6d2dbad22d98aec7a2.tar.gz
QPID-820 from tross
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@632087 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/managementgen/schema.py')
-rwxr-xr-xcpp/managementgen/schema.py85
1 files changed, 66 insertions, 19 deletions
diff --git a/cpp/managementgen/schema.py b/cpp/managementgen/schema.py
index a459db7a47..fd76ba9112 100755
--- a/cpp/managementgen/schema.py
+++ b/cpp/managementgen/schema.py
@@ -21,6 +21,7 @@
from xml.dom.minidom import parse, parseString, Node
from cStringIO import StringIO
+import md5
#=====================================================================================
#
@@ -575,15 +576,18 @@ class SchemaEvent:
def getArgCount (self):
return len (self.args)
-#=====================================================================================
-#
-#=====================================================================================
+
class SchemaClass:
- def __init__ (self, node, typespec):
+ def __init__ (self, package, node, typespec, fragments, options):
+ self.packageName = package
self.configElements = []
self.instElements = []
self.methods = []
self.events = []
+ self.options = options
+ self.md5Sum = md5.new ()
+
+ self.hash (node)
attrs = node.attributes
self.name = attrs['name'].nodeValue
@@ -607,9 +611,40 @@ class SchemaClass:
sub = SchemaEvent (self, child, typespec)
self.events.append (sub)
+ elif child.nodeName == 'group':
+ self.expandFragment (child, fragments)
+
else:
raise ValueError ("Unknown class tag '%s'" % child.nodeName)
+ def hash (self, node):
+ attrs = node.attributes
+ self.md5Sum.update (node.nodeName)
+
+ for idx in range (attrs.length):
+ self.md5Sum.update (attrs.item(idx).nodeName)
+ self.md5Sum.update (attrs.item(idx).nodeValue)
+
+ for child in node.childNodes:
+ if child.nodeType == Node.ELEMENT_NODE:
+ self.hash (child)
+
+ def expandFragment (self, node, fragments):
+ attrs = node.attributes
+ name = attrs['name'].nodeValue
+ for fragment in fragments:
+ if fragment.name == name:
+ for config in fragment.configElements:
+ self.configElements.append (config)
+ for inst in fragment.instElements:
+ self.instElements.append (inst)
+ for method in fragment.methods:
+ self.methods.append (method)
+ for event in fragment.events:
+ self.events.append (event)
+ return
+ raise ValueError ("Undefined group '%s'" % name)
+
def getName (self):
return self.name
@@ -644,13 +679,9 @@ class SchemaClass:
def genConstructorArgs (self, stream, variables):
# Constructor args are config elements with read-create access
result = ""
- first = 1
for element in self.configElements:
if element.isConstructorArg ():
- if first == 1:
- first = 0
- else:
- stream.write (", ")
+ stream.write (", ")
element.genFormalParam (stream)
def genConstructorInits (self, stream, variables):
@@ -715,8 +746,8 @@ class SchemaClass:
def genMethodArgIncludes (self, stream, variables):
for method in self.methods:
if method.getArgCount () > 0:
- stream.write ("#include \"qpid/management/Args" +\
- method.getFullName () + ".h\"\n")
+ stream.write ("#include \"" + (self.options.include_prefix or "") +\
+ "Args" + method.getFullName () + ".h\"\n")
def genMethodCount (self, stream, variables):
stream.write ("%d" % len (self.methods))
@@ -765,13 +796,16 @@ class SchemaClass:
def genNameLower (self, stream, variables):
stream.write (self.name.lower ())
+ def genNamePackageLower (self, stream, variables):
+ stream.write (self.packageName.lower ())
+
def genNameUpper (self, stream, variables):
stream.write (self.name.upper ())
def genParentArg (self, stream, variables):
for config in self.configElements:
if config.isParentRef == 1:
- stream.write (" _parent")
+ stream.write (", Manageable* _parent")
return
def genParentRefAssignment (self, stream, variables):
@@ -781,6 +815,13 @@ class SchemaClass:
" = _parent->GetManagementObject ()->getObjectId ();")
return
+ def genSchemaMD5 (self, stream, variables):
+ sum = self.md5Sum.digest ()
+ for idx in range (len (sum)):
+ if idx != 0:
+ stream.write (",")
+ stream.write (hex (ord (sum[idx])))
+
def genWriteConfig (self, stream, variables):
for config in self.configElements:
config.genWrite (stream);
@@ -790,14 +831,13 @@ class SchemaClass:
inst.genWrite (stream);
-#=====================================================================================
-#
-#=====================================================================================
+
class PackageSchema:
- def __init__ (self, typefile, schemafile):
+ def __init__ (self, typefile, schemafile, options):
- self.classes = []
- self.typespec = TypeSpec (typefile)
+ self.classes = []
+ self.fragments = []
+ self.typespec = TypeSpec (typefile)
dom = parse (schemafile)
document = dom.documentElement
@@ -810,8 +850,15 @@ class PackageSchema:
for child in children:
if child.nodeType == Node.ELEMENT_NODE:
if child.nodeName == 'class':
- cls = SchemaClass (child, self.typespec)
+ cls = SchemaClass (self.packageName, child, self.typespec,
+ self.fragments, options)
self.classes.append (cls)
+
+ elif child.nodeName == 'group':
+ cls = SchemaClass (self.packageName, child, self.typespec,
+ self.fragments, options)
+ self.fragments.append (cls)
+
else:
raise ValueError ("Unknown schema tag '%s'" % child.nodeName)