1 /*
2 * Copyright 2004-2008 the Seasar Foundation and the Others.
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,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.seasar.uruma.rcp.configuration.elements;
17
18 import java.io.Writer;
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.seasar.uruma.rcp.configuration.ConfigurationElement;
24 import org.seasar.uruma.rcp.configuration.ConfigurationElementContainer;
25
26 /**
27 * {@link ConfigurationElementContainer} のための基底クラスです。<br />
28 *
29 * @author y-komori
30 */
31 public abstract class AbstractConfigurationElementContainer extends
32 AbstractConfigurationElement implements ConfigurationElementContainer {
33
34 private List<ConfigurationElement> children = new ArrayList<ConfigurationElement>();
35
36 /*
37 * @see org.seasar.uruma.rcp.configuration.ConfigurationElementContainer#addElement(org.seasar.uruma.rcp.configuration.ConfigurationElement)
38 */
39 public void addElement(final ConfigurationElement element) {
40 children.add(element);
41 }
42
43 /*
44 * @see org.seasar.uruma.rcp.configuration.ConfigurationElementContainer#getElements()
45 */
46 public List<ConfigurationElement> getElements() {
47 return Collections.unmodifiableList(children);
48 }
49
50 /*
51 * @see org.seasar.uruma.rcp.configuration.elements.AbstractConfigurationElement#writeConfiguration(java.io.Writer)
52 */
53 @Override
54 public void writeConfiguration(final Writer writer) {
55 if (configurationWriter != null) {
56 configurationWriter.writeStartTag(this, writer, level);
57 }
58
59 for (ConfigurationElement element : children) {
60 element.setLevel(level + 1);
61 element.writeConfiguration(writer);
62 }
63
64 if (configurationWriter != null) {
65 configurationWriter.writeEndTag(this, writer, level);
66 }
67 }
68 }