Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<property name="jdk.version.class" value="1.8" description="JDK version of generated class files"/>
<property name="compile.debug" value="true"/>

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

<property name="cases.location" location="src/test/resources"/>
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


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

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/xmlbeans/impl/store/Cur.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static Xobj createElementXobj(Locale l, QName name, QName parentName) {
private void createHelper(Xobj x) {
assert x._locale == _locale;

// insert the new Xobj into an exisiting tree.
// insert the new Xobj into an existing tree.

if (isPositioned()) {
Cur from = tempCur(x, 0);
Expand Down
211 changes: 199 additions & 12 deletions src/main/java/org/apache/xmlbeans/impl/store/Xobj.java
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,19 @@ public <T extends XmlObject> void find_all_element_users(QName name, List<T> fil
}
}

@SuppressWarnings("unchecked")
@Override
public <T extends XmlObject> void find_multiple_element_users(final QName name, final List<T> fillMeUp,
final int maxCount) {
int count = 0;
for (Xobj x = _firstChild; x != null && count < maxCount; x = x._nextSibling) {
if (x.isElem() && x._name.equals(name)) {
fillMeUp.add((T) x.getUser());
count++;
}
}
}

@SuppressWarnings("unchecked")
@Override
public <T extends XmlObject> void find_all_element_users(QNameSet names, List<T> fillMeUp) {
Expand All @@ -2002,6 +2015,19 @@ public <T extends XmlObject> void find_all_element_users(QNameSet names, List<T>
}
}

@SuppressWarnings("unchecked")
@Override
public <T extends XmlObject> void find_multiple_element_users(final QNameSet names, final List<T> fillMeUp,
final int maxCount) {
int count = 0;
for (Xobj x = _firstChild; x != null && count < maxCount; x = x._nextSibling) {
if (x.isElem() && names.contains(x._name)) {
fillMeUp.add((T) x.getUser());
count++;
}
}
}

private static TypeStoreUser insertElement(QName name, Xobj x, int pos) {
x._locale.enter();

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

private static TypeStoreUser[] insertElements(final QName name, final Xobj x,
final int pos, final int count) {
x._locale.enter();

TypeStoreUser[] users = new TypeStoreUser[count];
try {
Cur c = x._locale.tempCur();
c.moveTo(x, pos);
for (int i = count - 1; i >= 0; i--) {
c.createElement(name);
users[i] = c.getUser();
}
c.release();
} finally {
x._locale.exit();
}
return users;
}

@Override
public TypeStoreUser insert_element_user(QName name, int i) {
if (i < 0) {
throw new IndexOutOfBoundsException();
Expand All @@ -2039,6 +2085,35 @@ public TypeStoreUser insert_element_user(QName name, int i) {
return insertElement(name, x, 0);
}

@Override
public TypeStoreUser[] insert_elements_users(final QName name, final int i,
final int count) {
if (i < 0) {
throw new IndexOutOfBoundsException();
}

if (!isContainer()) {
throw new IllegalStateException();
}

if (count <= 0) {
return new TypeStoreUser[0];
}

Xobj x = _locale.findNthChildElem(this, name, null, i);

if (x == null) {
if (i > _locale.count(this, name, null) + 1) {
throw new IndexOutOfBoundsException();
}

return add_elements_users(name, count);
}

return insertElements(name, x, 0, count);
}

@Override
public TypeStoreUser insert_element_user(QNameSet names, QName name, int i) {
if (i < 0) {
throw new IndexOutOfBoundsException();
Expand All @@ -2061,6 +2136,35 @@ public TypeStoreUser insert_element_user(QNameSet names, QName name, int i) {
return insertElement(name, x, 0);
}

@Override
public TypeStoreUser[] insert_elements_users(final QNameSet names, final QName name,
final int i, final int count) {
if (i < 0) {
throw new IndexOutOfBoundsException();
}

if (!isContainer()) {
throw new IllegalStateException();
}

if (count <= 0) {
return new TypeStoreUser[0];
}

Xobj x = _locale.findNthChildElem(this, null, names, i);

if (x == null) {
if (i > _locale.count(this, null, names) + 1) {
throw new IndexOutOfBoundsException();
}

return add_elements_users(name, count);
}

return insertElements(name, x, 0, count);
}

@Override
public TypeStoreUser add_element_user(QName name) {
if (!isContainer()) {
throw new IllegalStateException();
Expand Down Expand Up @@ -2094,6 +2198,51 @@ public TypeStoreUser add_element_user(QName name) {
: insertElement(name, candidate, 0);
}

@Override
public TypeStoreUser[] add_elements_users(final QName name, final int count) {
if (!isContainer()) {
throw new IllegalStateException();
}

if (count <= 0) {
return new TypeStoreUser[0];
}

QNameSet endSet = null;
boolean gotEndSet = false;

Xobj candidate = null;

for (Xobj x = _lastChild; x != null; x = x._prevSibling) {
if (x.isContainer()) {
if (x._name.equals(name)) {
break;
}

if (!gotEndSet) {
endSet = _user.get_element_ending_delimiters(name);
gotEndSet = true;
}

if (endSet == null || endSet.contains(x._name)) {
candidate = x;
}
}
}

final TypeStoreUser[] users;
if (candidate == null) {
// If there is no candidate, then I need to insert at the end of this container
// and create a new element for each of the count
users = insertElements(name, this, END_POS, count);
} else {
// If I have a candidate, then I need to insert at the candidate and create
// a new element for each of the count
users = insertElements(name, candidate, 0, count);
}
return users;
}

private static void removeElement(Xobj x) {
if (x == null) {
throw new IndexOutOfBoundsException();
Expand All @@ -2110,6 +2259,7 @@ private static void removeElement(Xobj x) {
}
}

@Override
public void remove_element(QName name, int i) {
if (i < 0) {
throw new IndexOutOfBoundsException();
Expand All @@ -2130,6 +2280,30 @@ public void remove_element(QName name, int i) {
removeElement(x);
}

@Override
public void remove_elements_after(QName name, int i) {
if (i < 0) {
throw new IndexOutOfBoundsException();
}

if (!isContainer()) {
throw new IllegalStateException();
}

ArrayList<Xobj> toRemove = new ArrayList<>();
Xobj x;
for (x = _firstChild; x != null; x = x._nextSibling) {
if (x.isElem() && x._name.equals(name) && --i < 0) {
toRemove.add(x);
}
}
final int size = toRemove.size();
for (int j = size - 1; j >= 0; j--) {
removeElement(toRemove.get(j));
}
}

@Override
public void remove_element(QNameSet names, int i) {
if (i < 0) {
throw new IndexOutOfBoundsException();
Expand All @@ -2150,6 +2324,25 @@ public void remove_element(QNameSet names, int i) {
removeElement(x);
}

@Override
public void remove_elements_after(QNameSet names, int i) {
if (i < 0) {
throw new IndexOutOfBoundsException();
}

if (!isContainer()) {
throw new IllegalStateException();
}

Xobj x;

for (x = _firstChild; x != null; x = x._nextSibling) {
if (x.isElem() && names.contains(x._name) && --i < 0) {
removeElement(x);
}
}
}

public TypeStoreUser find_attribute_user(QName name) {
Xobj a = getAttr(name);

Expand Down Expand Up @@ -2294,7 +2487,7 @@ public void array_setter(XmlObject[] sources, QName elementName) {
try {
// TODO - this is the quick and dirty implementation, make this faster

int m = sources.length;
final int m = sources.length;

List<Xobj> copies = new ArrayList<>();
List<SchemaType> types = new ArrayList<>();
Expand Down Expand Up @@ -2326,18 +2519,14 @@ public void array_setter(XmlObject[] sources, QName elementName) {
}
}

int n = count_elements(elementName);
final int n = count_elements(elementName);

for (; n > m; n--) {
remove_element(elementName, m);
if (n > m) {
remove_elements_after(elementName, m);
} else if (n < m) {
add_elements_users(elementName, m - n);
}

for (; m > n; n++) {
add_element_user(elementName);
}

assert m == n;

List<XmlObject> elementsUser = new ArrayList<>();

find_all_element_users(elementName, elementsUser);
Expand All @@ -2348,8 +2537,6 @@ public void array_setter(XmlObject[] sources, QName elementName) {
.map(x -> (Xobj) x)
.collect(Collectors.toList());

assert elements.size() == n;

Cur c = tempCur();

for (int i = 0; i < n; i++) {
Expand Down
Loading
Loading