You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2022/01/07 12:29:45 UTC
svn commit: r1896795 - in /xmlbeans/trunk/src/main/java/org/apache/xmlbeans: QNameSetBuilder.java XmlValidationError.java impl/inst2xsd/Inst2Xsd.java impl/xsd2inst/SchemaInstanceGenerator.java
Author: fanningpj
Date: Fri Jan 7 12:29:45 2022
New Revision: 1896795
URL: http://svn.apache.org/viewvc?rev=1896795&view=rev
Log:
use more generics internally
Modified:
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/QNameSetBuilder.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/XmlValidationError.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/Inst2Xsd.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/xsd2inst/SchemaInstanceGenerator.java
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/QNameSetBuilder.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/QNameSetBuilder.java?rev=1896795&r1=1896794&r2=1896795&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/QNameSetBuilder.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/QNameSetBuilder.java Fri Jan 7 12:29:45 2022
@@ -26,9 +26,9 @@ public class QNameSetBuilder implements
private static final long serialVersionUID = 1L;
private boolean _inverted;
- private Set _includedURIs;
- private Set _excludedQNames;
- private Set _includedQNames;
+ private Set<String> _includedURIs;
+ private Set<QName> _excludedQNames;
+ private Set<QName> _includedQNames;
/**
* Constructs an empty QNameSetBuilder.
@@ -36,9 +36,9 @@ public class QNameSetBuilder implements
public QNameSetBuilder()
{
_inverted = false;
- _includedURIs = new HashSet();
- _excludedQNames = new HashSet();
- _includedQNames = new HashSet();
+ _includedURIs = new HashSet<>();
+ _excludedQNames = new HashSet<>();
+ _includedQNames = new HashSet<>();
}
/**
@@ -48,20 +48,20 @@ public class QNameSetBuilder implements
*/
public QNameSetBuilder(QNameSetSpecification set)
{
- Set includedURIs = set.includedURIs();
+ Set<String> includedURIs = set.includedURIs();
if (includedURIs != null)
{
_inverted = false;
- _includedURIs = new HashSet(includedURIs);
- _excludedQNames = new HashSet(set.excludedQNamesInIncludedURIs());
- _includedQNames = new HashSet(set.includedQNamesInExcludedURIs());
+ _includedURIs = new HashSet<>(includedURIs);
+ _excludedQNames = new HashSet<>(set.excludedQNamesInIncludedURIs());
+ _includedQNames = new HashSet<>(set.includedQNamesInExcludedURIs());
}
else
{
_inverted = true;
- _includedURIs = new HashSet(set.excludedURIs());
- _excludedQNames = new HashSet(set.includedQNamesInExcludedURIs());
- _includedQNames = new HashSet(set.excludedQNamesInIncludedURIs());
+ _includedURIs = new HashSet<>(set.excludedURIs());
+ _excludedQNames = new HashSet<>(set.includedQNamesInExcludedURIs());
+ _includedQNames = new HashSet<>(set.excludedQNamesInIncludedURIs());
}
}
@@ -75,7 +75,7 @@ public class QNameSetBuilder implements
* @param excludedQNamesInIncludedURIs the finite set of exceptional QNames to exclude from the included namespaces
* @param includedQNamesInExcludedURIs the finite set of exceptional QNames to include that are in the excluded namespaces
*/
- public QNameSetBuilder(Set excludedURIs, Set includedURIs, Set excludedQNamesInIncludedURIs, Set includedQNamesInExcludedURIs)
+ public QNameSetBuilder(Set<String> excludedURIs, Set<String> includedURIs, Set excludedQNamesInIncludedURIs, Set includedQNamesInExcludedURIs)
{
if (includedURIs != null && excludedURIs == null)
{
@@ -181,7 +181,7 @@ public class QNameSetBuilder implements
if (s.length() == 0)
return EMPTY_STRINGARRAY;
- List<String> result = new ArrayList();
+ List<String> result = new ArrayList<>();
int i = 0;
int start = 0;
for (;;)
@@ -189,7 +189,7 @@ public class QNameSetBuilder implements
while (i < s.length() && isSpace(s.charAt(i)))
i += 1;
if (i >= s.length())
- return (String[])result.toArray(EMPTY_STRINGARRAY);
+ return result.toArray(EMPTY_STRINGARRAY);
start = i;
while (i < s.length() && !isSpace(s.charAt(i)))
i += 1;
@@ -200,11 +200,11 @@ public class QNameSetBuilder implements
/**
* Remove all xml names from qnameset whose namespace matches the uri.
*/
- private static void removeAllMatchingNs(String uri, Set qnameset)
+ private static void removeAllMatchingNs(String uri, Set<QName> qnameset)
{
- for (Iterator i = qnameset.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = qnameset.iterator(); i.hasNext(); )
{
- if (uri.equals(nsFromName((QName)i.next())))
+ if (uri.equals(nsFromName(i.next())))
i.remove();
}
}
@@ -213,11 +213,11 @@ public class QNameSetBuilder implements
* Remove all xml names from qnameset whose namespace is in the
* first set of uris but not the second.
*/
- private static void removeAllMatchingFirstOnly(Set setFirst, Set setSecond, Set qnameset)
+ private static void removeAllMatchingFirstOnly(Set<String> setFirst, Set<String> setSecond, Set<QName> qnameset)
{
- for (Iterator i = qnameset.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = qnameset.iterator(); i.hasNext(); )
{
- String ns = nsFromName((QName)i.next());
+ String ns = nsFromName(i.next());
if (setFirst.contains(ns) && !setSecond.contains(ns))
i.remove();
}
@@ -227,11 +227,11 @@ public class QNameSetBuilder implements
* Remove all xml names from qnameset whose namespace is in both
* sets of uris.
*/
- private static void removeAllMatchingBoth(Set setFirst, Set setSecond, Set qnameset)
+ private static void removeAllMatchingBoth(Set<String> setFirst, Set<String> setSecond, Set<QName> qnameset)
{
- for (Iterator i = qnameset.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = qnameset.iterator(); i.hasNext(); )
{
- String ns = nsFromName((QName)i.next());
+ String ns = nsFromName(i.next());
if (setFirst.contains(ns) && setSecond.contains(ns))
i.remove();
}
@@ -241,11 +241,11 @@ public class QNameSetBuilder implements
* Remove all xml names from qnameset whose namespace is in neither
* set of uris.
*/
- private static void removeAllMatchingNeither(Set setFirst, Set setSecond, Set qnameset)
+ private static void removeAllMatchingNeither(Set<String> setFirst, Set<String> setSecond, Set<QName> qnameset)
{
- for (Iterator i = qnameset.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = qnameset.iterator(); i.hasNext(); )
{
- String ns = nsFromName((QName)i.next());
+ String ns = nsFromName(i.next());
if (!setFirst.contains(ns) && !setSecond.contains(ns))
i.remove();
}
@@ -337,7 +337,7 @@ public class QNameSetBuilder implements
Set otherIncludeURIs = set2.includedURIs();
if (otherIncludeURIs != null)
{
- for (Iterator i = includeURIs.iterator(); i.hasNext(); )
+ for (Iterator<String> i = includeURIs.iterator(); i.hasNext(); )
{
if (otherIncludeURIs.contains(i.next()))
return false;
@@ -346,23 +346,23 @@ public class QNameSetBuilder implements
else
{
Set otherExcludeURIs = set2.excludedURIs();
- for (Iterator i = includeURIs.iterator(); i.hasNext(); )
+ for (Iterator<String> i = includeURIs.iterator(); i.hasNext(); )
{
if (!otherExcludeURIs.contains(i.next()))
return false;
}
}
- for (Iterator i = set1.includedQNamesInExcludedURIs().iterator(); i.hasNext(); )
+ for (Iterator<QName> i = set1.includedQNamesInExcludedURIs().iterator(); i.hasNext(); )
{
- if (set2.contains((QName)i.next()))
+ if (set2.contains(i.next()))
return false;
}
if (includeURIs.size() > 0)
- for (Iterator i = set2.includedQNamesInExcludedURIs().iterator(); i.hasNext(); )
+ for (Iterator<QName> i = set2.includedQNamesInExcludedURIs().iterator(); i.hasNext(); )
{
- if (set1.contains((QName)i.next()))
+ if (set1.contains(i.next()))
return false;
}
@@ -498,30 +498,30 @@ public class QNameSetBuilder implements
/**
* Implementation of add(set) that ignores inversion.
*/
- private void addAllImpl(Set includedURIs, Set excludedURIs, Set includedQNames, Set excludedQNames)
+ private void addAllImpl(Set<String> includedURIs, Set<String> excludedURIs, Set<QName> includedQNames, Set<QName> excludedQNames)
{
boolean exclude = (excludedURIs != null);
Set specialURIs = exclude ? excludedURIs : includedURIs;
- for (Iterator i = _excludedQNames.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = _excludedQNames.iterator(); i.hasNext(); )
{
- QName name = (QName)i.next();
+ QName name = i.next();
String uri = nsFromName(name);
if ((exclude ^ specialURIs.contains(uri)) && !excludedQNames.contains(name))
i.remove();
}
- for (Iterator i = excludedQNames.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = excludedQNames.iterator(); i.hasNext(); )
{
- QName name = (QName)i.next();
+ QName name = i.next();
String uri = nsFromName(name);
if (!_includedURIs.contains(uri) && !_includedQNames.contains(name))
_excludedQNames.add(name);
}
- for (Iterator i = includedQNames.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = includedQNames.iterator(); i.hasNext(); )
{
- QName name = (QName)i.next();
+ QName name = i.next();
String uri = nsFromName(name);
if (!_includedURIs.contains(uri))
_includedQNames.add(name);
@@ -537,16 +537,16 @@ public class QNameSetBuilder implements
else
{
removeAllMatchingNeither(excludedURIs, _includedURIs, _includedQNames);
- for (Iterator i = _includedURIs.iterator(); i.hasNext(); )
+ for (Iterator<String> i = _includedURIs.iterator(); i.hasNext(); )
{
- String uri = (String)i.next();
+ String uri = i.next();
if (!excludedURIs.contains(uri))
i.remove();
}
- for (Iterator i = excludedURIs.iterator(); i.hasNext(); )
+ for (Iterator<String> i = excludedURIs.iterator(); i.hasNext(); )
{
- String uri = (String)i.next();
+ String uri = i.next();
if (!_includedURIs.contains(uri))
_includedURIs.add(uri);
else
@@ -594,9 +594,9 @@ public class QNameSetBuilder implements
boolean exclude = (excludedURIs != null);
Set specialURIs = exclude ? excludedURIs : includedURIs;
- for (Iterator i = _includedQNames.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = _includedQNames.iterator(); i.hasNext(); )
{
- QName name = (QName)i.next();
+ QName name = i.next();
String uri = nsFromName(name);
if (exclude ^ specialURIs.contains(uri))
{
@@ -610,17 +610,17 @@ public class QNameSetBuilder implements
}
}
- for (Iterator i = includedQNames.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = includedQNames.iterator(); i.hasNext(); )
{
- QName name = (QName)i.next();
+ QName name = i.next();
String uri = nsFromName(name);
if (_includedURIs.contains(uri))
_excludedQNames.add(name);
}
- for (Iterator i = excludedQNames.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = excludedQNames.iterator(); i.hasNext(); )
{
- QName name = (QName)i.next();
+ QName name = i.next();
String uri = nsFromName(name);
if (_includedURIs.contains(uri) && !_excludedQNames.contains(name))
_includedQNames.add(name);
@@ -635,31 +635,31 @@ public class QNameSetBuilder implements
removeAllMatchingBoth(_includedURIs, includedURIs, _excludedQNames);
}
- for (Iterator i = _includedURIs.iterator(); i.hasNext(); )
+ for (Iterator<String> i = _includedURIs.iterator(); i.hasNext(); )
{
if (exclude ^ specialURIs.contains(i.next()))
i.remove();
}
}
- public Set excludedURIs()
+ public Set<String> excludedURIs()
{
if (_inverted) return Collections.unmodifiableSet(_includedURIs);
return null;
}
- public Set includedURIs()
+ public Set<String> includedURIs()
{
if (!_inverted) return _includedURIs;
return null;
}
- public Set excludedQNamesInIncludedURIs()
+ public Set<QName> excludedQNamesInIncludedURIs()
{
return Collections.unmodifiableSet(_inverted ? _includedQNames : _excludedQNames);
}
- public Set includedQNamesInExcludedURIs()
+ public Set<QName> includedQNamesInExcludedURIs()
{
return Collections.unmodifiableSet(_inverted ? _excludedQNames : _includedQNames);
}
@@ -679,22 +679,22 @@ public class QNameSetBuilder implements
StringBuilder sb = new StringBuilder();
sb.append("QNameSetBuilder");
sb.append(_inverted ? "-(" : "+(");
- for (Iterator i = _includedURIs.iterator(); i.hasNext(); )
+ for (Iterator<String> i = _includedURIs.iterator(); i.hasNext(); )
{
sb.append("+*@");
sb.append(i.next());
sb.append(", ");
}
- for (Iterator i = _excludedQNames.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = _excludedQNames.iterator(); i.hasNext(); )
{
sb.append("-");
- sb.append(prettyQName((QName)i.next()));
+ sb.append(prettyQName(i.next()));
sb.append(", ");
}
- for (Iterator i = _includedQNames.iterator(); i.hasNext(); )
+ for (Iterator<QName> i = _includedQNames.iterator(); i.hasNext(); )
{
sb.append("+");
- sb.append(prettyQName((QName)i.next()));
+ sb.append(prettyQName(i.next()));
sb.append(", ");
}
int index = sb.lastIndexOf(", ");
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/XmlValidationError.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/XmlValidationError.java?rev=1896795&r1=1896794&r2=1896795&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/XmlValidationError.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/XmlValidationError.java Fri Jan 7 12:29:45 2022
@@ -31,9 +31,9 @@ import java.util.List;
* <br>
* <pre>
* xobj.validate(new XmlOptions().setErrorListener(errors))
- * for (Iterator it = errors.iterator(); it.hasNext(); )
+ * for (Iterator<XmlError> it = errors.iterator(); it.hasNext(); )
* {
- * XmlError err = (XmlError)it.next());
+ * XmlError err = it.next());
* if (err instanceof XmlValidationError)
* {
* XmlValidationError validationError = (XmlValidationError) err;
@@ -126,7 +126,7 @@ public class XmlValidationError extends
private QName _offendingQName;
private SchemaType _expectedSchemaType;
- private List _expectedQNames;
+ private List<QName> _expectedQNames;
private int _errorType;
private SchemaType _badSchemaType;
@@ -138,7 +138,7 @@ public class XmlValidationError extends
// KHK: remove this
private XmlValidationError(String message, int severity,
XmlCursor cursor, QName fieldQName, QName offendingQname, SchemaType expectedSchemaType,
- List expectedQNames, int errorType, SchemaType badSchemaType)
+ List<QName> expectedQNames, int errorType, SchemaType badSchemaType)
{
super(message, (String)null, severity, cursor);
@@ -156,7 +156,7 @@ public class XmlValidationError extends
*/
private XmlValidationError(String code, Object[] args, int severity,
XmlCursor cursor, QName fieldQName, QName offendingQname, SchemaType expectedSchemaType,
- List expectedQNames, int errorType, SchemaType badSchemaType)
+ List<QName> expectedQNames, int errorType, SchemaType badSchemaType)
{
super(code, args, severity, cursor);
@@ -175,7 +175,7 @@ public class XmlValidationError extends
// KHK: remove this
private XmlValidationError(String message, int severity,
Location loc, QName fieldQName, QName offendingQname, SchemaType expectedSchemaType,
- List expectedQNames, int errorType, SchemaType badSchemaType)
+ List<QName> expectedQNames, int errorType, SchemaType badSchemaType)
{
super(message, (String)null, severity, loc);
@@ -193,7 +193,7 @@ public class XmlValidationError extends
*/
private XmlValidationError(String code, Object[] args, int severity,
Location loc, QName fieldQName, QName offendingQname, SchemaType expectedSchemaType,
- List expectedQNames, int errorType, SchemaType badSchemaType)
+ List<QName> expectedQNames, int errorType, SchemaType badSchemaType)
{
super(code, args, severity, loc);
@@ -207,7 +207,7 @@ public class XmlValidationError extends
public static XmlValidationError forCursorWithDetails( String message, String code, Object[] args, int severity,
XmlCursor cursor, QName fieldQName, QName offendingQname, SchemaType expectedSchemaType,
- List expectedQNames, int errorType, SchemaType badSchemaType)
+ List<QName> expectedQNames, int errorType, SchemaType badSchemaType)
{
if (code == null)
return new XmlValidationError(message, severity, cursor, fieldQName, offendingQname,
@@ -219,7 +219,7 @@ public class XmlValidationError extends
public static XmlValidationError forLocationWithDetails( String message, String code, Object[] args, int severity,
Location location, QName fieldQName, QName offendingQname, SchemaType expectedSchemaType,
- List expectedQNames, int errorType, SchemaType badSchemaType)
+ List<QName> expectedQNames, int errorType, SchemaType badSchemaType)
{
if (code == null)
return new XmlValidationError(message, severity, location, fieldQName, offendingQname,
@@ -269,12 +269,12 @@ public class XmlValidationError extends
this._errorType = _errorType;
}
- public List getExpectedQNames()
+ public List<QName> getExpectedQNames()
{
return _expectedQNames;
}
- public void setExpectedQNames(List _expectedQNames)
+ public void setExpectedQNames(List<QName> _expectedQNames)
{
this._expectedQNames = _expectedQNames;
}
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/Inst2Xsd.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/Inst2Xsd.java?rev=1896795&r1=1896794&r2=1896795&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/Inst2Xsd.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/inst2xsd/Inst2Xsd.java Fri Jan 7 12:29:45 2022
@@ -298,7 +298,7 @@ public class Inst2Xsd
private static boolean validateInstances(SchemaDocument[] sDocs, XmlObject[] instances)
{
SchemaTypeLoader sLoader;
- Collection compErrors = new ArrayList();
+ Collection<XmlError> compErrors = new ArrayList();
XmlOptions schemaOptions = new XmlOptions();
schemaOptions.setErrorListener(compErrors);
try
@@ -312,9 +312,9 @@ public class Inst2Xsd
e.printStackTrace(System.out);
}
System.out.println("\n-------------------\n\nInvalid schemas.");
- for (Iterator errors = compErrors.iterator(); errors.hasNext(); )
+ for (Iterator<XmlError> errors = compErrors.iterator(); errors.hasNext(); )
{
- XmlError xe = (XmlError)errors.next();
+ XmlError xe = errors.next();
System.out.println(xe.getLine() + ":" + xe.getColumn() + " " + xe.getMessage());
}
return false;
@@ -339,7 +339,7 @@ public class Inst2Xsd
continue;
}
- Collection errors = new ArrayList();
+ Collection<XmlError> errors = new ArrayList();
if (xobj.schemaType() == XmlObject.type)
{
@@ -352,9 +352,9 @@ public class Inst2Xsd
else
{
System.out.println("Instance[" + i + "] NOT valid - " + instances[i].documentProperties().getSourceName());
- for (Iterator it = errors.iterator(); it.hasNext(); )
+ for (Iterator<XmlError> it = errors.iterator(); it.hasNext(); )
{
- XmlError xe = (XmlError)it.next();
+ XmlError xe = it.next();
System.out.println(xe.getLine() + ":" + xe.getColumn() + " " + xe.getMessage());
}
result = false;
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/xsd2inst/SchemaInstanceGenerator.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/xsd2inst/SchemaInstanceGenerator.java?rev=1896795&r1=1896794&r2=1896795&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/xsd2inst/SchemaInstanceGenerator.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/xsd2inst/SchemaInstanceGenerator.java Fri Jan 7 12:29:45 2022
@@ -18,6 +18,7 @@ package org.apache.xmlbeans.impl.xsd2ins
import org.apache.xmlbeans.SchemaType;
import org.apache.xmlbeans.SchemaTypeSystem;
import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlError;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
@@ -29,6 +30,7 @@ import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -245,7 +247,9 @@ public class SchemaInstanceGenerator
SchemaTypeSystem sts = null;
if (schemas.length > 0)
{
+ List<XmlError> errors = new ArrayList<>();
XmlOptions compileOptions = new XmlOptions();
+ compileOptions.setErrorListener(errors);
if (options.isNetworkDownloads())
compileOptions.setCompileDownloadUrls();
if (options.isNopvr())
@@ -259,7 +263,12 @@ public class SchemaInstanceGenerator
}
catch (Exception e)
{
- e.printStackTrace();
+ if (errors.isEmpty() || !(e instanceof XmlException))
+ e.printStackTrace();
+
+ System.out.println("Schema compilation errors: ");
+ for (Iterator<XmlError> i = errors.iterator(); i.hasNext(); )
+ System.out.println(i.next());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org