You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2020/09/09 22:17:28 UTC
svn commit: r1881601 - in
/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl: store/ tool/ values/
Author: kiwiwings
Date: Wed Sep 9 22:17:28 2020
New Revision: 1881601
URL: http://svn.apache.org/viewvc?rev=1881601&view=rev
Log:
spotbugs fixes and cleanups
Modified:
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/AttrXobj.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/CommentXobj.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DocumentFragXobj.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DocumentXobj.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/ElementXobj.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/ProcInstXobj.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Saver.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Xobj.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/CodeGenUtil.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/TypeStore.java
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/XmlObjectBase.java
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/AttrXobj.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/AttrXobj.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/AttrXobj.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/AttrXobj.java Wed Sep 9 22:17:28 2020
@@ -22,6 +22,8 @@ import org.w3c.dom.TypeInfo;
import javax.xml.namespace.QName;
+import static org.apache.xmlbeans.impl.store.Cur.ATTR;
+
class AttrXobj extends NamedNodeXobj implements Attr {
AttrXobj(Locale l, QName name) {
super(l, ATTR, DomImpl.ATTR);
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/CommentXobj.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/CommentXobj.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/CommentXobj.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/CommentXobj.java Wed Sep 9 22:17:28 2020
@@ -19,6 +19,8 @@ import org.w3c.dom.Comment;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import static org.apache.xmlbeans.impl.store.Cur.COMMENT;
+
class CommentXobj extends NodeXobj implements Comment {
CommentXobj(Locale l) {
super(l, COMMENT, DomImpl.COMMENT);
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java Wed Sep 9 22:17:28 2020
@@ -302,7 +302,7 @@ public final class Cur {
return new ElementXobj(l, name);
}
- Class c = l._saaj.identifyElement(name, parentName);
+ Class<?> c = l._saaj.identifyElement(name, parentName);
if (c == SOAPElement.class) {
return new SoapElementXobj(l, name);
@@ -1204,7 +1204,6 @@ public final class Cur {
//noinspection StatementWithEmptyBody
while (toNextAttr()) {
- ;
}
return true;
@@ -2851,7 +2850,7 @@ public final class Cur {
private QName checkName(QName name, boolean local) {
if (_substituteNamespaces != null && (!local || name.getNamespaceURI().length() > 0)) {
- String substituteUri = (String) _substituteNamespaces.get(name.getNamespaceURI());
+ String substituteUri = _substituteNamespaces.get(name.getNamespaceURI());
if (substituteUri != null) {
name = _locale.makeQName(substituteUri, name.getLocalPart(), name.getPrefix());
@@ -2890,7 +2889,7 @@ public final class Cur {
// I change their value!
if (_substituteNamespaces != null) {
- String substituteUri = (String) _substituteNamespaces.get(uri);
+ String substituteUri = _substituteNamespaces.get(uri);
if (substituteUri != null) {
uri = substituteUri;
@@ -3078,7 +3077,6 @@ public final class Cur {
//noinspection StatementWithEmptyBody
while (c.toParent()) {
- ;
}
c.next();
@@ -3187,13 +3185,13 @@ public final class Cur {
private Xobj _lastXobj;
private int _lastPos;
- private boolean _discardDocElem;
- private QName _replaceDocElem;
+ private final boolean _discardDocElem;
+ private final QName _replaceDocElem;
private final boolean _stripWhitespace;
private final boolean _stripComments;
private final boolean _stripProcinsts;
- private final Map _substituteNamespaces;
- private final Map _additionalNamespaces;
+ private final Map<String,String> _substituteNamespaces;
+ private final Map<String,String> _additionalNamespaces;
private String _doctypeName;
private String _doctypePublicId;
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DocumentFragXobj.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DocumentFragXobj.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DocumentFragXobj.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DocumentFragXobj.java Wed Sep 9 22:17:28 2020
@@ -17,6 +17,8 @@ package org.apache.xmlbeans.impl.store;
import org.w3c.dom.DocumentFragment;
+import static org.apache.xmlbeans.impl.store.Cur.ROOT;
+
class DocumentFragXobj extends NodeXobj implements DocumentFragment {
DocumentFragXobj(Locale l) {
super(l, ROOT, DomImpl.DOCFRAG);
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DocumentXobj.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DocumentXobj.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DocumentXobj.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/DocumentXobj.java Wed Sep 9 22:17:28 2020
@@ -17,6 +17,8 @@ package org.apache.xmlbeans.impl.store;
import org.w3c.dom.*;
+import static org.apache.xmlbeans.impl.store.Cur.ROOT;
+
class DocumentXobj extends NodeXobj implements Document {
DocumentXobj(Locale l) {
super(l, ROOT, DomImpl.DOCUMENT);
@@ -79,9 +81,13 @@ class DocumentXobj extends NodeXobj impl
}
public Element getElementById(String elementId) {
- if (_idToElement == null) return null;
+ if (_idToElement == null) {
+ return null;
+ }
Xobj o = (Xobj) _idToElement.get(elementId);
- if (o == null) return null;
+ if (o == null) {
+ return null;
+ }
if (!isInSameTree(o)) {
_idToElement.remove(elementId);
}
@@ -162,15 +168,17 @@ class DocumentXobj extends NodeXobj impl
}
protected void addIdElement(String idVal, DomImpl.Dom e) {
- if (_idToElement == null)
- _idToElement = new java.util.Hashtable();
+ if (_idToElement == null) {
+ _idToElement = new java.util.Hashtable<>();
+ }
_idToElement.put(idVal, e);
}
void removeIdElement(String idVal) {
- if (_idToElement != null)
+ if (_idToElement != null) {
_idToElement.remove(idVal);
+ }
}
- private java.util.Hashtable _idToElement;
+ private java.util.Hashtable<String,DomImpl.Dom> _idToElement;
}
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/ElementXobj.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/ElementXobj.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/ElementXobj.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/ElementXobj.java Wed Sep 9 22:17:28 2020
@@ -19,6 +19,8 @@ import org.w3c.dom.*;
import javax.xml.namespace.QName;
+import static org.apache.xmlbeans.impl.store.Cur.ELEM;
+
class ElementXobj extends NamedNodeXobj implements Element {
ElementXobj(Locale l, QName name) {
super(l, ELEM, DomImpl.ELEMENT);
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/ProcInstXobj.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/ProcInstXobj.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/ProcInstXobj.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/ProcInstXobj.java Wed Sep 9 22:17:28 2020
@@ -18,6 +18,8 @@ package org.apache.xmlbeans.impl.store;
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
+import static org.apache.xmlbeans.impl.store.Cur.PROCINST;
+
class ProcInstXobj extends NodeXobj implements ProcessingInstruction {
ProcInstXobj(Locale l, String target) {
super(l, PROCINST, DomImpl.PROCINST);
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Saver.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Saver.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Saver.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Saver.java Wed Sep 9 22:17:28 2020
@@ -110,7 +110,7 @@ abstract class Saver {
// If the default prefix has not been mapped, do so now
if (getNamespaceForPrefix("") == null) {
- _initialDefaultUri = new String("");
+ _initialDefaultUri = "";
addMapping("", _initialDefaultUri);
}
@@ -262,7 +262,7 @@ abstract class Saver {
(ch >= 0x20 && ch <= 0xD7FF) ||
(ch >= 0xE000 && ch <= 0xFFFD) ||
// TODO: ch >= 0x10000 && ch <= 0x10FFFF is always false for a char, use codepoints/ints
- (ch >= 0x10000 && ch <= 0x10FFFF) ||
+ // (ch >= 0x10000 && ch <= 0x10FFFF) ||
(ch == 0x9) || (ch == 0xA) || (ch == 0xD)
);
}
@@ -2733,7 +2733,7 @@ abstract class Saver {
String prefix = null;
- if (uri != null && uri.length() != 0) {
+ if (!uri.isEmpty()) {
prefix = name.getPrefix();
String mappedUri = saver.getNamespaceForPrefix(prefix);
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Xobj.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Xobj.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Xobj.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Xobj.java Wed Sep 9 22:17:28 2020
@@ -31,19 +31,13 @@ import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.xmlbeans.impl.store.Cur.*;
// DOM Level 3
abstract class Xobj implements TypeStore {
- static final int TEXT = Cur.TEXT;
- static final int ROOT = Cur.ROOT;
- static final int ELEM = Cur.ELEM;
- static final int ATTR = Cur.ATTR;
- static final int COMMENT = Cur.COMMENT;
- static final int PROCINST = Cur.PROCINST;
-
- static final int END_POS = Cur.END_POS;
- static final int NO_POS = Cur.NO_POS;
Xobj(Locale l, int kind, int domType) {
assert kind == ROOT || kind == ELEM || kind == ATTR || kind == COMMENT || kind == PROCINST;
@@ -52,10 +46,6 @@ abstract class Xobj implements TypeStore
_bits = (domType << 4) + kind;
}
- final boolean entered() {
- return _locale.entered();
- }
-
final int kind() {
return _bits & 0xF;
}
@@ -101,10 +91,6 @@ abstract class Xobj implements TypeStore
return isAttr() && Locale.isXmlns(_name);
}
- final int cchValue() {
- return _cchValue;
- }
-
final int cchAfter() {
return _cchAfter;
}
@@ -209,8 +195,6 @@ abstract class Xobj implements TypeStore
/**
* can one use the _firstChild pointer to retrieve
* the first DOM child
- *
- * @return
*/
final protected boolean isFirstChildPtrDomUsable() {
if (_firstChild == null &&
@@ -233,8 +217,6 @@ abstract class Xobj implements TypeStore
/**
* can one use the _nextSibling pointer to retrieve
* the next DOM sibling
- *
- * @return
*/
final protected boolean isNextSiblingPtrDomUsable() {
if (_charNodesAfter == null &&
@@ -250,18 +232,13 @@ abstract class Xobj implements TypeStore
/**
* can one use the _charNodesValue pointer to retrieve
* the next DOM sibling
- *
- * @return
*/
final protected boolean isExistingCharNodesValueUsable() {
if (_srcValue == null) {
return false;
}
- if (_charNodesValue != null && _charNodesValue._next == null
- && _charNodesValue._cch == _cchValue) {
- return true;
- }
- return false;
+ return _charNodesValue != null && _charNodesValue._next == null
+ && _charNodesValue._cch == _cchValue;
}
final protected boolean isCharNodesValueUsable() {
@@ -274,8 +251,6 @@ abstract class Xobj implements TypeStore
/**
* can one use the _charNodesAfter pointer to retrieve
* the next DOM sibling
- *
- * @return
*/
final protected boolean isCharNodesAfterUsable() {
if (_srcAfter == null) {
@@ -357,7 +332,7 @@ abstract class Xobj implements TypeStore
}
public void dump(PrintStream o, Object ref) {
- Cur.dump(o, (Xobj) this, ref);
+ Cur.dump(o, this, ref);
}
public void dump(PrintStream o) {
@@ -404,7 +379,7 @@ abstract class Xobj implements TypeStore
offset = 0;
}
- return xIn == this && pIn >= p && pIn < p + (cch < 0 ? cchRight(p) : cch) + offset;
+ return xIn == this && pIn >= p && pIn < p + cch + offset;
}
// Is x/p just after the end of this
@@ -639,11 +614,7 @@ abstract class Xobj implements TypeStore
}
final boolean isValid() {
- if (isVacant() && (_cchValue != 0 || _user == null)) {
- return false;
- }
-
- return true;
+ return !isVacant() || (_cchValue == 0 && _user != null);
}
final int posTemp() {
@@ -676,7 +647,6 @@ abstract class Xobj implements TypeStore
// left!
final Xobj getDenormal(int p) {
- assert END_POS == -1;
assert !isRoot() || p == END_POS || p > 0;
Xobj x = this;
@@ -730,11 +700,7 @@ abstract class Xobj implements TypeStore
}
}
- if (p == posAfter() - 1) {
- return false;
- }
-
- return true;
+ return p != posAfter() - 1;
}
final Xobj walk(Xobj root, boolean walkChildren) {
@@ -751,7 +717,7 @@ abstract class Xobj implements TypeStore
return null;
}
- final Xobj removeXobj() {
+ final void removeXobj() {
if (_parent != null) {
if (_parent._firstChild == this) {
_parent._firstChild = _nextSibling;
@@ -774,10 +740,9 @@ abstract class Xobj implements TypeStore
_nextSibling = null;
}
- return this;
}
- final Xobj insertXobj(Xobj s) {
+ final void insertXobj(Xobj s) {
assert _locale == s._locale;
assert !s.isRoot() && !isRoot();
assert s._parent == null;
@@ -798,7 +763,6 @@ abstract class Xobj implements TypeStore
_prevSibling = s;
- return this;
}
final Xobj appendXobj(Xobj c) {
@@ -900,20 +864,6 @@ abstract class Xobj implements TypeStore
}
}
- static final void disbandXobjs(Xobj first, Xobj last) {
- assert last._locale == first._locale;
- assert first._parent == null && last._parent == null;
- assert first._prevSibling == null;
- assert last._nextSibling == null;
- assert !first.isRoot();
-
- while (first != null) {
- Xobj next = first._nextSibling;
- first._nextSibling = first._prevSibling = null;
- first = next;
- }
- }
-
// Potential attr is going to be moved/removed, invalidate parent if it is a special attr
final void invalidateSpecialAttr(Xobj newParent) {
@@ -1002,8 +952,6 @@ abstract class Xobj implements TypeStore
// no bookmarks in the span of text to be removed.
for (Bookmark b = _bookmarks; b != null; ) {
- Bookmark next = b._next;
-
// Similarly, as above, I can't call inChars here
assert b._xobj == this;
@@ -1255,42 +1203,6 @@ abstract class Xobj implements TypeStore
return getValueAsString(Locale.WS_PRESERVE);
}
- String getString(int p, int cch) {
- int cchRight = cchRight(p);
-
- if (cchRight == 0) {
- return "";
- }
-
- if (cch < 0 || cch > cchRight) {
- cch = cchRight;
- }
-
- int pa = posAfter();
-
- assert p > 0;
-
- String s;
-
- if (p >= pa) {
- s = CharUtil.getString(_srcAfter, _offAfter + p - pa, cch);
-
- if (p == pa && cch == _cchAfter) {
- _srcAfter = s;
- _offAfter = 0;
- }
- } else {
- s = CharUtil.getString(_srcValue, _offValue + p - 1, cch);
-
- if (p == 1 && cch == _cchValue) {
- _srcValue = s;
- _offValue = 0;
- }
- }
-
- return s;
- }
-
// Returns just chars just after the begin tag ... does not get all the text if there are
// children
@@ -1872,7 +1784,7 @@ abstract class Xobj implements TypeStore
try {
Cur c = tempCur();
- Validate validate = new Validate(c, eventSink);
+ new Validate(c, eventSink);
c.release();
} finally {
_locale.exit();
@@ -2072,7 +1984,8 @@ abstract class Xobj implements TypeStore
return null;
}
- public void find_all_element_users(QName name, List fillMeUp) {
+ @Override
+ public void find_all_element_users(QName name, List<TypeStoreUser> fillMeUp) {
for (Xobj x = _firstChild; x != null; x = x._nextSibling) {
if (x.isElem() && x._name.equals(name)) {
fillMeUp.add(x.getUser());
@@ -2080,7 +1993,8 @@ abstract class Xobj implements TypeStore
}
}
- public void find_all_element_users(QNameSet names, List fillMeUp) {
+ @Override
+ public void find_all_element_users(QNameSet names, List<TypeStoreUser> fillMeUp) {
for (Xobj x = _firstChild; x != null; x = x._nextSibling) {
if (x.isElem() && names.contains(x._name)) {
fillMeUp.add(x.getUser());
@@ -2346,7 +2260,6 @@ abstract class Xobj implements TypeStore
public TypeStoreUser copy(SchemaTypeLoader stl, SchemaType type, XmlOptions options) {
//do not use a user's Factory method for copying.
//XmlFactoryHook hook = XmlFactoryHook.ThreadContext.getHook();
- Xobj destination = null;
options = XmlOptions.maskNull(options);
SchemaType sType = options.getDocumentType();
@@ -2359,11 +2272,8 @@ abstract class Xobj implements TypeStore
locale = Locale.getLocale(stl, options);
}
- if (sType.isDocumentType() || (sType.isNoType() && (this instanceof DocumentXobj))) {
- destination = Cur.createDomDocumentRootXobj(locale, false);
- } else {
- destination = Cur.createDomDocumentRootXobj(locale, true);
- }
+ boolean isFragment = !sType.isDocumentType() && !(sType.isNoType() && (this instanceof DocumentXobj));
+ Xobj destination = Cur.createDomDocumentRootXobj(locale, isFragment);
locale.enter();
@@ -2375,8 +2285,7 @@ abstract class Xobj implements TypeStore
locale.exit();
}
- TypeStoreUser tsu = destination.copy_contents_from(this);
- return tsu;
+ return destination.copy_contents_from(this);
}
public void array_setter(XmlObject[] sources, QName elementName) {
@@ -2387,19 +2296,19 @@ abstract class Xobj implements TypeStore
int m = sources.length;
- ArrayList copies = new ArrayList();
- ArrayList types = new ArrayList();
+ List<Xobj> copies = new ArrayList<>();
+ List<SchemaType> types = new ArrayList<>();
- for (int i = 0; i < m; i++) {
+ for (XmlObject source : sources) {
// TODO - deal with null sources[ i ] here -- what to do?
- if (sources[i] == null) {
+ if (source == null) {
throw new IllegalArgumentException("Array element null");
- } else if (sources[i].isImmutable()) {
+ } else if (source.isImmutable()) {
copies.add(null);
types.add(null);
} else {
- Xobj x = ((Xobj) ((TypeStoreUser) sources[i]).get_store());
+ Xobj x = ((Xobj) ((TypeStoreUser) source).get_store());
if (x._locale == _locale) {
copies.add(x.copyNode(_locale));
@@ -2413,7 +2322,7 @@ abstract class Xobj implements TypeStore
}
}
- types.add(sources[i].schemaType());
+ types.add(source.schemaType());
}
}
@@ -2429,20 +2338,21 @@ abstract class Xobj implements TypeStore
assert m == n;
- ArrayList elements = new ArrayList();
+ List<TypeStoreUser> elementsUser = new ArrayList<>();
- find_all_element_users(elementName, elements);
+ find_all_element_users(elementName, elementsUser);
- for (int i = 0; i < elements.size(); i++) {
- elements.set(i, (Xobj) ((TypeStoreUser) elements.get(i)).get_store());
- }
+ List<Xobj> elements = elementsUser.stream()
+ .map(TypeStoreUser::get_store)
+ .map(x -> (Xobj)x)
+ .collect(Collectors.toList());
assert elements.size() == n;
Cur c = tempCur();
for (int i = 0; i < n; i++) {
- Xobj x = (Xobj) elements.get(i);
+ Xobj x = elements.get(i);
if (sources[i].isImmutable()) {
x.getObject().set(sources[i]);
@@ -2452,9 +2362,9 @@ abstract class Xobj implements TypeStore
c.moveTo(x);
c.next();
- Cur.moveNodeContents((Xobj) copies.get(i), c, true);
+ Cur.moveNodeContents(copies.get(i), c, true);
- x.change_type((SchemaType) types.get(i));
+ x.change_type(types.get(i));
}
}
@@ -2468,7 +2378,7 @@ abstract class Xobj implements TypeStore
throw new RuntimeException("Not implemeneted");
}
- public XmlObject[] exec_query(String queryExpr, XmlOptions options) throws XmlException {
+ public XmlObject[] exec_query(String queryExpr, XmlOptions options) {
_locale.enter();
try {
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/CodeGenUtil.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/CodeGenUtil.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/CodeGenUtil.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/tool/CodeGenUtil.java Wed Sep 9 22:17:28 2020
@@ -17,89 +17,68 @@ package org.apache.xmlbeans.impl.tool;
import org.apache.xmlbeans.SystemProperties;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Iterator;
-import java.util.Arrays;
-import java.io.File;
-import java.io.InputStream;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.FileFilter;
-import java.io.FileWriter;
+import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
-public class CodeGenUtil
-{
- public static String DEFAULT_MEM_START = "8m";
- public static String DEFAULT_MEM_MAX = "256m";
- public static String DEFAULT_COMPILER = "javac";
- public static String DEFAULT_JAR = "jar";
+public class CodeGenUtil {
+ public static final String DEFAULT_MEM_START = "8m";
+ public static final String DEFAULT_MEM_MAX = "256m";
+ public static final String DEFAULT_COMPILER = "javac";
+ public static final String DEFAULT_JAR = "jar";
//workaround for Sun bug # 4723726
- public static URI resolve(URI base, URI child)
- {
+ public static URI resolve(URI base, URI child) {
URI ruri = base.resolve(child);
-
+
//fix up normalization bug
- if ("file".equals(ruri.getScheme()) && ! child.equals(ruri))
- {
- if (base.getPath().startsWith("//") && !ruri.getPath().startsWith("//"))
- {
+ if ("file".equals(ruri.getScheme()) && !child.equals(ruri)) {
+ if (base.getPath().startsWith("//") && !ruri.getPath().startsWith("//")) {
String path = "///".concat(ruri.getPath());
- try
- {
+ try {
ruri = new URI("file", null, path, ruri.getQuery(), ruri.getFragment());
+ } catch (URISyntaxException ignored) {
}
- catch(URISyntaxException uris)
- {}
}
}
return ruri;
}
-
- static void addAllJavaFiles(List srcFiles, List args)
- {
- for (Iterator i = srcFiles.iterator(); i.hasNext(); )
- {
- File f = (File)i.next();
- if (!f.isDirectory())
- {
+
+ static void addAllJavaFiles(List<File> srcFiles, List<String> args) {
+ for (File f : srcFiles) {
+ if (f.isDirectory()) {
+ File[] files = f.listFiles(
+ file -> (file.isFile() && file.getName().endsWith(".java")) || file.isDirectory()
+ );
+ if (files != null) {
+ addAllJavaFiles(Arrays.asList(files), args);
+ }
+ } else {
args.add(quoteAndEscapeFilename(f.getAbsolutePath()));
}
- else
- {
- List inside = (Arrays.asList(f.listFiles(
- new FileFilter()
- {
- public boolean accept(File file)
- { return (file.isFile() && file.getName().endsWith(".java")) || file.isDirectory(); }
- }
- )));
- addAllJavaFiles(inside, args);
- }
}
}
- static private String quoteAndEscapeFilename(String filename)
- {
+ static private String quoteAndEscapeFilename(String filename) {
// don't quote if there's no space
- if (filename.indexOf(" ") < 0)
+ if (!filename.contains(" ")) {
return filename;
+ }
// bizarre. javac expects backslash escaping if we quote the classpath
// bizarre also. replaceAll expects replacement backslashes to be double escaped.
return "\"" + filename.replaceAll("\\\\", "\\\\\\\\") + "\"";
}
- static private String quoteNoEscapeFilename(String filename)
- {
+ static private String quoteNoEscapeFilename(String filename) {
// don't quote if there's no space, and don't quote on linux
- if (filename.indexOf(" ") < 0 || File.separatorChar == '/')
- return filename;
-
- return "\"" + filename + "\"";
+ return (!filename.contains(" ") || File.separatorChar == '/') ? filename : "\"" + filename + "\"";
}
/**
@@ -110,48 +89,40 @@ public class CodeGenUtil
*
* @deprecated
*/
- static public boolean externalCompile(List srcFiles, File outdir, File[] cp, boolean debug)
- {
+ public static boolean externalCompile(List<File> srcFiles, File outdir, File[] cp, boolean debug) {
return externalCompile(srcFiles, outdir, cp, debug, DEFAULT_COMPILER, null, DEFAULT_MEM_START, DEFAULT_MEM_MAX, false, false);
}
// KHK: temporary to avoid build break
- static public boolean externalCompile(List srcFiles, File outdir, File[] cp, boolean debug, String javacPath, String memStart, String memMax, boolean quiet, boolean verbose)
- {
+ public static boolean externalCompile(List<File> srcFiles, File outdir, File[] cp, boolean debug, String javacPath, String memStart, String memMax, boolean quiet, boolean verbose) {
return externalCompile(srcFiles, outdir, cp, debug, javacPath, null, memStart, memMax, quiet, verbose);
}
-
+
/**
* Invokes javac on the generated source files in order to turn them
* into binary files in the output directory. This will return a list of
* <code>GenFile</code>s for all of the classes produced or null if an
* error occurred.
*/
- static public boolean externalCompile(List srcFiles, File outdir, File[] cp, boolean debug, String javacPath, String genver, String memStart, String memMax, boolean quiet, boolean verbose)
- {
- List args = new ArrayList();
+ public static boolean externalCompile(List<File> srcFiles, File outdir, File[] cp, boolean debug, String javacPath, String genver, String memStart, String memMax, boolean quiet, boolean verbose) {
+ List<String> args = new ArrayList<>();
File javac = findJavaTool(javacPath == null ? DEFAULT_COMPILER : javacPath);
assert (javac.exists()) : "compiler not found " + javac;
args.add(javac.getAbsolutePath());
- if (outdir == null)
- {
+ if (outdir == null) {
outdir = new File(".");
- }
- else
- {
+ } else {
args.add("-d");
args.add(quoteAndEscapeFilename(outdir.getAbsolutePath()));
}
- if (cp == null)
- {
+ if (cp == null) {
cp = systemClasspath();
}
- if (cp.length > 0)
- {
+ if (cp.length > 0) {
StringBuilder classPath = new StringBuilder();
// Add the output directory to the classpath. We do this so that
// javac will be able to find classes that were compiled
@@ -159,10 +130,9 @@ public class CodeGenUtil
classPath.append(outdir.getAbsolutePath());
// Add everything on our classpath.
- for (int i = 0; i < cp.length; i++)
- {
+ for (File file : cp) {
classPath.append(File.pathSeparator);
- classPath.append(cp[i].getAbsolutePath());
+ classPath.append(file.getAbsolutePath());
}
args.add("-classpath");
@@ -171,8 +141,9 @@ public class CodeGenUtil
args.add(quoteAndEscapeFilename(classPath.toString()));
}
- if (genver == null)
+ if (genver == null) {
genver = "1.8";
+ }
args.add("-source");
args.add(genver);
@@ -182,49 +153,47 @@ public class CodeGenUtil
args.add(debug ? "-g" : "-g:none");
- if (verbose)
+ if (verbose) {
args.add("-verbose");
+ }
addAllJavaFiles(srcFiles, args);
File clFile = null;
- try
- {
+ try {
clFile = File.createTempFile("javac", "");
- FileWriter fw = new FileWriter(clFile);
- Iterator i = args.iterator();
- for (i.next(); i.hasNext();)
- {
- String arg = (String)i.next();
- fw.write(arg);
- fw.write('\n');
+ try (Writer fw = Files.newBufferedWriter(clFile.toPath(), StandardCharsets.ISO_8859_1)) {
+ Iterator<String> i = args.iterator();
+ for (i.next(); i.hasNext(); ) {
+ String arg = i.next();
+ fw.write(arg);
+ fw.write('\n');
+ }
}
- fw.close();
- List newargs = new ArrayList();
+ List<String> newargs = new ArrayList<>();
newargs.add(args.get(0));
-
- if (memStart != null && memStart.length() != 0)
+
+ if (memStart != null && memStart.length() != 0) {
newargs.add("-J-Xms" + memStart);
- if (memMax != null && memMax.length() != 0)
+ }
+ if (memMax != null && memMax.length() != 0) {
newargs.add("-J-Xmx" + memMax);
-
+ }
+
newargs.add("@" + clFile.getAbsolutePath());
args = newargs;
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
System.err.println("Could not create command-line file for javac");
}
- try
- {
- String[] strArgs = (String[]) args.toArray(new String[args.size()]);
+ try {
+ String[] strArgs = args.toArray(new String[0]);
- if (verbose)
- {
+ if (verbose) {
System.out.print("compile command:");
- for (int i = 0; i < strArgs.length; i++)
- System.out.print(" " + strArgs[i]);
+ for (String strArg : strArgs) {
+ System.out.print(" " + strArg);
+ }
System.out.println();
}
@@ -233,13 +202,12 @@ public class CodeGenUtil
StringBuilder errorBuffer = new StringBuilder();
StringBuilder outputBuffer = new StringBuilder();
- ThreadedReader out = new ThreadedReader(proc.getInputStream(), outputBuffer);
- ThreadedReader err = new ThreadedReader(proc.getErrorStream(), errorBuffer);
+ Thread out = copy(proc.getInputStream(), outputBuffer);
+ Thread err = copy(proc.getErrorStream(), errorBuffer);
proc.waitFor();
- if (verbose || proc.exitValue() != 0)
- {
+ if (verbose || proc.exitValue() != 0) {
if (outputBuffer.length() > 0) {
System.out.println(outputBuffer.toString());
System.out.flush();
@@ -248,50 +216,49 @@ public class CodeGenUtil
System.err.println(errorBuffer.toString());
System.err.flush();
}
-
- if (proc.exitValue() != 0)
+
+ if (proc.exitValue() != 0) {
return false;
+ }
}
- }
- catch (Throwable e)
- {
+ } catch (Throwable e) {
System.err.println(e.toString());
System.err.println(e.getCause());
e.printStackTrace(System.err);
return false;
}
- if (clFile != null)
+ if (clFile != null) {
clFile.delete();
+ }
return true;
}
- public static File[] systemClasspath()
- {
- List cp = new ArrayList();
- String[] systemcp = SystemProperties.getProperty("java.class.path").split(File.pathSeparator);
- for (int i = 0; i < systemcp.length; i++)
- {
- cp.add(new File(systemcp[i]));
- }
- return (File[])cp.toArray(new File[cp.size()]);
- }
-
- /**
- * @deprecated Use org.apache.xmlbeans.impl.common.JarHelper instead.
- */
- static public boolean externalJar(File srcdir, File outfile)
- {
+ public static File[] systemClasspath() {
+ List<File> cp = new ArrayList<>();
+ String jcp = SystemProperties.getProperty("java.class.path");
+ if (jcp != null) {
+ String[] systemcp = jcp.split(File.pathSeparator);
+ for (String s : systemcp) {
+ cp.add(new File(s));
+ }
+ }
+ return cp.toArray(new File[0]);
+ }
+
+ /**
+ * @deprecated Use org.apache.xmlbeans.impl.common.JarHelper instead.
+ */
+ public static boolean externalJar(File srcdir, File outfile) {
return externalJar(srcdir, outfile, DEFAULT_JAR, false, false);
}
- /**
- * @deprecated Use org.apache.xmlbeans.impl.common.JarHelper instead.
- */
- static public boolean externalJar(File srcdir, File outfile, String jarPath, boolean quiet, boolean verbose)
- {
- List args = new ArrayList();
+ /**
+ * @deprecated Use org.apache.xmlbeans.impl.common.JarHelper instead.
+ */
+ public static boolean externalJar(File srcdir, File outfile, String jarPath, boolean quiet, boolean verbose) {
+ List<String> args = new ArrayList<>();
File jar = findJavaTool(jarPath == null ? DEFAULT_JAR : jarPath);
assert (jar.exists()) : "jar not found " + jar;
@@ -305,15 +272,14 @@ public class CodeGenUtil
args.add(".");
- try
- {
- String[] strArgs = (String[]) args.toArray(new String[args.size()]);
+ try {
+ String[] strArgs = args.toArray(new String[0]);
- if (verbose)
- {
+ if (verbose) {
System.out.print("jar command:");
- for (int i = 0; i < strArgs.length; i++)
- System.out.print(" " + strArgs[i]);
+ for (String strArg : strArgs) {
+ System.out.print(" " + strArg);
+ }
System.out.println();
}
@@ -322,13 +288,12 @@ public class CodeGenUtil
StringBuilder errorBuffer = new StringBuilder();
StringBuilder outputBuffer = new StringBuilder();
- ThreadedReader out = new ThreadedReader(proc.getInputStream(), outputBuffer);
- ThreadedReader err = new ThreadedReader(proc.getErrorStream(), errorBuffer);
+ Thread out = copy(proc.getInputStream(), outputBuffer);
+ Thread err = copy(proc.getErrorStream(), errorBuffer);
proc.waitFor();
- if (verbose || proc.exitValue() != 0)
- {
+ if (verbose || proc.exitValue() != 0) {
if (outputBuffer.length() > 0) {
System.out.println(outputBuffer.toString());
System.out.flush();
@@ -338,12 +303,11 @@ public class CodeGenUtil
System.err.flush();
}
- if (proc.exitValue() != 0)
+ if (proc.exitValue() != 0) {
return false;
+ }
}
- }
- catch (Throwable e)
- {
+ } catch (Throwable e) {
e.printStackTrace(System.err);
return false;
}
@@ -353,9 +317,8 @@ public class CodeGenUtil
/**
* Look for tool in current directory and ${JAVA_HOME}/../bin and
* try with .exe file extension.
- */
- private static File findJavaTool(String tool)
- {
+ */
+ private static File findJavaTool(String tool) {
File toolFile = new File(tool);
if (toolFile.isFile()) {
return toolFile;
@@ -365,16 +328,16 @@ public class CodeGenUtil
if (result.isFile()) {
return result;
}
-
+
String home = SystemProperties.getProperty("java.home");
- String sep = File.separator;
+ String sep = File.separator;
result = new File(home + sep + ".." + sep + "bin", tool);
-
+
if (result.isFile()) {
return result;
}
-
+
result = new File(result.getPath() + ".exe");
if (result.isFile()) {
return result;
@@ -398,27 +361,12 @@ public class CodeGenUtil
* Reads the given input stream into the given buffer until there is
* nothing left to read.
*/
- static private class ThreadedReader
- {
- public ThreadedReader(InputStream stream, final StringBuilder output)
- {
- final BufferedReader reader =
- new BufferedReader(new InputStreamReader(stream));
-
- Thread readerThread = new Thread(new Runnable() {
- public void run()
- {
- String s;
- try
- {
- while ((s = reader.readLine()) != null)
- output.append(s + "\n");
- }
- catch (Exception e)
- {}
- }
- });
- readerThread.start();
- }
+ private static Thread copy(InputStream stream, final StringBuilder output) {
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.ISO_8859_1));
+ Thread readerThread = new Thread(() ->
+ reader.lines().forEach(s -> output.append(s).append("\n"))
+ );
+ readerThread.start();
+ return readerThread;
}
}
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/TypeStore.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/TypeStore.java?rev=1881601&r1=1881600&r2=1881601&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/TypeStore.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/values/TypeStore.java Wed Sep 9 22:17:28 2020
@@ -15,19 +15,13 @@
package org.apache.xmlbeans.impl.values;
-import org.apache.xmlbeans.SchemaField;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.SchemaTypeLoader;
-import org.apache.xmlbeans.XmlCursor;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.QNameSet;
-import java.util.List;
-import javax.xml.namespace.QName;
+import org.apache.xmlbeans.*;
import org.apache.xmlbeans.impl.common.ValidatorListener;
import org.apache.xmlbeans.impl.common.XmlLocale;
+import javax.xml.namespace.QName;
+import java.util.List;
+
public interface TypeStore extends NamespaceManager
{
/**
@@ -81,10 +75,10 @@ public interface TypeStore extends Names
// BUGBUG (ericvas) 12111
String fetch_text(int whitespaceRule);
- public static int WS_UNSPECIFIED = 0;
- public static int WS_PRESERVE = 1;
- public static int WS_REPLACE = 2;
- public static int WS_COLLAPSE = 3;
+ int WS_UNSPECIFIED = 0;
+ int WS_PRESERVE = 1;
+ int WS_REPLACE = 2;
+ int WS_COLLAPSE = 3;
/**
* A user of a TypeStore calls store_text when he wants the TypeStore
@@ -132,9 +126,9 @@ public interface TypeStore extends Names
*/
SchemaField get_schema_field();
- public static final int NILLABLE = 1;
- public static final int HASDEFAULT = 2;
- public static final int FIXED = 4; // always set with HASDEFAULT
+ int NILLABLE = 1;
+ int HASDEFAULT = 2;
+ int FIXED = 4; // always set with HASDEFAULT
/**
* Called when the value has been nilled or unnilled, so the textstore
@@ -170,11 +164,6 @@ public interface TypeStore extends Names
* and then follow with an add_element_etc if we choose to,
* without randomly catching exceptions.
*/
-// BUGBUG - this should be called find_element
-// BUGBUG - this should be called find_element
-// BUGBUG - this should be called find_element
-// BUGBUG - this should be called find_element
-// BUGBUG - this should be called find_element
TypeStoreUser find_element_user(QName name, int i);
/**
@@ -187,18 +176,14 @@ public interface TypeStore extends Names
* given name owned by this typestore, or the empty array of
* TypeStoreUsers if none was found.
*/
-// BUGBUG - this should be called find_all_element
-// BUGBUG - this should be called find_all_element
-// BUGBUG - this should be called find_all_element
-// BUGBUG - this should be called find_all_element
- void find_all_element_users(QName name, List fillMeUp);
+ void find_all_element_users(QName name, List<TypeStoreUser> fillMeUp);
/**
* Returns all TypeStoreUsers corresponding to elements with one
* of the names is the QNameSet.
*/
- void find_all_element_users(QNameSet name, List fillMeUp);
+ void find_all_element_users(QNameSet name, List<TypeStoreUser> fillMeUp);
/**
* Inserts a new element at the position that will make it
@@ -214,10 +199,6 @@ public interface TypeStore extends Names
* Should throw an IndexOutOfBoundsException if i < 0
* or if i > # of elts
*/
-
-// BUGBUG - this should be called insert_element
-// BUGBUG - this should be called insert_element
-// BUGBUG - this should be called insert_element
TypeStoreUser insert_element_user(QName name, int i);
/**
@@ -233,10 +214,6 @@ public interface TypeStore extends Names
* Note that if there are no existing elements of the given
* name, the same comment applies as with insert_element_user.
*/
-// BUGBUG - this should be called add_element
-// BUGBUG - this should be called add_element
-// BUGBUG - this should be called add_element
-// BUGBUG - this should be called add_element
TypeStoreUser add_element_user(QName name);
/**
@@ -327,7 +304,7 @@ public interface TypeStore extends Names
* 3. if i >= m and i < n, then the element #i and all its contents
* are removed.
*/
-
+
void array_setter ( XmlObject[] sources, QName elementName );
/**
@@ -336,13 +313,12 @@ public interface TypeStore extends Names
*/
void visit_elements(TypeStoreVisitor visitor);
- XmlObject[] exec_query ( String queryExpr, XmlOptions options )
- throws XmlException;
+ XmlObject[] exec_query ( String queryExpr, XmlOptions options );
/**
* Returns the monitor object, used for synchronizing access to the doc.
* @deprecated
- */
+ */
Object get_root_object();
/**
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=1881601&r1=1881600&r2=1881601&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 9 22:17:28 2020
@@ -547,12 +547,7 @@ public abstract class XmlObjectBase impl
new XmlRuntimeException(
"Cannot do XQuery on XML Value Objects");
}
-
- try {
- return _typedArray(typeStore.exec_query(queryExpr, options));
- } catch (XmlException e) {
- throw new XmlRuntimeException(e);
- }
+ return _typedArray(typeStore.exec_query(queryExpr, options));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org