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 javax.naming.ldap;
019:
020: import java.io.BufferedReader;
021: import java.io.IOException;
022: import java.io.InputStreamReader;
023: import java.net.URL;
024: import java.util.Enumeration;
025:
026: import javax.naming.NamingException;
027:
028: import org.apache.harmony.jndi.internal.nls.Messages;
029:
030: /**
031: * TODO: JavaDoc
032: */
033: public class StartTlsRequest implements ExtendedRequest {
034:
035: private static final long serialVersionUID = 4441679576360753397L;
036:
037: public static final String OID = "1.3.6.1.4.1.1466.20037"; //$NON-NLS-1$
038:
039: public byte[] getEncodedValue() {
040: return null;
041: }
042:
043: public String getID() {
044: return OID;
045: }
046:
047: public ExtendedResponse createExtendedResponse(String id,
048: byte[] berValue, int offset, int length)
049: throws NamingException {
050:
051: if (id != null && !OID.equals(id)) {
052: throw new NamingException(Messages.getString("ldap.07")
053: + " " + id);
054: }
055:
056: ClassLoader cl = Thread.currentThread().getContextClassLoader();
057:
058: try {
059: Enumeration<URL> en = cl
060: .getResources("META-INF/services/javax.naming.ldap.StartTlsResponse"); //$NON-NLS-1$
061: while (en.hasMoreElements()) {
062: URL confFile = en.nextElement();
063: BufferedReader reader = null;
064: try {
065: reader = new BufferedReader(new InputStreamReader(
066: confFile.openStream()));
067:
068: String line;
069: while ((line = reader.readLine()) != null) {
070: // remove comments, spaces, and tabs
071: String className = line.split("#")[0].trim(); //$NON-NLS-1$
072:
073: // try to load class
074: if (!(className.equals(""))) { //$NON-NLS-1$
075: try {
076: /*
077: * TODO: the spec requires to return an instance
078: * of the first class that might be successfully
079: * instantiated, RI breaks on the first
080: * unsuccessful attempt. We follow the spec
081: * here.
082: */
083: return (StartTlsResponse) Class
084: .forName(className, true, cl)
085: .newInstance();
086: } catch (Exception ignore) {
087: // ignore
088: }
089: }
090: }
091: } catch (IOException e) {
092: // ignore
093: } finally {
094: if (reader != null) {
095: reader.close();
096: }
097: }
098: }
099: } catch (IOException e) {
100: // ignore
101: }
102:
103: try {
104: return (StartTlsResponse) Class
105: .forName(
106: "org.apache.harmony.jndi.provider.ldap.ext.StartTlsResponseImpl",
107: true, cl).newInstance();
108: } catch (Exception e) {
109: // ignore
110: }
111:
112: throw new NamingException(Messages.getString("ldap.09")); //$NON-NLS-1$
113: }
114: }
|