1 16 package org.apache.cocoon.portal.layout.impl; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 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 37 public class CompositeLayoutImpl 38 extends AbstractLayout 39 implements CompositeLayout { 40 41 protected List items = new ArrayList (); 42 43 44 protected String itemClassName; 45 46 49 public CompositeLayoutImpl() { 50 } 52 53 58 public final void addItem(int index, Item item) { 59 this.items.add(index, item); 60 item.setParent(this); 61 } 62 63 67 public final void addItem(Item item) { 68 this.items.add(item); 69 item.setParent(this); 70 } 71 72 76 public final Item getItem(int index) { 77 return (Item) this.items.get(index); 78 } 79 80 84 public final List getItems() { 85 return this.items; 86 } 87 88 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 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 ignore) { 111 return new Item(); 112 } 113 } 114 115 118 public String getItemClassName() { 119 return this.itemClassName; 120 } 121 122 125 public void setItemClassName(String value) { 126 this.itemClassName = value; 127 } 128 129 132 protected Object clone() throws CloneNotSupportedException { 133 CompositeLayoutImpl clone = (CompositeLayoutImpl)super.clone(); 134 135 clone.items = new ArrayList (); 137 138 return clone; 139 } 140 141 144 public Layout copy() { 145 CompositeLayoutImpl clone = (CompositeLayoutImpl)super.copy(); 146 final Iterator 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 |