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 public GracefulDisconnectFactory( LdapApiService codec ) 045 { 046 this.codec = codec; 047 } 048 049 050 /** 051 * {@inheritDoc} 052 */ 053 public ExtendedRequestDecorator<ExtendedRequest> decorate( 054 ExtendedRequest modelRequest ) 055 { 056 // Nothing to do (there's no request associated to GracefulDisconnectResponse) 057 return null; 058 } 059 060 061 /** 062 * {@inheritDoc} 063 */ 064 public ExtendedResponse decorate( ExtendedResponse decoratedMessage ) 065 { 066 if ( decoratedMessage instanceof GracefulDisconnectResponseDecorator ) 067 { 068 return decoratedMessage; 069 } 070 071 return new GracefulDisconnectResponseDecorator( codec, ( GracefulDisconnectResponse ) decoratedMessage ); 072 } 073 074 075 /** 076 * {@inheritDoc} 077 */ 078 public String getOid() 079 { 080 return GracefulDisconnectResponse.EXTENSION_OID; 081 } 082 083 084 /** 085 * {@inheritDoc} 086 */ 087 public ExtendedRequest newRequest( byte[] value ) 088 { 089 // Nothing to do (there's no request associated to GracefulDisconnectResponse) 090 return null; 091 } 092 093 094 /** 095 * {@inheritDoc} 096 */ 097 public GracefulDisconnectResponse newResponse( byte[] encodedValue ) throws DecoderException 098 { 099 GracefulDisconnectResponseDecorator req = new GracefulDisconnectResponseDecorator( codec, 100 new GracefulDisconnectResponseImpl() ); 101 req.setResponseValue( encodedValue ); 102 103 return req; 104 } 105}