1 7 8 package javax.naming.ldap; 9 10 import java.io.IOException ; 11 import com.sun.jndi.ldap.Ber; 12 import com.sun.jndi.ldap.BerEncoder; 13 14 91 final public class SortControl extends BasicControl { 92 93 97 public static final String OID = "1.2.840.113556.1.4.473"; 98 99 private static final long serialVersionUID = -1965961680233330744L; 100 101 115 public SortControl(String sortBy, boolean criticality) throws IOException { 116 117 super(OID, criticality, null); 118 super.value = setEncodedValue(new SortKey []{ new SortKey (sortBy) }); 119 } 120 121 137 public SortControl(String [] sortBy, boolean criticality) 138 throws IOException { 139 140 super(OID, criticality, null); 141 SortKey [] sortKeys = new SortKey [sortBy.length]; 142 for (int i = 0; i < sortBy.length; i++) { 143 sortKeys[i] = new SortKey (sortBy[i]); 144 } 145 super.value = setEncodedValue(sortKeys); 146 } 147 148 163 public SortControl(SortKey [] sortBy, boolean criticality) 164 throws IOException { 165 166 super(OID, criticality, null); 167 super.value = setEncodedValue(sortBy); 168 } 169 170 180 private byte[] setEncodedValue(SortKey [] sortKeys) throws IOException { 181 182 BerEncoder ber = new BerEncoder(30 * sortKeys.length + 10); 184 String matchingRule; 185 186 ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR); 187 188 for (int i = 0; i < sortKeys.length; i++) { 189 ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR); 190 ber.encodeString(sortKeys[i].getAttributeID(), true); 192 if ((matchingRule = sortKeys[i].getMatchingRuleID()) != null) { 193 ber.encodeString(matchingRule, (Ber.ASN_CONTEXT | 0), true); 194 } 195 if (! sortKeys[i].isAscending()) { 196 ber.encodeBoolean(true, (Ber.ASN_CONTEXT | 1)); 197 } 198 ber.endSeq(); 199 } 200 ber.endSeq(); 201 202 return ber.getTrimmedBuf(); 203 } 204 } 205 | Popular Tags |