Browse Source

----------------------------------------------------------------------

Modified Files:
 	WSDLTools.py
        -- resolution of default WS-Action was incorrect when using
        imported portTypes.

        XMLSchema.py
        -- added a couple helper functions, and a few more Markers
        for introspecting modelGroups and simpleType derivations.

 ----------------------------------------------------------------------
main
Joshua Boverhof 20 years ago
parent
commit
7d821b2071
2 changed files with 103 additions and 18 deletions
  1. +7
    -2
      WSDLTools.py
  2. +96
    -16
      XMLSchema.py

+ 7
- 2
WSDLTools.py View File

@@ -439,6 +439,9 @@ class PortType(Element):
def getWSDL(self):
return self.parent().parent()

def getTargetNamespace(self):
return self.targetNamespace or self.getWSDL().targetNamespace

def getResourceProperties(self):
return self.resourceProperties

@@ -450,6 +453,8 @@ class PortType(Element):
def load(self, element):
self.name = DOM.getAttr(element, 'name')
self.documentation = GetDocumentation(element)
self.targetNamespace = DOM.getAttr(element, 'targetNamespace')
print "PORTYPE TNS: ", self.targetNamespace

if DOM.hasAttr(element, 'ResourceProperties', WSR.PROPERTIES):
rpref = DOM.getAttr(element, 'ResourceProperties', WSR.PROPERTIES)
@@ -1055,7 +1060,7 @@ def GetWSAActionInput(operation):
if attr is not None:
return attr
portType = operation.getPortType()
targetNamespace = portType.getWSDL().targetNamespace
targetNamespace = portType.getTargetNamespace()
ptName = portType.name
msgName = operation.input.name
if not msgName:
@@ -1069,7 +1074,7 @@ def GetWSAActionOutput(operation):
attr = operation.output.action
if attr is not None:
return attr
targetNamespace = operation.getPortType().getWSDL().targetNamespace
targetNamespace = operation.getPortType().getTargetNamespace()
ptName = operation.getPortType().name
msgName = operation.output.name
if not msgName:


+ 96
- 16
XMLSchema.py View File

@@ -332,6 +332,21 @@ class ModelGroupMarker:
"""
pass

class AllMarker(ModelGroupMarker):
"""marker for all model group
"""
pass

class ChoiceMarker(ModelGroupMarker):
"""marker for choice model group
"""
pass

class SequenceMarker(ModelGroupMarker):
"""marker for sequence model group
"""
pass

class ExtensionMarker:
"""marker for extensions
"""
@@ -349,6 +364,17 @@ class SimpleMarker:
"""
pass

class ListMarker:
"""marker for simple type list
"""
pass

class UnionMarker:
"""marker for simple type Union
"""
pass


class ComplexMarker:
"""marker for complex type information
"""
@@ -385,6 +411,15 @@ class MarkerInterface:
def isModelGroup(self):
return isinstance(self, ModelGroupMarker)

def isAll(self):
return isinstance(self, AllMarker)

def isChoice(self):
return isinstance(self, ChoiceMarker)

def isSequence(self):
return isinstance(self, SequenceMarker)

def isExtension(self):
return isinstance(self, ExtensionMarker)

@@ -400,6 +435,12 @@ class MarkerInterface:
def isLocal(self):
return isinstance(self, LocalMarker)

def isList(self):
return isinstance(self, ListMarker)

def isUnion(self):
return isinstance(self, UnionMarker)


##########################################################
# Schema Components
@@ -471,6 +512,18 @@ class XMLSchemaComponent(XMLBase, MarkerInterface):
tns = parent.attributes.get(targetNamespace)
return tns

def getAttributeDeclaration(self, attribute):
"""attribute -- attribute with a QName value (eg. type).
collection -- check types collection in parent Schema instance
"""
return self.getQNameAttribute('attr_decl', attribute)

def getAttributeGroup(self, attribute):
"""attribute -- attribute with a QName value (eg. type).
collection -- check types collection in parent Schema instance
"""
return self.getQNameAttribute('attr_groups', attribute)

def getTypeDefinition(self, attribute):
"""attribute -- attribute with a QName value (eg. type).
collection -- check types collection in parent Schema instance
@@ -1114,7 +1167,10 @@ class XMLSchema(XMLSchemaComponent):
self.setAttributes(node)
contents = self.getContents(node)

if self.attributes['namespace'] == self._parent().attributes['targetNamespace']:
print "PARENT: ", self._parent()
print "\ttns: ", self.getTargetNamespace()
#if self.attributes['namespace'] == self._parent().attributes['targetNamespace']:
if self.attributes['namespace'] == self.getTargetNamespace():
raise SchemaError, 'namespace of schema and import match'

for i in contents:
@@ -1361,6 +1417,9 @@ class AttributeReference(XMLSchemaComponent,\
XMLSchemaComponent.__init__(self, parent)
self.annotation = None

def getAttributeDeclaration(self, attribute='ref'):
return XMLSchemaComponent.getAttributeDeclaration(self, attribute)

def fromDom(self, node):
self.setAttributes(node)
contents = self.getContents(node)
@@ -1389,7 +1448,7 @@ class AttributeGroupDefinition(XMLSchemaComponent,\
required = ['name']
attributes = {'id':None,
'name':None}
contents = {'xsd':['annotation']}
contents = {'xsd':['annotation', 'attribute', 'attributeGroup', 'anyAttribute']}
tag = 'attributeGroup'

def __init__(self, parent):
@@ -1410,19 +1469,21 @@ class AttributeGroupDefinition(XMLSchemaComponent,\
if (component == 'annotation') and (not indx):
self.annotation = Annotation(self)
self.annotation.fromDom(contents[indx])
elif (component == 'attribute'):
elif component == 'attribute':
if contents[indx].hasattr('name'):
content.append(AttributeDeclaration())
content.append(AttributeDeclaration(self))
elif contents[indx].hasattr('ref'):
content.append(AttributeReference())
content.append(AttributeReference(self))
else:
raise SchemaError, 'Unknown attribute type'
content[-1].fromDom(contents[indx])
elif (component == 'attributeGroup'):
content.append(AttributeGroupReference())
elif component == 'attributeGroup':
content.append(AttributeGroupReference(self))
content[-1].fromDom(contents[indx])
elif (component == 'anyAttribute') and (len(contents) == x+1):
content.append(AttributeWildCard())
elif component == 'anyAttribute':
if len(contents) != indx+1:
raise SchemaError, 'anyAttribute is out of order in %s' %self.getItemTrace()
content.append(AttributeWildCard(self))
content[-1].fromDom(contents[indx])
else:
raise SchemaError, 'Unknown component (%s)' %(contents[indx].getTagName())
@@ -1451,6 +1512,12 @@ class AttributeGroupReference(XMLSchemaComponent,\
XMLSchemaComponent.__init__(self, parent)
self.annotation = None

def getAttributeGroup(self, attribute='ref'):
"""attribute -- attribute with a QName value (eg. type).
collection -- check types collection in parent Schema instance
"""
return XMLSchemaComponent.getQNameAttribute(self, 'attr_groups', attribute)

def fromDom(self, node):
self.setAttributes(node)
contents = self.getContents(node)
@@ -1849,7 +1916,7 @@ class ElementWildCard(LocalElementDeclaration,\
# Model Groups
#####################################################
class Sequence(XMLSchemaComponent,\
ModelGroupMarker):
SequenceMarker):
"""<sequence>
parents:
complexType, extension, restriction, group, choice, sequence
@@ -1907,7 +1974,7 @@ class Sequence(XMLSchemaComponent,\


class All(XMLSchemaComponent,\
ModelGroupMarker):
AllMarker):
"""<all>
parents:
complexType, extension, restriction, group
@@ -1956,7 +2023,7 @@ class All(XMLSchemaComponent,\


class Choice(XMLSchemaComponent,\
ModelGroupMarker):
ChoiceMarker):
"""<choice>
parents:
complexType, extension, restriction, group, choice, sequence
@@ -2626,7 +2693,8 @@ class SimpleType(XMLSchemaComponent,\
self.content = tuple(content)


class Union(XMLSchemaComponent):
class Union(XMLSchemaComponent,
UnionMarker):
"""<union>
parents:
simpleType
@@ -2664,7 +2732,8 @@ class SimpleType(XMLSchemaComponent,\
raise SchemaError, 'Unknown component (%s)' %(i.getTagName())
self.content = tuple(content)

class List(XMLSchemaComponent):
class List(XMLSchemaComponent,
ListMarker):
"""<list>
parents:
simpleType
@@ -2685,11 +2754,22 @@ class SimpleType(XMLSchemaComponent,\
self.annotation = None
self.content = None

def getItemType(self):
return self.attributes.get('itemType')

def getTypeDefinition(self, attribute='itemType'):
'''return the type refered to by itemType attribute or
the simpleType content. If returns None, then the
type refered to by itemType is primitive.
'''
tp = XMLSchemaComponent.getTypeDefinition(self, attribute)
return tp or self.content

def fromDom(self, node):
self.annotation = None
self.content = None
self.setAttributes(node)
contents = self.getContents(node)
self.content = []

for indx in range(len(contents)):
component = SplitQName(contents[indx].getTagName())[1]
if (component == 'annotation') and (not indx):


Loading…
Cancel
Save