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.cancel;
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.cancel.CancelRequest;
27  import org.apache.directory.api.ldap.extras.extended.cancel.CancelRequestImpl;
28  import org.apache.directory.api.ldap.extras.extended.cancel.CancelResponse;
29  import org.apache.directory.api.ldap.extras.extended.cancel.CancelResponseImpl;
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 CancelFactory implements ExtendedOperationFactory
41  {
42      private LdapApiService codec;
43  
44  
45      /**
46       * Creates a new instance of CancelFactory.
47       *
48       * @param codec The codec for this factory.
49       */
50      public CancelFactory( LdapApiService codec )
51      {
52          this.codec = codec;
53      }
54  
55  
56      /**
57       * {@inheritDoc}
58       */
59      @Override
60      public String getOid()
61      {
62          return CancelRequest.EXTENSION_OID;
63      }
64  
65  
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      public CancelResponse newResponse( byte[] encodedValue ) throws DecoderException
71      {
72          CancelResponseDecorator response = new CancelResponseDecorator( codec, new CancelResponseImpl() );
73          response.setResponseValue( encodedValue );
74  
75          return response;
76      }
77  
78  
79      /**
80       * {@inheritDoc}
81       */
82      @Override
83      public CancelRequest newRequest( byte[] value )
84      {
85          CancelRequestDecorator req = new CancelRequestDecorator( codec, new CancelRequestImpl() );
86          req.setRequestValue( value );
87  
88          return req;
89      }
90  
91  
92      /**
93       * {@inheritDoc}
94       */
95      @Override
96      public CancelRequestDecorator decorate( ExtendedRequest modelRequest )
97      {
98          if ( modelRequest instanceof CancelRequestDecorator )
99          {
100             return ( CancelRequestDecorator ) modelRequest;
101         }
102 
103         return new CancelRequestDecorator( codec, ( CancelRequest ) modelRequest );
104     }
105 
106 
107     /**
108      * {@inheritDoc}
109      */
110     @Override
111     public CancelResponseDecorator decorate( ExtendedResponse decoratedMessage )
112     {
113         if ( decoratedMessage instanceof CancelResponseDecorator )
114         {
115             return ( CancelResponseDecorator ) decoratedMessage;
116         }
117 
118         return new CancelResponseDecorator( codec, ( CancelResponse ) decoratedMessage );
119     }
120 }