ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1706469 - in /webservices/axiom/trunk: aspects/core-aspects/src/main/java/org/apache/axiom/core/ implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/
Date Fri, 02 Oct 2015 19:15:45 GMT
Author: veithen
Date: Fri Oct  2 19:15:45 2015
New Revision: 1706469

URL: http://svn.apache.org/viewvc?rev=1706469&view=rev
Log:
Rewrite some FOM code using the core model API.

Modified:
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractNodeIterator.java
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMPerson.java
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMSource.java
    webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMWorkspace.java

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractNodeIterator.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractNodeIterator.java?rev=1706469&r1=1706468&r2=1706469&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractNodeIterator.java
(original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/AbstractNodeIterator.java
Fri Oct  2 19:15:45 2015
@@ -139,10 +139,8 @@ public abstract class AbstractNodeIterat
     }
 
     public final void replace(CoreChildNode newNode) throws CoreModelException {
-        // TODO
-        throw new UnsupportedOperationException();
-//        // Move to next node before replacing the current one
-//        hasNext();
-//        ((CoreChildNode)currentNode).coreReplaceWith(newNode);
+        // Move to next node before replacing the current one
+        hasNext();
+        ((CoreChildNode)currentNode).coreReplaceWith(newNode, detachPolicy);
     }
 }

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj?rev=1706469&r1=1706468&r2=1706469&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj
Fri Oct  2 19:15:45 2015
@@ -203,21 +203,20 @@ public aspect CoreChildNodeSupport {
         CoreParentNode parent = coreGetParent();
         if (parent != null) {
             beforeDetach();
-            CoreDocument newOwnerDocument = newParent != null ? null : detachPolicy.getNewOwnerDocument(parent);
             if (previousSibling == null) {
                 parent.getContent(true).firstChild = nextSibling;
             } else {
                 previousSibling.nextSibling = nextSibling;
+                previousSibling = null;
             }
             if (nextSibling == null) {
                 parent.getContent(true).lastChild = previousSibling;
             } else {
                 nextSibling.previousSibling = previousSibling;
+                nextSibling = null;
             }
-            previousSibling = null;
-            nextSibling = null;
             if (newParent == null) {
-                internalUnsetParent(newOwnerDocument);
+                internalUnsetParent(detachPolicy.getNewOwnerDocument(parent));
             }
         }
         if (newParent != null) {
@@ -225,6 +224,30 @@ public aspect CoreChildNodeSupport {
         }
     }
 
+    public final void CoreChildNode.coreReplaceWith(CoreChildNode newNode, DetachPolicy detachPolicy)
{
+        newNode.coreDetach(DetachPolicy.NEW_DOCUMENT);
+        CoreParentNode parent = coreGetParent();
+        if (parent != null) {
+            beforeDetach();
+            if (previousSibling == null) {
+                parent.getContent(true).firstChild = newNode;
+            } else {
+                previousSibling.nextSibling = newNode;
+                newNode.previousSibling = previousSibling;
+                previousSibling = null;
+            }
+            if (nextSibling == null) {
+                parent.getContent(true).lastChild = newNode;
+            } else {
+                nextSibling.previousSibling = newNode;
+                newNode.nextSibling = nextSibling;
+                nextSibling = null;
+            }
+            internalUnsetParent(detachPolicy.getNewOwnerDocument(parent));
+            newNode.internalSetParent(parent);
+        }
+    }
+
     public final <T> CoreNode CoreChildNode.coreClone(ClonePolicy<T> policy,
T options, CoreParentNode targetParent) {
         return internalClone(policy, options, targetParent);
     }

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java?rev=1706469&r1=1706468&r2=1706469&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java
(original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java
Fri Oct  2 19:15:45 2015
@@ -53,7 +53,7 @@ public class FOMCollection extends FOMEx
     private Text setTitle(String title, Text.Type type) {
         Text text = getFactory().newText(PREFIXED_TITLE, type);
         text.setValue(title);
-        this._setChild(PREFIXED_TITLE, (OMElement)text);
+        this._setChild(PREFIXED_TITLE, text);
         return text;
     }
 

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java?rev=1706469&r1=1706468&r2=1706469&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
(original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
Fri Oct  2 19:15:45 2015
@@ -61,6 +61,7 @@ import org.apache.abdera.writer.WriterOp
 import org.apache.axiom.core.CoreChildNode;
 import org.apache.axiom.core.CoreNSAwareElement;
 import org.apache.axiom.fom.AbderaElement;
+import org.apache.axiom.fom.AbderaText;
 import org.apache.axiom.fom.FOMList;
 import org.apache.axiom.fom.IRIUtil;
 import org.apache.axiom.fom.Policies;
@@ -224,15 +225,26 @@ public class FOMElement extends FOMChild
         return new FOMList(new FOMElementIteratorWrapper(factory, getChildrenWithName(qname)));
     }
 
-    protected void _setChild(QName qname, OMElement element) {
-        OMElement e = getFirstChildWithName(qname);
+    protected void _setChild(QName qname, Element element) {
+        AbderaElement e = null;
+        CoreChildNode child = coreGetFirstChild();
+        while (child != null) {
+            if (child instanceof AbderaElement) {
+                AbderaElement candidate = (AbderaElement)child;
+                if (candidate.coreGetLocalName().equals(qname.getLocalPart())
+                        && candidate.coreGetNamespaceURI().equals(qname.getNamespaceURI()))
{
+                    e = candidate;
+                    break;
+                }
+            }
+            child = child.coreGetNextSibling();
+        }
         if (e == null && element != null) {
-            addChild(element);
+            coreAppendChild((AbderaElement)element, false);
         } else if (e != null && element != null) {
-            e.insertSiblingBefore(element);
-            e.discard();
+            e.coreReplaceWith((AbderaElement)element, Policies.DETACH_POLICY);
         } else if (e != null && element == null) {
-            e.discard();
+            e.coreDetach(Policies.DETACH_POLICY);
         }
     }
 
@@ -336,7 +348,7 @@ public class FOMElement extends FOMChild
     }
 
     protected <T extends Text> void setTextElement(QName qname, T text, boolean many)
{
-        _setChild(qname, (OMElement)text);
+        _setChild(qname, text);
     }
 
     public void setText(String text) {

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java?rev=1706469&r1=1706468&r2=1706469&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
(original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMEntry.java
Fri Oct  2 19:15:45 2015
@@ -106,7 +106,7 @@ public class FOMEntry extends FOMExtensi
     }
 
     public Entry setContentElement(Content content) {
-        _setChild(CONTENT, (OMElement)content);
+        _setChild(CONTENT, content);
         return this;
     }
 
@@ -297,7 +297,7 @@ public class FOMEntry extends FOMExtensi
     }
 
     public Entry setIdElement(IRIElement id) {
-        _setChild(ID, (OMElement)id);
+        _setChild(ID, id);
         return this;
     }
 
@@ -378,7 +378,7 @@ public class FOMEntry extends FOMExtensi
     }
 
     public Entry setPublishedElement(DateTime dateTime) {
-        _setChild(PUBLISHED, (OMElement)dateTime);
+        _setChild(PUBLISHED, dateTime);
         return this;
     }
 
@@ -460,7 +460,7 @@ public class FOMEntry extends FOMExtensi
     public Entry setSource(Source source) {
         if (source instanceof Feed)
             source = ((Feed)source).getAsSource();
-        _setChild(SOURCE, (OMElement)source);
+        _setChild(SOURCE, source);
         return this;
     }
 
@@ -553,7 +553,7 @@ public class FOMEntry extends FOMExtensi
     }
 
     public Entry setUpdatedElement(DateTime updated) {
-        _setChild(UPDATED, (OMElement)updated);
+        _setChild(UPDATED, updated);
         return this;
     }
 
@@ -596,7 +596,7 @@ public class FOMEntry extends FOMExtensi
     public void setEditedElement(DateTime updated) {
         declareNamespace(APP_NS, "app");
         _removeChildren(PRE_RFC_EDITED, false);
-        _setChild(EDITED, (OMElement)updated);
+        _setChild(EDITED, updated);
     }
 
     public Date getEdited() {
@@ -648,7 +648,7 @@ public class FOMEntry extends FOMExtensi
 
     public Entry setControl(Control control) {
         _removeChildren(PRE_RFC_CONTROL, true);
-        _setChild(CONTROL, (OMElement)control);
+        _setChild(CONTROL, control);
         return this;
     }
 

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMPerson.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMPerson.java?rev=1706469&r1=1706468&r2=1706469&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMPerson.java
(original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMPerson.java
Fri Oct  2 19:15:45 2015
@@ -26,7 +26,6 @@ import org.apache.abdera.model.Element;
 import org.apache.abdera.model.IRIElement;
 import org.apache.abdera.model.Person;
 import org.apache.axiom.fom.AbderaPerson;
-import org.apache.axiom.om.OMElement;
 
 public class FOMPerson extends FOMExtensibleElement implements AbderaPerson {
     public Element getNameElement() {
@@ -34,7 +33,7 @@ public class FOMPerson extends FOMExtens
     }
 
     public Person setNameElement(Element element) {
-        _setChild(NAME, (OMElement)element);
+        _setChild(NAME, element);
         return this;
     }
 
@@ -46,7 +45,7 @@ public class FOMPerson extends FOMExtens
         } else {
             el = null;
         }
-        _setChild(NAME, (OMElement)el);
+        _setChild(NAME, el);
         return el;
     }
 
@@ -60,7 +59,7 @@ public class FOMPerson extends FOMExtens
     }
 
     public Person setEmailElement(Element element) {
-        _setChild(EMAIL, (OMElement)element);
+        _setChild(EMAIL, element);
         return this;
     }
 
@@ -72,7 +71,7 @@ public class FOMPerson extends FOMExtens
         } else {
             el = null;
         }
-        _setChild(EMAIL, (OMElement)el);
+        _setChild(EMAIL, el);
         return el;
     }
 
@@ -86,7 +85,7 @@ public class FOMPerson extends FOMExtens
     }
 
     public Person setUriElement(IRIElement uri) {
-        _setChild(URI, (OMElement)uri);
+        _setChild(URI, uri);
         return this;
     }
 
@@ -98,7 +97,7 @@ public class FOMPerson extends FOMExtens
         } else {
             el = null;
         }
-        _setChild(URI, (OMElement)el);
+        _setChild(URI, el);
         return el;
     }
 

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMSource.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMSource.java?rev=1706469&r1=1706468&r2=1706469&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMSource.java
(original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMSource.java
Fri Oct  2 19:15:45 2015
@@ -117,7 +117,7 @@ public class FOMSource extends FOMExtens
     }
 
     public <T extends Source> T setIdElement(IRIElement id) {
-        _setChild(ID, (OMElement)id);
+        _setChild(ID, id);
         return (T)this;
     }
 
@@ -324,7 +324,7 @@ public class FOMSource extends FOMExtens
     }
 
     public <T extends Source> T setUpdatedElement(DateTime updated) {
-        _setChild(UPDATED, (OMElement)updated);
+        _setChild(UPDATED, updated);
         return (T)this;
     }
 
@@ -367,7 +367,7 @@ public class FOMSource extends FOMExtens
     }
 
     public <T extends Source> T setGenerator(Generator generator) {
-        _setChild(GENERATOR, (OMElement)generator);
+        _setChild(GENERATOR, generator);
         return (T)this;
     }
 
@@ -387,7 +387,7 @@ public class FOMSource extends FOMExtens
     }
 
     public <T extends Source> T setIconElement(IRIElement iri) {
-        _setChild(ICON, (OMElement)iri);
+        _setChild(ICON, iri);
         return (T)this;
     }
 
@@ -412,7 +412,7 @@ public class FOMSource extends FOMExtens
     }
 
     public <T extends Source> T setLogoElement(IRIElement iri) {
-        _setChild(LOGO, (OMElement)iri);
+        _setChild(LOGO, iri);
         return (T)this;
     }
 
@@ -487,7 +487,7 @@ public class FOMSource extends FOMExtens
 
     public <T extends Source> T setCollection(Collection collection) {
         _removeChildren(PRE_RFC_COLLECTION, true);
-        _setChild(COLLECTION, (OMElement)collection);
+        _setChild(COLLECTION, collection);
         return (T)this;
     }
 

Modified: webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMWorkspace.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMWorkspace.java?rev=1706469&r1=1706468&r2=1706469&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMWorkspace.java
(original)
+++ webservices/axiom/trunk/implementations/fom-impl/src/main/java/org/apache/abdera/parser/stax/FOMWorkspace.java
Fri Oct  2 19:15:45 2015
@@ -43,7 +43,7 @@ public class FOMWorkspace extends FOMExt
     private Text setTitle(String title, Text.Type type) {
         Text text = getFactory().newText(PREFIXED_TITLE, type);
         text.setValue(title);
-        this._setChild(PREFIXED_TITLE, (OMElement)text);
+        this._setChild(PREFIXED_TITLE, text);
         return text;
     }
 



Mime
View raw message