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.storedProcedure;
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.storedProcedure.StoredProcedureRequest;
27  import org.apache.directory.api.ldap.extras.extended.storedProcedure.StoredProcedureResponse;
28  import org.apache.directory.api.ldap.extras.extended.storedProcedure.StoredProcedureResponseImpl;
29  import org.apache.directory.api.ldap.model.message.ExtendedRequest;
30  import org.apache.directory.api.ldap.model.message.ExtendedResponse;
31  
32  
33  /**
34   * An {@link ExtendedOperationFactory} for creating cancel extended request response 
35   * pairs.
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   */
39  public class StoredProcedureFactory implements ExtendedOperationFactory
40  {
41      private LdapApiService codec;
42  
43  
44      /**
45       * Creates a new instance of StoredProcedureFactory.
46       *
47       * @param codec
48       */
49      public StoredProcedureFactory( LdapApiService codec )
50      {
51          this.codec = codec;
52      }
53  
54  
55      /**
56       * {@inheritDoc}
57       */
58      public String getOid()
59      {
60          return StoredProcedureRequest.EXTENSION_OID;
61      }
62  
63  
64      /**
65       * {@inheritDoc}
66       */
67      public StoredProcedureResponse newResponse( byte[] encodedValue ) throws DecoderException
68      {
69          StoredProcedureResponseDecorator response = new StoredProcedureResponseDecorator( codec,
70              new StoredProcedureResponseImpl() );
71          response.setResponseValue( encodedValue );
72          return response;
73      }
74  
75  
76      /**
77       * {@inheritDoc}
78       */
79      public StoredProcedureRequest newRequest( byte[] value )
80      {
81          StoredProcedureRequestDecorator req = new StoredProcedureRequestDecorator( codec );
82  
83          if ( value != null )
84          {
85              req.setRequestValue( value );
86          }
87          return req;
88      }
89  
90  
91      /**
92       * {@inheritDoc}
93       */
94      public StoredProcedureRequestDecorator decorate( ExtendedRequest modelRequest )
95      {
96          if ( modelRequest instanceof StoredProcedureRequestDecorator )
97          {
98              return ( StoredProcedureRequestDecorator ) modelRequest;
99          }
100 
101         return new StoredProcedureRequestDecorator( codec, ( StoredProcedureRequest ) modelRequest );
102     }
103 
104 
105     /**
106      * {@inheritDoc}
107      */
108     public StoredProcedureResponseDecorator decorate( ExtendedResponse decoratedMessage )
109     {
110         if ( decoratedMessage instanceof StoredProcedureResponseDecorator )
111         {
112             return ( StoredProcedureResponseDecorator ) decoratedMessage;
113         }
114 
115         return new StoredProcedureResponseDecorator( codec, ( StoredProcedureResponse ) decoratedMessage );
116     }
117 }