1. /*
  2. * @(#)SortKey.java 1.4 04/04/20
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.naming.ldap;
  8. /**
  9. * A sort key and its associated sort parameters.
  10. * This class implements a sort key which is used by the LDAPv3
  11. * Control for server-side sorting of search results as defined in
  12. * <a href="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>.
  13. *
  14. * @since 1.5
  15. * @see SortControl
  16. * @author Vincent Ryan
  17. */
  18. public class SortKey {
  19. /*
  20. * The ID of the attribute to sort by.
  21. */
  22. private String attrID;
  23. /*
  24. * The sort order. Ascending order, by default.
  25. */
  26. private boolean reverseOrder = false;
  27. /*
  28. * The ID of the matching rule to use for ordering attribute values.
  29. */
  30. private String matchingRuleID = null;
  31. /**
  32. * Creates the default sort key for an attribute. Entries will be sorted
  33. * according to the specified attribute in ascending order using the
  34. * ordering matching rule defined for use with that attribute.
  35. *
  36. * @param attrID The non-null ID of the attribute to be used as a sort
  37. * key.
  38. */
  39. public SortKey(String attrID) {
  40. this.attrID = attrID;
  41. }
  42. /**
  43. * Creates a sort key for an attribute. Entries will be sorted according to
  44. * the specified attribute in the specified sort order and using the
  45. * specified matching rule, if supplied.
  46. *
  47. * @param attrID The non-null ID of the attribute to be used as
  48. * a sort key.
  49. * @param ascendingOrder If true then entries are arranged in ascending
  50. * order. Otherwise there are arranged in
  51. * descending order.
  52. * @param matchingRuleID The possibly null ID of the matching rule to
  53. * use to order the attribute values. If not
  54. * specified then the ordering matching rule
  55. * defined for the sort key attribute is used.
  56. */
  57. public SortKey(String attrID, boolean ascendingOrder,
  58. String matchingRuleID) {
  59. this.attrID = attrID;
  60. reverseOrder = (! ascendingOrder);
  61. this.matchingRuleID = matchingRuleID;
  62. }
  63. /**
  64. * Retrieves the attribute ID of the sort key.
  65. *
  66. * @return The non-null Attribute ID of the sort key.
  67. */
  68. public String getAttributeID() {
  69. return attrID;
  70. }
  71. /**
  72. * Determines the sort order.
  73. *
  74. * @return true if the sort order is ascending, false if descending.
  75. */
  76. public boolean isAscending() {
  77. return (! reverseOrder);
  78. }
  79. /**
  80. * Retrieves the matching rule ID used to order the attribute values.
  81. *
  82. * @return The possibly null matching rule ID. If null then the
  83. * ordering matching rule defined for the sort key attribute
  84. * is used.
  85. */
  86. public String getMatchingRuleID() {
  87. return matchingRuleID;
  88. }
  89. }