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 The LDAP Service to use
48       */
49      public StoredProcedureFactory( LdapApiService codec )
50      {
51          this.codec = codec;
52      }
53  
54  
55      /**
56       * {@inheritDoc}
57       */
58      @Override
59      public String getOid()
60      {
61          return StoredProcedureRequest.EXTENSION_OID;
62      }
63  
64  
65      /**
66       * {@inheritDoc}
67       */
68      @Override
69      public StoredProcedureResponse newResponse( byte[] encodedValue ) throws DecoderException
70      {
71          StoredProcedureResponseDecorator response = new StoredProcedureResponseDecorator( codec,
72              new StoredProcedureResponseImpl() );
73          response.setResponseValue( encodedValue );
74          return response;
75      }
76  
77  
78      /**
79       * {@inheritDoc}
80       */
81      @Override
82      public StoredProcedureRequest newRequest( byte[] value )
83      {
84          StoredProcedureRequestDecorator req = new StoredProcedureRequestDecorator( codec );
85  
86          if ( value != null )
87          {
88              req.setRequestValue( value );
89          }
90          return req;
91      }
92  
93  
94      /**
95       * {@inheritDoc}
96       */
97      @Override
98      public StoredProcedureRequestDecorator decorate( ExtendedRequest modelRequest )
99      {
100         if ( modelRequest instanceof StoredProcedureRequestDecorator )
101         {
102             return ( StoredProcedureRequestDecorator ) modelRequest;
103         }
104 
105         return new StoredProcedureRequestDecorator( codec, ( StoredProcedureRequest ) modelRequest );
106     }
107 
108 
109     /**
110      * {@inheritDoc}
111      */
112     @Override
113     public StoredProcedureResponseDecorator decorate( ExtendedResponse decoratedMessage )
114     {
115         if ( decoratedMessage instanceof StoredProcedureResponseDecorator )
116         {
117             return ( StoredProcedureResponseDecorator ) decoratedMessage;
118         }
119 
120         return new StoredProcedureResponseDecorator( codec, ( StoredProcedureResponse ) decoratedMessage );
121     }
122 }