1/*
2 * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.jndi.ldap;
27
28import java.io.IOException;
29import javax.naming.*;
30import javax.naming.directory.*;
31import javax.naming.ldap.*;
32
33/**
34 * This class represents a factory for creating LDAPv3 response controls.
35 * The following response controls are supported:
36 * <ul>
37 * <li>
38 * Paged results, as defined in
39 * <a href="http://www.ietf.org/rfc/rfc2696.txt">RFC 2696</a>.
40 * <li>
41 * Server-side sorting, as defined in
42 * <a href="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>.
43 * <li>
44 * Entry change response control, as defined in
45 * <a href="http://www.ietf.org/internet-drafts/draft-ietf-ldapext-psearch-02.txt">draft-ietf-ldapext-psearch-02.txt</a>.
46 * </ul>
47 *
48 * @see javax.naming.ldap.SortResponseControl
49 * @see javax.naming.ldap.PagedResultsResponseControl
50 * @see PersistentSearchControl
51 * @see EntryChangeResponseControl
52 * @author Vincent Ryan
53 */
54public class DefaultResponseControlFactory extends ControlFactory {
55
56    /**
57     * Constructs a new instance of the response control factory.
58     */
59    public DefaultResponseControlFactory() {
60    }
61
62    /**
63     * Creates an instance of a response control class from a more
64     * generic control class (BasicControl).
65     *
66     * @param ctl A non-null control.
67     * @return    The LDAP control created or null if it cannot be created.
68     *            Null indicates that another factory should be attempted.
69     * @exception NamingException if this control factory encountered an
70     *            error condition while attempting to create the LDAP control,
71     *            and no other control factories are to be tried.
72     */
73    public Control getControlInstance(Control ctl)
74        throws NamingException {
75
76        String id = ctl.getID();
77//System.out.println(id);
78
79        try {
80            if (id.equals(SortResponseControl.OID)) {
81                return new SortResponseControl(id, ctl.isCritical(),
82                    ctl.getEncodedValue());
83
84            } else if (id.equals(PagedResultsResponseControl.OID)) {
85                return new PagedResultsResponseControl(id, ctl.isCritical(),
86                    ctl.getEncodedValue());
87
88            } else if (id.equals(EntryChangeResponseControl.OID)) {
89                return new EntryChangeResponseControl(id, ctl.isCritical(),
90                    ctl.getEncodedValue());
91
92            }
93        } catch (IOException e) {
94            NamingException ne = new NamingException();
95            ne.setRootCause(e);
96            throw ne;
97        }
98        return null;
99    }
100}
101