36
37 final class LdapSearchEnumeration extends LdapNamingEnumeration {
38
39 private Name startName; // prefix of names of search results
40 private LdapCtx.SearchArgs searchArgs = null;
41
42 LdapSearchEnumeration(LdapCtx homeCtx, LdapResult search_results,
43 String starter, LdapCtx.SearchArgs args, Continuation cont)
44 throws NamingException {
45
46 super(homeCtx, search_results,
47 args.name, /* listArg */
48 cont);
49
50 // fully qualified name of starting context of search
51 startName = new LdapName(starter);
52 searchArgs = args;
53 }
54
55 protected NameClassPair
56 createItem(String dn, Attributes attrs, Vector respCtls)
57 throws NamingException {
58
59 Object obj = null;
60
61 String relStart; // name relative to starting search context
62 String relHome; // name relative to homeCtx.currentDN
63 boolean relative = true; // whether relative to currentDN
64
65 // need to strip off all but lowest component of dn
66 // so that is relative to current context (currentDN)
67
68 try {
69 Name parsed = new LdapName(dn);
70 // System.err.println("dn string: " + dn);
71 // System.err.println("dn name: " + parsed);
72
73 if (startName != null && parsed.startsWith(startName)) {
74 relStart = parsed.getSuffix(startName.size()).toString();
75 relHome = parsed.getSuffix(homeCtx.currentParsedDN.size()).toString();
76 } else {
164 if (respCtls != null) {
165 sr = new SearchResultWithControls(
166 (relative ? cn.toString() : relStart), obj, attrs,
167 relative, homeCtx.convertControls(respCtls));
168 } else {
169 sr = new SearchResult(
170 (relative ? cn.toString() : relStart),
171 obj, attrs, relative);
172 }
173 sr.setNameInNamespace(dn);
174 return sr;
175 }
176
177 public void appendUnprocessedReferrals(LdapReferralException ex) {
178
179 // a referral has been followed so do not create relative names
180 startName = null;
181 super.appendUnprocessedReferrals(ex);
182 }
183
184 protected LdapNamingEnumeration
185 getReferredResults(LdapReferralContext refCtx) throws NamingException {
186 // repeat the original operation at the new context
187 return (LdapSearchEnumeration)
188 refCtx.search(searchArgs.name, searchArgs.filter, searchArgs.cons);
189 }
190
191 protected void update(LdapNamingEnumeration ne) {
192 super.update(ne);
193
194 // Update search-specific variables
195 LdapSearchEnumeration se = (LdapSearchEnumeration)ne;
196 startName = se.startName;
197 //VR - keep original args, don't overwite with current args
198 // searchArgs = se.searchArgs;
199 }
200
201 void setStartName(Name nm) {
202 startName = nm;
203 }
204 }
|
36
37 final class LdapSearchEnumeration extends LdapNamingEnumeration {
38
39 private Name startName; // prefix of names of search results
40 private LdapCtx.SearchArgs searchArgs = null;
41
42 LdapSearchEnumeration(LdapCtx homeCtx, LdapResult search_results,
43 String starter, LdapCtx.SearchArgs args, Continuation cont)
44 throws NamingException {
45
46 super(homeCtx, search_results,
47 args.name, /* listArg */
48 cont);
49
50 // fully qualified name of starting context of search
51 startName = new LdapName(starter);
52 searchArgs = args;
53 }
54
55 protected NameClassPair
56 createItem(String dn, Attributes attrs, Vector<Control> respCtls)
57 throws NamingException {
58
59 Object obj = null;
60
61 String relStart; // name relative to starting search context
62 String relHome; // name relative to homeCtx.currentDN
63 boolean relative = true; // whether relative to currentDN
64
65 // need to strip off all but lowest component of dn
66 // so that is relative to current context (currentDN)
67
68 try {
69 Name parsed = new LdapName(dn);
70 // System.err.println("dn string: " + dn);
71 // System.err.println("dn name: " + parsed);
72
73 if (startName != null && parsed.startsWith(startName)) {
74 relStart = parsed.getSuffix(startName.size()).toString();
75 relHome = parsed.getSuffix(homeCtx.currentParsedDN.size()).toString();
76 } else {
164 if (respCtls != null) {
165 sr = new SearchResultWithControls(
166 (relative ? cn.toString() : relStart), obj, attrs,
167 relative, homeCtx.convertControls(respCtls));
168 } else {
169 sr = new SearchResult(
170 (relative ? cn.toString() : relStart),
171 obj, attrs, relative);
172 }
173 sr.setNameInNamespace(dn);
174 return sr;
175 }
176
177 public void appendUnprocessedReferrals(LdapReferralException ex) {
178
179 // a referral has been followed so do not create relative names
180 startName = null;
181 super.appendUnprocessedReferrals(ex);
182 }
183
184 protected LdapSearchEnumeration
185 getReferredResults(LdapReferralContext refCtx) throws NamingException {
186 // repeat the original operation at the new context
187 return (LdapSearchEnumeration)(NamingEnumeration)
188 refCtx.search(searchArgs.name, searchArgs.filter, searchArgs.cons);
189 }
190
191 protected void update(LdapNamingEnumeration ne) {
192 super.update(ne);
193
194 // Update search-specific variables
195 LdapSearchEnumeration se = (LdapSearchEnumeration)ne;
196 startName = se.startName;
197 //VR - keep original args, don't overwite with current args
198 // searchArgs = se.searchArgs;
199 }
200
201 void setStartName(Name nm) {
202 startName = nm;
203 }
204 }
|