Source Code Cross Referenced for LdapUtils.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jndi » provider » ldap » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.jndi.provider.ldap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more 
003:         *  contributor license agreements.  See the NOTICE file distributed with 
004:         *  this work for additional information regarding copyright ownership. 
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0 
006:         *  (the "License"); you may not use this file except in compliance with 
007:         *  the License.  You may obtain a copy of the License at 
008:         * 
009:         *     http://www.apache.org/licenses/LICENSE-2.0 
010:         * 
011:         *  Unless required by applicable law or agreed to in writing, software 
012:         *  distributed under the License is distributed on an "AS IS" BASIS, 
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
014:         *  See the License for the specific language governing permissions and 
015:         *  limitations under the License. 
016:         */
017:
018:        package org.apache.harmony.jndi.provider.ldap;
019:
020:        import java.lang.reflect.Constructor;
021:        import java.util.HashMap;
022:
023:        import javax.naming.AuthenticationException;
024:        import javax.naming.AuthenticationNotSupportedException;
025:        import javax.naming.CommunicationException;
026:        import javax.naming.ContextNotEmptyException;
027:        import javax.naming.InvalidNameException;
028:        import javax.naming.LimitExceededException;
029:        import javax.naming.NameAlreadyBoundException;
030:        import javax.naming.NameNotFoundException;
031:        import javax.naming.NamingException;
032:        import javax.naming.NoPermissionException;
033:        import javax.naming.OperationNotSupportedException;
034:        import javax.naming.PartialResultException;
035:        import javax.naming.ServiceUnavailableException;
036:        import javax.naming.SizeLimitExceededException;
037:        import javax.naming.TimeLimitExceededException;
038:        import javax.naming.directory.AttributeInUseException;
039:        import javax.naming.directory.InvalidAttributeIdentifierException;
040:        import javax.naming.directory.InvalidAttributeValueException;
041:        import javax.naming.directory.InvalidSearchFilterException;
042:        import javax.naming.directory.NoSuchAttributeException;
043:        import javax.naming.directory.SchemaViolationException;
044:
045:        import org.apache.harmony.jndi.internal.nls.Messages;
046:        import org.apache.harmony.jndi.provider.ldap.parser.FilterParser;
047:        import org.apache.harmony.jndi.provider.ldap.parser.LdapUrlParser;
048:        import org.apache.harmony.jndi.provider.ldap.parser.ParseException;
049:
050:        @SuppressWarnings("boxing")
051:        public class LdapUtils {
052:            private static HashMap<Integer, Class<?>> errorCodesMap = new HashMap<Integer, Class<?>>();
053:
054:            static {
055:                errorCodesMap.put(1, NamingException.class);
056:                errorCodesMap.put(2, CommunicationException.class);
057:                errorCodesMap.put(3, TimeLimitExceededException.class);
058:                errorCodesMap.put(4, SizeLimitExceededException.class);
059:                errorCodesMap.put(7, AuthenticationNotSupportedException.class);
060:                errorCodesMap.put(8, AuthenticationNotSupportedException.class);
061:                errorCodesMap.put(9, PartialResultException.class);
062:                errorCodesMap.put(11, LimitExceededException.class);
063:                errorCodesMap.put(12, OperationNotSupportedException.class);
064:                errorCodesMap
065:                        .put(13, AuthenticationNotSupportedException.class);
066:                errorCodesMap.put(16, NoSuchAttributeException.class);
067:                errorCodesMap
068:                        .put(17, InvalidAttributeIdentifierException.class);
069:                errorCodesMap.put(18, InvalidSearchFilterException.class);
070:                errorCodesMap.put(19, InvalidAttributeValueException.class);
071:                errorCodesMap.put(20, AttributeInUseException.class);
072:                errorCodesMap.put(21, InvalidAttributeValueException.class);
073:                errorCodesMap.put(32, NameNotFoundException.class);
074:                errorCodesMap.put(33, NamingException.class);
075:                errorCodesMap.put(34, InvalidNameException.class);
076:                errorCodesMap.put(36, NamingException.class);
077:                errorCodesMap
078:                        .put(48, AuthenticationNotSupportedException.class);
079:                errorCodesMap.put(49, AuthenticationException.class);
080:                errorCodesMap.put(50, NoPermissionException.class);
081:                errorCodesMap.put(51, ServiceUnavailableException.class);
082:                errorCodesMap.put(52, ServiceUnavailableException.class);
083:                errorCodesMap.put(53, OperationNotSupportedException.class);
084:                errorCodesMap.put(54, NamingException.class);
085:                errorCodesMap.put(64, InvalidNameException.class);
086:                errorCodesMap.put(65, SchemaViolationException.class);
087:                errorCodesMap.put(66, ContextNotEmptyException.class);
088:                errorCodesMap.put(67, SchemaViolationException.class);
089:                errorCodesMap.put(68, NameAlreadyBoundException.class);
090:                errorCodesMap.put(69, SchemaViolationException.class);
091:                errorCodesMap.put(71, NamingException.class);
092:                errorCodesMap.put(80, NamingException.class);
093:            }
094:
095:            public static Filter parseFilter(String filter, Object[] args)
096:                    throws InvalidSearchFilterException {
097:                if (filter == null) {
098:                    // ldap.28=Parameter of filter should not be null
099:                    throw new NullPointerException(Messages
100:                            .getString("ldap.28")); //$NON-NLS-1$
101:                }
102:
103:                FilterParser parser = new FilterParser(filter);
104:
105:                if (args == null) {
106:                    args = new Object[0];
107:                }
108:
109:                parser.setArgs(args);
110:
111:                try {
112:                    return parser.parse();
113:                } catch (ParseException e) {
114:                    // ldap.29=Invalid search filter
115:                    InvalidSearchFilterException ex = new InvalidSearchFilterException(
116:                            Messages.getString("ldap.29")); //$NON-NLS-1$
117:                    ex.setRootCause(e);
118:                    throw ex;
119:                }
120:            }
121:
122:            public static LdapUrlParser parserURL(String url,
123:                    boolean isAllowedQuery) throws InvalidNameException {
124:                if (url == null) {
125:                    // ldap.2B=LDAP URL should not be null
126:                    throw new NullPointerException(Messages
127:                            .getString("ldap.2B")); //$NON-NLS-1$
128:                }
129:
130:                LdapUrlParser parser = new LdapUrlParser(url);
131:                try {
132:                    parser.parseURL();
133:                } catch (ParseException e) {
134:                    // ldap.2C=Invalid LDAP URL
135:                    IllegalArgumentException ex = new IllegalArgumentException(
136:                            Messages.getString("ldap.2C")); //$NON-NLS-1$
137:                    ex.initCause(e);
138:                    throw ex;
139:                }
140:
141:                if (!isAllowedQuery
142:                        && (parser.getFilter() != null || parser.getControls() != null)) {
143:                    // ldap.2D=LDAP URL may only contain host, port and dn components
144:                    throw new InvalidNameException(Messages
145:                            .getString("ldap.2D")); //$NON-NLS-1$
146:                }
147:
148:                return parser;
149:            }
150:
151:            public static NamingException getExceptionFromResult(
152:                    LdapResult result) {
153:                int errorCode = result.getResultCode();
154:                // 0 means successful
155:                if (errorCode == 0) {
156:                    return null;
157:                }
158:
159:                Class<?> exceptionClass = errorCodesMap.get(errorCode);
160:                // not in map, using NamingException
161:                if (exceptionClass == null) {
162:                    exceptionClass = NamingException.class;
163:                }
164:
165:                try {
166:                    Constructor<?> constructor = exceptionClass
167:                            .getConstructor(new Class[] { String.class });
168:                    String message = null;
169:
170:                    if (result.getErrorMessage() != null
171:                            && !result.getErrorMessage().equals("")) { //$NON-NLS-1$
172:                        // ldap.34=[LDAP: error code {0} - {1}]
173:                        message = Messages.getString("ldap.34", new Object[] { //$NON-NLS-1$
174:                                errorCode, result.getErrorMessage() });
175:                    } else {
176:                        // ldap.35=[LDAP: error code {0}]
177:                        message = Messages.getString("ldap.35", //$NON-NLS-1$
178:                                new Object[] { errorCode });
179:                    }
180:
181:                    return (NamingException) constructor
182:                            .newInstance(new Object[] { message });
183:                } catch (Exception e) {
184:                    // ldap.35=[LDAP: error code {0}]
185:                    return new NamingException(Messages.getString("ldap.35", //$NON-NLS-1$
186:                            new Object[] { errorCode }));
187:                }
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.