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.interceptor.context;
21
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import javax.naming.NamingException;
27
28 import org.apache.directory.shared.ldap.entry.EntryAttribute;
29 import org.apache.directory.server.core.CoreSession;
30 import org.apache.directory.server.core.entry.ClonedServerEntry;
31 import org.apache.directory.server.core.entry.ServerEntry;
32 import org.apache.directory.server.core.entry.ServerEntryUtils;
33 import org.apache.directory.server.core.entry.ServerModification;
34 import org.apache.directory.shared.ldap.entry.Modification;
35 import org.apache.directory.shared.ldap.entry.ModificationOperation;
36 import org.apache.directory.shared.ldap.entry.client.ClientModification;
37 import org.apache.directory.shared.ldap.message.MessageTypeEnum;
38 import org.apache.directory.shared.ldap.message.ModifyRequest;
39 import org.apache.directory.shared.ldap.name.LdapDN;
40
41
42
43
44
45
46
47
48
49
50
51 public class ModifyOperationContext extends AbstractChangeOperationContext
52 {
53
54 private List<Modification> modItems;
55
56
57 private ClonedServerEntry entry;
58
59
60
61
62
63 public ModifyOperationContext( CoreSession session )
64 {
65 super( session );
66 }
67
68
69
70
71
72
73
74
75 public ModifyOperationContext( CoreSession session, LdapDN dn, List<Modification> modItems )
76 {
77 super( session, dn );
78
79 this.modItems = modItems;
80 }
81
82
83 public ModifyOperationContext( CoreSession session, ModifyRequest modifyRequest ) throws Exception
84 {
85 super( session, modifyRequest.getName() );
86 this.modItems = ServerEntryUtils.toServerModification(
87 modifyRequest.getModificationItems().toArray( new ClientModification[0]),
88 session.getDirectoryService().getRegistries().getAttributeTypeRegistry() );
89 this.requestControls = modifyRequest.getControls();
90 }
91
92
93
94
95
96
97 public void setModItems( List<Modification> modItems )
98 {
99 this.modItems = modItems;
100 }
101
102
103
104
105
106 public List<Modification> getModItems()
107 {
108 return modItems;
109 }
110
111
112 public static List<Modification> createModItems( ServerEntry serverEntry, ModificationOperation modOp ) throws NamingException
113 {
114 List<Modification> items = new ArrayList<Modification>( serverEntry.size() );
115
116 for ( EntryAttribute attribute:serverEntry )
117 {
118 items.add( new ServerModification( modOp, attribute ) );
119 }
120
121 return items;
122 }
123
124
125
126
127
128 public String getName()
129 {
130 return MessageTypeEnum.MODIFY_REQUEST.name();
131 }
132
133
134 public void setEntry( ClonedServerEntry entry )
135 {
136 this.entry = entry;
137 }
138
139
140 public ClonedServerEntry getEntry()
141 {
142 return entry;
143 }
144
145
146
147
148
149 public String toString()
150 {
151 StringBuilder sb = new StringBuilder();
152
153 sb.append("ModifyContext for DN '").append( getDn().getUpName() ).append( "', modifications :\n" );
154
155 for ( Modification mod:modItems )
156 {
157 sb.append( mod ).append( '\n' );
158 }
159
160 return sb.toString();
161 }
162 }