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.shared.ldap.message;
021    
022    
023    import java.util.Map;
024    
025    import javax.naming.ldap.Control;
026    
027    
028    /**
029     * Root interface for all LDAP message type interfaces.
030     * 
031     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032     * @version $Rev: 764131 $
033     */
034    public interface InternalMessage
035    {
036        /**
037         * Gets the LDAP message type code associated with this Message. Each
038         * request and response type has a unique message type code defined by the
039         * protocol in <a href="http://www.faqs.org/rfcs/rfc2251.html">RFC 2251</a>.
040         * 
041         * @return the message type code.
042         */
043        MessageTypeEnum getType();
044    
045    
046        /**
047         * Gets the controls associated with this message mapped by OID.
048         * 
049         * @return Map of OID strings to Control object instances.
050         * @see InternalControl
051         */
052        Map<String, Control> getControls();
053    
054        
055        /**
056         * Checks whether or not this message has the specified control.
057         *
058         * @param oid the OID of the control
059         * @return true if this message has the control, false if it does not
060         */
061        boolean hasControl( String oid );
062        
063    
064        /**
065         * Adds a control to this Message.
066         * 
067         * @param control
068         *            the control to add.
069         * @throws MessageException
070         *             if controls cannot be added to this Message or the control is
071         *             not known etc.
072         */
073        void add( Control control ) throws MessageException;
074    
075    
076        /**
077         * Adds an array of controls to this Message.
078         * 
079         * @param controls the controls to add.
080         * @throws MessageException if controls cannot be added to this Message or they are not known etc.
081         */
082        void addAll( Control[] controls ) throws MessageException;
083    
084    
085        /**
086         * Deletes a control removing it from this Message.
087         * 
088         * @param control
089         *            the control to remove.
090         * @throws MessageException
091         *             if controls cannot be added to this Message or the control is
092         *             not known etc.
093         */
094        void remove( Control control ) throws MessageException;
095    
096    
097        /**
098         * Gets the session unique message sequence id for this message. Requests
099         * and their responses if any have the same message id. Clients at the
100         * initialization of a session start with the first message's id set to 1
101         * and increment it with each transaction.
102         * 
103         * @return the session unique message id.
104         */
105        int getMessageId();
106    
107    
108        /**
109         * Gets a message scope parameter. Message scope parameters are temporary
110         * variables associated with a message and are set locally to be used to
111         * associate housekeeping information with a request or its processing.
112         * These parameters are never transmitted nor recieved, think of them as
113         * transient data associated with the message or its processing. These
114         * transient parameters are not locked down so modifications can occur
115         * without firing LockExceptions even when this Lockable is in the locked
116         * state.
117         * 
118         * @param key
119         *            the key used to access a message parameter.
120         * @return the transient message parameter value.
121         */
122        Object get( Object key );
123    
124    
125        /**
126         * Sets a message scope parameter. These transient parameters are not locked
127         * down so modifications can occur without firing LockExceptions even when
128         * this Lockable is in the locked state.
129         * 
130         * @param key
131         *            the parameter key
132         * @param value
133         *            the parameter value
134         * @return the old value or null
135         */
136        Object put( Object key, Object value );
137    }