2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package javax.naming.ldap;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* A sort key and its associated sort parameters.
|
|
30 |
* This class implements a sort key which is used by the LDAPv3
|
|
31 |
* Control for server-side sorting of search results as defined in
|
|
32 |
* <a href="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>.
|
|
33 |
*
|
|
34 |
* @since 1.5
|
|
35 |
* @see SortControl
|
|
36 |
* @author Vincent Ryan
|
|
37 |
*/
|
|
38 |
public class SortKey {
|
|
39 |
|
|
40 |
/*
|
|
41 |
* The ID of the attribute to sort by.
|
|
42 |
*/
|
|
43 |
private String attrID;
|
|
44 |
|
|
45 |
/*
|
|
46 |
* The sort order. Ascending order, by default.
|
|
47 |
*/
|
|
48 |
private boolean reverseOrder = false;
|
|
49 |
|
|
50 |
/*
|
|
51 |
* The ID of the matching rule to use for ordering attribute values.
|
|
52 |
*/
|
|
53 |
private String matchingRuleID = null;
|
|
54 |
|
|
55 |
/**
|
|
56 |
* Creates the default sort key for an attribute. Entries will be sorted
|
|
57 |
* according to the specified attribute in ascending order using the
|
|
58 |
* ordering matching rule defined for use with that attribute.
|
|
59 |
*
|
|
60 |
* @param attrID The non-null ID of the attribute to be used as a sort
|
|
61 |
* key.
|
|
62 |
*/
|
|
63 |
public SortKey(String attrID) {
|
|
64 |
this.attrID = attrID;
|
|
65 |
}
|
|
66 |
|
|
67 |
/**
|
|
68 |
* Creates a sort key for an attribute. Entries will be sorted according to
|
|
69 |
* the specified attribute in the specified sort order and using the
|
|
70 |
* specified matching rule, if supplied.
|
|
71 |
*
|
|
72 |
* @param attrID The non-null ID of the attribute to be used as
|
|
73 |
* a sort key.
|
|
74 |
* @param ascendingOrder If true then entries are arranged in ascending
|
|
75 |
* order. Otherwise there are arranged in
|
|
76 |
* descending order.
|
|
77 |
* @param matchingRuleID The possibly null ID of the matching rule to
|
|
78 |
* use to order the attribute values. If not
|
|
79 |
* specified then the ordering matching rule
|
|
80 |
* defined for the sort key attribute is used.
|
|
81 |
*/
|
|
82 |
public SortKey(String attrID, boolean ascendingOrder,
|
|
83 |
String matchingRuleID) {
|
|
84 |
|
|
85 |
this.attrID = attrID;
|
|
86 |
reverseOrder = (! ascendingOrder);
|
|
87 |
this.matchingRuleID = matchingRuleID;
|
|
88 |
}
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Retrieves the attribute ID of the sort key.
|
|
92 |
*
|
|
93 |
* @return The non-null Attribute ID of the sort key.
|
|
94 |
*/
|
|
95 |
public String getAttributeID() {
|
|
96 |
return attrID;
|
|
97 |
}
|
|
98 |
|
|
99 |
/**
|
|
100 |
* Determines the sort order.
|
|
101 |
*
|
|
102 |
* @return true if the sort order is ascending, false if descending.
|
|
103 |
*/
|
|
104 |
public boolean isAscending() {
|
|
105 |
return (! reverseOrder);
|
|
106 |
}
|
|
107 |
|
|
108 |
/**
|
|
109 |
* Retrieves the matching rule ID used to order the attribute values.
|
|
110 |
*
|
|
111 |
* @return The possibly null matching rule ID. If null then the
|
|
112 |
* ordering matching rule defined for the sort key attribute
|
|
113 |
* is used.
|
|
114 |
*/
|
|
115 |
public String getMatchingRuleID() {
|
|
116 |
return matchingRuleID;
|
|
117 |
}
|
|
118 |
}
|