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.codec.protocol.mina;
21  
22  
23  import org.apache.directory.api.ldap.codec.api.LdapApiService;
24  import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory;
25  import org.apache.mina.core.session.IoSession;
26  import org.apache.mina.filter.codec.ProtocolCodecFactory;
27  import org.apache.mina.filter.codec.ProtocolDecoder;
28  import org.apache.mina.filter.codec.ProtocolEncoder;
29  
30  
31  /**
32   * The factory used to create the LDAP encoder and decoder.
33   *
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   */
36  public class LdapProtocolCodecFactory implements ProtocolCodecFactory
37  {
38      /** The tag stored into the session if we want to set a max PDU size */
39      public static final String MAX_PDU_SIZE = "MAX_PDU_SIZE";
40  
41      /** The LdapDecoder key */
42      public static final String LDAP_DECODER = "LDAP_DECODER";
43  
44      /** The LdapEncoder key */
45      public static final String LDAP_ENCODER = "LDAP_ENCODER";
46  
47      private LdapApiService ldapApiService;
48      
49      public LdapProtocolCodecFactory() 
50      {
51          this( LdapApiServiceFactory.getSingleton() );
52      }
53  
54      public LdapProtocolCodecFactory( LdapApiService ldapApiService ) 
55      {
56          this.ldapApiService = ldapApiService;
57      }
58  
59      /**
60       * Get the LDAP decoder.
61       *
62       * @param session the IO session
63       * @return the decoder
64       */
65      public ProtocolDecoder getDecoder( IoSession session )
66      {
67          return new LdapProtocolDecoder();
68      }
69  
70  
71      /**
72       * Get the LDAP encoder.
73       *
74       * @param session the IO session
75       * @return the encoder
76       */
77      public ProtocolEncoder getEncoder( IoSession session )
78      {
79          return new LdapProtocolEncoder( ldapApiService );
80      }
81  }