View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  package org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown;
21  
22  
23  import org.apache.directory.api.asn1.DecoderException;
24  import org.apache.directory.api.ldap.codec.api.ExtendedOperationFactory;
25  import org.apache.directory.api.ldap.codec.api.LdapApiService;
26  import org.apache.directory.api.ldap.extras.extended.gracefulShutdown.GracefulShutdownRequest;
27  import org.apache.directory.api.ldap.extras.extended.gracefulShutdown.GracefulShutdownRequestImpl;
28  import org.apache.directory.api.ldap.extras.extended.gracefulShutdown.GracefulShutdownResponse;
29  import org.apache.directory.api.ldap.extras.extended.gracefulShutdown.GracefulShutdownResponseImpl;
30  import org.apache.directory.api.ldap.model.message.ExtendedRequest;
31  import org.apache.directory.api.ldap.model.message.ExtendedResponse;
32  
33  
34  /**
35   * An {@link ExtendedOperationFactory} for creating cancel extended request response 
36   * pairs.
37   *
38   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39   */
40  public class GracefulShutdownFactory implements ExtendedOperationFactory
41  {
42      private LdapApiService codec;
43  
44  
45      /**
46       * Creates a new instance of GracefulShutdownFactory.
47       *
48       * @param codec The codec for this factory.
49       */
50      public GracefulShutdownFactory( LdapApiService codec )
51      {
52          this.codec = codec;
53      }
54  
55  
56      /**
57       * {@inheritDoc}
58       */
59      @Override
60      public String getOid()
61      {
62          return GracefulShutdownRequest.EXTENSION_OID;
63      }
64  
65  
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      public GracefulShutdownResponse newResponse( byte[] encodedValue ) throws DecoderException
71      {
72          GracefulShutdownResponseDecorator response = new GracefulShutdownResponseDecorator(
73              codec, new GracefulShutdownResponseImpl() );
74          response.setResponseValue( encodedValue );
75          return response;
76      }
77  
78  
79      /**
80       * {@inheritDoc}
81       */
82      @Override
83      public GracefulShutdownRequest newRequest( byte[] value )
84      {
85          GracefulShutdownRequestDecorator req = new GracefulShutdownRequestDecorator( codec,
86              new GracefulShutdownRequestImpl() );
87          req.setRequestValue( value );
88          return req;
89      }
90  
91  
92      /**
93       * {@inheritDoc}
94       */
95      @Override
96      public ExtendedRequest decorate( ExtendedRequest modelRequest )
97      {
98          if ( modelRequest instanceof GracefulShutdownRequestDecorator )
99          {
100             return modelRequest;
101         }
102 
103         return new GracefulShutdownRequestDecorator( codec, ( GracefulShutdownRequest ) modelRequest );
104     }
105 
106 
107     /**
108      * {@inheritDoc}
109      */
110     @Override
111     public ExtendedResponse decorate( ExtendedResponse decoratedMessage )
112     {
113         if ( decoratedMessage instanceof GracefulShutdownResponseDecorator )
114         {
115             return decoratedMessage;
116         }
117 
118         return new GracefulShutdownResponseDecorator( codec, ( GracefulShutdownResponse ) decoratedMessage );
119     }
120 }