001: /*
002: * Copyright 1999-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.jndi.ldap;
027:
028: import java.io.IOException;
029: import javax.naming.*;
030: import javax.naming.directory.*;
031: import javax.naming.ldap.*;
032:
033: /**
034: * This class represents a factory for creating LDAPv3 response controls.
035: * The following response controls are supported:
036: * <ul>
037: * <li>
038: * Paged results, as defined in
039: * <a href="http://www.ietf.org/rfc/rfc2696.txt">RFC 2696</a>.
040: * <li>
041: * Server-side sorting, as defined in
042: * <a href="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>.
043: * <li>
044: * Entry change response control, as defined in
045: * <a href="http://www.ietf.org/internet-drafts/draft-ietf-ldapext-psearch-02.txt">draft-ietf-ldapext-psearch-02.txt</a>.
046: * </ul>
047: *
048: * @see javax.naming.ldap.SortResponseControl
049: * @see javax.naming.ldap.PagedResultsResponseControl
050: * @see PersistentSearchControl
051: * @see EntryChangeResponseControl
052: * @author Vincent Ryan
053: */
054: public class DefaultResponseControlFactory extends ControlFactory {
055:
056: /**
057: * Constructs a new instance of the response control factory.
058: */
059: public DefaultResponseControlFactory() {
060: }
061:
062: /**
063: * Creates an instance of a response control class from a more
064: * generic control class (BasicControl).
065: *
066: * @param ctl A non-null control.
067: * @return The LDAP control created or null if it cannot be created.
068: * Null indicates that another factory should be attempted.
069: * @exception NamingException if this control factory encountered an
070: * error condition while attempting to create the LDAP control,
071: * and no other control factories are to be tried.
072: */
073: public Control getControlInstance(Control ctl)
074: throws NamingException {
075:
076: String id = ctl.getID();
077: //System.out.println(id);
078:
079: try {
080: if (id.equals(SortResponseControl.OID)) {
081: return new SortResponseControl(id, ctl.isCritical(),
082: ctl.getEncodedValue());
083:
084: } else if (id.equals(PagedResultsResponseControl.OID)) {
085: return new PagedResultsResponseControl(id, ctl
086: .isCritical(), ctl.getEncodedValue());
087:
088: } else if (id.equals(EntryChangeResponseControl.OID)) {
089: return new EntryChangeResponseControl(id, ctl
090: .isCritical(), ctl.getEncodedValue());
091:
092: }
093: } catch (IOException e) {
094: NamingException ne = new NamingException();
095: ne.setRootCause(e);
096: throw ne;
097: }
098: return null;
099: }
100: }
|