KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > parsing > CompositeComponentDefinition


1 /*
2  * Copyright 2002-2006 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  * 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 org.springframework.beans.factory.parsing;
18
19 import java.util.LinkedList JavaDoc;
20 import java.util.List JavaDoc;
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 AbstractComponentDefinition {
34
35     private final String JavaDoc name;
36
37     private final Object JavaDoc source;
38
39     private final List JavaDoc nestedComponents = new LinkedList JavaDoc();
40
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 JavaDoc name, Object JavaDoc source) {
48         Assert.notNull(name, "Name must not be null");
49         this.name = name;
50         this.source = source;
51     }
52
53
54     public String JavaDoc getName() {
55         return this.name;
56     }
57
58     public Object JavaDoc getSource() {
59         return this.source;
60     }
61
62
63     /**
64      * Add the given component as nested element of this composite component.
65      * @param component the nested component to add
66      */

67     public void addNestedComponent(ComponentDefinition component) {
68         Assert.notNull(component, "ComponentDefinition must not be null");
69         this.nestedComponents.add(component);
70     }
71
72     /**
73      * Return the nested components that this composite component holds.
74      * @return the array of nested components, or an empty array if none
75      */

76     public ComponentDefinition[] getNestedComponents() {
77         return (ComponentDefinition[])
78                 this.nestedComponents.toArray(new ComponentDefinition[this.nestedComponents.size()]);
79     }
80
81 }
82
Popular Tags