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 */ 020package org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect; 021 022 023import org.apache.directory.api.asn1.DecoderException; 024import org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory; 025import org.apache.directory.api.ldap.codec.api.ExtendedRequestDecorator; 026import org.apache.directory.api.ldap.codec.api.LdapApiService; 027import org.apache.directory.api.ldap.extras.extended.gracefulDisconnect.GracefulDisconnectResponse; 028import org.apache.directory.api.ldap.extras.extended.gracefulDisconnect.GracefulDisconnectResponseImpl; 029import org.apache.directory.api.ldap.model.message.ExtendedRequest; 030import org.apache.directory.api.ldap.model.message.ExtendedResponse; 031 032 033/** 034 * An {@link ExtendedOperationFactory} for creating cancel extended request response 035 * pairs. 036 * 037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 038 */ 039public class GracefulDisconnectFactory implements ExtendedOperationFactory 040{ 041 private LdapApiService codec; 042 043 044 /** 045 * Creates a new instance of GracefulDisconnectFactory. 046 * 047 * @param codec The codec for this factory. 048 */ 049 public GracefulDisconnectFactory( LdapApiService codec ) 050 { 051 this.codec = codec; 052 } 053 054 055 /** 056 * {@inheritDoc} 057 */ 058 @Override 059 public ExtendedRequestDecorator<ExtendedRequest> decorate( 060 ExtendedRequest modelRequest ) 061 { 062 // Nothing to do (there's no request associated to GracefulDisconnectResponse) 063 return null; 064 } 065 066 067 /** 068 * {@inheritDoc} 069 */ 070 @Override 071 public ExtendedResponse decorate( ExtendedResponse decoratedMessage ) 072 { 073 if ( decoratedMessage instanceof GracefulDisconnectResponseDecorator ) 074 { 075 return decoratedMessage; 076 } 077 078 return new GracefulDisconnectResponseDecorator( codec, ( GracefulDisconnectResponse ) decoratedMessage ); 079 } 080 081 082 /** 083 * {@inheritDoc} 084 */ 085 @Override 086 public String getOid() 087 { 088 return GracefulDisconnectResponse.EXTENSION_OID; 089 } 090 091 092 /** 093 * {@inheritDoc} 094 */ 095 @Override 096 public ExtendedRequest newRequest( byte[] value ) 097 { 098 // Nothing to do (there's no request associated to GracefulDisconnectResponse) 099 return null; 100 } 101 102 103 /** 104 * {@inheritDoc} 105 */ 106 @Override 107 public GracefulDisconnectResponse newResponse( byte[] encodedValue ) throws DecoderException 108 { 109 GracefulDisconnectResponseDecorator req = new GracefulDisconnectResponseDecorator( codec, 110 new GracefulDisconnectResponseImpl() ); 111 req.setResponseValue( encodedValue ); 112 113 return req; 114 } 115}