Author: kiwiwings
Date: Thu Sep 24 23:11:07 2020
New Revision: 1881992

URL: http://svn.apache.org/viewvc?rev=1881992&view=rev
Log:
spotbugs fixes

Modified:
    
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/RussianDollStrategy.java
    
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/util/Type.java
    
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderImpl.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cursor.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Locale.java
    xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Xobj.java
    
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/BaseSchemaResourceManager.java
    
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/JavaBase64Holder.java
    
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/JavaHexBinaryHolder.java

Modified: 
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/RussianDollStrategy.java
URL: 
http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/RussianDollStrategy.java?rev=1881992&r1=1881991&r2=1881992&view=diff
==============================================================================
--- 
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/RussianDollStrategy.java
 (original)
+++ 
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/RussianDollStrategy.java
 Thu Sep 24 23:11:07 2020
@@ -15,48 +15,45 @@
 package org.apache.xmlbeans.impl.inst2xsd;
 
 import org.apache.xmlbeans.*;
-import org.apache.xmlbeans.impl.common.PrefixResolver;
 import org.apache.xmlbeans.impl.common.ValidationContext;
 import org.apache.xmlbeans.impl.common.XmlWhitespace;
 import org.apache.xmlbeans.impl.inst2xsd.util.Attribute;
 import org.apache.xmlbeans.impl.inst2xsd.util.Element;
-import org.apache.xmlbeans.impl.inst2xsd.util.TypeSystemHolder;
 import org.apache.xmlbeans.impl.inst2xsd.util.Type;
+import org.apache.xmlbeans.impl.inst2xsd.util.TypeSystemHolder;
 import org.apache.xmlbeans.impl.util.XsTypeConverter;
 import org.apache.xmlbeans.impl.values.*;
 
 import javax.xml.namespace.QName;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Cezar Andrei ( cezar.andrei at bea.com )
  * Date: Jul 26, 2004
  */
 public class RussianDollStrategy
-    implements XsdGenStrategy
-{
-    static final String _xsi         = 
"http://www.w3.org/2001/XMLSchema-instance";;
-
-    static final QName _xsiNil          = new QName( _xsi, "nil", "xsi" );
-    static final QName _xsiType         = new QName( _xsi, "type", "xsi" );
-
-    public void processDoc(XmlObject[] instances, Inst2XsdOptions options, 
TypeSystemHolder typeSystemHolder)
-    {
-        for (int i = 0; i < instances.length; i++)
-        {
-            XmlObject instance = instances[i];
+    implements XsdGenStrategy {
+    static final String _xsi = "http://www.w3.org/2001/XMLSchema-instance";;
+
+    static final QName _xsiNil = new QName(_xsi, "nil", "xsi");
+
+    public void processDoc(XmlObject[] instances, Inst2XsdOptions options, 
TypeSystemHolder typeSystemHolder) {
+        for (XmlObject instance : instances) {
             XmlCursor xc = instance.newCursor();
             // xc on start doc
 
             StringBuilder comment = new StringBuilder();
 
-            while( !xc.isStart() )
-            {
+            while (!xc.isStart()) {
                 xc.toNextToken();
-                if( xc.isComment() )
+                if (xc.isComment()) {
                     comment.append(xc.getTextValue());
-                else if (xc.isEnddoc())
+                } else if (xc.isEnddoc()) {
                     return;
+                }
             }
             // xc now on the root element
 
@@ -67,18 +64,14 @@ public class RussianDollStrategy
         }
     }
 
-    protected Element addGlobalElement(Element withElem, TypeSystemHolder 
typeSystemHolder, Inst2XsdOptions options)
-    {
+    protected Element addGlobalElement(Element withElem, TypeSystemHolder 
typeSystemHolder, Inst2XsdOptions options) {
         assert withElem.isGlobal();
         Element intoElem = 
typeSystemHolder.getGlobalElement(withElem.getName());
 
-        if (intoElem==null)
-        {
+        if (intoElem == null) {
             typeSystemHolder.addGlobalElement(withElem);
             return withElem;
-        }
-        else
-        {
+        } else {
             combineTypes(intoElem.getType(), withElem.getType(), options);
             combineElementComments(intoElem, withElem);
             return intoElem;
@@ -86,8 +79,7 @@ public class RussianDollStrategy
     }
 
     protected Element processElement(XmlCursor xc, String comment,
-        Inst2XsdOptions options, TypeSystemHolder typeSystemHolder)
-    {
+                                     Inst2XsdOptions options, TypeSystemHolder 
typeSystemHolder) {
         assert xc.isStart();
         Element element = new Element();
         element.setName(xc.getName());
@@ -98,22 +90,22 @@ public class RussianDollStrategy
 
         StringBuilder textBuff = new StringBuilder();
         StringBuilder commentBuff = new StringBuilder();
-        List children = new ArrayList();
-        List attributes = new ArrayList();
+        List<Element> children = new ArrayList<>();
+        List<Attribute> attributes = new ArrayList<>();
 
-        loop: do
-        {
+        loop:
+        do {
             XmlCursor.TokenType tt = xc.toNextToken();
-            switch (tt.intValue())
-            {
+            switch (tt.intValue()) {
                 case XmlCursor.TokenType.INT_ATTR:
                     // todo check for xsi:type
                     // ignore xsi:... attributes other than xsi:nil
                     QName attName = xc.getName();
-                    if 
(!_xsiNil.getNamespaceURI().equals(attName.getNamespaceURI()))
+                    if 
(!_xsiNil.getNamespaceURI().equals(attName.getNamespaceURI())) {
                         attributes.add(processAttribute(xc, options, 
element.getName().getNamespaceURI(), typeSystemHolder));
-                    else if (_xsiNil.equals(attName))
+                    } else if (_xsiNil.equals(attName)) {
                         element.setNillable(true);
+                    }
 
                     break;
 
@@ -155,38 +147,31 @@ public class RussianDollStrategy
                     throw new IllegalStateException("Unknown TokenType.");
             }
         }
-        while( true );
+        while (true);
 
-        String collapsedText =  XmlWhitespace.collapse(textBuff.toString(), 
XmlWhitespace.WS_COLLAPSE);
+        String collapsedText = XmlWhitespace.collapse(textBuff.toString(), 
XmlWhitespace.WS_COLLAPSE);
 
         String commnetStr = (comment == null ?
-            ( commentBuff.length() == 0 ? null : commentBuff.toString() ) :
-            ( commentBuff.length() == 0 ? comment : commentBuff.insert(0, 
comment).toString()) );
+            (commentBuff.length() == 0 ? null : commentBuff.toString()) :
+            (commentBuff.length() == 0 ? comment : commentBuff.insert(0, 
comment).toString()));
         element.setComment(commnetStr);
 
-        if (children.size()>0)
-        {
+        if (children.size() > 0) {
             // complex content
-            if (collapsedText.length()>0)
-            {
+            if (collapsedText.length() > 0) {
                 elemType.setContentType(Type.COMPLEX_TYPE_MIXED_CONTENT);
-            }
-            else
-            {
+            } else {
                 elemType.setContentType(Type.COMPLEX_TYPE_COMPLEX_CONTENT);
             }
             processElementsInComplexType(elemType, children, 
element.getName().getNamespaceURI(), typeSystemHolder, options);
             processAttributesInComplexType(elemType, attributes);
-        }
-        else
-        {
+        } else {
             // simple content
             // hack workaround for being able to call 
xc.getNamespaceForPrefix()
             XmlCursor xcForNamespaces = xc.newCursor();
             xcForNamespaces.toParent();
 
-            if (attributes.size()>0)
-            {
+            if (attributes.size() > 0) {
                 elemType.setContentType(Type.COMPLEX_TYPE_SIMPLE_CONTENT);
 
                 Type extendedType = Type.createNamedType(
@@ -194,9 +179,7 @@ public class RussianDollStrategy
                 elemType.setExtensionType(extendedType);
 
                 processAttributesInComplexType(elemType, attributes);
-            }
-            else
-            {
+            } else {
                 elemType.setContentType(Type.SIMPLE_TYPE_SIMPLE_CONTENT);
                 elemType.setName(processSimpleContentType(textBuff.toString(), 
options, xcForNamespaces));
 
@@ -208,23 +191,18 @@ public class RussianDollStrategy
             xcForNamespaces.dispose(); // end hack
         }
 
-        checkIfReferenceToGlobalTypeIsNeeded( element, typeSystemHolder, 
options);
+        checkIfReferenceToGlobalTypeIsNeeded(element, typeSystemHolder, 
options);
 
         return element;
     }
 
-    protected void processElementsInComplexType(Type elemType, List children, 
String parentNamespace,
-        TypeSystemHolder typeSystemHolder, Inst2XsdOptions options)
-    {
-        Map elemNamesToElements = new HashMap();
+    protected void processElementsInComplexType(Type elemType, List<Element> 
children, String parentNamespace,
+                                                TypeSystemHolder 
typeSystemHolder, Inst2XsdOptions options) {
+        Map<QName, Element> elemNamesToElements = new HashMap<>();
         Element currentElem = null;
 
-        for (Iterator iterator = children.iterator(); iterator.hasNext();)
-        {
-            Element child = (Element) iterator.next();
-
-            if (currentElem==null)
-            {   // first element in this type
+        for (Element child : children) {
+            if (currentElem == null) {   // first element in this type
                 checkIfElementReferenceIsNeeded(child, parentNamespace, 
typeSystemHolder, options);
                 elemType.addElement(child);
                 elemNamesToElements.put(child.getName(), child);
@@ -232,25 +210,19 @@ public class RussianDollStrategy
                 continue;
             }
 
-            if (currentElem.getName()==child.getName())
-            {   // same contiguos element
+            if (currentElem.getName() == child.getName()) {   // same 
contiguos element
                 combineTypes(currentElem.getType(), child.getType(), options); 
// unify types
                 combineElementComments(currentElem, child);
                 // minOcc=0 maxOcc=unbounded
                 currentElem.setMinOccurs(0);
                 currentElem.setMaxOccurs(Element.UNBOUNDED);
-            }
-            else
-            {
-                Element sameElem = 
(Element)elemNamesToElements.get(child.getName());
-                if (sameElem==null)
-                {   // new element name
+            } else {
+                Element sameElem = elemNamesToElements.get(child.getName());
+                if (sameElem == null) {   // new element name
                     checkIfElementReferenceIsNeeded(child, parentNamespace, 
typeSystemHolder, options);
                     elemType.addElement(child);
                     elemNamesToElements.put(child.getName(), child);
-                }
-                else
-                {   //same non contiguos
+                } else {   //same non contiguos
                     combineTypes(currentElem.getType(), child.getType(), 
options);
                     combineElementComments(currentElem, child);
                     
elemType.setTopParticleForComplexOrMixedContent(Type.PARTICLE_CHOICE_UNBOUNDED);
@@ -261,17 +233,14 @@ public class RussianDollStrategy
     }
 
     protected void checkIfElementReferenceIsNeeded(Element child, String 
parentNamespace,
-        TypeSystemHolder typeSystemHolder, Inst2XsdOptions options)
-    {
-        if (!child.getName().getNamespaceURI().equals(parentNamespace))
-        {
+                                                   TypeSystemHolder 
typeSystemHolder, Inst2XsdOptions options) {
+        if (!child.getName().getNamespaceURI().equals(parentNamespace)) {
             Element referencedElem = new Element();
             referencedElem.setGlobal(true);
             referencedElem.setName(child.getName());
             referencedElem.setType(child.getType());
 
-            if (child.isNillable())
-            {
+            if (child.isNillable()) {
                 referencedElem.setNillable(true);
                 child.setNillable(false);
             }
@@ -283,24 +252,19 @@ public class RussianDollStrategy
     }
 
     protected void checkIfReferenceToGlobalTypeIsNeeded(Element elem, 
TypeSystemHolder typeSystemHolder,
-        Inst2XsdOptions options)
-    {
+                                                        Inst2XsdOptions 
options) {
         // RussianDollDesign doesn't define global types
     }
 
-    protected void processAttributesInComplexType(Type elemType, List 
attributes)
-    {
+    protected void processAttributesInComplexType(Type elemType, 
List<Attribute> attributes) {
         assert elemType.isComplexType();
-        for (Iterator iterator = attributes.iterator(); iterator.hasNext();)
-        {
-            Attribute att = (Attribute) iterator.next();
+        for (Attribute att : attributes) {
             elemType.addAttribute(att);
         }
     }
 
     protected Attribute processAttribute(XmlCursor xc, Inst2XsdOptions 
options, String parentNamespace,
-                                              TypeSystemHolder 
typeSystemHolder)
-    {
+                                         TypeSystemHolder typeSystemHolder) {
         assert xc.isAttr() : "xc not on attribute";
         Attribute attribute = new Attribute();
         QName attName = xc.getName();
@@ -322,11 +286,9 @@ public class RussianDollStrategy
         return attribute;
     }
 
-    protected void checkIfAttributeReferenceIsNeeded(Attribute attribute, 
String parentNamespace, TypeSystemHolder typeSystemHolder)
-    {
+    protected void checkIfAttributeReferenceIsNeeded(Attribute attribute, 
String parentNamespace, TypeSystemHolder typeSystemHolder) {
         if (!attribute.getName().getNamespaceURI().equals("") &&
-            !attribute.getName().getNamespaceURI().equals(parentNamespace))
-        {
+            !attribute.getName().getNamespaceURI().equals(parentNamespace)) {
             // make attribute be a reference to a top level attribute in a 
different targetNamespace
             Attribute referencedAtt = new Attribute();
             referencedAtt.setGlobal(true);
@@ -339,33 +301,28 @@ public class RussianDollStrategy
         }
     }
 
-    protected class SCTValidationContext
-        implements ValidationContext
-    {
+    protected static class SCTValidationContext
+        implements ValidationContext {
         protected boolean valid = true;
 
-        public boolean isValid()
-        {
+        public boolean isValid() {
             return valid;
         }
 
-        public void resetToValid()
-        {
+        public void resetToValid() {
             valid = true;
         }
 
-        public void invalid(String message)
-        {
+        public void invalid(String message) {
             valid = false;
         }
 
-        public void invalid(String code, Object[] args)
-        {
+        public void invalid(String code, Object[] args) {
             valid = false;
         }
     }
 
-    private SCTValidationContext _validationContext = new 
SCTValidationContext();
+    private final SCTValidationContext _validationContext = new 
SCTValidationContext();
 
 
     // List of precedence for smart simple primitive type determination
@@ -376,59 +333,54 @@ public class RussianDollStrategy
     // anyUri ? - triggered only for http:// or www. constructs,
     // list types ?
     // string
-    protected QName processSimpleContentType(String lexicalValue, 
Inst2XsdOptions options, final XmlCursor xc)
-    {
+    protected QName processSimpleContentType(String lexicalValue, 
Inst2XsdOptions options, final XmlCursor xc) {
         // check options and return xsd:string or if smart is enabled, look 
for a better type
-        if 
(options.getSimpleContentTypes()==Inst2XsdOptions.SIMPLE_CONTENT_TYPES_STRING)
+        if (options.getSimpleContentTypes() == 
Inst2XsdOptions.SIMPLE_CONTENT_TYPES_STRING) {
             return XmlString.type.getName();
+        }
 
-        if 
(options.getSimpleContentTypes()!=Inst2XsdOptions.SIMPLE_CONTENT_TYPES_SMART)
+        if (options.getSimpleContentTypes() != 
Inst2XsdOptions.SIMPLE_CONTENT_TYPES_SMART) {
             throw new IllegalArgumentException("Unknown value for 
Inst2XsdOptions.getSimpleContentTypes() :" + options.getSimpleContentTypes());
+        }
 
         // Inst2XsdOptions.SIMPLE_CONTENT_TYPES_SMART case
 
 
-        try
-        {
+        try {
             XsTypeConverter.lexByte(lexicalValue);
             return XmlByte.type.getName();
+        } catch (Exception ignored) {
         }
-        catch (Exception e) {}
 
-        try
-        {
+        try {
             XsTypeConverter.lexShort(lexicalValue);
             return XmlShort.type.getName();
+        } catch (Exception ignored) {
         }
-        catch (Exception e) {}
 
-        try
-        {
+        try {
             XsTypeConverter.lexInt(lexicalValue);
             return XmlInt.type.getName();
+        } catch (Exception ignored) {
         }
-        catch (Exception e) {}
 
-        try
-        {
+        try {
             XsTypeConverter.lexLong(lexicalValue);
             return XmlLong.type.getName();
+        } catch (Exception ignored) {
         }
-        catch (Exception e) {}
 
-        try
-        {
+        try {
             XsTypeConverter.lexInteger(lexicalValue);
             return XmlInteger.type.getName();
+        } catch (Exception ignored) {
         }
-        catch (Exception e) {}
 
-        try
-        {
+        try {
             XsTypeConverter.lexFloat(lexicalValue);
             return XmlFloat.type.getName();
+        } catch (Exception ignored) {
         }
-        catch (Exception e) {}
 
 //        // this not needed because it's lexical space is covered by float
 //        try
@@ -446,47 +398,45 @@ public class RussianDollStrategy
 //        catch (Exception e) {}
 
         XmlDateImpl.validateLexical(lexicalValue, XmlDate.type, 
_validationContext);
-        if (_validationContext.isValid())
+        if (_validationContext.isValid()) {
             return XmlDate.type.getName();
+        }
         _validationContext.resetToValid();
 
         XmlDateTimeImpl.validateLexical(lexicalValue, XmlDateTime.type, 
_validationContext);
-        if (_validationContext.isValid())
+        if (_validationContext.isValid()) {
             return XmlDateTime.type.getName();
+        }
         _validationContext.resetToValid();
 
         XmlTimeImpl.validateLexical(lexicalValue, XmlTime.type, 
_validationContext);
-        if (_validationContext.isValid())
+        if (_validationContext.isValid()) {
             return XmlTime.type.getName();
+        }
         _validationContext.resetToValid();
 
         XmlDurationImpl.validateLexical(lexicalValue, XmlDuration.type, 
_validationContext);
-        if (_validationContext.isValid())
+        if (_validationContext.isValid()) {
             return XmlDuration.type.getName();
+        }
         _validationContext.resetToValid();
 
         // check for uri
-        if (lexicalValue.startsWith("http://";) || 
lexicalValue.startsWith("www."))
-        {
+        if (lexicalValue.startsWith("http://";) || 
lexicalValue.startsWith("www.")) {
             XmlAnyUriImpl.validateLexical(lexicalValue, _validationContext);
-            if (_validationContext.isValid())
+            if (_validationContext.isValid()) {
                 return XmlAnyURI.type.getName();
+            }
             _validationContext.resetToValid();
         }
 
         // check for QName
         int idx = lexicalValue.indexOf(':');
-        if (idx>=0 && idx==lexicalValue.lastIndexOf(':') && 
idx+1<lexicalValue.length())
-        {
-            PrefixResolver prefixResolver = new PrefixResolver()
-            {
-                public String getNamespaceForPrefix(String prefix)
-                {  return xc.namespaceForPrefix(prefix); }
-            };
-
-            QName qname = XmlQNameImpl.validateLexical(lexicalValue, 
_validationContext, prefixResolver);
-            if (_validationContext.isValid())
+        if (idx >= 0 && idx == lexicalValue.lastIndexOf(':') && idx + 1 < 
lexicalValue.length()) {
+            XmlQNameImpl.validateLexical(lexicalValue, _validationContext, 
xc::namespaceForPrefix);
+            if (_validationContext.isValid()) {
                 return XmlQName.type.getName();
+            }
             _validationContext.resetToValid();
         }
 
@@ -496,27 +446,26 @@ public class RussianDollStrategy
     }
 
 
-    protected void combineTypes(Type into, Type with, Inst2XsdOptions options)
-    {
-        if (into==with)
+    protected void combineTypes(Type into, Type with, Inst2XsdOptions options) 
{
+        if (into == with) {
             return;
+        }
 
-        if (into.isGlobal() && with.isGlobal() && 
into.getName().equals(with.getName()))
+        if (into.isGlobal() && with.isGlobal() && 
into.getName().equals(with.getName())) {
             return;
+        }
 
 
-        if (into.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT &&
-            with.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT)
-        {
+        if (into.getContentType() == Type.SIMPLE_TYPE_SIMPLE_CONTENT &&
+            with.getContentType() == Type.SIMPLE_TYPE_SIMPLE_CONTENT) {
             combineSimpleTypes(into, with, options);
             return;
         }
 
-        if ((into.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
-            into.getContentType()==Type.COMPLEX_TYPE_SIMPLE_CONTENT) &&
-            (with.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
-            with.getContentType()==Type.COMPLEX_TYPE_SIMPLE_CONTENT) )
-        {
+        if ((into.getContentType() == Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
+             into.getContentType() == Type.COMPLEX_TYPE_SIMPLE_CONTENT) &&
+            (with.getContentType() == Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
+             with.getContentType() == Type.COMPLEX_TYPE_SIMPLE_CONTENT)) {
             // take the extension name if it's a complex type
             QName intoTypeName = into.isComplexType() ? 
into.getExtensionType().getName() : into.getName();
             QName withTypeName = with.isComplexType() ? 
with.getExtensionType().getName() : with.getName();
@@ -525,118 +474,121 @@ public class RussianDollStrategy
             into.setContentType(Type.COMPLEX_TYPE_SIMPLE_CONTENT);
 
             QName moreGeneralTypeName = 
combineToMoreGeneralSimpleType(intoTypeName, withTypeName);
-            if (into.isComplexType())
-            {
+            if (into.isComplexType()) {
                 Type extendedType = Type.createNamedType(moreGeneralTypeName, 
Type.SIMPLE_TYPE_SIMPLE_CONTENT);
                 into.setExtensionType(extendedType);
-            }
-            else
+            } else {
                 into.setName(moreGeneralTypeName);
+            }
 
             combineAttributesOfTypes(into, with);
             return;
         }
 
-        if (into.getContentType()==Type.COMPLEX_TYPE_COMPLEX_CONTENT &&
-            with.getContentType()==Type.COMPLEX_TYPE_COMPLEX_CONTENT)
-        {
+        if (into.getContentType() == Type.COMPLEX_TYPE_COMPLEX_CONTENT &&
+            with.getContentType() == Type.COMPLEX_TYPE_COMPLEX_CONTENT) {
             combineAttributesOfTypes(into, with);
-            combineElementsOfTypes(into, with, false, options);
+            combineElementsOfTypes(into, with, options);
             return;
         }
 
-        if (into.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
-            into.getContentType()==Type.COMPLEX_TYPE_SIMPLE_CONTENT ||
-            with.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
-            with.getContentType()==Type.COMPLEX_TYPE_SIMPLE_CONTENT)
-        {
+        if (into.getContentType() == Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
+            into.getContentType() == Type.COMPLEX_TYPE_SIMPLE_CONTENT ||
+            with.getContentType() == Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
+            with.getContentType() == Type.COMPLEX_TYPE_SIMPLE_CONTENT) {
             into.setContentType(Type.COMPLEX_TYPE_MIXED_CONTENT);
             combineAttributesOfTypes(into, with);
-            combineElementsOfTypes(into, with, true, options);
+            combineElementsOfTypes(into, with, options);
             return;
         }
 
-        if ((into.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
-            into.getContentType()==Type.COMPLEX_TYPE_SIMPLE_CONTENT ||
-            into.getContentType()==Type.COMPLEX_TYPE_COMPLEX_CONTENT ||
-            into.getContentType()==Type.COMPLEX_TYPE_MIXED_CONTENT) &&
-            (with.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
-            with.getContentType()==Type.COMPLEX_TYPE_SIMPLE_CONTENT ||
-            with.getContentType()==Type.COMPLEX_TYPE_COMPLEX_CONTENT ||
-            with.getContentType()==Type.COMPLEX_TYPE_MIXED_CONTENT) )
-        {
+        if ((into.getContentType() == Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
+             into.getContentType() == Type.COMPLEX_TYPE_SIMPLE_CONTENT ||
+             into.getContentType() == Type.COMPLEX_TYPE_COMPLEX_CONTENT ||
+             into.getContentType() == Type.COMPLEX_TYPE_MIXED_CONTENT) &&
+            (with.getContentType() == Type.SIMPLE_TYPE_SIMPLE_CONTENT ||
+             with.getContentType() == Type.COMPLEX_TYPE_SIMPLE_CONTENT ||
+             with.getContentType() == Type.COMPLEX_TYPE_COMPLEX_CONTENT ||
+             with.getContentType() == Type.COMPLEX_TYPE_MIXED_CONTENT)) {
             into.setContentType(Type.COMPLEX_TYPE_MIXED_CONTENT);
             combineAttributesOfTypes(into, with);
-            combineElementsOfTypes(into, with, false, options);
+            combineElementsOfTypes(into, with, options);
             return;
         }
 
         throw new IllegalArgumentException("Unknown content type.");
     }
 
-    protected void combineSimpleTypes(Type into, Type with, Inst2XsdOptions 
options)
-    {
-        assert (into.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT &&
-            with.getContentType()==Type.SIMPLE_TYPE_SIMPLE_CONTENT) : "Invalid 
arguments";
+    protected void combineSimpleTypes(Type into, Type with, Inst2XsdOptions 
options) {
+        assert (into.getContentType() == Type.SIMPLE_TYPE_SIMPLE_CONTENT &&
+                with.getContentType() == Type.SIMPLE_TYPE_SIMPLE_CONTENT) : 
"Invalid arguments";
 
         //simple type simple content
         into.setName(combineToMoreGeneralSimpleType(into.getName(), 
with.getName()));
 
         // take care of enumeration values
-        if (options.isUseEnumerations())
-        {
+        if (options.isUseEnumerations()) {
             into.addAllEnumerationsFrom(with);
 
-            if 
(into.getEnumerationValues().size()>options.getUseEnumerations())
-            {
+            if (into.getEnumerationValues().size() > 
options.getUseEnumerations()) {
                 into.closeEnumeration();
             }
         }
     }
 
-    protected QName combineToMoreGeneralSimpleType(QName t1, QName t2)
-    {
-        if (t1.equals(t2))
+    protected QName combineToMoreGeneralSimpleType(QName t1, QName t2) {
+        if (t1.equals(t2)) {
             return t1;
+        }
 
-        if (t2.equals(XmlShort.type.getName()) && 
t1.equals(XmlByte.type.getName()))
+        if (t2.equals(XmlShort.type.getName()) && 
t1.equals(XmlByte.type.getName())) {
             return t2;
-        if (t1.equals(XmlShort.type.getName()) && 
t2.equals(XmlByte.type.getName()))
+        }
+        if (t1.equals(XmlShort.type.getName()) && 
t2.equals(XmlByte.type.getName())) {
             return t1;
+        }
 
         if (t2.equals(XmlInt.type.getName()) &&
-            (t1.equals(XmlShort.type.getName()) || 
t1.equals(XmlByte.type.getName())) )
+            (t1.equals(XmlShort.type.getName()) || 
t1.equals(XmlByte.type.getName()))) {
             return t2;
+        }
         if (t1.equals(XmlInt.type.getName()) &&
-            (t2.equals(XmlShort.type.getName()) || 
t2.equals(XmlByte.type.getName())) )
+            (t2.equals(XmlShort.type.getName()) || 
t2.equals(XmlByte.type.getName()))) {
             return t1;
+        }
 
         if (t2.equals(XmlLong.type.getName()) &&
-            (t1.equals(XmlInt.type.getName()) || 
t1.equals(XmlShort.type.getName()) || t1.equals(XmlByte.type.getName())) )
+            (t1.equals(XmlInt.type.getName()) || 
t1.equals(XmlShort.type.getName()) || t1.equals(XmlByte.type.getName()))) {
             return t2;
+        }
         if (t1.equals(XmlLong.type.getName()) &&
-            (t2.equals(XmlInt.type.getName()) || 
t2.equals(XmlShort.type.getName()) || t2.equals(XmlByte.type.getName())) )
+            (t2.equals(XmlInt.type.getName()) || 
t2.equals(XmlShort.type.getName()) || t2.equals(XmlByte.type.getName()))) {
             return t1;
+        }
 
         if (t2.equals(XmlInteger.type.getName()) &&
             (t1.equals(XmlLong.type.getName()) || 
t1.equals(XmlInt.type.getName()) ||
-            t1.equals(XmlShort.type.getName()) || 
t1.equals(XmlByte.type.getName())) )
+             t1.equals(XmlShort.type.getName()) || 
t1.equals(XmlByte.type.getName()))) {
             return t2;
+        }
         if (t1.equals(XmlInteger.type.getName()) &&
             (t2.equals(XmlLong.type.getName()) || 
t2.equals(XmlInt.type.getName()) ||
-            t2.equals(XmlShort.type.getName()) || 
t2.equals(XmlByte.type.getName())) )
+             t2.equals(XmlShort.type.getName()) || 
t2.equals(XmlByte.type.getName()))) {
             return t1;
+        }
 
         if (t2.equals(XmlFloat.type.getName()) &&
             (t1.equals(XmlInteger.type.getName()) ||
-            t1.equals(XmlLong.type.getName()) || 
t1.equals(XmlInt.type.getName()) ||
-            t1.equals(XmlShort.type.getName()) || 
t1.equals(XmlByte.type.getName())) )
+             t1.equals(XmlLong.type.getName()) || 
t1.equals(XmlInt.type.getName()) ||
+             t1.equals(XmlShort.type.getName()) || 
t1.equals(XmlByte.type.getName()))) {
             return t2;
+        }
         if (t1.equals(XmlFloat.type.getName()) &&
             (t2.equals(XmlInteger.type.getName()) ||
-            t2.equals(XmlLong.type.getName()) || 
t2.equals(XmlInt.type.getName()) ||
-            t2.equals(XmlShort.type.getName()) || 
t2.equals(XmlByte.type.getName())) )
+             t2.equals(XmlLong.type.getName()) || 
t2.equals(XmlInt.type.getName()) ||
+             t2.equals(XmlShort.type.getName()) || 
t2.equals(XmlByte.type.getName()))) {
             return t1;
+        }
 
         //double, decimal will never get here since they don't get generated
 
@@ -644,18 +596,14 @@ public class RussianDollStrategy
         return XmlString.type.getName();
     }
 
-    protected void combineAttributesOfTypes(Type into, Type from)
-    {
+    protected void combineAttributesOfTypes(Type into, Type from) {
         // loop through attributes: add fromAtt if they don't exist, combine 
them if they exist
         outterLoop:
-        for (int i = 0; i < from.getAttributes().size(); i++)
-        {
-            Attribute fromAtt = (Attribute)from.getAttributes().get(i);
-            for (int j = 0; j < into.getAttributes().size(); j++)
-            {
-                Attribute intoAtt = (Attribute)into.getAttributes().get(j);
-                if (intoAtt.getName().equals(fromAtt.getName()))
-                {
+        for (int i = 0; i < from.getAttributes().size(); i++) {
+            Attribute fromAtt = from.getAttributes().get(i);
+            for (int j = 0; j < into.getAttributes().size(); j++) {
+                Attribute intoAtt = into.getAttributes().get(j);
+                if (intoAtt.getName().equals(fromAtt.getName())) {
                     intoAtt.getType().setName(
                         
combineToMoreGeneralSimpleType(intoAtt.getType().getName(), 
fromAtt.getType().getName()));
                     continue outterLoop;
@@ -666,15 +614,11 @@ public class RussianDollStrategy
         }
 
         //optional attributes: if there are atts in into that are not in from, 
make them optional
-        outterLoop:
-        for (int i = 0; i < into.getAttributes().size(); i++)
-        {
-            Attribute intoAtt = (Attribute)into.getAttributes().get(i);
-            for (int j = 0; j < from.getAttributes().size(); j++)
-            {
-                Attribute fromAtt = (Attribute)from.getAttributes().get(j);
-                if (fromAtt.getName().equals(intoAtt.getName()))
-                {
+        for (int i = 0; i < into.getAttributes().size(); i++) {
+            Attribute intoAtt = into.getAttributes().get(i);
+            for (int j = 0; j < from.getAttributes().size(); j++) {
+                Attribute fromAtt = from.getAttributes().get(j);
+                if (fromAtt.getName().equals(intoAtt.getName())) {
                     continue;
                 }
             }
@@ -683,38 +627,34 @@ public class RussianDollStrategy
         }
     }
 
-    protected void combineElementsOfTypes(Type into, Type from, boolean 
makeElementsOptional, Inst2XsdOptions options)
-    {
+    protected void combineElementsOfTypes(Type into, Type from, 
Inst2XsdOptions options) {
         boolean needsUnboundedChoice = false;
 
-        if 
(into.getTopParticleForComplexOrMixedContent()!=Type.PARTICLE_SEQUENCE ||
-            
from.getTopParticleForComplexOrMixedContent()!=Type.PARTICLE_SEQUENCE)
+        if (into.getTopParticleForComplexOrMixedContent() != 
Type.PARTICLE_SEQUENCE ||
+            from.getTopParticleForComplexOrMixedContent() != 
Type.PARTICLE_SEQUENCE) {
             needsUnboundedChoice = true;
+        }
 
-        List res = new ArrayList();
+        List<Element> res = new ArrayList<>();
 
         int fromStartingIndex = 0;
         int fromMatchedIndex = -1;
         int intoMatchedIndex = -1;
 
         // for each element in into
-        for (int i = 0; !needsUnboundedChoice && i < 
into.getElements().size(); i++)
-        {
+        for (int i = 0; !needsUnboundedChoice && i < 
into.getElements().size(); i++) {
             // try to find one with same name in from
-            Element intoElement = (Element) into.getElements().get(i);
-            for (int j = fromStartingIndex; j < from.getElements().size(); j++)
-            {
-                Element fromElement = (Element) from.getElements().get(j);
-                if (intoElement.getName().equals(fromElement.getName()))
-                {
+            Element intoElement = into.getElements().get(i);
+            for (int j = fromStartingIndex; j < from.getElements().size(); 
j++) {
+                Element fromElement = from.getElements().get(j);
+                if (intoElement.getName().equals(fromElement.getName())) {
                     fromMatchedIndex = j;
                     break;
                 }
             }
 
             // if not found, it's safe to add this one to result 'res' (as 
optional) and continue
-            if ( fromMatchedIndex < fromStartingIndex )
-            {
+            if (fromMatchedIndex < fromStartingIndex) {
                 res.add(intoElement);
                 intoElement.setMinOccurs(0);
                 continue;
@@ -723,79 +663,69 @@ public class RussianDollStrategy
             // else try out all from elemens between fromStartingIndex to 
fromMatchedIndex
             // to see if they match one of the into elements
             intoMatchingLoop:
-            for (int j2 = fromStartingIndex; j2 < fromMatchedIndex; j2++)
-            {
-                Element fromCandidate = (Element) from.getElements().get(j2);
-
-                for (int i2 = i+1; i2 < into.getElements().size(); i2++)
-                {
-                    Element intoCandidate = (Element) 
into.getElements().get(i2);
-                    if 
(fromCandidate.getName().equals(intoCandidate.getName()))
-                    {
+            for (int j2 = fromStartingIndex; j2 < fromMatchedIndex; j2++) {
+                Element fromCandidate = from.getElements().get(j2);
+
+                for (int i2 = i + 1; i2 < into.getElements().size(); i2++) {
+                    Element intoCandidate = into.getElements().get(i2);
+                    if 
(fromCandidate.getName().equals(intoCandidate.getName())) {
                         intoMatchedIndex = i2;
                         break intoMatchingLoop;
                     }
                 }
             }
 
-            if (intoMatchedIndex<i)
-            {
+            if (intoMatchedIndex < i) {
                 // if none matched they are safe to be added to res as optional
-                for (int j3 = fromStartingIndex; j3 < fromMatchedIndex; j3++)
-                {
-                    Element fromCandidate = (Element) 
from.getElements().get(j3);
+                for (int j3 = fromStartingIndex; j3 < fromMatchedIndex; j3++) {
+                    Element fromCandidate = from.getElements().get(j3);
                     res.add(fromCandidate);
                     fromCandidate.setMinOccurs(0);
                 }
                 // also since into[i] == from[fromMatchedIndex] add it only 
once
                 res.add(intoElement);
-                Element fromMatchedElement = 
(Element)from.getElements().get(fromMatchedIndex);
+                Element fromMatchedElement = 
from.getElements().get(fromMatchedIndex);
 
-                if (fromMatchedElement.getMinOccurs()<=0)
+                if (fromMatchedElement.getMinOccurs() <= 0) {
                     intoElement.setMinOccurs(0);
-                if (fromMatchedElement.getMaxOccurs()==Element.UNBOUNDED)
+                }
+                if (fromMatchedElement.getMaxOccurs() == Element.UNBOUNDED) {
                     intoElement.setMaxOccurs(Element.UNBOUNDED);
+                }
 
                 combineTypes(intoElement.getType(), 
fromMatchedElement.getType(), options);
                 combineElementComments(intoElement, fromMatchedElement);
 
                 fromStartingIndex = fromMatchedIndex + 1;
-                continue;
-            }
-            else
-            {
+            } else {
                 // if matched it means into type will transform into a choice 
unbounded type
                 needsUnboundedChoice = true;
             }
         }
 
-        for (int j = fromStartingIndex; j < from.getElements().size(); j++)
-        {
-            Element remainingFromElement = (Element) from.getElements().get(j);
+        for (int j = fromStartingIndex; j < from.getElements().size(); j++) {
+            Element remainingFromElement = from.getElements().get(j);
             res.add(remainingFromElement);
             remainingFromElement.setMinOccurs(0);
         }
 
         // if choice was detected
-        if (needsUnboundedChoice)
-        {
+        if (needsUnboundedChoice) {
             
into.setTopParticleForComplexOrMixedContent(Type.PARTICLE_CHOICE_UNBOUNDED);
 
             outterLoop:
-            for (int j = 0; j < from.getElements().size(); j++)
-            {
-                Element fromElem = (Element) from.getElements().get(j);
-                for (int i = 0; i < into.getElements().size(); i++)
-                {
-                    Element intoElem = (Element)into.getElements().get(i);
+            for (int j = 0; j < from.getElements().size(); j++) {
+                Element fromElem = from.getElements().get(j);
+                for (int i = 0; i < into.getElements().size(); i++) {
+                    Element intoElem = into.getElements().get(i);
                     intoElem.setMinOccurs(1);
                     intoElem.setMaxOccurs(1);
 
-                    if (intoElem==fromElem)
+                    if (intoElem == fromElem) {
                         continue outterLoop;
+                    }
 
-                    if (intoElem.getName().equals(fromElem.getName()))
-                    {
+                    if (intoElem.getName().equals(fromElem.getName())) {
                         combineTypes(intoElem.getType(), fromElem.getType(), 
options);
                         combineElementComments(intoElem, fromElem);
 
@@ -808,24 +738,19 @@ public class RussianDollStrategy
                 fromElem.setMinOccurs(1);
                 fromElem.setMaxOccurs(1);
             }
-            return;
-        }
-        else
-        {
+        } else {
             // into remains sequence but will contain the new list of elements 
res
             into.setElements(res);
-            return;
         }
     }
 
-    protected void combineElementComments(Element into, Element with)
-    {
-        if (with.getComment()!=null && with.getComment().length()>0)
-        {
-            if (into.getComment()==null)
+    protected void combineElementComments(Element into, Element with) {
+        if (with.getComment() != null && with.getComment().length() > 0) {
+            if (into.getComment() == null) {
                 into.setComment(with.getComment());
-            else
+            } else {
                 into.setComment(into.getComment() + with.getComment());
+            }
         }
     }
 }

Modified: 
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/util/Type.java
URL: 
http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/util/Type.java?rev=1881992&r1=1881991&r2=1881992&view=diff
==============================================================================
--- 
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/util/Type.java 
(original)
+++ 
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/util/Type.java 
Thu Sep 24 23:11:07 2020
@@ -14,310 +14,261 @@
  */
 package org.apache.xmlbeans.impl.inst2xsd.util;
 
-import org.apache.xmlbeans.XmlQName;
 import org.apache.xmlbeans.XmlCursor;
-import org.apache.xmlbeans.impl.common.PrefixResolver;
+import org.apache.xmlbeans.XmlQName;
 import org.apache.xmlbeans.impl.values.XmlQNameImpl;
 
 import javax.xml.namespace.QName;
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author Cezar Andrei (cezar.andrei at bea.com) Date: Jul 16, 2004
  */
-public class Type
-{
+public class Type {
     private QName _name;
 
     private int _kind = SIMPLE_TYPE_SIMPLE_CONTENT;
     // _kind value space
-    public static final int SIMPLE_TYPE_SIMPLE_CONTENT   = 1; // ie no atts, 
no elems, just text
-    public static final int COMPLEX_TYPE_SIMPLE_CONTENT  = 2; // ie atts*, no 
elems, text*   - simple type extension
+    public static final int SIMPLE_TYPE_SIMPLE_CONTENT = 1; // ie no atts, no 
elems, just text
+    public static final int COMPLEX_TYPE_SIMPLE_CONTENT = 2; // ie atts*, no 
elems, text*   - simple type extension
     public static final int COMPLEX_TYPE_COMPLEX_CONTENT = 3; // ie atts*, 
elems, no text
-    public static final int COMPLEX_TYPE_MIXED_CONTENT   = 4; // ie atts*, 
elems, text
-    public static final int COMPLEX_TYPE_EMPTY_CONTENT   = 5; // no elems, no 
text, just atts
+    public static final int COMPLEX_TYPE_MIXED_CONTENT = 4; // ie atts*, 
elems, text
+    public static final int COMPLEX_TYPE_EMPTY_CONTENT = 5; // no elems, no 
text, just atts
 
     private int _topParticleForComplexOrMixedContent = PARTICLE_SEQUENCE;
     // _topParticleForComplexOrMixedContent
-    public static final int PARTICLE_SEQUENCE         = 1;
+    public static final int PARTICLE_SEQUENCE = 1;
     public static final int PARTICLE_CHOICE_UNBOUNDED = 2;
 
-    private List _elements;  // size>0 COMPLEX
-    private List _attributes; // size>0 COMPLEX
+    private List<Element> _elements;  // size>0 COMPLEX
+    private List<Attribute> _attributes; // size>0 COMPLEX
 
     private Type _extensionType;
     private boolean _isGlobal = false;
 
-    private List _enumerationValues;
+    private List<String> _enumerationValues;
     private boolean _acceptsEnumerationValue = true;
-    private List _enumerationQNames;                    // This is a special 
case where the lexical representation
-                                                        // is not enough for a 
value, the QNames need to be remembered
-                                                        // in case the 
_extensionType is QName
-
-    protected Type()
-    {}
-
-    public static Type createNamedType(QName name, int contentType)
-    {
-        assert name!=null;
+    private List<QName> _enumerationQNames;                    // This is a 
special case where the lexical representation
+    // is not enough for a value, the QNames need to be remembered
+    // in case the _extensionType is QName
+
+    protected Type() {
+    }
+
+    public static Type createNamedType(QName name, int contentType) {
+        assert name != null;
         Type type = new Type();
         type.setName(name);
         type.setContentType(contentType);
         return type;
     }
 
-    public static Type createUnnamedType(int contentType)
-    {
-        assert contentType==SIMPLE_TYPE_SIMPLE_CONTENT ||
-            contentType==COMPLEX_TYPE_SIMPLE_CONTENT ||
-            contentType==COMPLEX_TYPE_COMPLEX_CONTENT ||
-            contentType==COMPLEX_TYPE_MIXED_CONTENT ||
-            contentType==COMPLEX_TYPE_EMPTY_CONTENT: "Unknown contentType: " + 
contentType;
+    public static Type createUnnamedType(int contentType) {
+        assert contentType == SIMPLE_TYPE_SIMPLE_CONTENT ||
+               contentType == COMPLEX_TYPE_SIMPLE_CONTENT ||
+               contentType == COMPLEX_TYPE_COMPLEX_CONTENT ||
+               contentType == COMPLEX_TYPE_MIXED_CONTENT ||
+               contentType == COMPLEX_TYPE_EMPTY_CONTENT : "Unknown 
contentType: " + contentType;
         Type type = new Type();
         type.setContentType(contentType);
         return type;
     }
 
 
-    public QName getName()
-    {
+    public QName getName() {
         return _name;
     }
 
-    public void setName(QName name)
-    {
+    public void setName(QName name) {
         this._name = name;
     }
 
     /**
-     * @return
-     *   SIMPLE_TYPE_SIMPLE_CONTENT   // ie no atts, no elems, just text
-     *   COMPLEX_TYPE_SIMPLE_CONTENT  // ie atts*, no elems, text*   - simple 
type extension
-     *   COMPLEX_TYPE_COMPLEX_CONTENT // ie atts*, elems, no text
-     *   COMPLEX_TYPE_MIXED_CONTENT   // ie atts*, elems, text
-     *   COMPLEX_TYPE_EMPTY_CONTENT   // no elems, no text, just atts
+     * @return SIMPLE_TYPE_SIMPLE_CONTENT   // ie no atts, no elems, just text
+     * COMPLEX_TYPE_SIMPLE_CONTENT  // ie atts*, no elems, text*   - simple 
type extension
+     * COMPLEX_TYPE_COMPLEX_CONTENT // ie atts*, elems, no text
+     * COMPLEX_TYPE_MIXED_CONTENT   // ie atts*, elems, text
+     * COMPLEX_TYPE_EMPTY_CONTENT   // no elems, no text, just atts
      */
-    public int getContentType()
-    {
+    public int getContentType() {
         return _kind;
     }
 
     /**
      * @param kind 4 kinds:
-     *   SIMPLE_TYPE_SIMPLE_CONTENT   // ie no atts, no elems, just text
-     *   COMPLEX_TYPE_SIMPLE_CONTENT  // ie atts*, no elems, text*   - simple 
type extension
-     *   COMPLEX_TYPE_COMPLEX_CONTENT // ie atts*, elems, no text
-     *   COMPLEX_TYPE_MIXED_CONTENT   // ie atts*, elems, text
-     *   COMPLEX_TYPE_EMPTY_CONTENT   // no elems, no text, just atts
+     *             SIMPLE_TYPE_SIMPLE_CONTENT   // ie no atts, no elems, just 
text
+     *             COMPLEX_TYPE_SIMPLE_CONTENT  // ie atts*, no elems, text*   
- simple type extension
+     *             COMPLEX_TYPE_COMPLEX_CONTENT // ie atts*, elems, no text
+     *             COMPLEX_TYPE_MIXED_CONTENT   // ie atts*, elems, text
+     *             COMPLEX_TYPE_EMPTY_CONTENT   // no elems, no text, just atts
      */
-    public void setContentType(int kind)
-    {
+    public void setContentType(int kind) {
         this._kind = kind;
     }
 
-    public List getElements()
-    {
+    public List<Element> getElements() {
         ensureElements();
         return _elements;
     }
 
-    public void addElement(Element element)
-    {
+    public void addElement(Element element) {
         ensureElements();
         _elements.add(element);
     }
 
-    public void setElements(List elements)
-    {
+    public void setElements(List<Element> elements) {
         ensureElements();
         _elements.clear();
         _elements.addAll(elements);
     }
 
-    private void ensureElements()
-    {
-        if (_elements==null)
-            _elements = new ArrayList();
+    private void ensureElements() {
+        if (_elements == null) {
+            _elements = new ArrayList<>();
+        }
     }
 
-    public List getAttributes()
-    {
+    public List<Attribute> getAttributes() {
         ensureAttributes();
         return _attributes;
     }
 
-    public void addAttribute(Attribute attribute)
-    {
+    public void addAttribute(Attribute attribute) {
         ensureAttributes();
         _attributes.add(attribute);
     }
 
-    public Attribute getAttribute(QName name)
-    {
-        for (int i = 0; i < _attributes.size(); i++)
-        {
-            Attribute attribute = (Attribute) _attributes.get(i);
-            if (attribute.getName().equals(name))
-                return attribute;
+    public Attribute getAttribute(QName name) {
+        for (Attribute value : _attributes) {
+            if (value.getName().equals(name)) {
+                return value;
+            }
         }
         return null;
     }
 
-    private void ensureAttributes()
-    {
-        if (_attributes==null)
-            _attributes = new ArrayList();
-    }
-
-    public boolean isComplexType()
-    {
-        return (_kind==COMPLEX_TYPE_COMPLEX_CONTENT ||
-            _kind==COMPLEX_TYPE_MIXED_CONTENT||
-            _kind==COMPLEX_TYPE_SIMPLE_CONTENT);
-    }
-
-    public boolean hasSimpleContent()
-    {
-        return (_kind==SIMPLE_TYPE_SIMPLE_CONTENT ||
-            _kind==COMPLEX_TYPE_SIMPLE_CONTENT);
+    private void ensureAttributes() {
+        if (_attributes == null) {
+            _attributes = new ArrayList<>();
+        }
+    }
+
+    public boolean isComplexType() {
+        return (_kind == COMPLEX_TYPE_COMPLEX_CONTENT ||
+                _kind == COMPLEX_TYPE_MIXED_CONTENT ||
+                _kind == COMPLEX_TYPE_SIMPLE_CONTENT);
+    }
+
+    public boolean hasSimpleContent() {
+        return (_kind == SIMPLE_TYPE_SIMPLE_CONTENT ||
+                _kind == COMPLEX_TYPE_SIMPLE_CONTENT);
     }
 
     /**
      * @return PARTICLE_SEQUENCE or PARTICLE_CHOICE_UNBOUNDED
      */
-    public int getTopParticleForComplexOrMixedContent()
-    {
+    public int getTopParticleForComplexOrMixedContent() {
         return _topParticleForComplexOrMixedContent;
     }
 
     /**
-     * @param topParticleForComplexOrMixedContent  PARTICLE_SEQUENCE or 
PARTICLE_CHOICE_UNBOUNDED
+     * @param topParticleForComplexOrMixedContent PARTICLE_SEQUENCE or 
PARTICLE_CHOICE_UNBOUNDED
      */
-    public void setTopParticleForComplexOrMixedContent(int 
topParticleForComplexOrMixedContent)
-    {
+    public void setTopParticleForComplexOrMixedContent(int 
topParticleForComplexOrMixedContent) {
         this._topParticleForComplexOrMixedContent = 
topParticleForComplexOrMixedContent;
     }
 
-    public boolean isGlobal()
-    {
+    public boolean isGlobal() {
         return _isGlobal;
     }
 
-    public void setGlobal(boolean isGlobal)
-    {
-        assert isGlobal && getName()!=null;
+    public void setGlobal(boolean isGlobal) {
+        assert isGlobal && getName() != null;
         _isGlobal = isGlobal;
     }
 
-    public Type getExtensionType()
-    {
+    public Type getExtensionType() {
         return _extensionType;
     }
 
-    public void setExtensionType(Type extendedType)
-    {
+    public void setExtensionType(Type extendedType) {
         assert _kind == COMPLEX_TYPE_SIMPLE_CONTENT : "Extension used only for 
type which are COMPLEX_TYPE_SIMPLE_CONTENT";
-        assert extendedType!=null && extendedType.getName()!=null : "Extended 
type must be a named type.";
+        assert extendedType != null && extendedType.getName() != null : 
"Extended type must be a named type.";
         _extensionType = extendedType;
     }
 
-    public List getEnumerationValues()
-    {
+    public List<String> getEnumerationValues() {
         ensureEnumerationValues();
         return _enumerationValues;
     }
 
-    public List getEnumerationQNames()
-    {
+    public List<QName> getEnumerationQNames() {
         ensureEnumerationValues();
         return _enumerationQNames;
     }
 
-    public void addEnumerationValue(String enumerationValue, final XmlCursor 
xc)
-    {
-        assert _kind==SIMPLE_TYPE_SIMPLE_CONTENT || 
_kind==COMPLEX_TYPE_SIMPLE_CONTENT : "Enumerations possible only on simple 
content";
+    public void addEnumerationValue(String enumerationValue, final XmlCursor 
xc) {
+        assert _kind == SIMPLE_TYPE_SIMPLE_CONTENT || _kind == 
COMPLEX_TYPE_SIMPLE_CONTENT : "Enumerations possible only on simple content";
         ensureEnumerationValues();
-        if (_acceptsEnumerationValue && 
!_enumerationValues.contains(enumerationValue))
-        {
+        if (_acceptsEnumerationValue && 
!_enumerationValues.contains(enumerationValue)) {
             _enumerationValues.add(enumerationValue);
-            if (_name.equals(XmlQName.type.getName()))
-            {
+            if (_name.equals(XmlQName.type.getName())) {
                 // check for QName
-                PrefixResolver prefixResolver = new PrefixResolver()
-                {
-                    public String getNamespaceForPrefix(String prefix)
-                    {  return xc.namespaceForPrefix(prefix); }
-                };
-
-                QName qname = XmlQNameImpl.validateLexical(enumerationValue, 
null, prefixResolver);
+                QName qname = XmlQNameImpl.validateLexical(enumerationValue, 
null, xc::namespaceForPrefix);
 
-                assert qname!=null : "The check for QName should allready have 
happened.";
+                assert qname != null : "The check for QName should allready 
have happened.";
                 _enumerationQNames.add(qname);
             }
         }
     }
 
-    private void ensureEnumerationValues()
-    {
-        if (_enumerationValues==null)
-        {
-            _enumerationValues = new ArrayList();
-            _enumerationQNames = new ArrayList();
+    private void ensureEnumerationValues() {
+        if (_enumerationValues == null) {
+            _enumerationValues = new ArrayList<>();
+            _enumerationQNames = new ArrayList<>();
         }
     }
 
-    public boolean isEnumeration()
-    {
-        return _acceptsEnumerationValue && _enumerationValues!=null && 
_enumerationValues.size()>1;
+    public boolean isEnumeration() {
+        return _acceptsEnumerationValue && _enumerationValues != null && 
_enumerationValues.size() > 1;
     }
 
-    public boolean isQNameEnumeration()
-    {
-        return isEnumeration() && _name.equals(XmlQName.type.getName()) && 
_enumerationQNames!=null && _enumerationQNames.size()>1;
+    public boolean isQNameEnumeration() {
+        return isEnumeration() && _name.equals(XmlQName.type.getName()) && 
_enumerationQNames != null && _enumerationQNames.size() > 1;
     }
 
-    public void closeEnumeration()
-    {
-        _acceptsEnumerationValue=false;
+    public void closeEnumeration() {
+        _acceptsEnumerationValue = false;
     }
 
-    public String toString()
-    {
+    public String toString() {
         return "Type{" +
-            "_name = " + _name +
-            ", _extensionType = " + _extensionType +
-            ", _kind = " + _kind +
-            ", _elements = " + _elements +
-            ", _attributes = " + _attributes +
-            "}";
+               "_name = " + _name +
+               ", _extensionType = " + _extensionType +
+               ", _kind = " + _kind +
+               ", _elements = " + _elements +
+               ", _attributes = " + _attributes +
+               "}";
     }
 
-    public void addAllEnumerationsFrom(Type from)
-    {
-        assert _kind==SIMPLE_TYPE_SIMPLE_CONTENT || 
_kind==COMPLEX_TYPE_SIMPLE_CONTENT : "Enumerations possible only on simple 
content";
+    public void addAllEnumerationsFrom(Type from) {
+        assert _kind == SIMPLE_TYPE_SIMPLE_CONTENT || _kind == 
COMPLEX_TYPE_SIMPLE_CONTENT : "Enumerations possible only on simple content";
         ensureEnumerationValues();
 
-        if (_name.equals(XmlQName.type.getName()) && 
from._name.equals(XmlQName.type.getName()))
-        {
-            for (int i = 0; i < from.getEnumerationValues().size(); i++)
-            {
-                String enumValue = (String) from.getEnumerationValues().get(i);
-                QName enumQNameValue = (QName) 
from.getEnumerationQNames().get(i);
-                if (_acceptsEnumerationValue && 
!_enumerationQNames.contains(enumQNameValue))
-                {
-                        _enumerationValues.add(enumValue);
-                        _enumerationQNames.add(enumQNameValue);
+        if (_name.equals(XmlQName.type.getName()) && 
from._name.equals(XmlQName.type.getName())) {
+            for (int i = 0; i < from.getEnumerationValues().size(); i++) {
+                String enumValue = from.getEnumerationValues().get(i);
+                QName enumQNameValue = from.getEnumerationQNames().get(i);
+                if (_acceptsEnumerationValue && 
!_enumerationQNames.contains(enumQNameValue)) {
+                    _enumerationValues.add(enumValue);
+                    _enumerationQNames.add(enumQNameValue);
                 }
             }
-        }
-        else
-        {
-            for (int i = 0; i < from.getEnumerationValues().size(); i++)
-            {
-                String enumValue = (String) from.getEnumerationValues().get(i);
-                if (_acceptsEnumerationValue && 
!_enumerationValues.contains(enumValue))
-                {
+        } else {
+            for (int i = 0; i < from.getEnumerationValues().size(); i++) {
+                String enumValue = from.getEnumerationValues().get(i);
+                if (_acceptsEnumerationValue && 
!_enumerationValues.contains(enumValue)) {
                     _enumerationValues.add(enumValue);
                 }
             }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to