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:
28: /**
29: * This class represents add operation in ldap protocol, inclue one request and
30: * one response. It encode request to ASN.1 and decode response from ASN.1
31: * formate bytes to java objects.
32: */
33: final public class AddOp implements LdapOperation, ASN1Encodable {
34: // Attribute list
35: private List<LdapAttribute> attrList;
36:
37: // LDAP distinguished name
38: private String entry;
39:
40: // LDAP operation result
41: private LdapResult result;
42:
43: public AddOp(String entry, List<LdapAttribute> attrList) {
44: this .entry = entry;
45: this .attrList = (attrList == null) ? new ArrayList<LdapAttribute>()
46: : attrList;
47: }
48:
49: public AddOp(String entry) {
50: this (entry, null);
51: }
52:
53: public void addAttribute(LdapAttribute attr) {
54: attrList.add(attr);
55: }
56:
57: public ASN1Encodable getRequest() {
58: return this ;
59: }
60:
61: public int getRequestId() {
62: return LdapASN1Constant.OP_ADD_REQUEST;
63: }
64:
65: public ASN1Decodable getResponse() {
66: return result = (result == null) ? new LdapResult() : result;
67: }
68:
69: public int getResponseId() {
70: return LdapASN1Constant.OP_ADD_RESPONSE;
71: }
72:
73: public LdapResult getResult() {
74: return result;
75: }
76:
77: public void encodeValues(Object[] values) {
78: values[0] = Utils.getBytes(entry);
79: values[1] = attrList;
80: }
81:
82: public List<LdapAttribute> getAttributeList() {
83: return attrList;
84: }
85:
86: public String getEntry() {
87: return entry;
88: }
89:
90: }
|