You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2021/11/27 20:02:11 UTC
[ws-axiom] 02/02: Partially migrate NodeFactory to use factory methods
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
commit 2766b2b4ddac73610e5b16521fc507424b702bd2
Author: Andreas Veithen <an...@gmail.com>
AuthorDate: Sat Nov 27 18:49:08 2021 +0000
Partially migrate NodeFactory to use factory methods
---
implementations/axiom-dom/pom.xml | 1 +
.../axiom/om/impl/dom/factory/DOOMNodeFactory.java | 1 +
implementations/axiom-impl/pom.xml | 1 +
.../om/impl/llom/factory/LLOMNodeFactory.java | 1 +
.../java/org/apache/axiom/core/NodeFactory.java | 2 +
.../java/org/apache/axiom/core/NodeFactory2.java | 60 ++++++++++++++++++++++
.../org/apache/axiom/core/NodeFactoryImpl.java | 13 ++++-
.../axiom/core/impl/builder/BuildableContext.java | 20 ++++----
.../axiom/core/impl/mixin/CoreNodeMixin.java | 2 +-
.../axiom/core/impl/mixin/CoreParentNodeMixin.java | 2 +-
.../impl/common/factory/AxiomNodeFactoryImpl.java | 4 +-
11 files changed, 92 insertions(+), 15 deletions(-)
diff --git a/implementations/axiom-dom/pom.xml b/implementations/axiom-dom/pom.xml
index 847af92..c864a64 100644
--- a/implementations/axiom-dom/pom.xml
+++ b/implementations/axiom-dom/pom.xml
@@ -115,6 +115,7 @@
<weavablePackage>org.apache.axiom.om.impl.dom.mixin</weavablePackage>
</weavablePackages>
<interfaces>
+ <interface>org.apache.axiom.core.NodeFactory2</interface>
<interface>org.apache.axiom.om.impl.dom.intf.DOOMCDATASection</interface>
<interface>org.apache.axiom.om.impl.dom.intf.DOOMComment</interface>
<interface>org.apache.axiom.om.impl.dom.intf.DOOMDocument</interface>
diff --git a/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/DOOMNodeFactory.java b/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/DOOMNodeFactory.java
index c40b953..13ffcd6 100644
--- a/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/DOOMNodeFactory.java
+++ b/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/DOOMNodeFactory.java
@@ -30,6 +30,7 @@ public final class DOOMNodeFactory extends AxiomNodeFactoryImpl implements DOMNo
private DOOMNodeFactory() {
super(DOOMNodeFactory.class.getClassLoader(),
+ "org.apache.axiom.om.impl.dom.NodeFactory2Impl",
"org.apache.axiom.om.impl.dom",
"org.apache.axiom.soap.impl.dom",
"org.apache.axiom.soap.impl.dom.soap11",
diff --git a/implementations/axiom-impl/pom.xml b/implementations/axiom-impl/pom.xml
index edf0cc5..e79fe91 100644
--- a/implementations/axiom-impl/pom.xml
+++ b/implementations/axiom-impl/pom.xml
@@ -102,6 +102,7 @@
<weavablePackage>org.apache.axiom.om.impl.llom.mixin</weavablePackage>
</weavablePackages>
<interfaces>
+ <interface>org.apache.axiom.core.NodeFactory2</interface>
<interface>org.apache.axiom.om.impl.intf.AxiomAttribute</interface>
<interface>org.apache.axiom.om.impl.intf.AxiomCDATASection</interface>
<interface>org.apache.axiom.om.impl.intf.AxiomCharacterDataNode</interface>
diff --git a/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/LLOMNodeFactory.java b/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/LLOMNodeFactory.java
index 9bc45c9..3714149 100644
--- a/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/LLOMNodeFactory.java
+++ b/implementations/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/LLOMNodeFactory.java
@@ -25,6 +25,7 @@ public final class LLOMNodeFactory extends AxiomNodeFactoryImpl {
private LLOMNodeFactory() {
super(LLOMNodeFactory.class.getClassLoader(),
+ "org.apache.axiom.om.impl.llom.NodeFactory2Impl",
"org.apache.axiom.om.impl.llom",
"org.apache.axiom.soap.impl.llom",
"org.apache.axiom.soap.impl.llom.soap11",
diff --git a/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactory.java b/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactory.java
index f539c5a..255ac2f 100644
--- a/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactory.java
+++ b/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactory.java
@@ -19,6 +19,8 @@
package org.apache.axiom.core;
public interface NodeFactory {
+ NodeFactory2 getFactory2();
+
/**
* Create the namespace helper object that will be passed to
* {@link CoreNSAwareNamedNode#initName(String, String, String, Object)}.
diff --git a/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactory2.java b/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactory2.java
new file mode 100644
index 0000000..e8922eb
--- /dev/null
+++ b/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactory2.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.core;
+
+import org.apache.axiom.weaver.annotation.FactoryMethod;
+
+// TODO: this should be fused into NodeFactory
+public interface NodeFactory2 {
+ @FactoryMethod
+ CoreDocument createDocument();
+
+ @FactoryMethod
+ CoreDocumentTypeDeclaration createDocumentTypeDeclaration();
+
+ @FactoryMethod
+ CoreNSAwareElement createNSAwareElement();
+
+ @FactoryMethod
+ CoreNSUnawareElement createNSUnawareElement();
+
+ @FactoryMethod
+ CoreNSAwareAttribute createNSAwareAttribute();
+
+ @FactoryMethod
+ CoreNSUnawareAttribute createNSUnawareAttribute();
+
+ @FactoryMethod
+ CoreNamespaceDeclaration createNamespaceDeclaration();
+
+ @FactoryMethod
+ CoreCharacterDataNode createCharacterDataNode();
+
+ @FactoryMethod
+ CoreProcessingInstruction createProcessingInstruction();
+
+ @FactoryMethod
+ CoreComment createComment();
+
+ @FactoryMethod
+ CoreCDATASection createCDATASection();
+
+ @FactoryMethod
+ CoreEntityReference createEntityReference();
+}
diff --git a/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactoryImpl.java b/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactoryImpl.java
index a91b80f..8cc3c73 100644
--- a/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactoryImpl.java
+++ b/mixins/core-mixins/src/main/java/org/apache/axiom/core/NodeFactoryImpl.java
@@ -34,9 +34,15 @@ import org.apache.axiom.core.util.EdgeRelation;
import org.apache.axiom.core.util.TopologicalSort;
public abstract class NodeFactoryImpl implements NodeFactory {
+ private final NodeFactory2 factory2;
private final Map<Class<?>,Constructor<?>> constructorMap;
- public NodeFactoryImpl(ClassLoader cl, String... packages) {
+ public NodeFactoryImpl(ClassLoader cl, String factory2ClassName, String... packages) {
+ try {
+ factory2 = cl.loadClass(factory2ClassName).asSubclass(NodeFactory2.class).getDeclaredConstructor().newInstance();
+ } catch (ReflectiveOperationException ex) {
+ throw new NodeFactoryException("Failed to instantiate NodeFactory2 implementation", ex);
+ }
List<Class<?>> implementations = new ArrayList<Class<?>>();
for (String pkg : packages) {
try {
@@ -111,6 +117,11 @@ public abstract class NodeFactoryImpl implements NodeFactory {
}
@Override
+ public NodeFactory2 getFactory2() {
+ return factory2;
+ }
+
+ @Override
public final <T extends CoreNode> T createNode(Class<T> type) {
Constructor<?> constructor = constructorMap.get(type);
if (constructor == null) {
diff --git a/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/builder/BuildableContext.java b/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/builder/BuildableContext.java
index b24c142..8f25d94 100644
--- a/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/builder/BuildableContext.java
+++ b/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/builder/BuildableContext.java
@@ -128,7 +128,7 @@ final class BuildableContext extends Context implements InputContext {
private void addChild(CoreChildNode node) {
if (pendingCharacterData != null) {
- CoreCharacterDataNode cdataNode = builderHandler.nodeFactory.createNode(CoreCharacterDataNode.class);
+ CoreCharacterDataNode cdataNode = builderHandler.nodeFactory.getFactory2().createCharacterDataNode();
cdataNode.coreSetCharacterData(pendingCharacterData);
target.internalAppendChildWithoutBuild(cdataNode);
pendingCharacterData = null;
@@ -163,7 +163,7 @@ final class BuildableContext extends Context implements InputContext {
if (passThroughHandler != null) {
passThroughHandler.processDocumentTypeDeclaration(rootName, publicId, systemId, internalSubset);
} else {
- CoreDocumentTypeDeclaration node = builderHandler.nodeFactory.createNode(CoreDocumentTypeDeclaration.class);
+ CoreDocumentTypeDeclaration node = builderHandler.nodeFactory.getFactory2().createDocumentTypeDeclaration();
node.coreSetRootName(rootName);
node.coreSetPublicId(publicId);
node.coreSetSystemId(systemId);
@@ -203,7 +203,7 @@ final class BuildableContext extends Context implements InputContext {
if (passThroughHandler != null) {
passThroughHandler.processAttribute(namespaceURI, localName, prefix, value, type, specified);
} else {
- CoreNSAwareAttribute attr = builderHandler.nodeFactory.createNode(CoreNSAwareAttribute.class);
+ CoreNSAwareAttribute attr = builderHandler.nodeFactory.getFactory2().createNSAwareAttribute();
attr.initName(namespaceURI, localName, prefix, builderHandler.namespaceHelper);
try {
attr.coreSetCharacterData(value, null);
@@ -221,7 +221,7 @@ final class BuildableContext extends Context implements InputContext {
if (passThroughHandler != null) {
passThroughHandler.processAttribute(name, value, type, specified);
} else {
- CoreNSUnawareAttribute attr = builderHandler.nodeFactory.createNode(CoreNSUnawareAttribute.class);
+ CoreNSUnawareAttribute attr = builderHandler.nodeFactory.getFactory2().createNSUnawareAttribute();
attr.coreSetName(name);
try {
attr.coreSetCharacterData(value, null);
@@ -239,7 +239,7 @@ final class BuildableContext extends Context implements InputContext {
if (passThroughHandler != null) {
passThroughHandler.processNamespaceDeclaration(prefix, namespaceURI);
} else {
- CoreNamespaceDeclaration decl = builderHandler.nodeFactory.createNode(CoreNamespaceDeclaration.class);
+ CoreNamespaceDeclaration decl = builderHandler.nodeFactory.getFactory2().createNamespaceDeclaration();
decl.init(prefix, namespaceURI, builderHandler.namespaceHelper);
((CoreElement)target).coreAppendAttribute(decl);
}
@@ -261,7 +261,7 @@ final class BuildableContext extends Context implements InputContext {
} else if (!ignorable && pendingCharacterData == null && target.coreGetFirstChildIfAvailable() == null) {
pendingCharacterData = data;
} else {
- CoreCharacterDataNode node = builderHandler.nodeFactory.createNode(CoreCharacterDataNode.class);
+ CoreCharacterDataNode node = builderHandler.nodeFactory.getFactory2().createCharacterDataNode();
node.coreSetCharacterData(data);
node.coreSetIgnorable(ignorable);
addChild(node);
@@ -275,7 +275,7 @@ final class BuildableContext extends Context implements InputContext {
passThroughHandler.startProcessingInstruction(piTarget);
return this;
} else {
- CoreProcessingInstruction node = builderHandler.nodeFactory.createNode(CoreProcessingInstruction.class);
+ CoreProcessingInstruction node = builderHandler.nodeFactory.getFactory2().createProcessingInstruction();
node.coreSetTarget(piTarget);
addChild(node);
return newContext(node);
@@ -299,7 +299,7 @@ final class BuildableContext extends Context implements InputContext {
passThroughHandler.startComment();
return this;
} else {
- CoreComment node = builderHandler.nodeFactory.createNode(CoreComment.class);
+ CoreComment node = builderHandler.nodeFactory.getFactory2().createComment();
addChild(node);
return newContext(node);
}
@@ -322,7 +322,7 @@ final class BuildableContext extends Context implements InputContext {
passThroughHandler.startCDATASection();
return this;
} else {
- CoreCDATASection node = builderHandler.nodeFactory.createNode(CoreCDATASection.class);
+ CoreCDATASection node = builderHandler.nodeFactory.getFactory2().createCDATASection();
addChild(node);
return newContext(node);
}
@@ -343,7 +343,7 @@ final class BuildableContext extends Context implements InputContext {
if (passThroughHandler != null) {
passThroughHandler.processEntityReference(name, replacementText);
} else {
- CoreEntityReference node = builderHandler.nodeFactory.createNode(CoreEntityReference.class);
+ CoreEntityReference node = builderHandler.nodeFactory.getFactory2().createEntityReference();
node.coreSetName(name);
node.coreSetReplacementText(replacementText);
addChild(node);
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 d361a9e..cb84d69 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
@@ -53,7 +53,7 @@ public abstract class CoreNodeMixin implements CoreNode {
if (root instanceof CoreDocument) {
return (CoreDocument)root;
} else if (create) {
- CoreDocument ownerDocument = root.coreGetNodeFactory().createNode(CoreDocument.class);
+ CoreDocument ownerDocument = root.coreGetNodeFactory().getFactory2().createDocument();
root.coreSetOwnerDocument(ownerDocument);
return ownerDocument;
} else {
diff --git a/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/mixin/CoreParentNodeMixin.java b/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/mixin/CoreParentNodeMixin.java
index 66e8176..1be6a1d 100644
--- a/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/mixin/CoreParentNodeMixin.java
+++ b/mixins/core-mixins/src/main/java/org/apache/axiom/core/impl/mixin/CoreParentNodeMixin.java
@@ -121,7 +121,7 @@ public abstract class CoreParentNodeMixin implements CoreParentNode {
public final Content internalGetContent(boolean create) {
if (getState() == COMPACT) {
Content content = new Content();
- CoreCharacterDataNode cdata = coreGetNodeFactory().createNode(CoreCharacterDataNode.class);
+ CoreCharacterDataNode cdata = coreGetNodeFactory().getFactory2().createCharacterDataNode();
cdata.internalSetParent(this);
cdata.coreSetCharacterData(this.content);
content.firstChild = cdata;
diff --git a/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactoryImpl.java b/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactoryImpl.java
index 1a413ed..159e56b 100644
--- a/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactoryImpl.java
+++ b/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/common/factory/AxiomNodeFactoryImpl.java
@@ -22,8 +22,8 @@ import org.apache.axiom.core.NodeFactoryImpl;
import org.apache.axiom.om.impl.common.builder.OMNamespaceCache;
public abstract class AxiomNodeFactoryImpl extends NodeFactoryImpl {
- public AxiomNodeFactoryImpl(ClassLoader cl, String... packages) {
- super(cl, packages);
+ public AxiomNodeFactoryImpl(ClassLoader cl, String factory2ClassName, String... packages) {
+ super(cl, factory2ClassName, packages);
}
@Override