diff --git a/core/pom.xml b/core/pom.xml index e927eb99..acbd63c0 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -4,7 +4,7 @@ com.predic8 soa-model-core - 1.5.0 + 1.5.1 jar diff --git a/core/src/main/groovy/com/predic8/schema/ComplexContent.groovy b/core/src/main/groovy/com/predic8/schema/ComplexContent.groovy index bdbd2ec6..c6a0e270 100644 --- a/core/src/main/groovy/com/predic8/schema/ComplexContent.groovy +++ b/core/src/main/groovy/com/predic8/schema/ComplexContent.groovy @@ -26,6 +26,7 @@ class ComplexContent extends SchemaComponent { boolean mixed Derivation derivation + BaseRestriction restriction protected parseAttributes(token, params){ mixed = token.getAttributeValue( null , 'mixed') @@ -35,14 +36,44 @@ class ComplexContent extends SchemaComponent { switch (child ){ case 'annotation' : annotation = new Annotation(schema: schema) - annotation.parse(token, params) ; break + annotation.parse(token, params) ; + return; case 'extension' : - derivation = new Extension(schema: schema) ; break - case 'restriction' : - derivation = new Restriction(schema: schema); break + derivation = new Extension(schema: schema) ; + break; + case 'restriction' : + def base = getTypeQName(token.getAttributeValue( null , 'base')) + if(base) { + def type = base.localPart + if(base.namespaceURI == SCHEMA_NS){ + // Are we parsing the schema of XML schema? + // e.g. the file schema/XSD Schema/schemas.xsd + // as in the AnySimpleTypeTest ? + if (schema.targetNamespace == SCHEMA_NS) { + derivation = new Restriction(base : base, schema: schema) + derivation.schema = schema + break; + } else { + // It is a build in type from XML Schema + restriction = RestrictionUtil.getRestriction(type, [base: base]) + restriction.schema = schema + break; + } + } else { + derivation = new Restriction(base : base, schema: schema) // Restriction can be Derivation if there are children e.g. sequence + break; + } + } else { + derivation = new Restriction(schema: schema) // Restriction can be Derivation if there are children e.g. sequence + } + break; + default: throw new RuntimeException("Invalid child element '$child' in complexContent. Possible elements are 'annotation', 'extension' or 'restriction'.") } - derivation?.parse(token, params) + + // One of both get parsed + restriction?.parse(token, params) + derivation?.parse(token, params) } boolean hasExtension(){ diff --git a/core/src/main/groovy/com/predic8/schema/creator/SchemaCreator.groovy b/core/src/main/groovy/com/predic8/schema/creator/SchemaCreator.groovy index 8f09d990..1f0cd7ae 100755 --- a/core/src/main/groovy/com/predic8/schema/creator/SchemaCreator.groovy +++ b/core/src/main/groovy/com/predic8/schema/creator/SchemaCreator.groovy @@ -130,8 +130,11 @@ class SchemaCreator extends AbstractSchemaCreator { } void createComplexContent(ComplexContent complexContent, SchemaCreatorContext ctx){ - builder.'xsd:complexContent'() { + def attrs = [:] + if(complexContent.mixed) attrs['mixed'] = 'true' + builder.'xsd:complexContent'(attrs) { complexContent.derivation?.create(this, ctx) + complexContent.restriction?.create(this, ctx) } } diff --git a/core/src/main/groovy/com/predic8/schema/restriction/AnyTypeRestriction.groovy b/core/src/main/groovy/com/predic8/schema/restriction/AnyTypeRestriction.groovy new file mode 100644 index 00000000..fbc8a2b5 --- /dev/null +++ b/core/src/main/groovy/com/predic8/schema/restriction/AnyTypeRestriction.groovy @@ -0,0 +1,21 @@ +/* Copyright 2012 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.schema.restriction; + +import com.predic8.wstool.creator.* + +class AnyTypeRestriction extends BaseRestriction { + +} diff --git a/core/src/main/groovy/com/predic8/schema/restriction/RestrictionUtil.groovy b/core/src/main/groovy/com/predic8/schema/restriction/RestrictionUtil.groovy index 4b97309b..757c453e 100644 --- a/core/src/main/groovy/com/predic8/schema/restriction/RestrictionUtil.groovy +++ b/core/src/main/groovy/com/predic8/schema/restriction/RestrictionUtil.groovy @@ -20,6 +20,10 @@ class RestrictionUtil { static def getRestriction(type, ctx) { switch(type) { + case "anySimpleType" : + return new AnySimpleTypeRestriction(ctx) + case "anyType" : + return new AnyTypeRestriction(ctx) case "string" : return new StringRestriction(ctx) case "normalizedString" : @@ -133,8 +137,7 @@ class RestrictionUtil { case "NMTOKENS" : return new NMTOKENSRestriction(ctx) - case "anySimpleType" : - return new AnySimpleTypeRestriction(ctx) + case "derivationControl" : return new DerivationControlRestriction(ctx) diff --git a/core/src/test/groovy/com/predic8/schema/AttributeGroupTest.groovy b/core/src/test/groovy/com/predic8/schema/AttributeGroupTest.groovy index 53804003..d4327862 100644 --- a/core/src/test/groovy/com/predic8/schema/AttributeGroupTest.groovy +++ b/core/src/test/groovy/com/predic8/schema/AttributeGroupTest.groovy @@ -48,7 +48,6 @@ class AttributeGroupTest extends GroovyTestCase{ assertEquals(new QName(Consts.SCHEMA_NS, 'string'), schema.getAttributeGroup('AttrG1').getAttribute('Attr2').type) assertEquals('AttrG1', schema.getType('EmployeeType').attributeGroups[0].ref.localPart) assertEquals(new QName('http://predic8.com/human-resources/', 'AttrG2'), schema.getAttributeGroup('AttrG1').attributeGroups[0].ref) -// println strWriter } void testRequestTemplateCreater() { diff --git a/core/src/test/groovy/com/predic8/schema/ComplexContentTest.groovy b/core/src/test/groovy/com/predic8/schema/ComplexContentTest.groovy index b23ffa38..28e73f8d 100644 --- a/core/src/test/groovy/com/predic8/schema/ComplexContentTest.groovy +++ b/core/src/test/groovy/com/predic8/schema/ComplexContentTest.groovy @@ -53,7 +53,9 @@ class ComplexContentTest extends GroovyTestCase{ def strWriter = new StringWriter() def creator = new SchemaCreator(builder : new MarkupBuilder(strWriter)) schemaA.create(creator, new SchemaCreatorContext()) - def testSchema = new XmlSlurper().parseText(strWriter.toString()) + def schemaAsString = strWriter.toString() + def testSchema = new XmlSlurper().parseText(schemaAsString) + assertEquals('true', testSchema.complexType[2].complexContent.@mixed.toString()) assertEquals('firstName', testSchema.complexType[2].complexContent.restriction.sequence.element.@name.toString()) } diff --git a/core/src/test/groovy/com/predic8/wsdl/WSDLInlineSchemaTest.groovy b/core/src/test/groovy/com/predic8/wsdl/WSDLInlineSchemaTest.groovy new file mode 100644 index 00000000..82ad178f --- /dev/null +++ b/core/src/test/groovy/com/predic8/wsdl/WSDLInlineSchemaTest.groovy @@ -0,0 +1,29 @@ +package com.predic8.wsdl + +import groovy.xml.MarkupBuilder + +import com.predic8.wsdl.creator.WSDLCreator +import com.predic8.wsdl.creator.WSDLCreatorContext +import com.predic8.xml.util.ClasspathResolver +import com.predic8.schema.creator.* + +class WSDLInlineSchemaTest extends GroovyTestCase { + + Definitions wsdl + WSDLParserContext ctx = new WSDLParserContext(input: 'wsdl/inline-schema-in-wsdl/test.wsdl') + + protected void setUp() throws Exception { + WSDLParser parser = new WSDLParser(resourceResolver: new ClasspathResolver()) + wsdl = parser.parse(ctx) + } + + void testThatSchemaInsideWSDLCanBeRead() { + def strWriter = new StringWriter() + def creator = new SchemaCreator(builder : new MarkupBuilder(strWriter)) + wsdl.schemas[0].create(creator, new SchemaCreatorContext()) + def schemaAsString = strWriter.toString() + def testSchema = new XmlSlurper().parseText(schemaAsString) + assertEquals('xsd:anyType', testSchema.complexType[0].complexContent.restriction.@base.toString()) + } + +} diff --git a/core/src/test/resources/wsdl/inline-schema-in-wsdl/test.wsdl b/core/src/test/resources/wsdl/inline-schema-in-wsdl/test.wsdl new file mode 100644 index 00000000..946a2201 --- /dev/null +++ b/core/src/test/resources/wsdl/inline-schema-in-wsdl/test.wsdl @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + WSDL File for HelloService + + + + +