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 org.apache.harmony.jndi.provider.ldap.event;
19:
20: import javax.naming.ldap.BasicControl;
21:
22: import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
23: import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
24: import org.apache.harmony.security.asn1.ASN1Integer;
25:
26: /**
27: * This class implements PersistentSearch control defined in
28: * {@link http://www3.ietf.org/proceedings/01mar/I-D/ldapext-psearch-03.txt}.
29: *
30: * This control extend LDAPv3 search operation, so client can receive
31: * notifications of changes from server.
32: */
33: public class PersistentSearchControl extends BasicControl implements
34: ASN1Encodable {
35:
36: private static final long serialVersionUID = -524784347976291935L;
37:
38: public static final String OID = "2.16.840.1.113730.3.4.3"; //$NON-NLS-1$
39:
40: private int changeTypes;
41:
42: private boolean changesOnly;
43:
44: private boolean returnECs;
45:
46: public PersistentSearchControl() {
47: // register all types of changes
48: this (1 | 2 | 4 | 8, true, true);
49: }
50:
51: public PersistentSearchControl(int types, boolean changesOnly,
52: boolean returnECs) {
53: super (OID, true, null);
54: this .changesOnly = changesOnly;
55: this .returnECs = returnECs;
56: this .changeTypes = types;
57: value = getValue();
58: }
59:
60: /**
61: * Get encoded content of persistent search control, which not include
62: * <code>OID</code>
63: *
64: * @return encoded content
65: */
66: private byte[] getValue() {
67: return LdapASN1Constant.PersistentSearchControl.encode(this );
68: }
69:
70: public void encodeValues(Object[] values) {
71: values[0] = ASN1Integer.fromIntValue(changeTypes);
72: values[1] = Boolean.valueOf(changesOnly);
73: values[2] = Boolean.valueOf(returnECs);
74:
75: }
76:
77: public boolean isChangesOnly() {
78: return changesOnly;
79: }
80:
81: public int getChangeTypes() {
82: return changeTypes;
83: }
84:
85: public boolean isReturnECs() {
86: return returnECs;
87: }
88:
89: }
|