1 17 18 19 package org.apache.naming; 20 21 import java.util.Iterator ; 22 23 import javax.naming.Binding ; 24 import javax.naming.CompositeName ; 25 import javax.naming.Context ; 26 import javax.naming.NamingEnumeration ; 27 import javax.naming.NamingException ; 28 29 35 36 public class NamingContextBindingsEnumeration 37 implements NamingEnumeration { 38 39 40 42 43 public NamingContextBindingsEnumeration(Iterator entries, Context ctx) { 44 iterator = entries; 45 this.ctx = ctx; 46 } 47 48 50 51 54 protected Iterator iterator; 55 56 57 60 private Context ctx; 61 62 63 65 66 69 public Object next() 70 throws NamingException { 71 return nextElementInternal(); 72 } 73 74 75 78 public boolean hasMore() 79 throws NamingException { 80 return iterator.hasNext(); 81 } 82 83 84 87 public void close() 88 throws NamingException { 89 } 90 91 92 public boolean hasMoreElements() { 93 return iterator.hasNext(); 94 } 95 96 97 public Object nextElement() { 98 try { 99 return nextElementInternal(); 100 } catch (NamingException e) { 101 throw new RuntimeException (e.getMessage(), e); 102 } 103 } 104 105 private Object nextElementInternal() throws NamingException { 106 NamingEntry entry = (NamingEntry) iterator.next(); 107 108 if (entry.type == NamingEntry.REFERENCE 110 || entry.type == NamingEntry.LINK_REF) { 111 try { 112 ctx.lookup(new CompositeName (entry.name)); 114 } catch (NamingException e) { 115 throw e; 116 } catch (Exception e) { 117 NamingException ne = new NamingException (e.getMessage()); 118 ne.initCause(e); 119 throw ne; 120 } 121 } 122 123 return new Binding (entry.name, entry.value.getClass().getName(), 124 entry.value, true); 125 } 126 127 128 } 129 130 | Popular Tags |