View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
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    *      http://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  
17  package net.sf.ehcache.config.generator;
18  
19  import java.io.PrintWriter;
20  import java.util.Arrays;
21  import java.util.HashSet;
22  import java.util.List;
23  import java.util.Set;
24  
25  import net.sf.ehcache.config.generator.model.NodeAttribute;
26  import net.sf.ehcache.config.generator.model.NodeElement;
27  import net.sf.ehcache.config.generator.model.XMLGeneratorVisitor;
28  
29  public class ElementIgnoringXMLGenerator extends XMLGeneratorVisitor {
30  
31      private final Set<String> ignoredElements;
32  
33      public ElementIgnoringXMLGenerator(PrintWriter out, String... ignoredElements) {
34          super(out);
35          this.ignoredElements = new HashSet<String>(Arrays.asList(ignoredElements));
36      }
37  
38      @Override
39      protected void endAttributes(NodeElement element) {
40          if (ignoredElements.contains(element.getName())) {
41              return;
42          }
43          super.endAttributes(element);
44      }
45  
46      @Override
47      protected void endChildren(NodeElement element) {
48          if (ignoredElements.contains(element.getName())) {
49              return;
50          }
51          super.endChildren(element);
52      }
53  
54      @Override
55      protected void endElement(NodeElement element) {
56          if (ignoredElements.contains(element.getName())) {
57              return;
58          }
59          super.endElement(element);
60      }
61  
62      @Override
63      protected void startAttributes(NodeElement element) {
64          if (ignoredElements.contains(element.getName())) {
65              return;
66          }
67          super.startAttributes(element);
68      }
69  
70      @Override
71      protected void startChildren(NodeElement element) {
72          if (ignoredElements.contains(element.getName())) {
73              return;
74          }
75          super.startChildren(element);
76      }
77  
78      @Override
79      protected void startElement(NodeElement element) {
80          if (ignoredElements.contains(element.getName())) {
81              return;
82          }
83          super.startElement(element);
84      }
85  
86      @Override
87      protected void visitAttributes(NodeElement element, List<NodeAttribute> attributes) {
88          if (ignoredElements.contains(element.getName())) {
89              return;
90          }
91          super.visitAttributes(element, attributes);
92      }
93  
94  }