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.internal;
19:
20: import java.util.HashMap;
21:
22: import javax.naming.AuthenticationNotSupportedException;
23: import javax.naming.CommunicationException;
24: import javax.naming.LimitExceededException;
25: import javax.naming.NamingException;
26: import javax.naming.NoPermissionException;
27: import javax.naming.OperationNotSupportedException;
28: import javax.naming.PartialResultException;
29: import javax.naming.ServiceUnavailableException;
30: import javax.naming.SizeLimitExceededException;
31: import javax.naming.TimeLimitExceededException;
32: import javax.naming.directory.InvalidSearchFilterException;
33: import javax.naming.directory.NoSuchAttributeException;
34:
35: import org.apache.harmony.jndi.internal.nls.Messages;
36:
37: /**
38: * Some useful utilities
39: */
40: public class Util {
41:
42: private static HashMap errorCodes = new HashMap();
43:
44: static {
45: // TODO Add every needed LDAP errror code description and exception
46: errorCodes.put(1, new NamingException(Messages
47: .getString("ldap.0A")));
48: errorCodes.put(2, new CommunicationException(Messages
49: .getString("ldap.0B")));
50: errorCodes.put(3, new TimeLimitExceededException(Messages
51: .getString("ldap.0C")));
52: errorCodes.put(4, new SizeLimitExceededException(Messages
53: .getString("ldap.0D")));
54: errorCodes.put(7, new AuthenticationNotSupportedException(
55: Messages.getString("ldap.0E")));
56: errorCodes.put(8, new AuthenticationNotSupportedException(
57: Messages.getString("ldap.0F")));
58: errorCodes.put(9, new PartialResultException(Messages
59: .getString("ldap.10")));
60: errorCodes.put(11, new LimitExceededException(Messages
61: .getString("ldap.11")));
62: errorCodes.put(16, new NoSuchAttributeException(Messages
63: .getString("ldap.12")));
64: errorCodes.put(18, new InvalidSearchFilterException(Messages
65: .getString("ldap.13")));
66: errorCodes.put(50, new NoPermissionException(Messages
67: .getString("ldap.14")));
68: errorCodes.put(51, new ServiceUnavailableException(Messages
69: .getString("ldap.15")));
70: errorCodes.put(53, new OperationNotSupportedException(Messages
71: .getString("ldap.16")));
72: errorCodes.put(80, new NamingException(Messages
73: .getString("ldap.17")));
74: }
75:
76: /**
77: * Return the correct exception for a given error code
78: *
79: * @param code
80: * error code
81: * @return the correct NamingException
82: */
83: public static NamingException getExceptionFromErrorCode(int code) {
84: if (code == 0) {
85: return null;
86: }
87: if (errorCodes.get(code) == null) {
88: return new NamingException(Messages.getString("ldap.18")
89: + " " + code + "]");
90: }
91: return (NamingException) errorCodes.get(code);
92: }
93:
94: }
|