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 09da34827 Remove createNode method from NodeFactory and clean up
related code
09da34827 is described below
commit 09da34827af58fbd7e7013a35dbfc23bdc7db70c
Author: Copilot <[email protected]>
AuthorDate: Sun May 24 15:23:02 2026 +0100
Remove createNode method from NodeFactory and clean up related code
Co-authored-by: Andreas Veithen-Knowles <[email protected]>
---
.../axiom/om/impl/dom/factory/DOOMNodeFactory.java | 8 +-
.../org/apache/axiom/om/impl/dom/nodetypes.index | 32 ------
.../org/apache/axiom/soap/impl/dom/nodetypes.index | 19 ----
.../axiom/soap/impl/dom/soap11/nodetypes.index | 27 ------
.../axiom/soap/impl/dom/soap12/nodetypes.index | 31 ------
.../om/impl/llom/factory/LLOMNodeFactory.java | 8 +-
.../org/apache/axiom/om/impl/llom/nodetypes.index | 29 ------
.../apache/axiom/soap/impl/llom/nodetypes.index | 19 ----
.../axiom/soap/impl/llom/soap11/nodetypes.index | 27 ------
.../axiom/soap/impl/llom/soap12/nodetypes.index | 31 ------
.../java/org/apache/axiom/core/NodeFactory.java | 2 -
.../org/apache/axiom/core/NodeFactoryImpl.java | 108 +--------------------
.../org/apache/axiom/core/util/EdgeRelation.java | 23 -----
.../apache/axiom/core/util/TopologicalSort.java | 60 ------------
14 files changed, 3 insertions(+), 421 deletions(-)
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 c67e3152d..3a4f1b3b7 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
@@ -24,12 +24,6 @@ public final class DOOMNodeFactory extends NodeFactoryImpl {
public static final DOOMNodeFactory INSTANCE = new DOOMNodeFactory();
private DOOMNodeFactory() {
- super(
- DOOMNodeFactory.class.getClassLoader(),
- "org.apache.axiom.om.impl.dom.factory.DOOMNodeFactoryImpl",
- "org.apache.axiom.om.impl.dom",
- "org.apache.axiom.soap.impl.dom",
- "org.apache.axiom.soap.impl.dom.soap11",
- "org.apache.axiom.soap.impl.dom.soap12");
+ super(DOOMNodeFactory.class.getClassLoader(),
"org.apache.axiom.om.impl.dom.factory.DOOMNodeFactoryImpl");
}
}
diff --git
a/implementations/axiom-dom/src/main/resources/org/apache/axiom/om/impl/dom/nodetypes.index
b/implementations/axiom-dom/src/main/resources/org/apache/axiom/om/impl/dom/nodetypes.index
deleted file mode 100644
index 3a9bceed7..000000000
---
a/implementations/axiom-dom/src/main/resources/org/apache/axiom/om/impl/dom/nodetypes.index
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# 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.
-#
-DOOMCDATASectionImpl
-DOOMCommentImpl
-DOOMDocumentFragmentImpl
-DOOMDocumentImpl
-DOOMDocumentTypeImpl
-DOOMEntityReferenceImpl
-DOOMNamespaceDeclarationImpl
-DOOMNSAwareAttributeImpl
-DOOMNSAwareElementImpl
-DOOMNSUnawareAttributeImpl
-DOOMNSUnawareElementImpl
-DOOMProcessingInstructionImpl
-DOOMSourcedElementImpl
-DOOMTextImpl
diff --git
a/implementations/axiom-dom/src/main/resources/org/apache/axiom/soap/impl/dom/nodetypes.index
b/implementations/axiom-dom/src/main/resources/org/apache/axiom/soap/impl/dom/nodetypes.index
deleted file mode 100644
index 69ebea4ca..000000000
---
a/implementations/axiom-dom/src/main/resources/org/apache/axiom/soap/impl/dom/nodetypes.index
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-DOOMSOAPMessageImpl
diff --git
a/implementations/axiom-dom/src/main/resources/org/apache/axiom/soap/impl/dom/soap11/nodetypes.index
b/implementations/axiom-dom/src/main/resources/org/apache/axiom/soap/impl/dom/soap11/nodetypes.index
deleted file mode 100644
index 9178e5a9f..000000000
---
a/implementations/axiom-dom/src/main/resources/org/apache/axiom/soap/impl/dom/soap11/nodetypes.index
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# 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.
-#
-DOOMSOAP11BodyImpl
-DOOMSOAP11EnvelopeImpl
-DOOMSOAP11FaultCodeImpl
-DOOMSOAP11FaultDetailImpl
-DOOMSOAP11FaultImpl
-DOOMSOAP11FaultReasonImpl
-DOOMSOAP11FaultRoleImpl
-DOOMSOAP11HeaderBlockImpl
-DOOMSOAP11HeaderImpl
diff --git
a/implementations/axiom-dom/src/main/resources/org/apache/axiom/soap/impl/dom/soap12/nodetypes.index
b/implementations/axiom-dom/src/main/resources/org/apache/axiom/soap/impl/dom/soap12/nodetypes.index
deleted file mode 100644
index 16cfb8e65..000000000
---
a/implementations/axiom-dom/src/main/resources/org/apache/axiom/soap/impl/dom/soap12/nodetypes.index
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# 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.
-#
-DOOMSOAP12BodyImpl
-DOOMSOAP12EnvelopeImpl
-DOOMSOAP12FaultCodeImpl
-DOOMSOAP12FaultDetailImpl
-DOOMSOAP12FaultImpl
-DOOMSOAP12FaultNodeImpl
-DOOMSOAP12FaultReasonImpl
-DOOMSOAP12FaultRoleImpl
-DOOMSOAP12FaultSubCodeImpl
-DOOMSOAP12FaultTextImpl
-DOOMSOAP12FaultValueImpl
-DOOMSOAP12HeaderBlockImpl
-DOOMSOAP12HeaderImpl
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 4b6d0d38d..921c84613 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
@@ -24,12 +24,6 @@ public final class LLOMNodeFactory extends NodeFactoryImpl {
public static LLOMNodeFactory INSTANCE = new LLOMNodeFactory();
private LLOMNodeFactory() {
- super(
- LLOMNodeFactory.class.getClassLoader(),
- "org.apache.axiom.om.impl.llom.factory.AxiomNodeFactoryImpl",
- "org.apache.axiom.om.impl.llom",
- "org.apache.axiom.soap.impl.llom",
- "org.apache.axiom.soap.impl.llom.soap11",
- "org.apache.axiom.soap.impl.llom.soap12");
+ super(LLOMNodeFactory.class.getClassLoader(),
"org.apache.axiom.om.impl.llom.factory.AxiomNodeFactoryImpl");
}
}
diff --git
a/implementations/axiom-impl/src/main/resources/org/apache/axiom/om/impl/llom/nodetypes.index
b/implementations/axiom-impl/src/main/resources/org/apache/axiom/om/impl/llom/nodetypes.index
deleted file mode 100644
index c7e00bde8..000000000
---
a/implementations/axiom-impl/src/main/resources/org/apache/axiom/om/impl/llom/nodetypes.index
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# 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.
-#
-AxiomAttributeImpl
-AxiomCDATASectionImpl
-AxiomCharacterDataNodeImpl
-AxiomCommentImpl
-AxiomDocTypeImpl
-AxiomDocumentImpl
-AxiomElementImpl
-AxiomEntityReferenceImpl
-AxiomNamespaceDeclarationImpl
-AxiomProcessingInstructionImpl
-AxiomSourcedElementImpl
diff --git
a/implementations/axiom-impl/src/main/resources/org/apache/axiom/soap/impl/llom/nodetypes.index
b/implementations/axiom-impl/src/main/resources/org/apache/axiom/soap/impl/llom/nodetypes.index
deleted file mode 100644
index 57872a1ac..000000000
---
a/implementations/axiom-impl/src/main/resources/org/apache/axiom/soap/impl/llom/nodetypes.index
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-AxiomSOAPMessageImpl
diff --git
a/implementations/axiom-impl/src/main/resources/org/apache/axiom/soap/impl/llom/soap11/nodetypes.index
b/implementations/axiom-impl/src/main/resources/org/apache/axiom/soap/impl/llom/soap11/nodetypes.index
deleted file mode 100644
index 9deef0ba9..000000000
---
a/implementations/axiom-impl/src/main/resources/org/apache/axiom/soap/impl/llom/soap11/nodetypes.index
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# 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.
-#
-AxiomSOAP11BodyImpl
-AxiomSOAP11EnvelopeImpl
-AxiomSOAP11FaultCodeImpl
-AxiomSOAP11FaultDetailImpl
-AxiomSOAP11FaultImpl
-AxiomSOAP11FaultReasonImpl
-AxiomSOAP11FaultRoleImpl
-AxiomSOAP11HeaderBlockImpl
-AxiomSOAP11HeaderImpl
diff --git
a/implementations/axiom-impl/src/main/resources/org/apache/axiom/soap/impl/llom/soap12/nodetypes.index
b/implementations/axiom-impl/src/main/resources/org/apache/axiom/soap/impl/llom/soap12/nodetypes.index
deleted file mode 100644
index 4535770e9..000000000
---
a/implementations/axiom-impl/src/main/resources/org/apache/axiom/soap/impl/llom/soap12/nodetypes.index
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# 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.
-#
-AxiomSOAP12BodyImpl
-AxiomSOAP12EnvelopeImpl
-AxiomSOAP12FaultCodeImpl
-AxiomSOAP12FaultDetailImpl
-AxiomSOAP12FaultImpl
-AxiomSOAP12FaultNodeImpl
-AxiomSOAP12FaultReasonImpl
-AxiomSOAP12FaultRoleImpl
-AxiomSOAP12FaultSubCodeImpl
-AxiomSOAP12FaultTextImpl
-AxiomSOAP12FaultValueImpl
-AxiomSOAP12HeaderBlockImpl
-AxiomSOAP12HeaderImpl
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 482852198..3b5784a2f 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
@@ -20,6 +20,4 @@ package org.apache.axiom.core;
public interface NodeFactory {
NodeFactory2 getFactory2();
-
- <T extends CoreNode> T createNode(Class<T> type);
}
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 e9ca43de3..4e800639b 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
@@ -18,126 +18,20 @@
*/
package org.apache.axiom.core;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-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 factory2ClassName, String...
packages) {
+ public NodeFactoryImpl(ClassLoader cl, String factory2ClassName) {
try {
factory2 = (NodeFactory2)
cl.loadClass(factory2ClassName).getDeclaredField("INSTANCE").get(null);
} catch (ReflectiveOperationException ex) {
throw new NodeFactoryException("Failed to instantiate NodeFactory2
implementation", ex);
}
- List<Class<?>> implementations = new ArrayList<Class<?>>();
- for (String pkg : packages) {
- try {
- BufferedReader in = new BufferedReader(new InputStreamReader(
- cl.getResourceAsStream(pkg.replace('.', '/') +
"/nodetypes.index"), StandardCharsets.UTF_8));
- try {
- String line;
- while ((line = in.readLine()) != null) {
- if (line.startsWith("#")) {
- continue;
- }
- String className = pkg + "." + line;
- try {
- implementations.add(cl.loadClass(className));
- } catch (ClassNotFoundException ex) {
- throw new NodeFactoryException("Failed to load
class " + className, ex);
- }
- }
- } finally {
- in.close();
- }
- } catch (IOException ex) {
- throw new NodeFactoryException("Failed to load node type index
for package " + pkg, ex);
- }
- }
- implementations = TopologicalSort.sort(implementations, new
EdgeRelation<Class<?>>() {
- @Override
- public boolean isEdge(Class<?> from, Class<?> to) {
- return to.isAssignableFrom(from);
- }
- });
- Map<Class<?>, Class<?>> interfaceToImplementationMap = new
HashMap<Class<?>, Class<?>>();
- Map<Class<?>, Constructor<?>> implementationToConstructorMap = new
HashMap<Class<?>, Constructor<?>>();
- Set<Class<?>> ambiguousInterfaces = new HashSet<Class<?>>();
- for (Class<?> implementation : implementations) {
- Set<Class<?>> interfaces = new HashSet<Class<?>>();
- collectInterfaces(implementation, interfaces);
- for (Class<?> iface : interfaces) {
- if (!ambiguousInterfaces.contains(iface)) {
- Class<?> clazz = interfaceToImplementationMap.get(iface);
- if (clazz == null ||
implementation.isAssignableFrom(clazz)) {
- interfaceToImplementationMap.put(iface,
implementation);
- } else if (!clazz.isAssignableFrom(implementation)) {
- interfaceToImplementationMap.remove(iface);
- ambiguousInterfaces.add(iface);
- }
- }
- }
- try {
- implementationToConstructorMap.put(implementation,
implementation.getConstructor());
- } catch (NoSuchMethodException ex) {
- throw new NodeFactoryException("Failed to get constructor for
" + implementation.getName(), ex);
- }
- }
- constructorMap = new HashMap<Class<?>, Constructor<?>>();
- for (Map.Entry<Class<?>, Class<?>> entry :
interfaceToImplementationMap.entrySet()) {
- constructorMap.put(entry.getKey(),
implementationToConstructorMap.get(entry.getValue()));
- }
- // TODO: this should eventually go away
- constructorMap.putAll(implementationToConstructorMap);
- }
-
- private static void collectInterfaces(Class<?> clazz, Set<Class<?>>
interfaces) {
- for (Class<?> iface : clazz.getInterfaces()) {
- if (interfaces.add(iface)) {
- collectInterfaces(iface, interfaces);
- }
- }
- Class<?> superclass = clazz.getSuperclass();
- if (superclass != null) {
- collectInterfaces(superclass, interfaces);
- }
}
@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) {
- throw new NodeFactoryException("Unknown node type " +
type.getName());
- } else {
- try {
- return type.cast(constructor.newInstance());
- } catch (InvocationTargetException ex) {
- throw new NodeFactoryException("Caught exception thrown by
constructor", ex.getCause());
- } catch (InstantiationException ex) {
- throw new NodeFactoryException("Failed to invoke constructor",
ex);
- } catch (IllegalAccessException ex) {
- throw new NodeFactoryException("Failed to invoke constructor",
ex);
- }
- }
- }
}
diff --git
a/mixins/core-mixins/src/main/java/org/apache/axiom/core/util/EdgeRelation.java
b/mixins/core-mixins/src/main/java/org/apache/axiom/core/util/EdgeRelation.java
deleted file mode 100644
index cf446d1b4..000000000
---
a/mixins/core-mixins/src/main/java/org/apache/axiom/core/util/EdgeRelation.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.util;
-
-public interface EdgeRelation<T> {
- boolean isEdge(T from, T to);
-}
diff --git
a/mixins/core-mixins/src/main/java/org/apache/axiom/core/util/TopologicalSort.java
b/mixins/core-mixins/src/main/java/org/apache/axiom/core/util/TopologicalSort.java
deleted file mode 100644
index 39c085f7f..000000000
---
a/mixins/core-mixins/src/main/java/org/apache/axiom/core/util/TopologicalSort.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/** Implements topological sorting. */
-public final class TopologicalSort {
- private TopologicalSort() {}
-
- private static <T> void visit(
- Collection<T> vertices, EdgeRelation<? super T> edgeRelation,
List<T> result, Set<T> visited, T vertex) {
- if (visited.add(vertex)) {
- for (T vertex2 : vertices) {
- if (vertex2 != vertex && edgeRelation.isEdge(vertex, vertex2))
{
- visit(vertices, edgeRelation, result, visited, vertex2);
- }
- }
- result.add(vertex);
- }
- }
-
- /**
- * Apply topological ordering to a given collection.
- *
- * @param <T> the vertex type
- * @param vertices the vertices of the directed acyclic graph
- * @param edgeRelation the relation defining the edges of the graph
- * @return the topologically sorted list of vertices, where the vertices
with no incoming edges
- * come first
- */
- public static <T> List<T> sort(Collection<T> vertices, EdgeRelation<?
super T> edgeRelation) {
- List<T> result = new ArrayList<T>(vertices.size());
- Set<T> visited = new HashSet<T>();
- for (T vertex : vertices) {
- visit(vertices, edgeRelation, result, visited, vertex);
- }
- return result;
- }
-}