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      public CancelFactory( LdapApiService codec )
46      {
47          this.codec = codec;
48      }
49  
50  
51      /**
52       * {@inheritDoc}
53       */
54      public String getOid()
55      {
56          return CancelRequest.EXTENSION_OID;
57      }
58  
59  
60      /**
61       * {@inheritDoc}
62       */
63      public CancelResponse newResponse( byte[] encodedValue ) throws DecoderException
64      {
65          CancelResponseDecorator response = new CancelResponseDecorator( codec, new CancelResponseImpl() );
66          response.setResponseValue( encodedValue );
67  
68          return response;
69      }
70  
71  
72      /**
73       * {@inheritDoc}
74       */
75      public CancelRequest newRequest( byte[] value )
76      {
77          CancelRequestDecorator req = new CancelRequestDecorator( codec, new CancelRequestImpl() );
78          req.setRequestValue( value );
79  
80          return req;
81      }
82  
83  
84      /**
85       * {@inheritDoc}
86       */
87      public CancelRequestDecorator decorate( ExtendedRequest modelRequest )
88      {
89          if ( modelRequest instanceof CancelRequestDecorator )
90          {
91              return ( CancelRequestDecorator ) modelRequest;
92          }
93  
94          return new CancelRequestDecorator( codec, ( CancelRequest ) modelRequest );
95      }
96  
97  
98      /**
99       * {@inheritDoc}
100      */
101     public CancelResponseDecorator decorate( ExtendedResponse decoratedMessage )
102     {
103         if ( decoratedMessage instanceof CancelResponseDecorator )
104         {
105             return ( CancelResponseDecorator ) decoratedMessage;
106         }
107 
108         return new CancelResponseDecorator( codec, ( CancelResponse ) decoratedMessage );
109     }
110 }