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.List;
24: import java.util.Set;
25:
26: import javax.naming.InvalidNameException;
27: import javax.naming.Name;
28: import javax.naming.NamingException;
29: import javax.naming.directory.Attributes;
30: import javax.naming.directory.BasicAttribute;
31: import javax.naming.directory.BasicAttributes;
32:
33: public class LdapSchemaAttrDefContextImpl extends LdapContextImpl {
34:
35: private Hashtable<String, Object> attrTree;
36:
37: public LdapSchemaAttrDefContextImpl(Name name,
38: Hashtable<Object, Object> env,
39: Hashtable<String, Object> classTree, LdapContextImpl ctx)
40: throws InvalidNameException {
41: super (ctx, env, "");
42: this .attrTree = classTree;
43: }
44:
45: public Attributes getAttributes(Name name) throws NamingException {
46: return getAttributes(name, new String[0]);
47: }
48:
49: public Attributes getAttributes(Name name, String[] as)
50: throws NamingException {
51: BasicAttributes attributes = new BasicAttributes();
52: Set<String> keySet = attrTree.keySet();
53: Iterator<String> iter = keySet.iterator();
54: while (iter.hasNext()) {
55: String key = iter.next();
56: if (key.equals("orig"))
57: continue;
58: Object value = attrTree.get(key);
59: BasicAttribute attr = new BasicAttribute(key);
60: if (value instanceof ArrayList) {
61: List list = (List) value;
62: for (int i = 0; i < list.size(); i++) {
63: attr.add(list.get(i));
64: }
65: } else {
66: attr.add(value);
67: }
68: attributes.put(attr);
69: }
70: return attributes;
71: }
72:
73: public Attributes getAttributes(String s) throws NamingException {
74: return getAttributes(convertFromStringToName(s));
75: }
76: }
|