01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package javax.naming.ldap;
19:
20: import java.io.IOException;
21: import java.math.BigInteger;
22:
23: import org.apache.harmony.jndi.internal.PagedResultSearchControlValue;
24: import org.apache.harmony.security.asn1.ASN1Integer;
25: import org.apache.harmony.security.asn1.ASN1OctetString;
26: import org.apache.harmony.security.asn1.ASN1Sequence;
27: import org.apache.harmony.security.asn1.ASN1Type;
28: import org.apache.harmony.security.asn1.BerInputStream;
29:
30: /**
31: * TODO: JavaDoc
32: */
33: public final class PagedResultsControl extends BasicControl {
34:
35: private static final long serialVersionUID = 6684806685736844298L;
36:
37: public static final String OID = "1.2.840.113556.1.4.319"; //$NON-NLS-1$
38:
39: /**
40: * Static ASN1 Encoder for Paged Result Control using
41: * PagedResultSearchControlValue
42: */
43: static ASN1Type ASN1_ENCODER = new ASN1Sequence(new ASN1Type[] {
44: ASN1Integer.getInstance(), // size
45: ASN1OctetString.getInstance(), // cookie
46: }) {
47:
48: public Object getDecodedObject(BerInputStream in) {
49: Object values[] = (Object[]) in.content;
50: int size = new BigInteger((byte[]) values[0]).intValue();
51: byte[] cookie = (byte[]) values[1];
52: return new PagedResultSearchControlValue(size, cookie);
53: }
54:
55: public void getValues(Object object, Object values[]) {
56: PagedResultSearchControlValue pg = (PagedResultSearchControlValue) object;
57: values[0] = BigInteger.valueOf(pg.getSize()).toByteArray();
58: if (pg.getCookie() == null) {
59: values[1] = "".getBytes(); //$NON-NLS-1$
60: } else {
61: values[1] = pg.getCookie();
62: }
63:
64: }
65: };
66:
67: public PagedResultsControl(int pageSize, boolean criticality)
68: throws IOException {
69: super (OID, criticality, null);
70: this .value = ASN1_ENCODER
71: .encode(new PagedResultSearchControlValue(pageSize,
72: "".getBytes())); //$NON-NLS-1$
73: }
74:
75: public PagedResultsControl(int pageSize, byte[] cookie,
76: boolean criticality) throws IOException {
77: super (OID, criticality, null);
78: this .value = ASN1_ENCODER
79: .encode(new PagedResultSearchControlValue(pageSize,
80: cookie));
81: }
82: }
|