1 28 29 package com.caucho.naming; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.CharBuffer; 33 import com.caucho.util.L10N; 34 35 import javax.naming.Binding ; 36 import javax.naming.NamingEnumeration ; 37 import javax.naming.NamingException ; 38 import java.util.ArrayList ; 39 import java.util.Collections ; 40 import java.util.List ; 41 import java.util.logging.Level ; 42 import java.util.logging.Logger ; 43 44 public class QBindingEnumeration implements NamingEnumeration { 45 private static final Logger log = Log.open(QBindingEnumeration.class); 46 private static final L10N L = new L10N(QBindingEnumeration.class); 47 48 private ContextImpl _context; 49 private List _list; 50 private int _index; 51 52 QBindingEnumeration(ContextImpl context, List list) 53 { 54 _context = context; 55 _list = list; 56 } 57 58 public boolean hasMore() 59 { 60 return _index < _list.size(); 61 } 62 63 public Binding next() 64 throws NamingException 65 { 66 String name = (String ) _list.get(_index++); 67 68 Object obj = _context.lookup(name); 69 70 return new Binding (name, obj, true); 71 } 72 73 public boolean hasMoreElements() 74 { 75 return hasMore(); 76 } 77 78 public Object nextElement() 79 { 80 try { 81 return next(); 82 } catch (Exception e) { 83 log.log(Level.FINE, e.toString(), e); 84 85 return null; 86 } 87 } 88 89 public void close() 90 { 91 } 92 93 public String toString() 94 { 95 CharBuffer cb = new CharBuffer(); 96 97 ArrayList list = new ArrayList (_list); 98 Collections.sort(list); 99 100 cb.append("QBindingEnumeration["); 101 for (int i = 0; i < list.size(); i++) { 102 String name = (String ) list.get(i); 103 104 if (i != 0) 105 cb.append(" "); 106 107 try { 108 cb.append("{" + name + ", " + _context.lookup(name) + "}"); 109 } catch (Exception e) { 110 cb.append("{" + name + ", " + e + "}"); 111 } 112 } 113 cb.append("]"); 114 115 return cb.toString(); 116 } 117 } 118 | Popular Tags |