Author: bbrodt
Date: 2011-02-04 13:57:19 -0500 (Fri, 04 Feb 2011)
New Revision: 29018
Modified:
trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/resource/BPELWriter.java
trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/util/ElementPlacer.java
Log:
https://issues.jboss.org/browse/JBIDE-8246
Fix serialization problems with extensionActivities that have TEXT nodes.
See also
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335458
Modified:
trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/resource/BPELWriter.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/resource/BPELWriter.java 2011-02-04
18:36:48 UTC (rev 29017)
+++
trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/resource/BPELWriter.java 2011-02-04
18:57:19 UTC (rev 29018)
@@ -1332,15 +1332,18 @@
QName qName = new QName(namespace, localName);
BPELActivitySerializer serializer = extensionRegistry
.getActivitySerializer(qName);
+ DocumentFragment fragment = null;
if (serializer != null) {
- DocumentFragment fragment = document.createDocumentFragment();
+ fragment = document.createDocumentFragment();
serializer.marshall(qName, activity, fragment, getProcess(), this);
- Element child = (Element) fragment.getFirstChild();
- activityElement.appendChild(child);
- // Standard attributes
- addStandardAttributes(child, activity);
- // Standard elements
- addStandardElements(child, activity);
+ //
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335458
+ //
https://issues.jboss.org/browse/JBIDE-8246
+ // Only append Element nodes generated by the serializer
+ // XML beautification is handled by the ElementPlacer class
+ Element child = getFirstChildElement(fragment);
+ if (child!=null) {
+ activityElement.appendChild(child);
+ }
}
return activityElement;
@@ -1634,7 +1637,8 @@
serializer.marshall(ExtensibleElement.class, qname,
extensibilityElement, fragment, getProcess(),
extensionRegistry, this);
- Element child = (Element) fragment.getFirstChild();
+ //
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335458
+ Element child = getFirstChildElement(fragment);
return child;
} catch (WSDLException e) {
throw new WrappedException(e);
@@ -1648,7 +1652,9 @@
DocumentFragment fragment = document.createDocumentFragment();
serializer.marshall(value, fragment, getProcess(), serviceRef
.eContainer(), this);
- Element child = (Element) fragment.getFirstChild();
+ //
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335458
+ //
https://issues.jboss.org/browse/JBIDE-8246
+ Element child = getFirstChildElement(fragment);
return child;
} else {
CDATASection cdata = BPELUtils.createCDATASection(document,
@@ -2363,12 +2369,15 @@
.marshall(ExtensibleElement.class, qname,
extensibilityElement, fragment, getProcess(),
extensionRegistry, this);
- return (Element) fragment.getFirstChild();
+ //
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335458
+ //
https://issues.jboss.org/browse/JBIDE-8246
+ Element child = getFirstChildElement(fragment);
+ return child;
} catch (WSDLException e) {
throw new WrappedException(e);
}
}
-
+
protected Element createBPELElement(String tagName) {
String namespaceURI = null;
@@ -2467,4 +2476,17 @@
return addNewRootPrefix("ns", namespace) + ":" +
qname.getLocalPart();
}
+ //
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335458
+ //
https://issues.jboss.org/browse/JBIDE-8246
+ private Element getFirstChildElement(DocumentFragment fragment) {
+ //
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335458
+ // first child may be a TEXT Node (e.g. whitespace)
+ Node child = fragment.getFirstChild();
+ while (child != null && !(child instanceof Element)) {
+ child = child.getNextSibling();
+ }
+ if (child instanceof Element)
+ return (Element) child;
+ throw new IllegalArgumentException("Document Fragment does not contain any
Elements");
+ }
}
Modified:
trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/util/ElementPlacer.java
===================================================================
---
trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/util/ElementPlacer.java 2011-02-04
18:36:48 UTC (rev 29017)
+++
trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/util/ElementPlacer.java 2011-02-04
18:57:19 UTC (rev 29018)
@@ -214,23 +214,37 @@
// DO:
// Format children of the newChild.
+ //
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335458
+ // traverse the child's descendants also, inserting the
+ // proper indentation for each
+ StringBuffer childIndent = new StringBuffer(indent);
+ Node nextNewChild = newChild;
Node innerChild = newChild.getFirstChild();
- if (innerChild != null) {
+ while (innerChild != null) {
// add "\n" + indent before every child
- while (innerChild != null) {
- if (innerChild.getNodeType() == Node.TEXT_NODE) {
+ Node nextInnerChild = innerChild;
+ while (nextInnerChild != null) {
+ boolean textNodeIsWhitespaceOnly = false;
+ if (nextInnerChild.getNodeType() == Node.TEXT_NODE) {
+ String content = nextInnerChild.getTextContent();
+ textNodeIsWhitespaceOnly = (content==null || content.trim().isEmpty());
+ }
+ if (textNodeIsWhitespaceOnly) {
// remove an old indentation
- newChild.removeChild(innerChild);
+ nextNewChild.removeChild(nextInnerChild);
} else {
- newChild.insertBefore(newChild.getOwnerDocument()
- .createTextNode("\n" + indent + " "),
- innerChild);
+ nextNewChild.insertBefore(nextNewChild.getOwnerDocument()
+ .createTextNode("\n" + childIndent + " "),
+ nextInnerChild);
}
- innerChild = innerChild.getNextSibling();
+ nextInnerChild = nextInnerChild.getNextSibling();
}
// add "\n" after the last child
- newChild.appendChild(newChild.getOwnerDocument()
- .createTextNode("\n" + indent + " "));
+ nextNewChild.appendChild(nextNewChild.getOwnerDocument()
+ .createTextNode("\n" + childIndent + " "));
+ childIndent.append(" ");
+ nextNewChild = innerChild;
+ innerChild = innerChild.getFirstChild();
}
if (referenceChild != null) {