View Javadoc
1   /*
2    *    Copyright 2006-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.generator.api.dom.xml;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  public class XmlElement implements VisitableElement {
22  
23      private final List<Attribute> attributes = new ArrayList<>();
24  
25      private final List<VisitableElement> elements = new ArrayList<>();
26  
27      private String name;
28  
29      public XmlElement(String name) {
30          this.name = name;
31      }
32  
33      /**
34       * Copy constructor. Not a truly deep copy, but close enough for most purposes.
35       *
36       * @param original
37       *            the original
38       */
39      public XmlElement(XmlElement original) {
40          super();
41          attributes.addAll(original.attributes);
42          elements.addAll(original.elements);
43          this.name = original.name;
44      }
45  
46      public List<Attribute> getAttributes() {
47          return attributes;
48      }
49  
50      public void addAttribute(Attribute attribute) {
51          attributes.add(attribute);
52      }
53  
54      public List<VisitableElement> getElements() {
55          return elements;
56      }
57  
58      public void addElement(VisitableElement element) {
59          elements.add(element);
60      }
61  
62      public void addElement(int index, VisitableElement element) {
63          elements.add(index, element);
64      }
65  
66      public String getName() {
67          return name;
68      }
69  
70      public boolean hasChildren() {
71          return !elements.isEmpty();
72      }
73  
74      public void setName(String name) {
75          this.name = name;
76      }
77  
78      @Override
79      public <R> R accept(ElementVisitor<R> visitor) {
80          return visitor.visit(this);
81      }
82  }