1418N/A/*
1472N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
1418N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1418N/A *
1418N/A * This code is free software; you can redistribute it and/or modify it
1418N/A * under the terms of the GNU General Public License version 2 only, as
1418N/A * published by the Free Software Foundation. Oracle designates this
1418N/A * particular file as subject to the "Classpath" exception as provided
1418N/A * by Oracle in the LICENSE file that accompanied this code.
1418N/A *
1418N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1418N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1418N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1418N/A * version 2 for more details (a copy is included in the LICENSE file that
1418N/A * accompanied this code).
1418N/A *
1418N/A * You should have received a copy of the GNU General Public License version
1418N/A * 2 along with this work; if not, write to the Free Software Foundation,
1472N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1472N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1418N/A * or visit www.oracle.com if you need additional information or have any
1418N/A * questions.
1418N/A */
1418N/A
1418N/Apackage com.sun.jndi.ldap;
1418N/A
1418N/Aimport javax.naming.ldap.*;
1418N/A
1418N/A/**
1418N/A * This class provides a basic implementation of the <tt>Control</tt>
1418N/A * interface. It represents an LDAPv3 Control as defined in RFC-2251.
1418N/A *
1418N/A * @author Vincent Ryan
1418N/A */
1418N/Apublic class BasicControl implements Control {
1418N/A
1418N/A /**
1418N/A * The control's object identifier string.
1418N/A *
1418N/A * @serial
1418N/A */
1418N/A protected String id;
1418N/A
1418N/A /**
1418N/A * The control's criticality.
1418N/A *
1418N/A * @serial
1418N/A */
1418N/A protected boolean criticality = false; // default
1418N/A
1418N/A /**
1418N/A * The control's ASN.1 BER encoded value.
1418N/A *
1418N/A * @serial
1418N/A */
1418N/A protected byte[] value = null;
1418N/A
1418N/A private static final long serialVersionUID = -5914033725246428413L;
1418N/A
1418N/A /**
1418N/A * Constructs a new instance of BasicControl.
1418N/A * It is a non-critical control.
1418N/A *
1418N/A * @param id The control's object identifier string.
1418N/A *
1418N/A */
1418N/A public BasicControl(String id) {
1418N/A this.id = id;
1418N/A }
1418N/A
1418N/A /**
1418N/A * Constructs a new instance of BasicControl.
1418N/A *
1418N/A * @param id The control's object identifier string.
1418N/A * @param criticality The control's criticality.
1418N/A * @param value The control's ASN.1 BER encoded value.
1418N/A * May be null.
1418N/A */
1418N/A public BasicControl(String id, boolean criticality, byte[] value) {
1418N/A this.id = id;
1418N/A this.criticality = criticality;
1418N/A if (value != null) {
1418N/A this.value = value;
1418N/A }
1418N/A }
1418N/A
1418N/A /**
1418N/A * Retrieves the control's object identifier string.
1418N/A *
1418N/A * @return The non-null object identifier string.
1418N/A */
1418N/A public String getID() {
1418N/A return id;
1418N/A }
1418N/A
1418N/A /**
1418N/A * Determines the control's criticality.
1418N/A *
1418N/A * @return true if the control is critical; false otherwise.
1418N/A */
1418N/A public boolean isCritical() {
1418N/A return criticality;
1418N/A }
1418N/A
1418N/A /**
1418N/A * Retrieves the control's ASN.1 BER encoded value.
1418N/A * The result is the raw BER bytes including the tag and length of
1418N/A * the control's value. It does not include the control's object
1418N/A * identifier string or criticality.
1418N/A *
1418N/A * @return A possibly null byte array representing the control's
1418N/A * ASN.1 BER encoded value.
1418N/A */
1418N/A public byte[] getEncodedValue() {
1418N/A return value == null ? null : value.clone();
1418N/A }
1418N/A}
1418N/A