KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > layout > impl > CompositeLayoutImpl


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
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 package org.apache.cocoon.portal.layout.impl;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.apache.cocoon.portal.layout.AbstractLayout;
23 import org.apache.cocoon.portal.layout.CompositeLayout;
24 import org.apache.cocoon.portal.layout.Item;
25 import org.apache.cocoon.portal.layout.Layout;
26 import org.apache.cocoon.util.ClassUtils;
27
28
29 /**
30  * A composite layout is a layout that contains other layouts.
31  *
32  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
33  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
34  *
35  * @version CVS $Id: CompositeLayoutImpl.java 219049 2005-07-14 15:11:52Z cziegeler $
36  */

37 public class CompositeLayoutImpl
38     extends AbstractLayout
39     implements CompositeLayout {
40
41     protected List JavaDoc items = new ArrayList JavaDoc();
42
43     /** The class name of the items */
44     protected String JavaDoc itemClassName;
45     
46     /**
47      * Constructor
48      */

49     public CompositeLayoutImpl() {
50         // nothing to do
51
}
52     
53     /**
54      * Add indexed item to the itemList.
55      * @param index index for the position inside the list
56      * @param item item to add
57      */

58     public final void addItem(int index, Item item) {
59         this.items.add(index, item);
60         item.setParent(this);
61     }
62
63     /**
64      * Add Item to the ItemList.
65      * @param item item to add
66      */

67     public final void addItem(Item item) {
68         this.items.add(item);
69         item.setParent(this);
70     }
71
72     /**
73      * Get Item from the ItemList.
74      * @return Item
75      */

76     public final Item getItem(int index) {
77         return (Item) this.items.get(index);
78     }
79
80     /**
81      * Get the ItemList.
82      * @return items
83      */

84     public final List JavaDoc getItems() {
85         return this.items;
86     }
87
88     /**
89      * Get size of ItemList.
90      * @return size
91      */

92     public final int getSize() {
93         return this.items.size();
94     }
95     
96     public final void removeItem(Item item) {
97         this.items.remove(item);
98         item.setParent(null);
99     }
100     
101     /* (non-Javadoc)
102      * @see org.apache.cocoon.portal.layout.CompositeLayout#createNewItem()
103      */

104     public Item createNewItem() {
105         if ( this.itemClassName == null ) {
106             return new Item();
107         }
108         try {
109             return (Item)ClassUtils.newInstance(this.itemClassName);
110         } catch (Exception JavaDoc ignore) {
111             return new Item();
112         }
113     }
114         
115     /**
116      * @return Returns the item class name.
117      */

118     public String JavaDoc getItemClassName() {
119         return this.itemClassName;
120     }
121     
122     /**
123      * @param value The item class name to set.
124      */

125     public void setItemClassName(String JavaDoc value) {
126         this.itemClassName = value;
127     }
128
129     /* (non-Javadoc)
130      * @see java.lang.Object#clone()
131      */

132     protected Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
133         CompositeLayoutImpl clone = (CompositeLayoutImpl)super.clone();
134         
135         // we are not cloning the items
136
clone.items = new ArrayList JavaDoc();
137
138         return clone;
139     }
140     
141     /* (non-Javadoc)
142      * @see org.apache.cocoon.portal.layout.Layout#copy(java.util.Map)
143      */

144     public Layout copy() {
145         CompositeLayoutImpl clone = (CompositeLayoutImpl)super.copy();
146         final Iterator JavaDoc i = this.items.iterator();
147         while ( i.hasNext() ) {
148             final Item current = (Item)i.next();
149             final Item clonedItem = current.copy(clone);
150             clone.addItem(clonedItem);
151         }
152         return clone;
153     }
154     
155 }
156
Popular Tags