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.NameClassPair ; 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 QNameClassEnumeration implements NamingEnumeration { 45 private static final Logger log = Log.open(QNameClassEnumeration.class); 46 private static final L10N L = new L10N(QNameClassEnumeration.class); 47 48 private ContextImpl _context; 49 private List _list; 50 private int _index; 51 52 QNameClassEnumeration(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 Object next() 64 throws NamingException 65 { 66 String name = (String ) _list.get(_index++); 67 68 Object obj = _context.lookup(name); 69 70 if (obj != null) 71 return new NameClassPair (name, obj.getClass().getName()); 72 else 73 return new NameClassPair (name, "java.lang.Object"); 74 } 75 76 public boolean hasMoreElements() 77 { 78 return hasMore(); 79 } 80 81 public Object nextElement() 82 { 83 try { 84 return next(); 85 } catch (Exception e) { 86 log.log(Level.FINE, e.toString(), e); 87 88 return null; 89 } 90 } 91 92 public void close() 93 { 94 } 95 96 public String toString() 97 { 98 CharBuffer cb = new CharBuffer(); 99 100 cb.append("QNameClassEnumeration["); 101 ArrayList list = new ArrayList (_list); 102 Collections.sort(list); 103 104 for (int i = 0; i < list.size(); i++) { 105 String name = (String ) list.get(i); 106 try { 107 Object value = _context.lookup(name); 108 if (i != 0) 109 cb.append(' '); 110 111 if (value != null) 112 cb.append("{" + name + ", " + value.getClass() + "}"); 113 else 114 cb.append("{" + name + ", " + null + "}"); 115 } catch (Exception e) { 116 log.log(Level.FINE, e.toString(), e); 117 118 cb.append(" {" + name + ", " + e + "}"); 119 } 120 } 121 cb.append("]"); 122 123 return cb.toString(); 124 } 125 } 126 | Popular Tags |