From 48ea38de4f0d4fd35b7ac9ce00b0d509e29296a8 Mon Sep 17 00:00:00 2001 From: keshavarzi Date: Fri, 9 Aug 2013 17:39:33 +0200 Subject: [PATCH] Several bug fixes for RTC and other creators. --- core/pom.xml | 2 +- .../com/predic8/schema/Attribute.groovy | 2 +- .../com/predic8/schema/Derivation.groovy | 3 -- .../com/predic8/schema/Extension.groovy | 6 +++ .../com/predic8/schema/Restriction.groovy | 6 +++ .../com/predic8/schema/SchemaValidator.groovy | 21 +++++++--- .../com/predic8/wsdl/Definitions.groovy | 1 + .../creator/RequestTemplateCreator.groovy | 38 +++++++++---------- distribution/pom.xml | 2 +- 9 files changed, 49 insertions(+), 32 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index cc5d5c3f..4e3a8160 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.predic8 soa-model-core - 1.4.0.7 + 1.4.0.8-SNAPSHOT diff --git a/core/src/main/groovy/com/predic8/schema/Attribute.groovy b/core/src/main/groovy/com/predic8/schema/Attribute.groovy index dd33c55c..9f9751fa 100644 --- a/core/src/main/groovy/com/predic8/schema/Attribute.groovy +++ b/core/src/main/groovy/com/predic8/schema/Attribute.groovy @@ -81,7 +81,7 @@ class Attribute extends Declaration { } String toString(){ - "attribute[name= $name, ref=$ref]" + "attribute[name= $name, ref=$ref, type=$type]" } } diff --git a/core/src/main/groovy/com/predic8/schema/Derivation.groovy b/core/src/main/groovy/com/predic8/schema/Derivation.groovy index 70b21012..a882558d 100644 --- a/core/src/main/groovy/com/predic8/schema/Derivation.groovy +++ b/core/src/main/groovy/com/predic8/schema/Derivation.groovy @@ -80,8 +80,5 @@ abstract class Derivation extends SchemaComponent{ attrs } - String toString() { - "Extension{ name: $name, base: $basePN}" - } } diff --git a/core/src/main/groovy/com/predic8/schema/Extension.groovy b/core/src/main/groovy/com/predic8/schema/Extension.groovy index 55b37eb4..121bd4bb 100644 --- a/core/src/main/groovy/com/predic8/schema/Extension.groovy +++ b/core/src/main/groovy/com/predic8/schema/Extension.groovy @@ -15,7 +15,9 @@ package com.predic8.schema import com.predic8.soamodel.CreatorContext + import javax.xml.namespace.QName as JQName + import static com.predic8.soamodel.Consts.SCHEMA_NS class Extension extends Derivation { @@ -27,5 +29,9 @@ class Extension extends Derivation { def create(creator, CreatorContext ctx){ creator.createExtension(this, ctx) } + + String toString() { + "Extension{ name: $name, base: $basePN}" + } } diff --git a/core/src/main/groovy/com/predic8/schema/Restriction.groovy b/core/src/main/groovy/com/predic8/schema/Restriction.groovy index dea711de..2805fd8f 100644 --- a/core/src/main/groovy/com/predic8/schema/Restriction.groovy +++ b/core/src/main/groovy/com/predic8/schema/Restriction.groovy @@ -15,7 +15,9 @@ package com.predic8.schema import com.predic8.soamodel.CreatorContext + import javax.xml.namespace.QName as JQName + import static com.predic8.soamodel.Consts.SCHEMA_NS class Restriction extends Derivation { @@ -27,5 +29,9 @@ class Restriction extends Derivation { def create(creator, CreatorContext ctx){ creator.createComplexContentRestriction(this, ctx) } + + String toString() { + "Restriction{ name: $name, base: $basePN}" + } } diff --git a/core/src/main/groovy/com/predic8/schema/SchemaValidator.groovy b/core/src/main/groovy/com/predic8/schema/SchemaValidator.groovy index 0e027a72..f32eaa3d 100644 --- a/core/src/main/groovy/com/predic8/schema/SchemaValidator.groovy +++ b/core/src/main/groovy/com/predic8/schema/SchemaValidator.groovy @@ -25,7 +25,6 @@ class SchemaValidator { elements.each { if(it.type) { try { - if(it.type.namespaceURI == Consts.SCHEMA_NS) return if(!schema.getType(it.type)) { ctx.errors << new ValidationError(invalidElement : it, message : "Element ${it.name} uses '${it.type}' as its type, which is not defined in this schema.") } @@ -44,26 +43,38 @@ class SchemaValidator { } } } - + void validateComplexTypes(complexTypes, schema, ctx) { complexTypes.each { ct -> if(ct.superTypes) { ct.superTypes.each { - if(it.namespaceURI == Consts.SCHEMA_NS) return if(!schema.getType(it)) { ctx.errors << new ValidationError(invalidElement : ct, message : "ComplexType ${ct.name} inherits from '${it}', which is not definded in this schema.") } } } + + //TODO Validating Attributes has to be refactored. Otherwise tests fail! +// if(ct.allAttributes){ +// ct.allAttributes.each {attr -> +// try { +// //An attribute should have either a ref or a type. +// if(ct.schema.getAttribute(attr.ref) || ct.schema.getType(attr.type)) { return } +// ctx.errors << new ValidationError(invalidElement : ct, message : "ComplexType ${ct.name} defines an attribute, which is not valid in this schema.") +// } catch (Exception e) { +// ctx.errors << new ValidationError(invalidElement : ct, message : "ComplexType ${ct.name} defines an attribute, which is not valid in this schema.") +// } +// } +// } + if(ct.model?.hasProperty("particles")) validateElements(ct.model.particles.grep(Element), ct.schema, ctx) } } - + void validateSimpleTypes(simpleTypes, schema, ctx) { simpleTypes.each { st -> if(st.superTypes) { st.superTypes.each { - if(it.namespaceURI == Consts.SCHEMA_NS) return if(!schema.getType(it)) { ctx.errors << new ValidationError(invalidElement : st, message : "SimpleType ${st.name} inherits from '${it}', which is not definded in this schema.") } diff --git a/core/src/main/groovy/com/predic8/wsdl/Definitions.groovy b/core/src/main/groovy/com/predic8/wsdl/Definitions.groovy index fcdc568e..8ef13320 100644 --- a/core/src/main/groovy/com/predic8/wsdl/Definitions.groovy +++ b/core/src/main/groovy/com/predic8/wsdl/Definitions.groovy @@ -154,6 +154,7 @@ class Definitions extends WSDLElement{ } TypeDefinition getSchemaType(GQName qname) { + //BuiltInSchemaTypes should be returned here, because Definitions maybe contains no schema! if(qname?.namespaceURI == Consts.SCHEMA_NS) return new BuiltInSchemaType(qname: qname) schemas.find{ it.getType(qname) }?.getType(qname) } diff --git a/core/src/main/groovy/com/predic8/wstool/creator/RequestTemplateCreator.groovy b/core/src/main/groovy/com/predic8/wstool/creator/RequestTemplateCreator.groovy index 10abbd5d..9fcbba25 100644 --- a/core/src/main/groovy/com/predic8/wstool/creator/RequestTemplateCreator.groovy +++ b/core/src/main/groovy/com/predic8/wstool/creator/RequestTemplateCreator.groovy @@ -74,7 +74,7 @@ class RequestTemplateCreator extends AbstractSchemaCreator ') + if(element.type.localPart=='dateTime') yield('') builder."${getElementTagName(element, ctx)}"(TemplateUtil.getTemplateValue(element.type),attrs) } if(!element.type && !element.embeddedType) { @@ -82,19 +82,17 @@ class RequestTemplateCreator extends AbstractSchemaCreator ') -// builder."${getElementTagName(element, ctx)}"(TemplateUtil.getTemplateValue(type),attrs) -// } -// } - void createComplexType(ComplexType complexType, RequestTemplateCreatorContext ctx){ log.debug "ComplexType ${complexType?.name}" def schema = complexType.schema ctx.path = "${ctx.path}${ctx.element.name}/" + + if(complexType.model instanceof ComplexContent && complexType.model.hasRestriction()){ + complexType.model?.create(this, ctx) + complexType.anyAttribute?.create(this, ctx) + return + } + def attrs = [:] declNSifNeeded(getNSPrefix(ctx.element, ctx),ctx.element.namespaceUri,attrs,ctx) attrs.putAll(createAttributes(complexType, ctx)) @@ -108,11 +106,6 @@ class RequestTemplateCreator extends AbstractSchemaCreator ") + /*TODO + * Change the yield calls to comment, like the followin: + * yield("") + */ + builder.mkp.comment "This element can be extended by any element from ${any.namespace ?: 'any'} namespace" } void createAnyAttribute(AnyAttribute anyAttribute, RequestTemplateCreatorContext ctx){ - yield("\n") + yield("") } - //TODO createComplexContentRestriction has to be implemented. void createComplexContentRestriction(Restriction restriction, RequestTemplateCreatorContext ctx){ - //throw new RuntimeException("createComplexContentRestriction not implemented yet in ${this.class}") + if(restriction.base) restriction.schema.getType(restriction.base).create(this, ctx) } private yield(s) { diff --git a/distribution/pom.xml b/distribution/pom.xml index 1a67a3c3..f0814608 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.predic8 soa-model-distribution - 1.4.0.7 + 1.4.0.8-SNAPSHOT