1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.internal.xml;
20
21 import org.apache.maven.api.xml.XmlNode;
22 import org.codehaus.plexus.configuration.DefaultPlexusConfiguration;
23 import org.codehaus.plexus.configuration.PlexusConfiguration;
24
25 /**
26 * Original implementation of XmlPlexusConfiguration before optimization.
27 * This class is used for performance benchmarking to compare against the optimized version.
28 *
29 * Key characteristics of this implementation:
30 * - Performs expensive deep copying in constructor
31 * - Creates all child configurations eagerly during construction
32 * - Uses non-thread-safe HashMap for child storage
33 * - Higher memory usage due to duplicated data structures
34 */
35 public class XmlPlexusConfigurationOld extends DefaultPlexusConfiguration {
36
37 public static PlexusConfiguration toPlexusConfiguration(XmlNode node) {
38 return new XmlPlexusConfigurationOld(node);
39 }
40
41 /**
42 * Constructor that performs deep copying of the entire XML tree.
43 * This is the performance bottleneck that was optimized in the new implementation.
44 */
45 public XmlPlexusConfigurationOld(XmlNode node) {
46 super(node.name(), node.value());
47
48 // Copy all attributes
49 node.attributes().forEach(this::setAttribute);
50
51 // Recursively create child configurations (expensive deep copying)
52 node.children().forEach(c -> this.addChild(new XmlPlexusConfigurationOld(c)));
53 }
54
55 @Override
56 public String toString() {
57 final StringBuilder buf = new StringBuilder().append('<').append(getName());
58 for (final String a : getAttributeNames()) {
59 buf.append(' ').append(a).append("=\"").append(getAttribute(a)).append('"');
60 }
61 if (getChildCount() > 0) {
62 buf.append('>');
63 for (int i = 0, size = getChildCount(); i < size; i++) {
64 buf.append(getChild(i));
65 }
66 buf.append("</").append(getName()).append('>');
67 } else if (null != getValue()) {
68 buf.append('>').append(getValue()).append("</").append(getName()).append('>');
69 } else {
70 buf.append("/>");
71 }
72 return buf.append('\n').toString();
73 }
74 }