1 17 package org.apache.ldap.server.db; 18 19 20 import org.apache.ldap.common.message.LockableAttributesImpl; 21 22 import javax.naming.NamingEnumeration ; 23 import javax.naming.NamingException ; 24 import javax.naming.directory.Attribute ; 25 import javax.naming.directory.Attributes ; 26 27 28 39 public class SearchResultEnumeration implements NamingEnumeration 40 { 41 42 private Database db = null; 43 44 45 private final String [] attrIds; 46 47 private final NamingEnumeration underlying; 48 49 50 57 public SearchResultEnumeration( String [] attrIds, 58 NamingEnumeration underlying, 59 Database db ) 60 { 61 this.db = db; 62 this.attrIds = attrIds; 63 this.underlying = underlying; 64 } 65 66 67 70 public void close() throws NamingException 71 { 72 underlying.close(); 73 } 74 75 76 79 public boolean hasMore() throws NamingException 80 { 81 return underlying.hasMore(); 82 } 83 84 85 88 public Object next() throws NamingException 89 { 90 IndexRecord rec = ( IndexRecord ) underlying.next(); 91 Attributes entry; 92 String name = db.getEntryUpdn( rec.getEntryId() ); 93 94 if ( null == rec.getAttributes() ) 95 { 96 rec.setAttributes( db.lookup( rec.getEntryId() ) ); 97 } 98 99 if ( attrIds == null ) 100 { 101 entry = ( Attributes ) rec.getAttributes().clone(); 102 } 103 else 104 { 105 entry = new LockableAttributesImpl(); 106 107 for ( int ii = 0; ii < attrIds.length; ii++ ) 108 { 109 if ( null == rec.getAttributes().get( attrIds[ii] ) ) 111 { 112 continue; 113 } 114 115 Attribute attr = ( Attribute ) rec.getAttributes().get( attrIds[ii] ).clone(); 117 entry.put( attr ); 118 } 119 } 120 121 return new DbSearchResult( rec.getEntryId(), name, null, entry ); 122 } 123 124 125 128 public boolean hasMoreElements() 129 { 130 return underlying.hasMoreElements(); 131 } 132 133 134 137 public Object nextElement() 138 { 139 return underlying.nextElement(); 140 } 141 } 142 | Popular Tags |