Skip to content

Commit

Permalink
ComplexContent.groovy:
Browse files Browse the repository at this point in the history
Implemented support for complexContent/restriction
Fixed: membrane/api-gateway#180

SchemaCreator:
Added support for complexContent/@mixed

Added support for anyType restriction
  • Loading branch information
predic8 committed Mar 31, 2015
1 parent e597a5d commit 6cbb57b
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.predic8</groupId>
<artifactId>soa-model-core</artifactId>
<version>1.5.0</version>
<version>1.5.1</version>
<packaging>jar</packaging>


Expand Down
41 changes: 36 additions & 5 deletions core/src/main/groovy/com/predic8/schema/ComplexContent.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ComplexContent extends SchemaComponent {

boolean mixed
Derivation derivation
BaseRestriction restriction

protected parseAttributes(token, params){
mixed = token.getAttributeValue( null , 'mixed')
Expand All @@ -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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ class SchemaCreator extends AbstractSchemaCreator <SchemaCreatorContext>{
}

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)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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" :
Expand Down Expand Up @@ -133,8 +137,7 @@ class RestrictionUtil {
case "NMTOKENS" :
return new NMTOKENSRestriction(ctx)

case "anySimpleType" :
return new AnySimpleTypeRestriction(ctx)


case "derivationControl" :
return new DerivationControlRestriction(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
29 changes: 29 additions & 0 deletions core/src/test/groovy/com/predic8/wsdl/WSDLInlineSchemaTest.groovy
Original file line number Diff line number Diff line change
@@ -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())
}

}
72 changes: 72 additions & 0 deletions core/src/test/resources/wsdl/inline-schema-in-wsdl/test.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<definitions name="HelloService"
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<types>

<schema targetNamespace="http://www.example.com/IPO"
attributeFormDefault="unqualified"
elementFormDefault="unqualified"
xmlns="http://www.w3.org/2001/XMLSchema">

<simpleType name="SKU2">
<restriction base="string"/>
</simpleType>

<complexType name="SKU">
<complexContent>
<restriction base="anyType"/>
</complexContent>
</complexType>

</schema>

</types>

<message name="SayHelloRequest">
<part name="firstName" type="SKU"/>
</message>

<message name="SayHelloResponse">
<part name="greeting" type="string"/>
</message>

<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>

<binding name="Hello_Binding" type="tns:Hello_PortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">
<soap:operation soapAction="sayHello"/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</input>

<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:helloservice"
use="encoded"/>
</output>
</operation>
</binding>

<service name="Hello_Service">
<documentation>WSDL File for HelloService</documentation>
<port binding="tns:Hello_Binding" name="Hello_Port">
<soap:address
location="http://www.examples.com/SayHello/" />
</port>
</service>
</definitions>

0 comments on commit 6cbb57b

Please sign in to comment.