Author: sagara Date: Sat Jul 7 04:08:20 2012 New Revision: 1358497 URL: http://svn.apache.org/viewvc?rev=1358497&view=rev Log: Axis2-5357 - Merged r1358494 and r1358495 to 1.6 branch. Note - I had to modify some newly added tests for 1.6 branch hence can't guarantee 1.6.x version will handle all variance of XSD restrictions.
Added: axis/axis2/java/core/branches/1_6/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java - copied, changed from r1358494, axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java Modified: axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java axis/axis2/java/core/branches/1_6/modules/adb-codegen/test-resources/testsuite/restrictions.xsd Modified: axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java?rev=1358497&r1=1358496&r2=1358497&view=diff ============================================================================== --- axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java (original) +++ axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/BeanWriterMetaInfoHolder.java Sat Jul 7 04:08:20 2012 @@ -253,8 +253,14 @@ public class BeanWriterMetaInfoHolder { */ public boolean isRestrictionBaseType(QName restrictionBaseType) { QName baseTypeQName = this.elementToSchemaQNameMap.get(restrictionBaseType); - return (this.restrictionBaseType != null) && (baseTypeQName != null) && - this.restrictionBaseType.equals(baseTypeQName); + if (restriction && simple && baseTypeQName != null && restrictionBaseType != null) { + return true; + } else if (this.restrictionBaseType != null && baseTypeQName != null + && this.restrictionBaseType.equals(baseTypeQName)) { + return true; + + } + return false; } /** @@ -933,4 +939,34 @@ public class BeanWriterMetaInfoHolder { return this.xmlNameJavaNameMap.get(xmlName); } + public QName getRestrictionBaseType() { + return restrictionBaseType; + } + + @Override + public String toString() { + return "BeanWriterMetaInfoHolder [anonymous=" + anonymous + ", choice=" + choice + + ", elementQNameToDefulatValueMap=" + elementQNameToDefulatValueMap + + ", elementToJavaClassMap=" + elementToJavaClassMap + ", elementToSchemaQNameMap=" + + elementToSchemaQNameMap + ", enumFacet=" + enumFacet + ", extension=" + extension + + ", extensionBaseType=" + extensionBaseType + ", extensionClassName=" + + extensionClassName + ", hasParticleType=" + hasParticleType + ", isList=" + + isList + ", isParticleClass=" + isParticleClass + ", isUnion=" + isUnion + + ", itemTypeClassName=" + itemTypeClassName + ", itemTypeQName=" + itemTypeQName + + ", lengthFacet=" + lengthFacet + ", maxExclusiveFacet=" + maxExclusiveFacet + + ", maxInclusiveFacet=" + maxInclusiveFacet + ", maxLengthFacet=" + maxLengthFacet + + ", memberTypes=" + memberTypes + ", memberTypesKeys=" + memberTypesKeys + + ", minExclusiveFacet=" + minExclusiveFacet + ", minInclusiveFacet=" + + minInclusiveFacet + ", minLengthFacet=" + minLengthFacet + ", nillableQNameList=" + + nillableQNameList + ", ordered=" + ordered + ", ownClassName=" + ownClassName + + ", ownQname=" + ownQname + ", parent=" + parent + ", patternFacet=" + + patternFacet + ", qNameMaxOccursCountMap=" + qNameMaxOccursCountMap + + ", qNameMinOccursCountMap=" + qNameMinOccursCountMap + ", qNameOrderMap=" + + qNameOrderMap + ", restriction=" + restriction + ", restrictionBaseType=" + + restrictionBaseType + ", restrictionClassName=" + restrictionClassName + + ", simple=" + simple + ", specialTypeFlagMap=" + specialTypeFlagMap + + ", totalDigitsFacet=" + totalDigitsFacet + ", xmlNameJavaNameMap=" + + xmlNameJavaNameMap + "]"; + } + } Modified: axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java?rev=1358497&r1=1358496&r2=1358497&view=diff ============================================================================== --- axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java (original) +++ axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/SchemaCompiler.java Sat Jul 7 04:08:20 2012 @@ -1410,8 +1410,27 @@ public class SchemaCompiler { } } else if (content instanceof XmlSchemaSimpleContent) { - throw new SchemaCompilationException( - SchemaCompilerMessages.getMessage("schema.unsupportedcontenterror", "Simple Content")); + + XmlSchemaSimpleContent simpleContent = (XmlSchemaSimpleContent) content; + if (simpleContent.getContent() instanceof XmlSchemaSimpleContentExtension) { + XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension) simpleContent + .getContent(); + // recursively call the copyMetaInfoHierarchy + // method + copyMetaInfoHierarchy(baseMetaInfoHolder, + extension.getBaseTypeName(), resolvedSchema); + + } else if (simpleContent.getContent() instanceof XmlSchemaSimpleContentRestriction) { + + XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) simpleContent + .getContent(); + // recursively call the copyMetaInfoHierarchy + // method + copyMetaInfoHierarchy(baseMetaInfoHolder, + restriction.getBaseTypeName(), resolvedSchema); + + } + } else { throw new SchemaCompilationException( SchemaCompilerMessages.getMessage("schema.unknowncontenterror")); @@ -1539,6 +1558,10 @@ public class SchemaCompiler { metaInfHolder, parentSchema); metaInfHolder.setSimple(true); + + if (!SchemaConstants.XSD_BOOLEAN.equals(restriction.getBaseTypeName())){ + processFacets(restriction.getFacets(), restriction.getBaseTypeName(), metaInfHolder, parentSchema); + } } } @@ -1653,12 +1676,12 @@ public class SchemaCompiler { * Process Facets. * * @param metaInfHolder + * @param facets */ - private void processFacets(XmlSchemaSimpleTypeRestriction restriction, + private void processFacets( XmlSchemaObjectCollection facets,QName restrictionName, BeanWriterMetaInfoHolder metaInfHolder, XmlSchema parentSchema) { - - XmlSchemaObjectCollection facets = restriction.getFacets(); + Iterator facetIterator = facets.getIterator(); while (facetIterator.hasNext()) { @@ -1681,7 +1704,7 @@ public class SchemaCompiler { else if (obj instanceof XmlSchemaEnumerationFacet) { XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet) obj; - if (restriction.getBaseTypeName().equals(SchemaConstants.XSD_QNAME)) { + if (restrictionName.equals(SchemaConstants.XSD_QNAME)) { // we have to process the qname here and shoud find the local part and namespace uri String value = enumeration.getValue().toString(); String prefix = value.substring(0, value.indexOf(":")); @@ -2535,7 +2558,7 @@ public class SchemaCompiler { processSimpleRestrictionBaseType(parentSimpleTypeQname, restriction.getBaseTypeName(), metaInfHolder, parentSchema); //process facets if (!SchemaConstants.XSD_BOOLEAN.equals(baseTypeName)){ - processFacets(restriction, metaInfHolder, parentSchema); + processFacets(restriction.getFacets(), restriction.getBaseTypeName(), metaInfHolder, parentSchema); } } else { //recurse Modified: axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl?rev=1358497&r1=1358496&r2=1358497&view=diff ============================================================================== --- axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl (original) +++ axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate-bean.xsl Sat Jul 7 04:08:20 2012 @@ -159,12 +159,12 @@ protected void validate<xsl:value-of select="$javaName"/>(<xsl:value-of select="$propertyType"/> param){ <xsl:if test="not(@unbound) and @array"> if ((param != null) && (param.length > <xsl:value-of select="@maxOccurs"/>)){ - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:if> <xsl:if test="$min!=0 and @array"> if ((param != null) && (param.length < <xsl:value-of select="$min"/>)){ - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:if> } @@ -331,12 +331,12 @@ protected void validate<xsl:value-of select="$javaName"/>(<xsl:value-of select="$propertyType"/> param){ <xsl:if test="not(@unbound)"> if ((param != null) && (param.length > <xsl:value-of select="@maxOccurs"/>)){ - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:if> <xsl:if test="$min!=0"> if ((param != null) && (param.length < <xsl:value-of select="$min"/>)){ - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:if> } @@ -456,7 +456,7 @@ this.<xsl:value-of select="$varName"/>=param; } else { - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:when> <xsl:when test="(@lenFacet)"> @@ -464,7 +464,7 @@ this.<xsl:value-of select="$varName"/>=param; } else { - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:when> <xsl:when test="(@maxLenFacet) or (@minLenFacet)"> @@ -473,7 +473,7 @@ this.<xsl:value-of select="$varName"/>=param; } else { - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:when> <xsl:when test="(@totalDigitsFacet)"> @@ -482,7 +482,7 @@ this.<xsl:value-of select="$varName"/>=param; } else { - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:when> <xsl:when test="@maxExFacet or @minExFacet or @maxInFacet or @minInFacet"> @@ -491,7 +491,7 @@ this.<xsl:value-of select="$varName"/>=param; } else { - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:if> <xsl:if test="@minExFacet"> @@ -499,7 +499,7 @@ this.<xsl:value-of select="$varName"/>=param; } else { - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:if> <xsl:if test="@maxInFacet"> @@ -507,7 +507,7 @@ this.<xsl:value-of select="$varName"/>=param; } else { - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:if> <xsl:if test="@minInFacet"> @@ -515,7 +515,7 @@ this.<xsl:value-of select="$varName"/>=param; } else { - throw new java.lang.RuntimeException(); + throw new java.lang.RuntimeException("Input values do not follow defined XSD restrictions"); } </xsl:if> </xsl:when> @@ -3177,4 +3177,4 @@ } <!-- end of main template --> </xsl:template> -</xsl:stylesheet> \ No newline at end of file +</xsl:stylesheet> Modified: axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?rev=1358497&r1=1358496&r2=1358497&view=diff ============================================================================== --- axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java (original) +++ axis/axis2/java/core/branches/1_6/modules/adb-codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java Sat Jul 7 04:08:20 2012 @@ -684,10 +684,26 @@ public class JavaBeanWriter implements B // we should add parent class details only if it is // an extension or simple restriction // should not in complex restrictions - if (metainf.getParent() != null && (!metainf.isRestriction() || (metainf.isRestriction() && metainf.isSimple()))) - { - populateInfo(metainf.getParent(), model, rootElt, propertyNames, - typeMap, groupTypeMap, true); + if (metainf.getParent() != null + && (!metainf.isRestriction() || (metainf.isRestriction() && metainf.isSimple()))) { + + BeanWriterMetaInfoHolder parent = metainf.getParent(); + + /** + * Before we recursively call populateInfo() with parent (base) + * BeanWriterMetaInfoHolder we need to apply restrictions on current + * BeanWriterMetaInfoHolder to parent BeanWriterMetaInfoHolder. + * Otherwise those restrictions not available on generated code. see + * Axis2- + * + * TODO - Here just copy restrictions to parent + * BeanWriterMetaInfoHolder object, but may be the correct way to do + * this is create a new BeanWriterMetaInfoHolder with merging + * current and parent BeanWriterMetaInfoHolders.Decide best approach + * ? + */ + mergeBeanWriterMetaInfoHolderForRestriction(metainf, parent); + populateInfo(parent, model, rootElt, propertyNames, typeMap, groupTypeMap, true); } addPropertyEntries(metainf, model, rootElt, propertyNames, typeMap, groupTypeMap, isInherited); @@ -1514,5 +1530,53 @@ public class JavaBeanWriter implements B } return xmlName; } + + private void mergeBeanWriterMetaInfoHolderForRestriction(BeanWriterMetaInfoHolder metainf, + BeanWriterMetaInfoHolder parent) { + parent.setRestriction(true); + if (metainf.getPatternFacet() != null) { + parent.setPatternFacet(metainf.getPatternFacet()); + } + if (metainf.getMaxExclusiveFacet() != null) { + parent.setMaxExclusiveFacet(metainf.getMaxExclusiveFacet()); + } + if (metainf.getMinExclusiveFacet() != null) { + parent.setMinExclusiveFacet(metainf.getMinExclusiveFacet()); + } + if (metainf.getMinInclusiveFacet() != null) { + parent.setMinInclusiveFacet(metainf.getMinInclusiveFacet()); + } + if (metainf.getMaxInclusiveFacet() != null) { + parent.setMaxInclusiveFacet(metainf.getMaxInclusiveFacet()); + } + if (metainf.getLengthFacet() != -1) { + parent.setLengthFacet(metainf.getLengthFacet()); + + } + if (metainf.getMaxLengthFacet() != -1) { + parent.setMaxLengthFacet(metainf.getMaxLengthFacet()); + + } + if (metainf.getMinLengthFacet() != -1) { + parent.setMinLengthFacet(metainf.getMinLengthFacet()); + + } + + if (metainf.getTotalDigitsFacet() != null) { + parent.setTotalDigitsFacet(metainf.getTotalDigitsFacet()); + + } + + if (metainf.getTotalDigitsFacet() != null) { + parent.setTotalDigitsFacet(metainf.getTotalDigitsFacet()); + + } + + if (metainf.getEnumFacet() != null && metainf.getEnumFacet().size() > 0) { + parent.getEnumFacet().addAll(metainf.getEnumFacet()); + + } + + } } \ No newline at end of file Modified: axis/axis2/java/core/branches/1_6/modules/adb-codegen/test-resources/testsuite/restrictions.xsd URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/adb-codegen/test-resources/testsuite/restrictions.xsd?rev=1358497&r1=1358496&r2=1358497&view=diff ============================================================================== --- axis/axis2/java/core/branches/1_6/modules/adb-codegen/test-resources/testsuite/restrictions.xsd (original) +++ axis/axis2/java/core/branches/1_6/modules/adb-codegen/test-resources/testsuite/restrictions.xsd Sat Jul 7 04:08:20 2012 @@ -213,4 +213,29 @@ <xsd:attribute name="responseMessage" type="xsd:string" use="optional"/> </xsd:attributeGroup> + <xsd:element name="LimitedString" type="tns:limitedString" /> + <xsd:complexType name="limitedString"> + <xsd:simpleContent> + <xsd:restriction base="tns:rating"> + <xsd:minLength value="2" /> + <xsd:maxLength value="4" /> + <xsd:pattern value="([a-d])*" /> + </xsd:restriction> + </xsd:simpleContent> + </xsd:complexType> + <xsd:complexType name="rating"> + <xsd:simpleContent> + <xsd:restriction base="tns:anyString"> + <xsd:minLength value="2" /> + <xsd:maxLength value="8" /> + <xsd:pattern value="([a-z])*" /> + </xsd:restriction> + </xsd:simpleContent> + </xsd:complexType> + <xsd:complexType name="anyString"> + <xsd:simpleContent> + <xsd:extension base="xs:string" /> + </xsd:simpleContent> + </xsd:complexType> + </xsd:schema> \ No newline at end of file Copied: axis/axis2/java/core/branches/1_6/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java (from r1358494, axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java) URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java?p2=axis/axis2/java/core/branches/1_6/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java&p1=axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java&r1=1358494&r2=1358497&rev=1358497&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java (original) +++ axis/axis2/java/core/branches/1_6/modules/adb-codegen/test/org/apache/axis2/schema/restriction/SchemaRestrictionTest.java Sat Jul 7 04:08:20 2012 @@ -56,20 +56,6 @@ public class SchemaRestrictionTest exten LimitedString.Factory.parse(omElement.getXMLStreamReader()); } - public void testLimitedStringParse2() throws Exception { - OMFactory factory = OMAbstractFactory.getOMFactory(); - OMElement element = factory.createOMElement(new QName( - "http://apache.org/axis2/schema/restriction", "LimitedString")); - element.setText("a"); - try { - LimitedStringE.Factory.parse(element.getXMLStreamReader()); - fail("This should throw RuntimeException"); - } catch (RuntimeException e) { - assertEquals(toString(e), ERROR_MSG, e.getMessage()); - - } - } - public void testLimitedStringParse3() throws Exception { OMFactory factory = OMAbstractFactory.getOMFactory(); OMElement element = factory.createOMElement(new QName( @@ -98,19 +84,6 @@ public class SchemaRestrictionTest exten } } - public void testLimitedStringParse5() throws Exception { - OMFactory factory = OMAbstractFactory.getOMFactory(); - OMElement element = factory.createOMElement(new QName( - "http://apache.org/axis2/schema/restriction", "LimitedString")); - element.setText(""); - try { - LimitedString.Factory.parse(element.getXMLStreamReader()); - fail("This should throw RuntimeException"); - } catch (RuntimeException e) { - assertEquals(toString(e), ERROR_MSG, e.getMessage()); - - } - } public void testLimitedStringParse6() throws Exception { OMFactory factory = OMAbstractFactory.getOMFactory(); @@ -134,19 +107,6 @@ public class SchemaRestrictionTest exten LimitedString.Factory.parse(omElement.getXMLStreamReader()); } - public void testRatingParse2() throws Exception { - OMFactory factory = OMAbstractFactory.getOMFactory(); - OMElement element = factory.createOMElement(new QName( - "http://apache.org/axis2/schema/restriction", "Rating")); - element.setText("a"); - try { - Rating.Factory.parse(element.getXMLStreamReader()); - fail("This should throw RuntimeException"); - } catch (RuntimeException e) { - assertEquals(toString(e), ERROR_MSG, e.getMessage()); - - } - } public void testRatingParse3() throws Exception { OMFactory factory = OMAbstractFactory.getOMFactory(); @@ -176,19 +136,7 @@ public class SchemaRestrictionTest exten } } - public void testRatingParse5() throws Exception { - OMFactory factory = OMAbstractFactory.getOMFactory(); - OMElement element = factory.createOMElement(new QName( - "http://apache.org/axis2/schema/restriction", "Rating")); - element.setText(""); - try { - Rating.Factory.parse(element.getXMLStreamReader()); - fail("This should throw RuntimeException"); - } catch (RuntimeException e) { - assertEquals(toString(e), ERROR_MSG, e.getMessage()); - } - } public void testRatingParse6() throws Exception { OMFactory factory = OMAbstractFactory.getOMFactory();