01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.jndi.provider.ldap;
19:
20: import java.util.ArrayList;
21: import java.util.Hashtable;
22: import java.util.Iterator;
23: import java.util.Set;
24:
25: import javax.naming.InvalidNameException;
26: import javax.naming.Name;
27: import javax.naming.NamingEnumeration;
28: import javax.naming.NamingException;
29: import javax.naming.directory.Attributes;
30: import javax.naming.directory.BasicAttributes;
31: import javax.naming.directory.SearchResult;
32:
33: public class LdapSchemaClassDefContextImpl extends LdapContextImpl {
34:
35: private Hashtable<String, ArrayList<String>> classTree;
36: private LdapContextImpl context;
37:
38: public LdapSchemaClassDefContextImpl(Name name,
39: Hashtable<Object, Object> env,
40: Hashtable<String, ArrayList<String>> classTree,
41: LdapContextImpl ctx) throws InvalidNameException {
42: super (ctx, env, "");
43: context = ctx;
44: this .classTree = classTree;
45: }
46:
47: public NamingEnumeration<SearchResult> search(Name name,
48: Attributes attributes) throws NamingException {
49: Set<String> keyset = classTree.keySet();
50: LdapNamingEnumeration<SearchResult> enumeration = new LdapNamingEnumeration<SearchResult>(
51: null, null);
52: Attributes as = null;
53: for (Iterator<String> iter = keyset.iterator(); iter.hasNext();) {
54: ArrayList<String> classes = classTree.get(iter.next());
55: for (int j = 0; j < classes.size(); j++) {
56: String className = classes.get(j);
57: Hashtable<String, Object> classDefInfo = context
58: .findSchemaDefInfo(
59: LdapSchemaContextImpl.OBJECT_CLASSES,
60: className.toLowerCase());
61: as = new BasicAttributes();
62: Set<String> keySet = classDefInfo.keySet();
63: for (Iterator<String> iterator = keySet.iterator(); iterator
64: .hasNext();) {
65: String key = iterator.next();
66: Object value = classDefInfo.get(key);
67: as.put(key, value);
68: }
69: SearchResult result = new SearchResult(className, null,
70: as);
71: enumeration.add(result);
72: }
73: }
74: return enumeration;
75: }
76:
77: public NamingEnumeration<SearchResult> search(String name,
78: Attributes attributes) throws NamingException {
79: return search(convertFromStringToName(name), attributes);
80: }
81: }
|