1. /*
  2. * @(#)BasicControl.java 1.3 03/12/19
  3. *
  4. *
  5. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  6. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  7. */
  8. package javax.naming.ldap;
  9. /**
  10. * This class provides a basic implementation of the <tt>Control</tt>
  11. * interface. It represents an LDAPv3 Control as defined in
  12. * <a href="http://www.ietf.org/rfc/rfc2251.txt">RFC 2251</a>.
  13. *
  14. * @since 1.5
  15. * @author Vincent Ryan
  16. */
  17. public class BasicControl implements Control {
  18. /**
  19. * The control's object identifier string.
  20. *
  21. * @serial
  22. */
  23. protected String id;
  24. /**
  25. * The control's criticality.
  26. *
  27. * @serial
  28. */
  29. protected boolean criticality = false; // default
  30. /**
  31. * The control's ASN.1 BER encoded value.
  32. *
  33. * @serial
  34. */
  35. protected byte[] value = null;
  36. private static final long serialVersionUID = -4233907508771791687L;
  37. /**
  38. * Constructs a non-critical control.
  39. *
  40. * @param id The control's object identifier string.
  41. *
  42. */
  43. public BasicControl(String id) {
  44. this.id = id;
  45. }
  46. /**
  47. * Constructs a control using the supplied arguments.
  48. *
  49. * @param id The control's object identifier string.
  50. * @param criticality The control's criticality.
  51. * @param value The control's ASN.1 BER encoded value.
  52. * It is not cloned - any changes to value
  53. * will affect the contents of the control.
  54. * It may be null.
  55. */
  56. public BasicControl(String id, boolean criticality, byte[] value) {
  57. this.id = id;
  58. this.criticality = criticality;
  59. this.value = value;
  60. }
  61. /**
  62. * Retrieves the control's object identifier string.
  63. *
  64. * @return The non-null object identifier string.
  65. */
  66. public String getID() {
  67. return id;
  68. }
  69. /**
  70. * Determines the control's criticality.
  71. *
  72. * @return true if the control is critical; false otherwise.
  73. */
  74. public boolean isCritical() {
  75. return criticality;
  76. }
  77. /**
  78. * Retrieves the control's ASN.1 BER encoded value.
  79. * The result includes the BER tag and length for the control's value but
  80. * does not include the control's object identifier and criticality setting.
  81. *
  82. * @return A possibly null byte array representing the control's
  83. * ASN.1 BER encoded value. It is not cloned - any changes to the
  84. * returned value will affect the contents of the control.
  85. */
  86. public byte[] getEncodedValue() {
  87. return value;
  88. }
  89. }