KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > support > ManagedList


1 /*
2  * Copyright 2002-2007 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.support;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.springframework.beans.BeanMetadataElement;
23 import org.springframework.beans.Mergeable;
24
25 /**
26  * Tag collection class used to hold managed List elements, which may
27  * include runtime bean references (to be resolved into bean objects).
28  *
29  * @author Rod Johnson
30  * @author Rob Harrop
31  * @author Juergen Hoeller
32  * @since 27.05.2003
33  */

34 public class ManagedList extends ArrayList JavaDoc implements Mergeable, BeanMetadataElement {
35
36     private Object JavaDoc source;
37
38     private boolean mergeEnabled;
39
40
41     public ManagedList() {
42     }
43
44     public ManagedList(int initialCapacity) {
45         super(initialCapacity);
46     }
47
48
49     /**
50      * Set the configuration source <code>Object</code> for this metadata element.
51      * <p>The exact type of the object will depend on the configuration mechanism used.
52      */

53     public void setSource(Object JavaDoc source) {
54         this.source = source;
55     }
56
57     public Object JavaDoc getSource() {
58         return this.source;
59     }
60
61     /**
62      * Set whether merging should be enabled for this collection,
63      * in case of a 'parent' collection value being present.
64      */

65     public void setMergeEnabled(boolean mergeEnabled) {
66         this.mergeEnabled = mergeEnabled;
67     }
68
69     public boolean isMergeEnabled() {
70         return this.mergeEnabled;
71     }
72
73     public Object JavaDoc merge(Object JavaDoc parent) {
74         if (!this.mergeEnabled) {
75             throw new IllegalStateException JavaDoc("Not allowed to merge when the 'mergeEnabled' property is set to 'false'");
76         }
77         if (parent == null) {
78             return this;
79         }
80         if (!(parent instanceof List JavaDoc)) {
81             throw new IllegalArgumentException JavaDoc("Cannot merge with object of type [" + parent.getClass() + "]");
82         }
83         List JavaDoc merged = new ManagedList();
84         merged.addAll((List JavaDoc) parent);
85         merged.addAll(this);
86         return merged;
87     }
88
89 }
90
Popular Tags