This is an automated email from the ASF dual-hosted git repository.

veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git


The following commit(s) were added to refs/heads/master by this push:
     new 7e778947e refactor: replace ClonePolicy.getTargetNodeClass with 
createTargetNode(options, node, factory)
7e778947e is described below

commit 7e778947e693488f6e4ac4c941c42dcc64381f44
Author: Copilot <[email protected]>
AuthorDate: Sat May 23 22:13:37 2026 +0100

    refactor: replace ClonePolicy.getTargetNodeClass with 
createTargetNode(options, node, factory)
    
    Co-authored-by: Andreas Veithen-Knowles <[email protected]>
---
 .../src/main/java/org/apache/axiom/core/ClonePolicy.java      |  2 +-
 .../java/org/apache/axiom/core/impl/mixin/CoreNodeMixin.java  |  2 +-
 .../src/main/java/org/apache/axiom/dom/DOMSemantics.java      |  9 +++++----
 .../java/org/apache/axiom/om/impl/common/AxiomSemantics.java  | 11 +++++++----
 4 files changed, 14 insertions(+), 10 deletions(-)

diff --git 
a/mixins/core-mixins/src/main/java/org/apache/axiom/core/ClonePolicy.java 
b/mixins/core-mixins/src/main/java/org/apache/axiom/core/ClonePolicy.java
index c0bd69eac..29dccf7f5 100644
--- a/mixins/core-mixins/src/main/java/org/apache/axiom/core/ClonePolicy.java
+++ b/mixins/core-mixins/src/main/java/org/apache/axiom/core/ClonePolicy.java
@@ -20,7 +20,7 @@ package org.apache.axiom.core;
 
 /** Defines how an object model tree is to be cloned. */
 public interface ClonePolicy<T> {
-    Class<? extends CoreNode> getTargetNodeClass(T options, CoreNode node);
+    CoreNode createTargetNode(T options, CoreNode node, NodeFactory factory);
 
     boolean repairNamespaces(T options);
 
diff --git 
a/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/mixin/CoreNodeMixin.java
 
b/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/mixin/CoreNodeMixin.java
index 708959540..03d5317bc 100644
--- 
a/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/mixin/CoreNodeMixin.java
+++ 
b/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/mixin/CoreNodeMixin.java
@@ -81,7 +81,7 @@ public abstract class CoreNodeMixin implements CoreNode {
 
     // TODO: merge this into internalClone once it is no longer referenced 
elsewhere
     public final <T> CoreNode shallowClone(ClonePolicy<T> policy, T options) 
throws CoreModelException {
-        CoreNode clone = 
coreGetNodeFactory().createNode(policy.getTargetNodeClass(options, this));
+        CoreNode clone = policy.createTargetNode(options, this, 
coreGetNodeFactory());
         clone.init(policy, options, this);
         clone.initAncillaryData(policy, options, this);
         return clone;
diff --git 
a/mixins/dom-mixins/src/main/java/org/apache/axiom/dom/DOMSemantics.java 
b/mixins/dom-mixins/src/main/java/org/apache/axiom/dom/DOMSemantics.java
index be9625fc7..9077f2a82 100644
--- a/mixins/dom-mixins/src/main/java/org/apache/axiom/dom/DOMSemantics.java
+++ b/mixins/dom-mixins/src/main/java/org/apache/axiom/dom/DOMSemantics.java
@@ -29,6 +29,7 @@ import org.apache.axiom.core.CoreNode;
 import org.apache.axiom.core.DetachPolicy;
 import org.apache.axiom.core.NSAwareAttributeMatcher;
 import org.apache.axiom.core.NamespaceDeclarationMatcher;
+import org.apache.axiom.core.NodeFactory;
 import org.apache.axiom.core.NodeFactory2;
 import org.apache.axiom.core.NodeType;
 import org.apache.axiom.core.Semantics;
@@ -115,10 +116,10 @@ public final class DOMSemantics implements Semantics {
 
     public static final ClonePolicy<Void> DEEP_CLONE = new ClonePolicy<Void>() 
{
         @Override
-        public Class<? extends CoreNode> getTargetNodeClass(Void options, 
CoreNode node) {
+        public CoreNode createTargetNode(Void options, CoreNode node, 
NodeFactory factory) {
             // This is not specified by the API, but it's compatible with 
versions before
             // 1.2.14
-            return node.coreGetNodeClass();
+            return factory.createNode(node.coreGetNodeClass());
         }
 
         @Override
@@ -142,10 +143,10 @@ public final class DOMSemantics implements Semantics {
 
     public static final ClonePolicy<Void> SHALLOW_CLONE = new 
ClonePolicy<Void>() {
         @Override
-        public Class<? extends CoreNode> getTargetNodeClass(Void options, 
CoreNode node) {
+        public CoreNode createTargetNode(Void options, CoreNode node, 
NodeFactory factory) {
             // This is not specified by the API, but it's compatible with 
versions before
             // 1.2.14
-            return node.coreGetNodeClass();
+            return factory.createNode(node.coreGetNodeClass());
         }
 
         @Override
diff --git 
a/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/common/AxiomSemantics.java
 
b/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/common/AxiomSemantics.java
index 5669ccac5..d5c8896d4 100644
--- 
a/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/common/AxiomSemantics.java
+++ 
b/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/common/AxiomSemantics.java
@@ -26,6 +26,7 @@ import org.apache.axiom.core.CoreNode;
 import org.apache.axiom.core.DetachPolicy;
 import org.apache.axiom.core.NSAwareAttributeMatcher;
 import org.apache.axiom.core.NamespaceDeclarationMatcher;
+import org.apache.axiom.core.NodeFactory;
 import org.apache.axiom.core.NodeType;
 import org.apache.axiom.core.Semantics;
 import org.apache.axiom.om.OMCloneOptions;
@@ -61,14 +62,16 @@ public final class AxiomSemantics implements Semantics {
 
     public static final ClonePolicy<OMCloneOptions> CLONE_POLICY = new 
ClonePolicy<OMCloneOptions>() {
         @Override
-        public Class<? extends CoreNode> getTargetNodeClass(OMCloneOptions 
options, CoreNode node) {
+        public CoreNode createTargetNode(OMCloneOptions options, CoreNode 
node, NodeFactory factory) {
+            Class<? extends CoreNode> nodeClass;
             if (options != null && options.isPreserveModel()) {
-                return node.coreGetNodeClass();
+                nodeClass = node.coreGetNodeClass();
             } else if (options != null && options.isCopyOMDataSources() && 
node instanceof AxiomSourcedElement) {
-                return AxiomSourcedElement.class;
+                nodeClass = AxiomSourcedElement.class;
             } else {
-                return node.coreGetNodeType().getInterface();
+                nodeClass = node.coreGetNodeType().getInterface();
             }
+            return factory.createNode(nodeClass);
         }
 
         @Override

Reply via email to