01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.commons.digester;
19:
20: import java.util.List;
21: import java.util.LinkedList;
22: import java.util.Iterator;
23:
24: /**
25: * Simple class for use in unit tests. A box has an ID, and can have
26: * multiple boxes within it.
27: */
28: public class Box {
29: private String id;
30:
31: private List children = new LinkedList();
32:
33: public Box() {
34: }
35:
36: public String getId() {
37: return id;
38: }
39:
40: public void setId(String id) {
41: this .id = id;
42: }
43:
44: public void addChild(Box child) {
45: this .children.add(child);
46: }
47:
48: public List getChildren() {
49: return children;
50: }
51:
52: public String toString() {
53: StringBuffer buf = new StringBuffer();
54: buf.append("[Box] id=");
55: buf.append(id);
56: buf.append(" nchildren=");
57: buf.append(children.size());
58:
59: for (Iterator i = children.iterator(); i.hasNext();) {
60: Box child = (Box) i.next();
61: buf.append(" ");
62: buf.append(child.toString());
63: }
64: return buf.toString();
65: }
66:
67: /**
68: * Return a string containing this object's name value, followed by the
69: * names of all child objects (and their children etc) in pre-order
70: * sequence. Each name is separated by a space from the preceding one.
71: */
72: public String getIds() {
73: StringBuffer buf = new StringBuffer();
74: buf.append(this .id);
75: for (Iterator i = children.iterator(); i.hasNext();) {
76: Box child = (Box) i.next();
77: buf.append(" ");
78: buf.append(child.getIds());
79: }
80: return buf.toString();
81: }
82: }
|