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;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Decodable;
24: import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
25: import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
26: import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
27: import org.apache.harmony.security.asn1.ASN1Integer;
28:
29: public class ModifyOp implements LdapOperation, ASN1Encodable {
30:
31: private String dn;
32:
33: private List<Modification> modifications = new ArrayList<Modification>();
34:
35: private LdapResult result;
36:
37: public ModifyOp(String dn) {
38: this .dn = dn;
39: }
40:
41: public ASN1Encodable getRequest() {
42: return this ;
43: }
44:
45: public int getRequestId() {
46: return LdapASN1Constant.OP_MODIFY_REQUEST;
47: }
48:
49: public ASN1Decodable getResponse() {
50: return result = (result == null) ? new LdapResult() : result;
51: }
52:
53: public int getResponseId() {
54: return LdapASN1Constant.OP_MODIFY_RESPONSE;
55: }
56:
57: public void encodeValues(Object[] values) {
58: values[0] = Utils.getBytes(dn);
59: values[1] = modifications;
60: }
61:
62: /**
63: *
64: * @param type
65: * ldap modify type, must be one of ModifyOp.ADD, ModifyOp.DELETE
66: * or ModifyOp.REPLACE
67: * @param attr
68: */
69: public void addModification(int type, LdapAttribute attr) {
70: if (type >= 0 && type <= 2 && attr != null) {
71: modifications.add(new Modification(type, attr));
72: }
73:
74: // FIXME: what exception be thrown?
75: }
76:
77: private static class Modification implements ASN1Encodable {
78: int type;
79:
80: LdapAttribute attr;
81:
82: public Modification(int type, LdapAttribute attr) {
83: this .type = type;
84: this .attr = attr;
85: }
86:
87: public void encodeValues(Object[] values) {
88: values[0] = ASN1Integer.fromIntValue(type);
89: values[1] = attr;
90: }
91: }
92:
93: public LdapResult getResult() {
94: return result;
95: }
96:
97: }
|