Skip to content

Commit cbe8aab

Browse files
committed
[XMLBeans-438] revert changes as the changes seem to make things worse
git-svn-id: https://svn.apache.org/repos/asf/xmlbeans/trunk@1927290 13f79535-47bb-0310-9956-ffa450edef68
1 parent 0791dad commit cbe8aab

File tree

8 files changed

+67
-559
lines changed

8 files changed

+67
-559
lines changed

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<property name="jdk.version.class" value="1.8" description="JDK version of generated class files"/>
2222
<property name="compile.debug" value="true"/>
2323

24-
<property name="version.base" value="5.4.0-SNAPSHOT"/>
24+
<property name="version.base" value="5.3.1-SNAPSHOT"/>
2525
<property name="version.rc" value=""/>
2626

2727
<property name="cases.location" location="src/test/resources"/>

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515

1616
# comment-out, because of naming problems with the distribution plugin
17-
#project.version=5.4.0-SNAPSHOT
18-
XMLBeansVersion=5.4.0-SNAPSHOT
17+
#project.version=5.3.1-SNAPSHOT
18+
XMLBeansVersion=5.3.1-SNAPSHOT
1919

2020
# Specifies the JVM arguments used for the daemon process.
2121
# The setting is particularly useful for tweaking memory settings.

src/main/java/org/apache/xmlbeans/impl/store/Cur.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static Xobj createElementXobj(Locale l, QName name, QName parentName) {
343343
private void createHelper(Xobj x) {
344344
assert x._locale == _locale;
345345

346-
// insert the new Xobj into an existing tree.
346+
// insert the new Xobj into an exisiting tree.
347347

348348
if (isPositioned()) {
349349
Cur from = tempCur(x, 0);
@@ -3425,4 +3425,4 @@ void setId(String id) {
34253425
public Locale getLocale() {
34263426
return _locale;
34273427
}
3428-
}
3428+
}

src/main/java/org/apache/xmlbeans/impl/store/Xobj.java

Lines changed: 12 additions & 265 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,19 +1992,6 @@ public <T extends XmlObject> void find_all_element_users(QName name, List<T> fil
19921992
}
19931993
}
19941994

1995-
@SuppressWarnings("unchecked")
1996-
@Override
1997-
public <T extends XmlObject> void find_multiple_element_users(final QName name, final List<T> fillMeUp,
1998-
final int maxCount) {
1999-
int count = 0;
2000-
for (Xobj x = _firstChild; x != null && count < maxCount; x = x._nextSibling) {
2001-
if (x.isElem() && x._name.equals(name)) {
2002-
fillMeUp.add((T) x.getUser());
2003-
count++;
2004-
}
2005-
}
2006-
}
2007-
20081995
@SuppressWarnings("unchecked")
20091996
@Override
20101997
public <T extends XmlObject> void find_all_element_users(QNameSet names, List<T> fillMeUp) {
@@ -2015,19 +2002,6 @@ public <T extends XmlObject> void find_all_element_users(QNameSet names, List<T>
20152002
}
20162003
}
20172004

2018-
@SuppressWarnings("unchecked")
2019-
@Override
2020-
public <T extends XmlObject> void find_multiple_element_users(final QNameSet names, final List<T> fillMeUp,
2021-
final int maxCount) {
2022-
int count = 0;
2023-
for (Xobj x = _firstChild; x != null && count < maxCount; x = x._nextSibling) {
2024-
if (x.isElem() && names.contains(x._name)) {
2025-
fillMeUp.add((T) x.getUser());
2026-
count++;
2027-
}
2028-
}
2029-
}
2030-
20312005
private static TypeStoreUser insertElement(QName name, Xobj x, int pos) {
20322006
x._locale.enter();
20332007

@@ -2043,26 +2017,6 @@ private static TypeStoreUser insertElement(QName name, Xobj x, int pos) {
20432017
}
20442018
}
20452019

2046-
private static TypeStoreUser[] insertElements(final QName name, final Xobj x,
2047-
final int pos, final int count) {
2048-
x._locale.enter();
2049-
2050-
TypeStoreUser[] users = new TypeStoreUser[count];
2051-
try {
2052-
Cur c = x._locale.tempCur();
2053-
c.moveTo(x, pos);
2054-
for (int i = count - 1; i >= 0; i--) {
2055-
c.createElement(name);
2056-
users[i] = c.getUser();
2057-
}
2058-
c.release();
2059-
} finally {
2060-
x._locale.exit();
2061-
}
2062-
return users;
2063-
}
2064-
2065-
@Override
20662020
public TypeStoreUser insert_element_user(QName name, int i) {
20672021
if (i < 0) {
20682022
throw new IndexOutOfBoundsException();
@@ -2085,35 +2039,6 @@ public TypeStoreUser insert_element_user(QName name, int i) {
20852039
return insertElement(name, x, 0);
20862040
}
20872041

2088-
@Override
2089-
public TypeStoreUser[] insert_elements_users(final QName name, final int i,
2090-
final int count) {
2091-
if (i < 0) {
2092-
throw new IndexOutOfBoundsException();
2093-
}
2094-
2095-
if (!isContainer()) {
2096-
throw new IllegalStateException();
2097-
}
2098-
2099-
if (count <= 0) {
2100-
return new TypeStoreUser[0];
2101-
}
2102-
2103-
Xobj x = _locale.findNthChildElem(this, name, null, i);
2104-
2105-
if (x == null) {
2106-
if (i > _locale.count(this, name, null) + 1) {
2107-
throw new IndexOutOfBoundsException();
2108-
}
2109-
2110-
return add_elements_users(name, count);
2111-
}
2112-
2113-
return insertElements(name, x, 0, count);
2114-
}
2115-
2116-
@Override
21172042
public TypeStoreUser insert_element_user(QNameSet names, QName name, int i) {
21182043
if (i < 0) {
21192044
throw new IndexOutOfBoundsException();
@@ -2136,35 +2061,6 @@ public TypeStoreUser insert_element_user(QNameSet names, QName name, int i) {
21362061
return insertElement(name, x, 0);
21372062
}
21382063

2139-
@Override
2140-
public TypeStoreUser[] insert_elements_users(final QNameSet names, final QName name,
2141-
final int i, final int count) {
2142-
if (i < 0) {
2143-
throw new IndexOutOfBoundsException();
2144-
}
2145-
2146-
if (!isContainer()) {
2147-
throw new IllegalStateException();
2148-
}
2149-
2150-
if (count <= 0) {
2151-
return new TypeStoreUser[0];
2152-
}
2153-
2154-
Xobj x = _locale.findNthChildElem(this, null, names, i);
2155-
2156-
if (x == null) {
2157-
if (i > _locale.count(this, null, names) + 1) {
2158-
throw new IndexOutOfBoundsException();
2159-
}
2160-
2161-
return add_elements_users(name, count);
2162-
}
2163-
2164-
return insertElements(name, x, 0, count);
2165-
}
2166-
2167-
@Override
21682064
public TypeStoreUser add_element_user(QName name) {
21692065
if (!isContainer()) {
21702066
throw new IllegalStateException();
@@ -2198,51 +2094,6 @@ public TypeStoreUser add_element_user(QName name) {
21982094
: insertElement(name, candidate, 0);
21992095
}
22002096

2201-
@Override
2202-
public TypeStoreUser[] add_elements_users(final QName name, final int count) {
2203-
if (!isContainer()) {
2204-
throw new IllegalStateException();
2205-
}
2206-
2207-
if (count <= 0) {
2208-
return new TypeStoreUser[0];
2209-
}
2210-
2211-
QNameSet endSet = null;
2212-
boolean gotEndSet = false;
2213-
2214-
Xobj candidate = null;
2215-
2216-
for (Xobj x = _lastChild; x != null; x = x._prevSibling) {
2217-
if (x.isContainer()) {
2218-
if (x._name.equals(name)) {
2219-
break;
2220-
}
2221-
2222-
if (!gotEndSet) {
2223-
endSet = _user.get_element_ending_delimiters(name);
2224-
gotEndSet = true;
2225-
}
2226-
2227-
if (endSet == null || endSet.contains(x._name)) {
2228-
candidate = x;
2229-
}
2230-
}
2231-
}
2232-
2233-
final TypeStoreUser[] users;
2234-
if (candidate == null) {
2235-
// If there is no candidate, then I need to insert at the end of this container
2236-
// and create a new element for each of the count
2237-
users = insertElements(name, this, END_POS, count);
2238-
} else {
2239-
// If I have a candidate, then I need to insert at the candidate and create
2240-
// a new element for each of the count
2241-
users = insertElements(name, candidate, 0, count);
2242-
}
2243-
return users;
2244-
}
2245-
22462097
private static void removeElement(Xobj x) {
22472098
if (x == null) {
22482099
throw new IndexOutOfBoundsException();
@@ -2259,7 +2110,6 @@ private static void removeElement(Xobj x) {
22592110
}
22602111
}
22612112

2262-
@Override
22632113
public void remove_element(QName name, int i) {
22642114
if (i < 0) {
22652115
throw new IndexOutOfBoundsException();
@@ -2280,63 +2130,6 @@ public void remove_element(QName name, int i) {
22802130
removeElement(x);
22812131
}
22822132

2283-
@Override
2284-
public void remove_elements_after(QName name, int i) {
2285-
if (i < 0) {
2286-
throw new IndexOutOfBoundsException();
2287-
}
2288-
2289-
if (!isContainer()) {
2290-
throw new IllegalStateException();
2291-
}
2292-
2293-
ArrayList<Xobj> toRemove = new ArrayList<>();
2294-
Xobj x;
2295-
for (x = _firstChild; x != null; x = x._nextSibling) {
2296-
if (x.isElem() && x._name.equals(name) && --i < 0) {
2297-
toRemove.add(x);
2298-
}
2299-
}
2300-
final int size = toRemove.size();
2301-
for (int j = size - 1; j >= 0; j--) {
2302-
removeElement(toRemove.get(j));
2303-
}
2304-
}
2305-
2306-
@Override
2307-
public void remove_elements_between(final QName name, final int m, final int n) {
2308-
if (m < 0 || n < 0) {
2309-
throw new IndexOutOfBoundsException();
2310-
}
2311-
2312-
if (!isContainer()) {
2313-
throw new IllegalStateException();
2314-
}
2315-
2316-
if (m >= n) {
2317-
return;
2318-
}
2319-
2320-
ArrayList<Xobj> toRemove = new ArrayList<>();
2321-
Xobj x;
2322-
int i = m;
2323-
int count = 0;
2324-
for (x = _firstChild; x != null; x = x._nextSibling) {
2325-
if (x.isElem() && x._name.equals(name) && --i < 0) {
2326-
toRemove.add(x);
2327-
count++;
2328-
if (count >= n - m) {
2329-
break; // no need to continue if we've removed enough
2330-
}
2331-
}
2332-
}
2333-
final int size = toRemove.size();
2334-
for (int j = size - 1; j >= 0; j--) {
2335-
removeElement(toRemove.get(j));
2336-
}
2337-
}
2338-
2339-
@Override
23402133
public void remove_element(QNameSet names, int i) {
23412134
if (i < 0) {
23422135
throw new IndexOutOfBoundsException();
@@ -2357,58 +2150,6 @@ public void remove_element(QNameSet names, int i) {
23572150
removeElement(x);
23582151
}
23592152

2360-
@Override
2361-
public void remove_elements_after(QNameSet names, int i) {
2362-
if (i < 0) {
2363-
throw new IndexOutOfBoundsException();
2364-
}
2365-
2366-
if (!isContainer()) {
2367-
throw new IllegalStateException();
2368-
}
2369-
2370-
Xobj x;
2371-
2372-
for (x = _firstChild; x != null; x = x._nextSibling) {
2373-
if (x.isElem() && names.contains(x._name) && --i < 0) {
2374-
removeElement(x);
2375-
}
2376-
}
2377-
}
2378-
2379-
@Override
2380-
public void remove_elements_between(final QNameSet names, final int m, final int n) {
2381-
if (m < 0 || n < 0) {
2382-
throw new IndexOutOfBoundsException();
2383-
}
2384-
2385-
if (!isContainer()) {
2386-
throw new IllegalStateException();
2387-
}
2388-
2389-
if (m >= n) {
2390-
return;
2391-
}
2392-
2393-
ArrayList<Xobj> toRemove = new ArrayList<>();
2394-
Xobj x;
2395-
int i = m;
2396-
int count = 0;
2397-
for (x = _firstChild; x != null; x = x._nextSibling) {
2398-
if (x.isElem() && names.contains(x._name) && --i < 0) {
2399-
toRemove.add(x);
2400-
count++;
2401-
if (count >= n - m) {
2402-
break; // no need to continue if we've removed enough
2403-
}
2404-
}
2405-
}
2406-
final int size = toRemove.size();
2407-
for (int j = size - 1; j >= 0; j--) {
2408-
removeElement(toRemove.get(j));
2409-
}
2410-
}
2411-
24122153
public TypeStoreUser find_attribute_user(QName name) {
24132154
Xobj a = getAttr(name);
24142155

@@ -2553,7 +2294,7 @@ public void array_setter(XmlObject[] sources, QName elementName) {
25532294
try {
25542295
// TODO - this is the quick and dirty implementation, make this faster
25552296

2556-
final int m = sources.length;
2297+
int m = sources.length;
25572298

25582299
List<Xobj> copies = new ArrayList<>();
25592300
List<SchemaType> types = new ArrayList<>();
@@ -2585,14 +2326,18 @@ public void array_setter(XmlObject[] sources, QName elementName) {
25852326
}
25862327
}
25872328

2588-
final int n = count_elements(elementName);
2329+
int n = count_elements(elementName);
2330+
2331+
for (; n > m; n--) {
2332+
remove_element(elementName, m);
2333+
}
25892334

2590-
if (n > m) {
2591-
remove_elements_after(elementName, m);
2592-
} else if (n < m) {
2593-
add_elements_users(elementName, m - n);
2335+
for (; m > n; n++) {
2336+
add_element_user(elementName);
25942337
}
25952338

2339+
assert m == n;
2340+
25962341
List<XmlObject> elementsUser = new ArrayList<>();
25972342

25982343
find_all_element_users(elementName, elementsUser);
@@ -2603,6 +2348,8 @@ public void array_setter(XmlObject[] sources, QName elementName) {
26032348
.map(x -> (Xobj) x)
26042349
.collect(Collectors.toList());
26052350

2351+
assert elements.size() == n;
2352+
26062353
Cur c = tempCur();
26072354

26082355
for (int i = 0; i < n; i++) {

0 commit comments

Comments
 (0)