001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.server.core.interceptor.context;
021
022
023 import org.apache.directory.server.core.CoreSession;
024 import org.apache.directory.server.core.entry.ClonedServerEntry;
025 import org.apache.directory.shared.ldap.codec.MessageTypeEnum;
026 import org.apache.directory.shared.ldap.codec.controls.ManageDsaITControl;
027 import org.apache.directory.shared.ldap.entry.DefaultServerEntry;
028 import org.apache.directory.shared.ldap.entry.ServerEntry;
029 import org.apache.directory.shared.ldap.message.internal.InternalAddRequest;
030 import org.apache.directory.shared.ldap.name.DN;
031
032
033 /**
034 * A Add context used for Interceptors. It contains all the informations
035 * needed for the add operation, and used by all the interceptors
036 *
037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
038 * @version $Rev$, $Date$
039 */
040 public class AddOperationContext extends AbstractChangeOperationContext
041 {
042 /**
043 * Creates a new instance of AddOperationContext.
044 *
045 * @param session the current Session
046 */
047 public AddOperationContext( CoreSession session )
048 {
049 super( session );
050 }
051
052
053 /**
054 * Creates a new instance of AddOperationContext.
055 *
056 * @param session the current Session
057 * @param dn the name of the entry being added
058 */
059 public AddOperationContext( CoreSession session, DN dn )
060 {
061 super( session, dn );
062 }
063
064
065 /**
066 * Creates a new instance of AddOperationContext.
067 *
068 * @param session the current Session
069 * @param entry the entry being added
070 */
071 public AddOperationContext( CoreSession session, ServerEntry entry )
072 {
073 super( session, entry.getDn() );
074 this.entry = new ClonedServerEntry( entry );
075 }
076
077
078 /**
079 * Creates a new instance of ModifyOperationContext.
080 *
081 * @param session the current Session
082 * @param dn the name of the entry being added
083 * @param entry the entry being added
084 */
085 public AddOperationContext( CoreSession session, DN dn, ServerEntry entry )
086 {
087 super( session, dn );
088 this.entry = new ClonedServerEntry( entry );
089 }
090
091
092 public AddOperationContext( CoreSession session, InternalAddRequest addRequest ) throws Exception
093 {
094 super( session );
095 entry = new ClonedServerEntry(
096 new DefaultServerEntry( session.getDirectoryService().getSchemaManager(), addRequest.getEntry() ) );
097 dn = addRequest.getEntry().getDn();
098 requestControls = addRequest.getControls();
099
100 if ( requestControls.containsKey( ManageDsaITControl.CONTROL_OID ) )
101 {
102 ignoreReferral();
103 }
104 else
105 {
106 throwReferral();
107 }
108 }
109
110
111 /**
112 * @return the operation name
113 */
114 public String getName()
115 {
116 return MessageTypeEnum.ADD_REQUEST.name();
117 }
118
119
120 /**
121 * @see Object#toString()
122 */
123 public String toString()
124 {
125 return "AddContext for DN '" + getDn().getName() + "'" + ", added entry: " + entry;
126 }
127 }