1 16 17 package org.apache.jetspeed.om.registry.base; 18 19 import java.util.Iterator ; 20 import java.util.Vector ; 21 22 import java.util.NoSuchElementException ; 23 import java.lang.UnsupportedOperationException ; 24 import java.lang.IllegalStateException ; 25 26 import org.apache.jetspeed.services.Registry; 27 28 29 36 public class PortletIterator implements Iterator 37 { 38 protected BasePortletEntry entry; 39 protected String method; 40 protected Vector vector ; 41 protected int index = 0; 42 43 public PortletIterator(BasePortletEntry entry, String method) 44 { 45 this.entry = entry; 46 this.method = method; 47 this.vector = getVector(); 48 } 49 50 public boolean hasNext() 51 { 52 int size = vector.size(); 53 54 if (size == 0) 55 return false; 56 57 if (index >= size) 58 { 59 entry = getParentEntry(entry); 60 if (entry == null) 61 return false; 62 vector = getVector(); 63 64 if (vector == null) 65 { 66 return false; 67 } 68 index = 0; 69 if (vector.size() == 0) 70 return false; 71 } 72 return true; 73 } 74 75 public void remove() throws IllegalStateException , UnsupportedOperationException 76 { 77 throw new UnsupportedOperationException ("The remove() method is not supported"); 78 } 79 80 protected BasePortletEntry getParentEntry(BasePortletEntry entry) 81 { 82 String parentName = entry.getParent(); 83 if (parentName == null || parentName.equals("")) 84 return null; 85 86 BasePortletEntry parent = null; 87 parent = (BasePortletEntry)Registry.getEntry( Registry.PORTLET, entry.getParent() ); 88 return parent; 89 } 90 91 public Object next() throws NoSuchElementException 92 { 93 Object o = vector.elementAt(index); 94 index++; 95 return o; 96 } 97 98 protected Vector getVector() 99 { 100 try 101 { 102 this.vector = (Vector )this.entry.getClass().getMethod(this.method, null).invoke(this.entry, null); 103 } 104 catch (Exception e) 105 { 106 this.vector = null; 107 } 108 109 return this.vector; 110 } 111 } 112 113 | Popular Tags |