001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.naming.ldap;
019:
020: import java.io.IOException;
021: import java.math.BigInteger;
022:
023: import javax.naming.NamingException;
024:
025: import org.apache.harmony.jndi.internal.SortResult;
026: import org.apache.harmony.jndi.internal.Util;
027: import org.apache.harmony.security.asn1.ASN1Enumerated;
028: import org.apache.harmony.security.asn1.ASN1OctetString;
029: import org.apache.harmony.security.asn1.ASN1Sequence;
030: import org.apache.harmony.security.asn1.ASN1Type;
031: import org.apache.harmony.security.asn1.BerInputStream;
032:
033: /**
034: * TODO: JavaDoc
035: */
036: public final class SortResponseControl extends BasicControl {
037:
038: /**
039: * Represents the following ASN1 Syntax to use with the Harmony ASN1 Parser:<br>
040: * <br>
041: *
042: * SortResult ::= SEQUENCE { sortResult ENUMERATED { success (0), -- results
043: * are sorted operationsError (1), -- server internal failure
044: * timeLimitExceeded (3), -- timelimit reached before -- sorting was
045: * completed strongAuthRequired (8), -- refused to return sorted -- results
046: * via insecure -- protocol adminLimitExceeded (11), -- too many matching
047: * entries -- for the server to sort noSuchAttribute (16), -- unrecognized
048: * attribute -- type in sort key inappropriateMatching (18), -- unrecognized
049: * or -- inappropriate matching -- rule in sort key insufficientAccessRights
050: * (50), -- refused to return sorted -- results to this client busy (51), --
051: * too busy to process unwillingToPerform (53), -- unable to sort other (80) },
052: * attributeType [0] AttributeDescription OPTIONAL }
053: *
054: */
055: static ASN1Type ASN1_SORTRESPONSE = new ASN1Sequence(
056: new ASN1Type[] { ASN1Enumerated.getInstance(), // sortResult
057: ASN1OctetString.getInstance(), // attributeType
058: }) {
059:
060: {
061: setOptional(1);
062: }
063:
064: public Object getDecodedObject(BerInputStream in) {
065: Object values[] = (Object[]) in.content;
066: int sortresult = new BigInteger((byte[]) values[0])
067: .intValue();
068: String attrtype = null;
069: try {
070: attrtype = new String((byte[]) values[1]);
071: } catch (NullPointerException e) {
072: }
073: return new SortResult(sortresult, attrtype);
074: }
075:
076: };
077:
078: private static final long serialVersionUID = 5142939176006310877L;
079:
080: private int resultCode;
081:
082: private String badAttrId;
083:
084: private transient boolean sorted = false;
085:
086: public static final String OID = "1.2.840.113556.1.4.474";
087:
088: public SortResponseControl(String id, boolean criticality,
089: byte[] value) throws IOException {
090: super (OID, criticality, value);
091: SortResult sr;
092: sr = (SortResult) ASN1_SORTRESPONSE.decode(value);
093: resultCode = sr.getSortresult();
094: badAttrId = sr.getAttributeType();
095: if (getResultCode() == 0) {
096: sorted = true;
097: } else {
098: sorted = false;
099: }
100: }
101:
102: public String getAttributeID() {
103: return badAttrId;
104: }
105:
106: public int getResultCode() {
107: return resultCode;
108: }
109:
110: public boolean isSorted() {
111: return sorted;
112: }
113:
114: public NamingException getException() {
115: return Util.getExceptionFromErrorCode(getResultCode());
116: }
117:
118: }
|