From commits-return-13296-apmail-poi-commits-archive=poi.apache.org@poi.apache.org Wed Sep 23 22:26:02 2020 Return-Path: X-Original-To: apmail-poi-commits-archive@locus.apache.org Delivered-To: apmail-poi-commits-archive@locus.apache.org Received: from mailroute1-lw-us.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with ESMTP id 47E321A9CE for ; Wed, 23 Sep 2020 22:26:01 +0000 (UTC) Received: from mail.apache.org (localhost [127.0.0.1]) by mailroute1-lw-us.apache.org (ASF Mail Server at mailroute1-lw-us.apache.org) with SMTP id A0234124400 for ; Wed, 23 Sep 2020 22:26:01 +0000 (UTC) Received: (qmail 63959 invoked by uid 500); 23 Sep 2020 22:26:01 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 63860 invoked by uid 500); 23 Sep 2020 22:26:01 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 63838 invoked by uid 99); 23 Sep 2020 22:26:01 -0000 Received: from Unknown (HELO svn01-us-east.apache.org) (13.90.137.153) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Sep 2020 22:26:01 +0000 Received: from svn01-us-east.apache.org (svn01-us-east.apache.org [127.0.0.1]) by svn01-us-east.apache.org (ASF Mail Server at svn01-us-east.apache.org) with ESMTP id CBBC217A658 for ; Wed, 23 Sep 2020 22:26:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1881967 [2/2] - in /xmlbeans/trunk/src/main/java/org/apache/xmlbeans: ./ impl/schema/ impl/values/ Date: Wed, 23 Sep 2020 22:26:00 -0000 To: commits@poi.apache.org From: kiwiwings@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20200923222600.CBBC217A658@svn01-us-east.apache.org> Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java?rev=1881967&r1=1881966&r2=1881967&view=diff ============================================================================== --- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java (original) +++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java Wed Sep 23 22:26:00 2020 @@ -63,14 +63,12 @@ public final class SchemaTypeImpl implem private PrePostExtension _prepost; // runtime java type support: volatile because they're cached - private volatile Class _javaClass; - private volatile Class _javaEnumClass; - private volatile Class _javaImplClass; - private volatile Constructor _javaImplConstructor; - private volatile Constructor _javaImplConstructor2; + private volatile Class _javaClass; + private volatile Class _javaEnumClass; + private volatile Class _javaImplClass; + private volatile Constructor _javaImplConstructor; + private volatile Constructor _javaImplConstructor2; private volatile boolean _implNotAvailable; - private volatile Class _userTypeClass; - private volatile Class _userTypeHandlerClass; // user data objects not persisted private volatile Object _userData; @@ -84,10 +82,10 @@ public final class SchemaTypeImpl implem // complex content support private SchemaParticle _contentModel; private volatile SchemaLocalElement[] _localElts; // lazily computed - private volatile Map _eltToIndexMap; // lazily computed - private volatile Map _attrToIndexMap; // lazily computed - private Map _propertyModelByElementName; - private Map _propertyModelByAttributeName; + private volatile Map _eltToIndexMap; // lazily computed + private volatile Map _attrToIndexMap; // lazily computed + private Map _propertyModelByElementName; + private Map _propertyModelByAttributeName; private boolean _hasAllContent; private boolean _orderSensitive; private QNameSet _typedWildcardElements; @@ -95,7 +93,7 @@ public final class SchemaTypeImpl implem private boolean _hasWildcardElements; private boolean _hasWildcardAttributes; // set of valid QNames that can be substituted for a property - private Set _validSubstitutions = Collections.EMPTY_SET; + private Set _validSubstitutions = Collections.emptySet(); // simple content support private int _complexTypeVariety; @@ -147,9 +145,9 @@ public final class SchemaTypeImpl implem private XmlValueRef[] _enumerationValues; private SchemaType.Ref _baseEnumTyperef; private boolean _stringEnumEnsured; - private volatile Map _lookupStringEnum; - private volatile List _listOfStringEnum; - private volatile Map _lookupStringEnumEntry; + private volatile Map _lookupStringEnum; + private volatile List _listOfStringEnum; + private volatile Map _lookupStringEnumEntry; private SchemaStringEnumEntry[] _stringEnumEntries; // for lists only @@ -174,7 +172,7 @@ public final class SchemaTypeImpl implem // for document types only - only valid during compilation private QName _sg; - private List _sgMembers = new ArrayList(); + private final List _sgMembers = new ArrayList<>(); public boolean isUnloaded() { return _unloaded; @@ -479,8 +477,10 @@ public final class SchemaTypeImpl implem if (_containerFieldCode == 0) { _containerField = _containerFieldRef == null ? null : (SchemaField) _containerFieldRef.getComponent(); } else if (_containerFieldCode == 1) { + assert (outer != null); _containerField = outer.getAttributeModel().getAttributes()[_containerFieldIndex]; } else { + assert (outer != null); _containerField = ((SchemaTypeImpl) outer).getLocalElementByIndex(_containerFieldIndex); } _containerFieldCode = -1; @@ -535,9 +535,8 @@ public final class SchemaTypeImpl implem public boolean isSkippedAnonymousType() { SchemaType outerType = getOuterType(); - return ((outerType == null) ? false : - (outerType.getBaseType() == this || - outerType.getContentBasedOnType() == this)); + return (outerType != null && (outerType.getBaseType() == this || + outerType.getContentBasedOnType() == this)); } public String getShortJavaName() { @@ -612,7 +611,7 @@ public final class SchemaTypeImpl implem public void setInterfaceExtensions(InterfaceExtension[] interfaces) { assertResolved(); - _interfaces = interfaces; + _interfaces = (interfaces == null) ? null : interfaces.clone(); } public InterfaceExtension[] getInterfaceExtensions() { @@ -653,31 +652,31 @@ public final class SchemaTypeImpl implem return _contentModel; } - private static void buildEltList(List eltList, SchemaParticle contentModel) { + private static void buildEltList(List eltList, SchemaParticle contentModel) { if (contentModel == null) { return; } switch (contentModel.getParticleType()) { case SchemaParticle.ELEMENT: - eltList.add(contentModel); - return; + eltList.add((SchemaLocalElement) contentModel); + break; case SchemaParticle.ALL: case SchemaParticle.CHOICE: case SchemaParticle.SEQUENCE: for (int i = 0; i < contentModel.countOfParticleChild(); i++) { buildEltList(eltList, contentModel.getParticleChild(i)); } - return; + break; default: - return; + break; } } private void buildLocalElts() { - List eltList = new ArrayList(); + List eltList = new ArrayList<>(); buildEltList(eltList, _contentModel); - _localElts = (SchemaLocalElement[]) eltList.toArray(new SchemaLocalElement[eltList.size()]); + _localElts = eltList.toArray(new SchemaLocalElement[0]); } public SchemaLocalElement getLocalElementByIndex(int i) { @@ -690,31 +689,31 @@ public final class SchemaTypeImpl implem } public int getIndexForLocalElement(SchemaLocalElement elt) { - Map localEltMap = _eltToIndexMap; + Map localEltMap = _eltToIndexMap; if (localEltMap == null) { if (_localElts == null) { buildLocalElts(); } - localEltMap = new HashMap(); + localEltMap = new HashMap<>(); for (int i = 0; i < _localElts.length; i++) { - localEltMap.put(_localElts[i], new Integer(i)); + localEltMap.put(_localElts[i], i); } _eltToIndexMap = localEltMap; } - return ((Integer) localEltMap.get(elt)).intValue(); + return localEltMap.get(elt); } public int getIndexForLocalAttribute(SchemaLocalAttribute attr) { - Map localAttrMap = _attrToIndexMap; + Map localAttrMap = _attrToIndexMap; if (localAttrMap == null) { - localAttrMap = new HashMap(); + localAttrMap = new HashMap<>(); SchemaLocalAttribute[] attrs = this._attributeModel.getAttributes(); for (int i = 0; i < attrs.length; i++) { - localAttrMap.put(attrs[i], new Integer(i)); + localAttrMap.put(attrs[i], i); } _attrToIndexMap = localAttrMap; } - return ((Integer) localAttrMap.get(attr)).intValue(); + return localAttrMap.get(attr); } public SchemaAttributeModel getAttributeModel() { @@ -730,10 +729,10 @@ public final class SchemaTypeImpl implem return getElementProperties(); } - List list = new ArrayList(); + List list = new ArrayList<>(); list.addAll(_propertyModelByElementName.values()); list.addAll(_propertyModelByAttributeName.values()); - return (SchemaProperty[]) list.toArray(new SchemaProperty[list.size()]); + return list.toArray(new SchemaProperty[0]); } private static final SchemaProperty[] NO_PROPERTIES = new SchemaProperty[0]; @@ -744,7 +743,7 @@ public final class SchemaTypeImpl implem return getProperties(); } - List results = new ArrayList(); + List results = new ArrayList<>(); if (_propertyModelByElementName != null) { results.addAll(_propertyModelByElementName.values()); @@ -754,8 +753,8 @@ public final class SchemaTypeImpl implem results.addAll(_propertyModelByAttributeName.values()); } - for (Iterator it = results.iterator(); it.hasNext(); ) { - SchemaProperty prop = (SchemaProperty) it.next(); + for (Iterator it = results.iterator(); it.hasNext(); ) { + SchemaProperty prop = it.next(); SchemaProperty baseProp = prop.isAttribute() ? baseType.getAttributeProperty(prop.getName()) : baseType.getElementProperty(prop.getName()); @@ -777,7 +776,7 @@ public final class SchemaTypeImpl implem } - return (SchemaProperty[]) results.toArray(new SchemaProperty[results.size()]); + return results.toArray(new SchemaProperty[0]); } private static boolean eq(BigInteger a, BigInteger b) { @@ -805,8 +804,7 @@ public final class SchemaTypeImpl implem return NO_PROPERTIES; } - return (SchemaProperty[]) - _propertyModelByElementName.values().toArray(new SchemaProperty[_propertyModelByElementName.size()]); + return _propertyModelByElementName.values().toArray(new SchemaProperty[0]); } public SchemaProperty[] getAttributeProperties() { @@ -814,16 +812,15 @@ public final class SchemaTypeImpl implem return NO_PROPERTIES; } - return (SchemaProperty[]) - _propertyModelByAttributeName.values().toArray(new SchemaProperty[_propertyModelByAttributeName.size()]); + return _propertyModelByAttributeName.values().toArray(new SchemaProperty[0]); } public SchemaProperty getElementProperty(QName eltName) { - return _propertyModelByElementName == null ? null : (SchemaProperty) _propertyModelByElementName.get(eltName); + return _propertyModelByElementName == null ? null : _propertyModelByElementName.get(eltName); } public SchemaProperty getAttributeProperty(QName attrName) { - return _propertyModelByAttributeName == null ? null : (SchemaProperty) _propertyModelByAttributeName.get(attrName); + return _propertyModelByAttributeName == null ? null : _propertyModelByAttributeName.get(attrName); } public boolean hasAllContent() { @@ -842,8 +839,8 @@ public final class SchemaTypeImpl implem public void setContentModel( SchemaParticle contentModel, SchemaAttributeModel attrModel, - Map propertyModelByElementName, - Map propertyModelByAttributeName, + Map propertyModelByElementName, + Map propertyModelByAttributeName, boolean isAll) { assertResolving(); _contentModel = contentModel; @@ -855,14 +852,13 @@ public final class SchemaTypeImpl implem // Add entries for each element property for substitution group members if (_propertyModelByElementName != null) { - _validSubstitutions = new LinkedHashSet(); - Collection eltProps = _propertyModelByElementName.values(); - for (Iterator it = eltProps.iterator(); it.hasNext(); ) { - SchemaProperty prop = (SchemaProperty) it.next(); + _validSubstitutions = new LinkedHashSet<>(); + Collection eltProps = _propertyModelByElementName.values(); + for (SchemaProperty prop : eltProps) { QName[] names = prop.acceptedNames(); - for (int i = 0; i < names.length; i++) { - if (!_propertyModelByElementName.containsKey(names[i])) { - _validSubstitutions.add(names[i]); + for (QName name : names) { + if (!_propertyModelByElementName.containsKey(name)) { + _validSubstitutions.add(name); } } } @@ -891,8 +887,8 @@ public final class SchemaTypeImpl implem return BuiltinSchemaTypeSystem.ST_NO_TYPE; } - SchemaType type = null; - SchemaProperty prop = (SchemaProperty) _propertyModelByElementName.get(eltName); + SchemaType type; + SchemaProperty prop = _propertyModelByElementName.get(eltName); if (prop != null) { type = prop.getType(); } else { @@ -925,9 +921,7 @@ public final class SchemaTypeImpl implem sghead = sghead.substitutionGroup(); } */ - if (type == null) { - return BuiltinSchemaTypeSystem.ST_NO_TYPE; - } + return BuiltinSchemaTypeSystem.ST_NO_TYPE; } } @@ -955,7 +949,7 @@ public final class SchemaTypeImpl implem return BuiltinSchemaTypeSystem.ST_ANY_SIMPLE; } - SchemaProperty prop = (SchemaProperty) _propertyModelByAttributeName.get(attrName); + SchemaProperty prop = _propertyModelByAttributeName.get(attrName); if (prop != null) { return prop.getType(); } @@ -979,12 +973,12 @@ public final class SchemaTypeImpl implem * things, they can't be refactored to share code, so exercise caution */ public XmlObject createElementType(QName eltName, QName xsiType, SchemaTypeLoader wildcardTypeLoader) { - SchemaType type = null; + SchemaType type; SchemaProperty prop = null; if (isSimpleType() || !containsElements() || isNoType()) { type = BuiltinSchemaTypeSystem.ST_NO_TYPE; } else { - prop = (SchemaProperty) _propertyModelByElementName.get(eltName); + prop = _propertyModelByElementName.get(eltName); if (prop != null) { type = prop.getType(); } else if (_typedWildcardElements.contains(eltName) || @@ -1019,9 +1013,7 @@ public final class SchemaTypeImpl implem sghead = sghead.substitutionGroup(); } */ - if (type == null) { - type = BuiltinSchemaTypeSystem.ST_NO_TYPE; - } + type = BuiltinSchemaTypeSystem.ST_NO_TYPE; } if (xsiType != null) { @@ -1044,14 +1036,14 @@ public final class SchemaTypeImpl implem } public XmlObject createAttributeType(QName attrName, SchemaTypeLoader wildcardTypeLoader) { - SchemaTypeImpl type = null; + SchemaTypeImpl type; SchemaProperty prop = null; if (isSimpleType() || isNoType()) { type = BuiltinSchemaTypeSystem.ST_NO_TYPE; } else if (isURType()) { type = BuiltinSchemaTypeSystem.ST_ANY_SIMPLE; } else { - prop = (SchemaProperty) _propertyModelByAttributeName.get(attrName); + prop = _propertyModelByAttributeName.get(attrName); if (prop != null) { type = (SchemaTypeImpl) prop.getType(); } else if (!_typedWildcardAttributes.contains(attrName)) { @@ -1090,7 +1082,7 @@ public final class SchemaTypeImpl implem } public void setAnonymousTypeRefs(SchemaType.Ref[] anonymousTyperefs) { - _anonymousTyperefs = anonymousTyperefs; + _anonymousTyperefs = anonymousTyperefs == null ? null : anonymousTyperefs.clone(); } @@ -1223,7 +1215,7 @@ public final class SchemaTypeImpl implem public void setUnionMemberTypeRefs(SchemaType.Ref[] typerefs) { assertResolving(); - _unionMemberTyperefs = typerefs; + _unionMemberTyperefs = typerefs == null ? null : typerefs.clone(); } public int getAnonymousUnionMemberOrdinal() { @@ -1272,14 +1264,14 @@ public final class SchemaTypeImpl implem if (getSimpleVariety() != SchemaType.UNION) { throw new IllegalStateException("Operation is only supported on union types"); } - Set constituentMemberTypes = new LinkedHashSet(); - Set allSubTypes = new LinkedHashSet(); + Set constituentMemberTypes = new LinkedHashSet<>(); + Set allSubTypes = new LinkedHashSet<>(); SchemaType commonBaseType = null; allSubTypes.add(this); - for (int i = 0; i < _unionMemberTyperefs.length; i++) { - SchemaTypeImpl mImpl = (SchemaTypeImpl) _unionMemberTyperefs[i].get(); + for (Ref unionMemberTyperef : _unionMemberTyperefs) { + SchemaTypeImpl mImpl = (SchemaTypeImpl) unionMemberTyperef.get(); switch (mImpl.getSimpleVariety()) { case SchemaType.LIST: @@ -1305,10 +1297,8 @@ public final class SchemaTypeImpl implem } } - setUnionConstituentTypes((SchemaType[]) - constituentMemberTypes.toArray(StscState.EMPTY_ST_ARRAY)); - setUnionSubTypes((SchemaType[]) - allSubTypes.toArray(StscState.EMPTY_ST_ARRAY)); + setUnionConstituentTypes(constituentMemberTypes.toArray(StscState.EMPTY_ST_ARRAY)); + setUnionSubTypes(allSubTypes.toArray(StscState.EMPTY_ST_ARRAY)); setUnionCommonBaseType(commonBaseType); } @@ -1327,8 +1317,7 @@ public final class SchemaTypeImpl implem } public QName[] getSubstitutionGroupMembers() { - QName[] result = new QName[_sgMembers.size()]; - return (QName[]) _sgMembers.toArray(result); + return _sgMembers.toArray(new QName[0]); } public int getWhiteSpaceRule() { @@ -1369,8 +1358,8 @@ public final class SchemaTypeImpl implem public void setBasicFacets(XmlValueRef[] values, boolean[] fixed) { assertResolving(); - _facetArray = values; - _fixedFacetArray = fixed; + _facetArray = values == null ? null : values.clone(); + _fixedFacetArray = fixed == null ? null : fixed.clone(); } public int ordered() { @@ -1461,7 +1450,7 @@ public final class SchemaTypeImpl implem public void setPatterns(org.apache.xmlbeans.impl.regex.RegularExpression[] list) { assertResolving(); - _patterns = list; + _patterns = list == null ? null : list.clone(); } public XmlAnySimpleType[] getEnumerationValues() { @@ -1479,7 +1468,7 @@ public final class SchemaTypeImpl implem public void setEnumerationValues(XmlValueRef[] a) { assertResolving(); - _enumerationValues = a; + _enumerationValues = a == null ? null : a.clone(); } public StringEnumAbstractBase enumForString(String s) { @@ -1487,7 +1476,7 @@ public final class SchemaTypeImpl implem if (_lookupStringEnum == null) { return null; } - return (StringEnumAbstractBase) _lookupStringEnum.get(s); + return _lookupStringEnum.get(s); } public StringEnumAbstractBase enumForInt(int i) { @@ -1495,7 +1484,7 @@ public final class SchemaTypeImpl implem if (_listOfStringEnum == null || i < 0 || i >= _listOfStringEnum.size()) { return null; } - return (StringEnumAbstractBase) _listOfStringEnum.get(i); + return _listOfStringEnum.get(i); } public SchemaStringEnumEntry enumEntryForString(String s) { @@ -1503,7 +1492,7 @@ public final class SchemaTypeImpl implem if (_lookupStringEnumEntry == null) { return null; } - return (SchemaStringEnumEntry) _lookupStringEnumEntry.get(s); + return _lookupStringEnumEntry.get(s); } public SchemaType getBaseEnumType() { @@ -1523,9 +1512,9 @@ public final class SchemaTypeImpl implem return result; } - public void setStringEnumEntries(SchemaStringEnumEntry sEnums[]) { + public void setStringEnumEntries(SchemaStringEnumEntry[] sEnums) { assertJavaizing(); - _stringEnumEntries = sEnums; + _stringEnumEntries = sEnums == null ? null : sEnums.clone(); } private void ensureStringEnumInfo() { @@ -1539,22 +1528,22 @@ public final class SchemaTypeImpl implem return; } - Map lookupStringEnum = new HashMap(sEnums.length); - List listOfStringEnum = new ArrayList(sEnums.length + 1); - Map lookupStringEnumEntry = new HashMap(sEnums.length); + Map lookupStringEnum = new HashMap<>(sEnums.length); + List listOfStringEnum = new ArrayList<>(sEnums.length + 1); + Map lookupStringEnumEntry = new HashMap<>(sEnums.length); - for (int i = 0; i < sEnums.length; i++) { - lookupStringEnumEntry.put(sEnums[i].getString(), sEnums[i]); + for (SchemaStringEnumEntry sEnum : sEnums) { + lookupStringEnumEntry.put(sEnum.getString(), sEnum); } - Class jc = _baseEnumTyperef.get().getEnumJavaClass(); + Class jc = _baseEnumTyperef.get().getEnumJavaClass(); if (jc != null) { try { StringEnumAbstractBase.Table table = (StringEnumAbstractBase.Table) jc.getField("table").get(null); - for (int i = 0; i < sEnums.length; i++) { - int j = sEnums[i].getIntValue(); + for (SchemaStringEnumEntry sEnum : sEnums) { + int j = sEnum.getIntValue(); StringEnumAbstractBase enumVal = table.forInt(j); - lookupStringEnum.put(sEnums[i].getString(), enumVal); + lookupStringEnum.put(sEnum.getString(), enumVal); while (listOfStringEnum.size() <= j) { listOfStringEnum.add(null); } @@ -1569,9 +1558,9 @@ public final class SchemaTypeImpl implem } if (jc == null) { - for (int i = 0; i < sEnums.length; i++) { - int j = sEnums[i].getIntValue(); - String s = sEnums[i].getString(); + for (SchemaStringEnumEntry sEnum : sEnums) { + int j = sEnum.getIntValue(); + String s = sEnum.getString(); StringEnumAbstractBase enumVal = new StringEnumValue(s, j); lookupStringEnum.put(s, enumVal); while (listOfStringEnum.size() <= j) { @@ -1620,11 +1609,11 @@ public final class SchemaTypeImpl implem SchemaProperty[] eltProps = getElementProperties(); SchemaParticle contentModel = getContentModel(); - Map state = new HashMap(); + Map state = new HashMap<>(); QNameSet allContents = computeAllContainedElements(contentModel, state); - for (int i = 0; i < eltProps.length; i++) { - SchemaPropertyImpl sImpl = (SchemaPropertyImpl) eltProps[i]; + for (SchemaProperty eltProp : eltProps) { + SchemaPropertyImpl sImpl = (SchemaPropertyImpl) eltProp; QNameSet nde = computeNondelimitingElements(sImpl.getName(), contentModel, state); QNameSetBuilder builder = new QNameSetBuilder(allContents); builder.removeAll(nde); @@ -1640,7 +1629,7 @@ public final class SchemaTypeImpl implem * contentModel. When appending an element, it comes before the first * one that is not in this set. */ - private static QNameSet computeNondelimitingElements(QName target, SchemaParticle contentModel, Map state) { + private static QNameSet computeNondelimitingElements(QName target, SchemaParticle contentModel, Map state) { QNameSet allContents = computeAllContainedElements(contentModel, state); if (!allContents.contains(target)) { return QNameSet.EMPTY; @@ -1698,9 +1687,9 @@ public final class SchemaTypeImpl implem * to record the results, so that if they are needed again later, * they do not need to be recomputed. */ - private static QNameSet computeAllContainedElements(SchemaParticle contentModel, Map state) { + private static QNameSet computeAllContainedElements(SchemaParticle contentModel, Map state) { // Remember previously computed results to avoid complexity explosion - QNameSet result = (QNameSet) state.get(contentModel); + QNameSet result = state.get(contentModel); if (result != null) { return result; } @@ -1725,23 +1714,21 @@ public final class SchemaTypeImpl implem case SchemaParticle.ELEMENT: // Fix for XMLBEANS-228 - result = ((SchemaLocalElementImpl) contentModel).acceptedStartNames(); + result = contentModel.acceptedStartNames(); break; } state.put(contentModel, result); return result; } - public Class getJavaClass() { + @SuppressWarnings("unchecked") + public Class getJavaClass() { // This field is declared volatile and Class is immutable so this is allowed. if (_javaClass == null && getFullJavaName() != null) { try { - _javaClass = Class.forName(getFullJavaName(), false, getTypeSystem().getClassLoader()); + _javaClass = (Class) Class.forName(getFullJavaName(), false, getTypeSystem().getClassLoader()); } catch (ClassNotFoundException e) { -// This is a legitimate use, when users get a SchemaTypeSystem without compiling classes -// System.err.println("Could not find class name " + getFullJavaName()); -// System.err.println("Searched in classloader " + getTypeSystem().getClassLoader()); -// e.printStackTrace(System.err); + // This is a legitimate use, when users get a SchemaTypeSystem without compiling classes _javaClass = null; } } @@ -1749,7 +1736,8 @@ public final class SchemaTypeImpl implem return _javaClass; } - public Class getJavaImplClass() { + @SuppressWarnings("unchecked") + public Class getJavaImplClass() { if (_implNotAvailable) { return null; } @@ -1757,7 +1745,7 @@ public final class SchemaTypeImpl implem if (_javaImplClass == null) { try { if (getFullJavaImplName() != null) { - _javaImplClass = Class.forName(getFullJavaImplName(), false, getTypeSystem().getClassLoader()); + _javaImplClass = (Class) Class.forName(getFullJavaImplName(), false, getTypeSystem().getClassLoader()); } else { _implNotAvailable = true; } @@ -1769,42 +1757,14 @@ public final class SchemaTypeImpl implem return _javaImplClass; } - public Class getUserTypeClass() { - // This field is declared volatile and Class is immutable so this is allowed. - if (_userTypeClass == null && getUserTypeName() != null) { - try { - _userTypeClass = Class.forName(_userTypeName, false, - getTypeSystem().getClassLoader()); - } catch (ClassNotFoundException e) { - _userTypeClass = null; - } - } - - return _userTypeClass; - } - - public Class getUserTypeHandlerClass() { - // This field is declared volatile and Class is immutable so this is allowed. - if (_userTypeHandlerClass == null && getUserTypeHandlerName() != null) { - try { - _userTypeHandlerClass = Class.forName(_userTypeHandler, false, - getTypeSystem().getClassLoader()); - } catch (ClassNotFoundException e) { - _userTypeHandlerClass = null; - } - } - - return _userTypeHandlerClass; - } - - public Constructor getJavaImplConstructor() { + public Constructor getJavaImplConstructor() { if (_javaImplConstructor == null && !_implNotAvailable) { - final Class impl = getJavaImplClass(); + final Class impl = getJavaImplClass(); if (impl == null) { return null; } try { - _javaImplConstructor = impl.getConstructor(new Class[]{SchemaType.class}); + _javaImplConstructor = impl.getConstructor(SchemaType.class); } catch (NoSuchMethodException e) { e.printStackTrace(); } @@ -1814,14 +1774,14 @@ public final class SchemaTypeImpl implem } - public Constructor getJavaImplConstructor2() { + public Constructor getJavaImplConstructor2() { if (_javaImplConstructor2 == null && !_implNotAvailable) { - final Class impl = getJavaImplClass(); + final Class impl = getJavaImplClass(); if (impl == null) { return null; } try { - _javaImplConstructor2 = impl.getDeclaredConstructor(new Class[]{SchemaType.class, boolean.class}); + _javaImplConstructor2 = impl.getDeclaredConstructor(SchemaType.class, boolean.class); } catch (NoSuchMethodException e) { e.printStackTrace(); } @@ -1831,12 +1791,14 @@ public final class SchemaTypeImpl implem } - public Class getEnumJavaClass() { + @SuppressWarnings("unchecked") + @Override + public Class getEnumJavaClass() { // This field is declared volatile and Class is immutable so this is allowed. if (_javaEnumClass == null) { if (getBaseEnumType() != null) { try { - _javaEnumClass = Class.forName(getBaseEnumType().getFullJavaName() + "$Enum", false, getTypeSystem().getClassLoader()); + _javaEnumClass = (Class) Class.forName(getBaseEnumType().getFullJavaName() + "$Enum", false, getTypeSystem().getClassLoader()); } catch (ClassNotFoundException e) { _javaEnumClass = null; } @@ -1846,7 +1808,7 @@ public final class SchemaTypeImpl implem return _javaEnumClass; } - public void setJavaClass(Class javaClass) { + public void setJavaClass(Class javaClass) { assertResolved(); _javaClass = javaClass; setFullJavaName(javaClass.getName()); @@ -1863,8 +1825,7 @@ public final class SchemaTypeImpl implem public XmlObject createUnwrappedNode() { // Todo: attach a new xml store! - XmlObject result = createUnattachedNode(null); - return result; + return createUnattachedNode(null); } /** @@ -1918,11 +1879,10 @@ public final class SchemaTypeImpl implem if (!isBuiltinType() && !isNoType()) { // System.out.println("Attempting to load impl class: " + getFullJavaImplName()); - Constructor ctr = getJavaImplConstructor(); + Constructor ctr = getJavaImplConstructor(); if (ctr != null) { try { - // System.out.println("Succeeded!"); - return (XmlObject) ctr.newInstance(_ctrArgs); + return ctr.newInstance(_ctrArgs); } catch (Exception e) { System.out.println("Exception trying to instantiate impl class."); e.printStackTrace(); @@ -1944,14 +1904,13 @@ public final class SchemaTypeImpl implem private XmlObject createUnattachedSubclass(SchemaType sType) { if (!isBuiltinType() && !isNoType()) { // System.out.println("Attempting to load impl class: " + getFullJavaImplName()); - Constructor ctr = getJavaImplConstructor2(); + Constructor ctr = getJavaImplConstructor2(); if (ctr != null) { boolean accessible = ctr.isAccessible(); try { ctr.setAccessible(true); - // System.out.println("Succeeded!"); try { - return (XmlObject) ctr.newInstance(new Object[]{sType, sType.isSimpleType() ? Boolean.FALSE : Boolean.TRUE}); + return ctr.newInstance(sType, !sType.isSimpleType()); } catch (Exception e) { System.out.println("Exception trying to instantiate impl class."); e.printStackTrace(); @@ -1959,7 +1918,7 @@ public final class SchemaTypeImpl implem // Make a best-effort try to set the accessibility back to what it was try { ctr.setAccessible(accessible); - } catch (SecurityException se) { + } catch (SecurityException ignored) { } } } catch (Exception e) { @@ -2210,10 +2169,7 @@ public final class SchemaTypeImpl implem while (sImpl2.getBaseDepth() > sImpl1.getBaseDepth()) { sImpl2 = (SchemaTypeImpl) sImpl2.getBaseType(); } - for (; ; ) { - if (sImpl1.equals(sImpl2)) { - break; - } + while (!sImpl1.equals(sImpl2)) { sImpl1 = (SchemaTypeImpl) sImpl1.getBaseType(); sImpl2 = (SchemaTypeImpl) sImpl2.getBaseType(); assert (sImpl1 != null && sImpl2 != null); // must meet at anyType @@ -2232,8 +2188,8 @@ public final class SchemaTypeImpl implem if (getSimpleVariety() == UNION) { SchemaType[] members = getUnionMemberTypes(); - for (int i = 0; i < members.length; i++) { - if (members[i].isAssignableFrom(type)) { + for (SchemaType member : members) { + if (member.isAssignableFrom(type)) { return true; } } @@ -2337,7 +2293,7 @@ public final class SchemaTypeImpl implem return _redefinition; } - private SchemaType.Ref _selfref = new SchemaType.Ref(this); + private final SchemaType.Ref _selfref = new SchemaType.Ref(this); public SchemaType.Ref getRef() { return _selfref; @@ -2351,7 +2307,7 @@ public final class SchemaTypeImpl implem * Gives access to the internals of element validation */ private static class SequencerImpl implements SchemaTypeElementSequencer { - private SchemaTypeVisitorImpl _visitor; + private final SchemaTypeVisitorImpl _visitor; private SequencerImpl(SchemaTypeVisitorImpl visitor) { _visitor = visitor; @@ -2396,8 +2352,7 @@ public final class SchemaTypeImpl implem QNameSetBuilder qnsb = new QNameSetBuilder(wildcardSet); SchemaProperty[] props = this.getElementProperties(); - for (int i = 0; i < props.length; i++) { - SchemaProperty prop = props[i]; + for (SchemaProperty prop : props) { qnsb.remove(prop.getName()); } @@ -2441,8 +2396,7 @@ public final class SchemaTypeImpl implem SchemaProperty[] props = this.getAttributeProperties(); - for (int i = 0; i < props.length; i++) { - SchemaProperty prop = props[i]; + for (SchemaProperty prop : props) { qnsb.remove(prop.getName()); } Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java?rev=1881967&r1=1881966&r2=1881967&view=diff ============================================================================== --- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java (original) +++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java Wed Sep 23 22:26:00 2020 @@ -61,7 +61,7 @@ public class SchemaTypeSystemCompiler { } public void setSchemas(SchemaDocument.Schema[] schemas) { - this.schemas = schemas; + this.schemas = (schemas == null) ? null : schemas.clone(); } public BindingConfig getConfig() { Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/StscChecker.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/StscChecker.java?rev=1881967&r1=1881966&r2=1881967&view=diff ============================================================================== --- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/StscChecker.java (original) +++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/schema/StscChecker.java Wed Sep 23 22:26:00 2020 @@ -158,10 +158,6 @@ public class StscChecker { * Checks the default values of elements.

* Also checks that the type of elements is not one of ID, IDREF, IDREFS, ENTITY, ENTITIES or * NOTATION as per XMLSchema part 2. - * - * @param model - * @param location - * @param parentType */ private static void checkElementDefaults(SchemaParticle model, XmlObject location, SchemaType parentType) { if (model == null) { @@ -317,6 +313,7 @@ public class StscChecker { XmlObject location = sType.getParseObject(); SchemaType baseType = sType.getBaseType(); + assert (baseType != null); if (baseType.isSimpleType()) { state.error(XmlErrorCodes.SCHEMA_COMPLEX_TYPE$COMPLEX_CONTENT, new Object[]{QNameHelper.pretty(baseType.getName())}, @@ -448,7 +445,7 @@ public class StscChecker { * @param baseModel - The base schema particle * @param derivedModel - The derived (restricted) schema particle * @param errors - Invalid restriction errors are put into this collection - * @param context + * @param context . the context * @return boolean, true if valid restruction, false if invalid restriction * @ */ @@ -487,11 +484,7 @@ public class StscChecker { restrictionValid = nsSubset(baseModel, derivedModel, errors, context); break; case SchemaParticle.ALL: - restrictionValid = nsRecurseCheckCardinality(baseModel, derivedModel, errors, context); - break; case SchemaParticle.CHOICE: - restrictionValid = nsRecurseCheckCardinality(baseModel, derivedModel, errors, context); - break; case SchemaParticle.SEQUENCE: restrictionValid = nsRecurseCheckCardinality(baseModel, derivedModel, errors, context); break; @@ -573,7 +566,6 @@ public class StscChecker { // mapAndSum is call if base: CHOICE, derived: SEQUENCE assert baseModel.getParticleType() == SchemaParticle.CHOICE; assert derivedModel.getParticleType() == SchemaParticle.SEQUENCE; - boolean mapAndSumValid = true; // Schema Component Constraint: Particle Derivation OK (Sequence:Choice -- MapAndSum) // For a sequence group particle to be a �valid restriction� of a choice group particle all of the following // must be true: @@ -604,13 +596,11 @@ public class StscChecker { } } if (!foundMatch) { - mapAndSumValid = false; errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_DERIVATION_MAP_AND_SUM$MAP, new Object[]{printParticle(derivedParticle)}, context)); // KHK: if we don't return false now, this error may get swallowed by an error produced below return false; - //break; } } @@ -631,6 +621,7 @@ public class StscChecker { // 2.1 The other's {max occurs} is unbounded. // 2.2 Both {max occurs} are numbers, and the particle's is less than or equal to the other's. + boolean mapAndSumValid = true; if (derivedRangeMin.compareTo(baseModel.getMinOccurs()) < 0) { mapAndSumValid = false; errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_DERIVATION_MAP_AND_SUM$SUM_MIN_OCCURS_GTE_MIN_OCCURS, @@ -960,6 +951,8 @@ public class StscChecker { // Check for valid Wildcard/Group derivation nsRecurseCheckCardinality = nsRecurseCheckCardinality(asIfPart, particle, errors, context); break; + default: + break; } // If any particle is invalid then break the loop if (!nsRecurseCheckCardinality) { @@ -992,6 +985,8 @@ public class StscChecker { minRange = getEffectiveMinRangeChoice(derivedModel); maxRange = getEffectiveMaxRangeChoice(derivedModel); break; + default: + break; } // Check min occurs for validity @@ -1080,6 +1075,8 @@ public class StscChecker { } } break; + default: + break; } // if an unbounded has been found then we are done if (maxRange == null) { @@ -1156,6 +1153,8 @@ public class StscChecker { } } break; + default: + break; } // if an unbounded has been found then we are done if (maxRange == null) { @@ -1219,6 +1218,8 @@ public class StscChecker { minRange = mrc; } break; + default: + break; } } if (minRange == null) { @@ -1256,6 +1257,8 @@ public class StscChecker { case SchemaParticle.CHOICE: particleTotalMinOccurs = particleTotalMinOccurs.add(getEffectiveMinRangeChoice(particle)); break; + default: + break; } } @@ -1300,13 +1303,7 @@ public class StscChecker { // as defined by Wildcard allows Namespace Name (�3.10.4). if (baseModel.getWildcardSet().contains(derivedElement.getName())) { // 2 R's occurrence range is a valid restriction of B's occurrence range as defined by Occurrence Range OK (�3.9.6). - if (occurrenceRangeOK(baseModel, (SchemaParticle) derivedElement, errors, context)) { - nsCompat = true; - } else { - nsCompat = false; - // error already produced by occurrenceRangeOK - //errors.add(XmlError.forObject(formatOccurenceRangeMinError(baseModel, (SchemaParticle) derivedElement), context)); - } + nsCompat = occurrenceRangeOK(baseModel, (SchemaParticle) derivedElement, errors, context); } else { nsCompat = false; errors.add(XmlError.forObject(XmlErrorCodes.PARTICLE_DERIVATION_NS_COMPAT$WILDCARD_VALID, Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/XmlObjectBase.java URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/XmlObjectBase.java?rev=1881967&r1=1881966&r2=1881967&view=diff ============================================================================== --- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/XmlObjectBase.java (original) +++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/XmlObjectBase.java Wed Sep 23 22:26:00 2020 @@ -461,7 +461,7 @@ public abstract class XmlObjectBase impl return input; } } - Class desiredClass = commonType.getJavaClass(); + Class desiredClass = commonType.getJavaClass(); while (desiredClass == null) { commonType = commonType.getBaseType(); if (XmlObject.type.equals(commonType)) { @@ -1549,12 +1549,12 @@ public abstract class XmlObjectBase impl new Object[]{getPrimitiveTypeName(), "QName"}); } - public List getListValue() { + public List getListValue() { throw new XmlValueNotSupportedException(XmlErrorCodes.EXCEPTION_VALUE_NOT_SUPPORTED_S2J, new Object[]{getPrimitiveTypeName(), "List"}); } - public List xgetListValue() { + public List xgetListValue() { throw new XmlValueNotSupportedException(XmlErrorCodes.EXCEPTION_VALUE_NOT_SUPPORTED_S2J, new Object[]{getPrimitiveTypeName(), "List"}); } @@ -2836,7 +2836,7 @@ public abstract class XmlObjectBase impl private static class SerializedRootObject implements Serializable { private static final long serialVersionUID = 1; - transient Class _xbeanClass; + transient Class _xbeanClass; transient XmlObject _impl; private SerializedRootObject(XmlObject impl) { @@ -2861,13 +2861,14 @@ public abstract class XmlObjectBase impl out.writeBoolean(false); } + @SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException { try { // read class object first - this is // first just for historical reasons - really // it would be better to have the version numbers // first - _xbeanClass = (Class) in.readObject(); + _xbeanClass = (Class) in.readObject(); int utfBytes = in.readUnsignedShort(); @@ -2891,16 +2892,13 @@ public abstract class XmlObjectBase impl break; case 1: - switch (minorVersionNum) { - case 1: - xmlText = (String) in.readObject(); - in.readBoolean(); // ignored - break; - - default: - throw new IOException("Deserialization error: " + - "version number " + majorVersionNum + "." + - minorVersionNum + " not supported."); + if (minorVersionNum == 1) { + xmlText = (String) in.readObject(); + in.readBoolean(); // ignored + } else { + throw new IOException("Deserialization error: " + + "version number " + majorVersionNum + "." + + minorVersionNum + " not supported."); } break; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org