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.extended;
021    
022    
023    import org.apache.directory.shared.ldap.message.ExtendedResponseImpl;
024    import org.apache.directory.shared.ldap.message.ResultCodeEnum;
025    
026    
027    /**
028     * The response sent back from the server with a LaunchDiagnosticUiRequest
029     * extended operation.
030     * 
031     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
032     * @version $Rev: 482294 $
033     */
034    public class LaunchDiagnosticUiResponse extends ExtendedResponseImpl
035    {
036        private static final long serialVersionUID = -3824715470944544189L;
037    
038        public static final String EXTENSION_OID = "1.3.6.1.4.1.18060.0.1.2";
039    
040        private static final byte[] EMPTY_RESPONSE = new byte[0];
041    
042    
043        public LaunchDiagnosticUiResponse(int messageId, ResultCodeEnum rcode)
044        {
045            super( messageId, EXTENSION_OID );
046    
047            switch ( rcode )
048            {
049                case SUCCESS :
050                    break;
051                
052                case OPERATIONS_ERROR :
053                    break;
054                
055                case INSUFFICIENT_ACCESS_RIGHTS :
056                    break;
057                
058                default:
059                    throw new IllegalArgumentException( "The result code can only be one of: " + ResultCodeEnum.SUCCESS
060                        + ", " + ResultCodeEnum.OPERATIONS_ERROR + ", " + ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS );
061            }
062            
063            super.getLdapResult().setMatchedDn( null );
064            super.getLdapResult().setResultCode( rcode );
065        }
066    
067    
068        public LaunchDiagnosticUiResponse(int messageId)
069        {
070            super( messageId, EXTENSION_OID );
071            super.getLdapResult().setMatchedDn( null);
072            super.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
073        }
074    
075    
076        // ------------------------------------------------------------------------
077        // ExtendedResponse Interface Method Implementations
078        // ------------------------------------------------------------------------
079    
080        /**
081         * Gets the reponse OID specific encoded response values.
082         * 
083         * @return the response specific encoded response values.
084         */
085        public byte[] getResponse()
086        {
087            return EMPTY_RESPONSE;
088        }
089    
090    
091        /**
092         * Sets the reponse OID specific encoded response values.
093         * 
094         * @param value
095         *            the response specific encoded response values.
096         */
097        public void setResponse( byte[] value )
098        {
099            throw new UnsupportedOperationException( "the response is hardcoded as zero length array" );
100        }
101    
102    
103        /**
104         * Gets the OID uniquely identifying this extended response (a.k.a. its
105         * name).
106         * 
107         * @return the OID of the extended response type.
108         */
109        public String getResponseName()
110        {
111            return EXTENSION_OID;
112        }
113    
114    
115        /**
116         * Sets the OID uniquely identifying this extended response (a.k.a. its
117         * name).
118         * 
119         * @param oid
120         *            the OID of the extended response type.
121         */
122        public void setResponseName( String oid )
123        {
124            throw new UnsupportedOperationException( "the OID is fixed: " + EXTENSION_OID );
125        }
126    
127    
128        public boolean equals( Object obj )
129        {
130            if ( obj == this )
131            {
132                return true;
133            }
134    
135            if ( obj instanceof LaunchDiagnosticUiResponse )
136            {
137                return true;
138            }
139    
140            return false;
141        }
142    }