1 package org.codehaus.plexus.configuration.xml;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.IOException;
20 import java.io.StringWriter;
21
22 import org.codehaus.plexus.configuration.DefaultPlexusConfiguration;
23 import org.codehaus.plexus.configuration.io.XmlPlexusConfigurationWriter;
24 import org.codehaus.plexus.util.xml.Xpp3Dom;
25
26
27
28 public class XmlPlexusConfiguration extends DefaultPlexusConfiguration {
29 public XmlPlexusConfiguration() {
30 super();
31 }
32
33 public XmlPlexusConfiguration(String name) {
34 super(name);
35 }
36
37 public XmlPlexusConfiguration(String name, String value) {
38 super(name, value);
39 }
40
41 public XmlPlexusConfiguration(Xpp3Dom dom) {
42 super(dom.getName(), dom.getValue());
43
44
45 String[] attributes = dom.getAttributeNames();
46
47 for (String attribute : attributes) {
48 setAttribute(attribute, dom.getAttribute(attribute));
49 }
50
51
52 int childCount = dom.getChildCount();
53 for (int i = 0; i < childCount; i++) {
54 addChild(new XmlPlexusConfiguration(dom.getChild(i)));
55 }
56 }
57
58
59
60
61
62 public String toString() {
63 StringWriter sw = new StringWriter();
64
65 XmlPlexusConfigurationWriter xw = new XmlPlexusConfigurationWriter();
66
67 try {
68 xw.write(sw, this);
69 } catch (IOException e) {
70
71 }
72
73 return sw.toString();
74 }
75 }