ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1777889 - in /webservices/xmlschema/trunk/xmlschema-walker/src: main/java/org/apache/ws/commons/schema/walker/ test/java/org/apache/ws/commons/schema/walker/ test/resources/
Date Sun, 08 Jan 2017 17:01:56 GMT
Author: veithen
Date: Sun Jan  8 17:01:56 2017
New Revision: 1777889

URL: http://svn.apache.org/viewvc?rev=1777889&view=rev
Log:
XMLSCHEMA-42: Add support for xs:attribute without type attribute to xmlschema-walker. Patch
contributed by Tobias Crawley.

Modified:
    webservices/xmlschema/trunk/xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaScope.java
    webservices/xmlschema/trunk/xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaWalker.java
    webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/walker/TestSchemaWalker.java
    webservices/xmlschema/trunk/xmlschema-walker/src/test/resources/test_schema.xsd

Modified: webservices/xmlschema/trunk/xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaScope.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaScope.java?rev=1777889&r1=1777888&r2=1777889&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaScope.java
(original)
+++ webservices/xmlschema/trunk/xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaScope.java
Sun Jan  8 17:01:56 2017
@@ -572,8 +572,10 @@ final class XmlSchemaScope {
         XmlSchemaSimpleType schemaType = globalAttr.getSchemaType();
         if (schemaType == null) {
             final QName typeQName = globalAttr.getSchemaTypeName();
-            XmlSchema typeSchema = schemasByNamespace.get(typeQName.getNamespaceURI());
-            schemaType = (XmlSchemaSimpleType)typeSchema.getTypeByName(typeQName);
+            if (typeQName != null) {
+                XmlSchema typeSchema = schemasByNamespace.get(typeQName.getNamespaceURI());
+                schemaType = (XmlSchemaSimpleType) typeSchema.getTypeByName(typeQName);
+            }
         }
 
         /*

Modified: webservices/xmlschema/trunk/xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaWalker.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaWalker.java?rev=1777889&r1=1777888&r2=1777889&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaWalker.java
(original)
+++ webservices/xmlschema/trunk/xmlschema-walker/src/main/java/org/apache/ws/commons/schema/walker/XmlSchemaWalker.java
Sun Jan  8 17:01:56 2017
@@ -252,21 +252,23 @@ public final class XmlSchemaWalker {
                 if (attrs != null) {
                     for (XmlSchemaAttrInfo attr : attrs) {
                         XmlSchemaType attrType = attr.getAttribute().getSchemaType();
-                        XmlSchemaScope attrScope = null;
-                        if ((attrType.getQName() != null) && scopeCache.containsKey(attrType.getQName()))
{
-                            attrScope = scopeCache.get(attrType.getQName());
-                        } else {
-                            attrScope = new XmlSchemaScope(attr.getAttribute().getSchemaType(),
-                                                           schemasByNamespace, scopeCache,
-                                                           userRecognizedTypes);
+                        if (attrType != null) {
+                            XmlSchemaScope attrScope;
+                            if ((attrType.getQName() != null) && scopeCache.containsKey(attrType.getQName()))
{
+                                attrScope = scopeCache.get(attrType.getQName());
+                            } else {
+                                attrScope = new XmlSchemaScope(attrType,
+                                                               schemasByNamespace, scopeCache,
+                                                               userRecognizedTypes);
 
-                            if (attrType.getName() != null) {
-                                scopeCache.put(attrType.getQName(), attrScope);
+                                if (attrType.getName() != null) {
+                                    scopeCache.put(attrType.getQName(), attrScope);
+                                }
                             }
-                        }
 
-                        final XmlSchemaTypeInfo attrTypeInfo = attrScope.getTypeInfo();
-                        attr.setType(attrTypeInfo);
+                            final XmlSchemaTypeInfo attrTypeInfo = attrScope.getTypeInfo();
+                            attr.setType(attrTypeInfo);
+                        }
 
                         for (XmlSchemaVisitor visitor : visitors) {
                             visitor.onVisitAttribute(element, attr);

Modified: webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/walker/TestSchemaWalker.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/walker/TestSchemaWalker.java?rev=1777889&r1=1777888&r2=1777889&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/walker/TestSchemaWalker.java
(original)
+++ webservices/xmlschema/trunk/xmlschema-walker/src/test/java/org/apache/ws/commons/schema/walker/TestSchemaWalker.java
Sun Jan  8 17:01:56 2017
@@ -295,7 +295,9 @@ public class TestSchemaWalker {
             for (; index < attrs.size(); ++index) {
                 Attribute attr = attrs.get(index);
                 if (attr.name.equals(attribute.getName())) {
-                    if ((attr.typeName == null) && !attribute.getSchemaType().isAnonymous())
{
+                    if ((attr.typeName == null)
+                            && attribute.getSchemaType() != null
+                            && !attribute.getSchemaType().isAnonymous()) {
 
                         throw new IllegalStateException("Element \"" + element.getName()
                                                         + "\" has an attribute named \""
+ attr.name
@@ -303,7 +305,9 @@ public class TestSchemaWalker {
                                                         + "but actually is named \""
                                                         + attribute.getSchemaType().getName()
+ "\"");
 
-                    } else if ((attr.typeName != null) && attribute.getSchemaType().isAnonymous())
{
+                    } else if ((attr.typeName != null)
+                            && attribute.getSchemaType() != null
+                            && attribute.getSchemaType().isAnonymous()) {
 
                         throw new IllegalStateException("Element \"" + element.getName()
                                                         + "\" has an attribute named \""
+ attr.name
@@ -311,7 +315,8 @@ public class TestSchemaWalker {
                                                         + attr.typeName + "\"; but is anonymous
instead.");
 
                     } else if ((attr.typeName != null)
-                               && !attr.typeName.equals(attribute.getSchemaType().getName()))
{
+                            && attribute.getSchemaType() != null
+                            && !attr.typeName.equals(attribute.getSchemaType().getName()))
{
 
                         throw new IllegalStateException("Element \"" + element.getName()
                                                         + "\" has an attribute named \""
+ attr.name
@@ -336,13 +341,13 @@ public class TestSchemaWalker {
                                                         + "\" whose usage was expected to
be required,"
                                                         + " but is actually optional.");
 
-                    } else if (!attr.type.equals(attributeType.getType())) {
+                    } else if (attr.type != null && !attr.type.equals(attributeType.getType()))
{
                         throw new IllegalStateException("Element \"" + element.getName()
                                                         + "\" has an attribute named \""
+ attr.name
                                                         + "\" whose type was expected to
be " + attr.type
                                                         + " but actually was " + attributeType.getType());
 
-                    } else if (attr.type.equals(XmlSchemaTypeInfo.Type.ATOMIC)
+                    } else if (attr.type != null && attr.type.equals(XmlSchemaTypeInfo.Type.ATOMIC)
                                && !attr.baseType.equals(attributeType.getBaseType()))
{
 
                         throw new IllegalStateException("Element \"" + element.getName()
@@ -351,7 +356,7 @@ public class TestSchemaWalker {
                                                         + attr.baseType.name() + " but actually
was "
                                                         + attributeType.getBaseType());
 
-                    } else if (attr.type.equals(XmlSchemaTypeInfo.Type.LIST)
+                    } else if (attr.type != null && attr.type.equals(XmlSchemaTypeInfo.Type.LIST)
                                && !attr.baseType.equals(attributeType.getChildTypes().get(0).getBaseType()))
{
 
                         throw new IllegalStateException("Element \"" + element.getName()
@@ -683,6 +688,8 @@ public class TestSchemaWalker {
         attrGroupAttrs.add(new Attribute("unsignedByte", "unsignedByte", XmlSchemaTypeInfo.Type.ATOMIC,
                                          XmlSchemaBaseSimpleType.DECIMAL, true, unsignedByteFacets));
 
+        attrGroupAttrs.add(new Attribute("unknown", null, null, null, true));
+
         HashSet<XmlSchemaRestriction> stringFacets = new HashSet<XmlSchemaRestriction>();
         stringFacets.add(new XmlSchemaRestriction(new XmlSchemaWhiteSpaceFacet("preserve",
false)));
         attrGroupAttrs.add(new Attribute("string", "string", XmlSchemaTypeInfo.Type.ATOMIC,
@@ -878,6 +885,10 @@ public class TestSchemaWalker {
 
     private static void checkFacets(String nextName, XmlSchemaTypeInfo typeInfo,
                                     Set<XmlSchemaRestriction> nextFacets) {
+        if (typeInfo == null) {
+            return;
+        }
+
         final HashMap<XmlSchemaRestriction.Type, List<XmlSchemaRestriction>>
facets = typeInfo.getFacets();
 
         if ((facets == null) && (nextFacets != null)) {

Modified: webservices/xmlschema/trunk/xmlschema-walker/src/test/resources/test_schema.xsd
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-walker/src/test/resources/test_schema.xsd?rev=1777889&r1=1777888&r2=1777889&view=diff
==============================================================================
Binary files - no diff available.



Mime
View raw message