> From: Andrew Dorrycott
> Sent: Thursday, July 23, 2009 10:07:50 AM
> Subject: Re: Working with Jboss JPDL-3.2.xsd
>
> I made the change on my side to see what would happen, and I
> noticed that the task element on line 335 has an attribute with the
> type priorityType with a default value. When I create an object of
> the task class in the super class, the priorityType does not
> contain the default value and has no ties to the priorityType
> itself that is provided in the xsd.
>
> Is there a painless solution to the missing default value?
>
Andrew -
Ah. Default value plus simpleType. OK. ... I think I've fixed
that now.
> Should there not be some kind of list of the allowed values in the
> specific priorityType?
>
The code generated by generateDS.py does not automatically check
values specified in a restriction. However, if you have a need for
this, take a look at the section "simpleType and validators" in the
documentation:
http://www.rexx.com/~dkuhlman/generateDS.html#simpletype-and-validators
I believe that I've also fixed the problem related to the following
message that you reported:
"Element assignment extension chain contains mixed and
non-mixed content. Not generated"
> Sample code
> ========
> import jpdl_super as jpdl
>
> task = jpdl.task()
>
> print(task.priorityType)
> # notice the value is None
>
> dir(jpdl)
> # No mention of priorityType, where'd it go? :P
>
With the attached patch, you should see generated code that
initializes to the default value.
So here is a summary of changes:
* Fix for exception with simpleType that is an extension of
another simpleType.
* Change to mixed extension chain -- Will now generate class.
* Fix to generation of constructors -- Will now initialize to
default value for simpleTypes.
* Fixed generations of validator methods, validator bodies,
and call to validator bodies for attributes.
A patch file that can be applied to generateDS.py version 1.18a is
attached.
Let me know how that patch works. If it seems OK, I'll try to upload a
new version tomorrow or the next day.
- Dave
--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
--- Tmp/generateDS-1.18a/generateDS.py 2009-07-10 10:41:18.000000000 -0700
+++ generateDS.py 2009-07-27 16:59:12.000000000 -0700
@@ -542,10 +542,36 @@
# an extension, then all of its bases (base, base of base, ...)
# must be mixed-content. Mark it as an error, if not.
def checkMixedBases(self):
+ self.rationalizeMixedBases()
self.checkMixedBasesChain(self, self.mixed)
for child in self.children:
child.checkMixedBases()
+ def rationalizeMixedBases(self):
+ mixed = self.hasMixedInChain()
+ if mixed:
+ #print '-----\nrationalizing mixed. name: "%s"' % (self.getName(), )
+ self.equalizeMixedBases()
+
+ def hasMixedInChain(self):
+ if self.isMixed():
+ return True
+ base = self.getBase()
+ if base and base in ElementDict:
+ parent = ElementDict[base]
+ return parent.hasMixedInChain()
+ else:
+ return False
+
+ def equalizeMixedBases(self):
+ if not self.isMixed():
+ self.setMixed(True)
+ #print 'setting mixed. name: "%s"' % (self.getName(), )
+ base = self.getBase()
+ if base and base in ElementDict:
+ parent = ElementDict[base]
+ parent.equalizeMixedBases()
+
def checkMixedBasesChain(self, child, childMixed):
base = self.getBase()
if base and base in ElementDict:
@@ -1119,7 +1145,7 @@
def endElement(self, name):
logging.debug("End element: %s" % (name))
logging.debug("End element stack: %d" % (len(self.stack)))
- if name == SimpleTypeType and self.inSimpleType:
+ if name == SimpleTypeType: # and self.inSimpleType:
self.inSimpleType = 0
if self.inAttribute:
pass
@@ -2059,6 +2085,10 @@
s1 = " self.%s = attrs.get('%s').value\n" % \
(mappedName, name, )
outfile.write(s1)
+ if atype in SimpleTypeDict:
+ s1 = " self.validate_%s(self.%s) # validate type %s\n" % (
+ atype, mappedName, atype, )
+ outfile.write(s1)
if element.getAnyAttribute():
hasAttributes += 1
s1 = ' self.anyAttributes_ = {}\n'
@@ -2530,7 +2560,7 @@
mappedName, mappedName, )
wrt(s1)
if typeName:
- s1 = " self.validate_%s(self.%s) # validate type 1aaaa %s\n" % (
+ s1 = " self.validate_%s(self.%s) # validate type %s\n" % (
typeName, mappedName, typeName, )
wrt(s1)
@@ -2711,7 +2741,10 @@
else:
add(', %s=%s' % (mappedName, default))
else:
- add(', %s=None' % mappedName)
+ if default is None:
+ add(', %s=None' % mappedName)
+ else:
+ add(", %s='%s'" % (mappedName, default, ))
nestedElements = 0
for child in element.getChildren():
cleanName = child.getCleanName()
@@ -2784,7 +2817,10 @@
else:
add(', %s=%s' % (cleanName, default, ))
else:
- add(', %s=None' % cleanName)
+ if default is None:
+ add(', %s=None' % cleanName)
+ else:
+ add(", '%s=%s'" % (cleanName, default, ))
# end buildCtorArgs_aux
@@ -2944,18 +2980,18 @@
elif (childType in ElementDict and
ElementDict[childType].getSimpleType()):
typeName = ElementDict[childType].getType()
- if typeName:
+ if typeName and typeName not in generatedSimpleTypes:
generatedSimpleTypes.append(typeName)
#s1 = ' def validate_%s(self, value):\n' % (capName, )
s1 = ' def validate_%s(self, value):\n' % (typeName, )
outfile.write(s1)
if typeName in SimpleTypeDict:
stObj = SimpleTypeDict[typeName]
- s1 = ' # Validate type 2aaaa %s, a restriction on %s.\n' % (
+ s1 = ' # Validate type %s, a restriction on %s.\n' % (
typeName, stObj.getBase(), )
outfile.write(s1)
else:
- s1 = ' # validate type 3aaaa %s\n' % (typeName, )
+ s1 = ' # validate type %s\n' % (typeName, )
outfile.write(s1)
s1 = getValidatorBody(typeName)
outfile.write(s1)
@@ -2986,6 +3022,23 @@
s1 = ' %sProp = property(get%s, set%s)\n' % \
(mappedName, capName, capName)
outfile.write(s1)
+ typeName = attrDef.getType()
+ if (typeName and
+ typeName in SimpleTypeDict and
+ typeName not in generatedSimpleTypes):
+ generatedSimpleTypes.append(typeName)
+ s1 = ' def validate_%s(self, value):\n' % (typeName, )
+ outfile.write(s1)
+ if typeName in SimpleTypeDict:
+ stObj = SimpleTypeDict[typeName]
+ s1 = ' # Validate type %s, a restriction on %s.\n' % (
+ typeName, stObj.getBase(), )
+ outfile.write(s1)
+ else:
+ s1 = ' # validate type %s\n' % (typeName, )
+ outfile.write(s1)
+ s1 = getValidatorBody(typeName)
+ outfile.write(s1)
if childCount == 0:
s1 = ' def getValueOf_(self): return self.valueOf_\n'
outfile.write(s1)
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users