1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.api.interceptor.context;
21
22
23 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
24 import org.apache.directory.api.ldap.model.entry.Entry;
25 import org.apache.directory.api.ldap.model.exception.LdapException;
26 import org.apache.directory.api.ldap.model.exception.LdapOperationErrorException;
27 import org.apache.directory.api.ldap.model.message.AddRequest;
28 import org.apache.directory.api.ldap.model.message.MessageTypeEnum;
29 import org.apache.directory.api.ldap.model.message.controls.ManageDsaIT;
30 import org.apache.directory.api.ldap.model.name.Dn;
31 import org.apache.directory.server.core.api.CoreSession;
32 import org.apache.directory.server.core.api.OperationEnum;
33 import org.apache.directory.server.core.api.entry.ClonedServerEntry;
34
35
36
37
38
39
40
41
42 public class AddOperationContext extends AbstractChangeOperationContext
43 {
44
45
46
47
48
49 public AddOperationContext( CoreSession session )
50 {
51 super( session );
52
53 if ( session != null )
54 {
55 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.ADD ) );
56 }
57 }
58
59
60
61
62
63
64
65
66 public AddOperationContext( CoreSession session, Dn dn )
67 {
68 super( session, dn );
69
70 if ( session != null )
71 {
72 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.ADD ) );
73 }
74 }
75
76
77
78
79
80
81
82
83 public AddOperationContext( CoreSession session, Entry entry )
84 {
85 super( session, entry.getDn() );
86 this.entry = new ClonedServerEntry( entry );
87 if ( session != null )
88 {
89 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.ADD ) );
90 }
91 }
92
93
94
95
96
97
98
99
100
101 public AddOperationContext( CoreSession session, Dn dn, Entry entry )
102 {
103 super( session, dn );
104
105 if ( session != null )
106 {
107 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.ADD ) );
108 }
109
110 this.entry = new ClonedServerEntry( entry );
111 }
112
113
114
115
116
117
118
119
120
121 public AddOperationContext( CoreSession session, AddRequest addRequest ) throws LdapException
122 {
123 super( session );
124
125 if ( session != null )
126 {
127 setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.ADD ) );
128 }
129 else
130 {
131 throw new LdapOperationErrorException( "No session to proceed the operation" );
132 }
133
134 Entry addEntry = addRequest.getEntry();
135
136 if ( addEntry.isSchemaAware() )
137 {
138 entry = new ClonedServerEntry( addEntry );
139 }
140 else
141 {
142 entry = new ClonedServerEntry(
143 new DefaultEntry( session.getDirectoryService().getSchemaManager(), addRequest.getEntry() ) );
144 }
145
146 dn = addRequest.getEntry().getDn();
147 requestControls = addRequest.getControls();
148
149 if ( requestControls.containsKey( ManageDsaIT.OID ) )
150 {
151 ignoreReferral();
152 }
153 else
154 {
155 throwReferral();
156 }
157 }
158
159
160
161
162
163 public String getName()
164 {
165 return MessageTypeEnum.ADD_REQUEST.name();
166 }
167
168
169
170
171
172 public String toString()
173 {
174 return "AddContext for Dn '" + getDn().getName() + "'" + ", added entry: " + entry;
175 }
176 }