Merged in brasseld/openesb-components/ESBCOMP-87-problem-when-using-flow-with- (pull request #20)

ESBCOMP-87 Thread safety issue on DOM manipulation
master
David Brassely 2014-01-13 16:13:13 +01:00
commit 19fffa1e20
1 changed files with 374 additions and 370 deletions

View File

@ -27,7 +27,6 @@
* *
* END_HEADER - DO NOT EDIT * END_HEADER - DO NOT EDIT
*/ */
package com.sun.xml.transform.sware.impl; package com.sun.xml.transform.sware.impl;
import java.math.BigInteger; import java.math.BigInteger;
@ -70,10 +69,10 @@ import com.sun.xml.transform.sware.schema.SwareParticle.ParticleType;
/** /**
* Sorts a DOM tree at one level. The algorithm looks up an aggregated particle * Sorts a DOM tree at one level. The algorithm looks up an aggregated particle
* from a flattened complex type model group and then uses the particle path * from a flattened complex type model group and then uses the particle path
* stored in the aggregated particle to determine if an ordered insertion to * stored in the aggregated particle to determine if an ordered insertion to the
* the sorted list is possible. A dynamic particle tree is maintained, * sorted list is possible. A dynamic particle tree is maintained, which
* which reflects the static particle tree structure but adds another * reflects the static particle tree structure but adds another dimention, which
* dimention, which represents the axis for repeating nodes. * represents the axis for repeating nodes.
* *
* @author Jun Xu * @author Jun Xu
* @since 6.0 * @since 6.0
@ -89,12 +88,11 @@ class DOMSorter {
private final List<Tile> mUnsortedList = new ArrayList<Tile>(); private final List<Tile> mUnsortedList = new ArrayList<Tile>();
private final PureLinkedList<Tile> mSortedList = new PureLinkedList<Tile>(); private final PureLinkedList<Tile> mSortedList = new PureLinkedList<Tile>();
private final RootXNode mRootX; private final RootXNode mRootX;
private boolean mInplace = true; private boolean mInplace = true;
/** /**
* Constructs from a transformer, a flattened complex type, a source * Constructs from a transformer, a flattened complex type, a source elemnt
* elemnt and a target element. * and a target element.
* *
* @param transformer the reordering transformer that provides context * @param transformer the reordering transformer that provides context
* information * information
@ -136,6 +134,7 @@ class DOMSorter {
public boolean checkSortNeeded() public boolean checkSortNeeded()
throws TransformerException, DOMException { throws TransformerException, DOMException {
NodeList childNodes = mSourceElement.getChildNodes(); NodeList childNodes = mSourceElement.getChildNodes();
synchronized (childNodes) {
ParticlePath lastPath = null; ParticlePath lastPath = null;
for (int i = 0; i < childNodes.getLength(); i++) { for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i); Node childNode = childNodes.item(i);
@ -249,6 +248,7 @@ class DOMSorter {
throw new InvalidSchemaException("Invalid Schema.", e); throw new InvalidSchemaException("Invalid Schema.", e);
} }
} }
}
return false; return false;
} }
@ -261,6 +261,7 @@ class DOMSorter {
public void sort() throws TransformerException, DOMException { public void sort() throws TransformerException, DOMException {
NodeList childNodes = mSourceElement.getChildNodes(); NodeList childNodes = mSourceElement.getChildNodes();
synchronized (childNodes) {
List<Node> otherNodes = null; List<Node> otherNodes = null;
boolean noSort = false; boolean noSort = false;
int i = 0; int i = 0;
@ -382,8 +383,8 @@ class DOMSorter {
DOMUtil.getQName(tgtElem)); DOMUtil.getQName(tgtElem));
if (aggPart != null) { if (aggPart != null) {
partApp = partApp =
aggPart.getParticleAppearances().size() > 0 ? aggPart.getParticleAppearances().size() > 0
aggPart.getParticleAppearances().iterator().next() : null; ? aggPart.getParticleAppearances().iterator().next() : null;
} }
if (partApp != null) { if (partApp != null) {
elemDecl = (SwareElement) partApp.getParticle(); elemDecl = (SwareElement) partApp.getParticle();
@ -426,6 +427,7 @@ class DOMSorter {
} }
} }
} }
}
/** /**
* Analyzes order and adds an element to the sorted list. * Analyzes order and adds an element to the sorted list.
@ -433,8 +435,7 @@ class DOMSorter {
* @param source the source element * @param source the source element
* @param target the target element * @param target the target element
* @param others other DOM nodes than element nodes before this element * @param others other DOM nodes than element nodes before this element
* @return an instance of Entry<Tile> if adding to sorted list is * @return an instance of Entry<Tile> if adding to sorted list is successful
* successful
* @throws OrderIndeterministicException thrown if the order is not * @throws OrderIndeterministicException thrown if the order is not
* deterministic * deterministic
* @throws TooManyElementsException thrown if maxOccurs is reached * @throws TooManyElementsException thrown if maxOccurs is reached
@ -542,9 +543,9 @@ class DOMSorter {
} }
/** /**
* Determines where to add the new element into the sorted list and * Determines where to add the new element into the sorted list and then
* then adds it, and also update the dynamic particle tree based * adds it, and also update the dynamic particle tree based on the new
* on the new element added. * element added.
* *
* @param partApp the particle appearance instance * @param partApp the particle appearance instance
* @param s the source element * @param s the source element
@ -552,8 +553,7 @@ class DOMSorter {
* @param others other DOM nodes than DOM elements before this element * @param others other DOM nodes than DOM elements before this element
* *
* @return non-null instance of Entry<Tile> if the element is * @return non-null instance of Entry<Tile> if the element is
* successfully added to the sorted list, otherwise * successfully added to the sorted list, otherwise <code>null</code>
* <code>null</code>
* @throws SwareSchemaException invalid schema exception * @throws SwareSchemaException invalid schema exception
*/ */
public Entry<Tile> addLeafParticle(ParticleAppearance partApp, public Entry<Tile> addLeafParticle(ParticleAppearance partApp,
@ -634,8 +634,8 @@ class DOMSorter {
} }
/** /**
* Cracks out the new repeating indices path assuming that a new * Cracks out the new repeating indices path assuming that a new element
* element is going to be added. * is going to be added.
* *
* @param path the path of the particle appearance * @param path the path of the particle appearance
* @return the repeating indices path * @return the repeating indices path
@ -742,10 +742,12 @@ class DOMSorter {
* Generic node type for the dynamic particle tree. * Generic node type for the dynamic particle tree.
*/ */
abstract class GNode { abstract class GNode {
final GNode mOwner; final GNode mOwner;
/** /**
* Constructs from an owner. * Constructs from an owner.
*
* @param owner * @param owner
*/ */
GNode(GNode owner) { GNode(GNode owner) {
@ -754,6 +756,7 @@ class DOMSorter {
/** /**
* Gets the owner. * Gets the owner.
*
* @return the owner * @return the owner
*/ */
public GNode getOwner() { public GNode getOwner() {
@ -761,17 +764,17 @@ class DOMSorter {
} }
/** /**
* Locally adds an element, which only searches for the posibility * Locally adds an element, which only searches for the posibility in
* in direct child or repeating nodes. * direct child or repeating nodes.
* *
* @param partApp the particle appearance instance * @param partApp the particle appearance instance
* @param i either the particle index or the repeating index * @param i either the particle index or the repeating index
* @param s the source element * @param s the source element
* @param e the target element * @param e the target element
* @param others other DOM nodes than DOM element nodes before * @param others other DOM nodes than DOM element nodes before this
* this element * element
* @return A reference to a tile in the sorted list or * @return A reference to a tile in the sorted list or <code>null</code>
* <code>null</code> if unable to insert * if unable to insert
*/ */
abstract Entry<Tile> localAdd(ParticleAppearance partApp, int i, abstract Entry<Tile> localAdd(ParticleAppearance partApp, int i,
Element s, Element e, List<Node> others); Element s, Element e, List<Node> others);
@ -791,6 +794,7 @@ class DOMSorter {
} }
class RootYNode extends YNode { class RootYNode extends YNode {
RootYNode(XNode owner, SwareGroup g) throws SwareSchemaException { RootYNode(XNode owner, SwareGroup g) throws SwareSchemaException {
super(owner, g, true); super(owner, g, true);
} }
@ -801,7 +805,6 @@ class DOMSorter {
static final int NO_OP = 0; static final int NO_OP = 0;
static final int ADD_BEFORE = 1; static final int ADD_BEFORE = 1;
static final int ADD_AFTER = 2; static final int ADD_AFTER = 2;
final SwareParticle mPart; final SwareParticle mPart;
final SwareParticle[] mChildParts; final SwareParticle[] mChildParts;
final XNode[] mXNodes; final XNode[] mXNodes;
@ -928,6 +931,7 @@ class DOMSorter {
} }
class XNode extends GNode { class XNode extends GNode {
final int[] mPCounters; final int[] mPCounters;
final List<YNode> mYNodes = new ArrayList<YNode>(); final List<YNode> mYNodes = new ArrayList<YNode>();
final SwareParticle mPart; final SwareParticle mPart;
@ -1006,8 +1010,8 @@ class DOMSorter {
protected final List<Node> mOthers; protected final List<Node> mOthers;
/** /**
* Constructs from source element, target element and a list of * Constructs from source element, target element and a list of other
* other nodes that are before the source node. * nodes that are before the source node.
* *
* @param source source element * @param source source element
* @param target target element * @param target target element
@ -1037,8 +1041,8 @@ class DOMSorter {
protected final ParticleAppearance mPartApp; protected final ParticleAppearance mPartApp;
/** /**
* Constructs from source element, target element, a list of other * Constructs from source element, target element, a list of other nodes
* nodes that are before the source node and a particle appearance. * that are before the source node and a particle appearance.
* *
* @param source source element * @param source source element
* @param target target element * @param target target element