Skip to content

Commit

Permalink
Several bug fixes for RTC and other creators.
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavarzi committed Aug 9, 2013
1 parent c9d0e93 commit 48ea38d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 32 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.predic8</groupId>
<artifactId>soa-model-core</artifactId>
<version>1.4.0.7</version>
<version>1.4.0.8-SNAPSHOT</version>

<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/groovy/com/predic8/schema/Attribute.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Attribute extends Declaration {
}

String toString(){
"attribute[name= $name, ref=$ref]"
"attribute[name= $name, ref=$ref, type=$type]"
}

}
3 changes: 0 additions & 3 deletions core/src/main/groovy/com/predic8/schema/Derivation.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,5 @@ abstract class Derivation extends SchemaComponent{
attrs
}

String toString() {
"Extension{ name: $name, base: $basePN}"
}
}

6 changes: 6 additions & 0 deletions core/src/main/groovy/com/predic8/schema/Extension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,5 +29,9 @@ class Extension extends Derivation {
def create(creator, CreatorContext ctx){
creator.createExtension(this, ctx)
}

String toString() {
"Extension{ name: $name, base: $basePN}"
}
}

6 changes: 6 additions & 0 deletions core/src/main/groovy/com/predic8/schema/Restriction.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,5 +29,9 @@ class Restriction extends Derivation {
def create(creator, CreatorContext ctx){
creator.createComplexContentRestriction(this, ctx)
}

String toString() {
"Restriction{ name: $name, base: $basePN}"
}
}

21 changes: 16 additions & 5 deletions core/src/main/groovy/com/predic8/schema/SchemaValidator.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand All @@ -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.")
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/groovy/com/predic8/wsdl/Definitions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,25 @@ class RequestTemplateCreator extends AbstractSchemaCreator <RequestTemplateCreat
if(refType && (refType instanceof BuiltInSchemaType)){
def attrs = [:]
declNSifNeeded(getNSPrefix(element, ctx),element.namespaceUri,attrs,ctx)
if(element.type.localPart=='dateTime') new MarkupBuilderHelper(builder).yieldUnescaped('<!--dateTime-->')
if(element.type.localPart=='dateTime') yield('<!--dateTime-->')
builder."${getElementTagName(element, ctx)}"(TemplateUtil.getTemplateValue(element.type),attrs)
}
if(!element.type && !element.embeddedType) {
builder."${getElementTagName(element, ctx)}"()
}
}

// void createBuiltInSchemaType(BuiltInSchemaType type, RequestTemplateCreatorContext ctx){
// if(type.namespaceURI.equals(Consts.SCHEMA_NS)){
// def attrs = [:]
// declNSifNeeded('xsd',Consts.SCHEMA_NS,attrs,ctx)
// if(type.localPart=='dateTime') new MarkupBuilderHelper(builder).yieldUnescaped('<!--dateTime-->')
// 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))
Expand All @@ -108,11 +106,6 @@ class RequestTemplateCreator extends AbstractSchemaCreator <RequestTemplateCreat
def res = [:]
def attrs = obj.allAttributes
attrs.each{

/*TODO A method in class Attribute should resolve the attribute object
* from ref or it self. There should the object be checked and an error
* should be added to SchemaValidator if attribute object is null.
*/
def attr = it.ref ? obj.schema.getAttribute(it.ref) : it
if(attr.fixedValue) {
res[attr.name] = attr.fixedValue
Expand All @@ -123,8 +116,8 @@ class RequestTemplateCreator extends AbstractSchemaCreator <RequestTemplateCreat
res[attr.name] = TemplateUtil.getTemplateValue(attr.simpleType.restriction.base)
}
} else {
//TODO If attr is referenced from another namespace, the prefix should be created also and not only 'attr.name'.
res[attr.name] = TemplateUtil.getTemplateValue(attr.type)
declNSifNeeded(getNSPrefix(attr, ctx),attr.namespaceUri,res,ctx)
res["${getNSPrefix(attr, ctx)}:${attr.name}"] = TemplateUtil.getTemplateValue(attr.type)
}
}
res
Expand Down Expand Up @@ -214,16 +207,19 @@ class RequestTemplateCreator extends AbstractSchemaCreator <RequestTemplateCreat
}

void createAny(Any any, RequestTemplateCreatorContext ctx){
yield("\n<!-- This element can be extended by any element from ${any.namespace ?: 'any'} namespace -->")
/*TODO
* Change the yield calls to comment, like the followin:
* yield("<!-- This element can be extended by any element from ${any.namespace ?: 'any'} namespace -->")
*/
builder.mkp.comment "This element can be extended by any element from ${any.namespace ?: 'any'} namespace"
}

void createAnyAttribute(AnyAttribute anyAttribute, RequestTemplateCreatorContext ctx){
yield("\n<!-- This element can be extended by any attribute from ${anyAttribute.namespace ?: 'any'} namespace -->")
yield("<!-- This element can be extended by any attribute from ${anyAttribute.namespace ?: 'any'} namespace -->")
}

//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) {
Expand Down
2 changes: 1 addition & 1 deletion distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.predic8</groupId>
<artifactId>soa-model-distribution</artifactId>
<version>1.4.0.7</version>
<version>1.4.0.8-SNAPSHOT</version>

<dependencies>
<dependency>
Expand Down

0 comments on commit 48ea38d

Please sign in to comment.