01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 org.springframework.beans.factory.parsing;
18:
19: import java.util.LinkedList;
20: import java.util.List;
21:
22: import org.springframework.util.Assert;
23:
24: /**
25: * {@link ComponentDefinition} implementation that holds one or more nested
26: * {@link ComponentDefinition} instances, aggregating them into a named group
27: * of components.
28: *
29: * @author Juergen Hoeller
30: * @since 2.0.1
31: * @see #getNestedComponents()
32: */
33: public class CompositeComponentDefinition extends
34: AbstractComponentDefinition {
35:
36: private final String name;
37:
38: private final Object source;
39:
40: private final List nestedComponents = new LinkedList();
41:
42: /**
43: * Create a new CompositeComponentDefinition.
44: * @param name the name of the composite component
45: * @param source the source element that defines the root of the composite component
46: */
47: public CompositeComponentDefinition(String name, Object source) {
48: Assert.notNull(name, "Name must not be null");
49: this .name = name;
50: this .source = source;
51: }
52:
53: public String getName() {
54: return this .name;
55: }
56:
57: public Object getSource() {
58: return this .source;
59: }
60:
61: /**
62: * Add the given component as nested element of this composite component.
63: * @param component the nested component to add
64: */
65: public void addNestedComponent(ComponentDefinition component) {
66: Assert.notNull(component,
67: "ComponentDefinition must not be null");
68: this .nestedComponents.add(component);
69: }
70:
71: /**
72: * Return the nested components that this composite component holds.
73: * @return the array of nested components, or an empty array if none
74: */
75: public ComponentDefinition[] getNestedComponents() {
76: return (ComponentDefinition[]) this .nestedComponents
77: .toArray(new ComponentDefinition[this.nestedComponents
78: .size()]);
79: }
80:
81: }
|