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 21 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): def getWSDL(self):
return self.parent().parent() return self.parent().parent()


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

def getResourceProperties(self): def getResourceProperties(self):
return self.resourceProperties return self.resourceProperties


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


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


+ 96
- 16
XMLSchema.py View File

@@ -332,6 +332,21 @@ class ModelGroupMarker:
""" """
pass 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: class ExtensionMarker:
"""marker for extensions """marker for extensions
""" """
@@ -349,6 +364,17 @@ class SimpleMarker:
""" """
pass pass


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

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


class ComplexMarker: class ComplexMarker:
"""marker for complex type information """marker for complex type information
""" """
@@ -385,6 +411,15 @@ class MarkerInterface:
def isModelGroup(self): def isModelGroup(self):
return isinstance(self, ModelGroupMarker) 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): def isExtension(self):
return isinstance(self, ExtensionMarker) return isinstance(self, ExtensionMarker)


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


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

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



########################################################## ##########################################################
# Schema Components # Schema Components
@@ -471,6 +512,18 @@ class XMLSchemaComponent(XMLBase, MarkerInterface):
tns = parent.attributes.get(targetNamespace) tns = parent.attributes.get(targetNamespace)
return tns 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): def getTypeDefinition(self, attribute):
"""attribute -- attribute with a QName value (eg. type). """attribute -- attribute with a QName value (eg. type).
collection -- check types collection in parent Schema instance collection -- check types collection in parent Schema instance
@@ -1114,7 +1167,10 @@ class XMLSchema(XMLSchemaComponent):
self.setAttributes(node) self.setAttributes(node)
contents = self.getContents(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' raise SchemaError, 'namespace of schema and import match'


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


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

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


def __init__(self, parent): def __init__(self, parent):
@@ -1410,19 +1469,21 @@ class AttributeGroupDefinition(XMLSchemaComponent,\
if (component == 'annotation') and (not indx): if (component == 'annotation') and (not indx):
self.annotation = Annotation(self) self.annotation = Annotation(self)
self.annotation.fromDom(contents[indx]) self.annotation.fromDom(contents[indx])
elif (component == 'attribute'):
elif component == 'attribute':
if contents[indx].hasattr('name'): if contents[indx].hasattr('name'):
content.append(AttributeDeclaration())
content.append(AttributeDeclaration(self))
elif contents[indx].hasattr('ref'): elif contents[indx].hasattr('ref'):
content.append(AttributeReference())
content.append(AttributeReference(self))
else: else:
raise SchemaError, 'Unknown attribute type' raise SchemaError, 'Unknown attribute type'
content[-1].fromDom(contents[indx]) content[-1].fromDom(contents[indx])
elif (component == 'attributeGroup'):
content.append(AttributeGroupReference())
elif component == 'attributeGroup':
content.append(AttributeGroupReference(self))
content[-1].fromDom(contents[indx]) 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]) content[-1].fromDom(contents[indx])
else: else:
raise SchemaError, 'Unknown component (%s)' %(contents[indx].getTagName()) raise SchemaError, 'Unknown component (%s)' %(contents[indx].getTagName())
@@ -1451,6 +1512,12 @@ class AttributeGroupReference(XMLSchemaComponent,\
XMLSchemaComponent.__init__(self, parent) XMLSchemaComponent.__init__(self, parent)
self.annotation = None 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): def fromDom(self, node):
self.setAttributes(node) self.setAttributes(node)
contents = self.getContents(node) contents = self.getContents(node)
@@ -1849,7 +1916,7 @@ class ElementWildCard(LocalElementDeclaration,\
# Model Groups # Model Groups
##################################################### #####################################################
class Sequence(XMLSchemaComponent,\ class Sequence(XMLSchemaComponent,\
ModelGroupMarker):
SequenceMarker):
"""<sequence> """<sequence>
parents: parents:
complexType, extension, restriction, group, choice, sequence complexType, extension, restriction, group, choice, sequence
@@ -1907,7 +1974,7 @@ class Sequence(XMLSchemaComponent,\




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




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




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


class List(XMLSchemaComponent):
class List(XMLSchemaComponent,
ListMarker):
"""<list> """<list>
parents: parents:
simpleType simpleType
@@ -2685,11 +2754,22 @@ class SimpleType(XMLSchemaComponent,\
self.annotation = None self.annotation = None
self.content = 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): def fromDom(self, node):
self.annotation = None
self.content = None
self.setAttributes(node) self.setAttributes(node)
contents = self.getContents(node) contents = self.getContents(node)
self.content = []

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


Loading…
Cancel
Save