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      /** The statefull LDAP decoder */
48      private LdapProtocolDecoder ldapDecoder;
49  
50      /** The statefull LDAP edcoder */
51      private LdapProtocolEncoder ldapEncoder;
52      
53      
54      /**
55       * Creates a new instance of LdapProtocolCodecFactory.
56       */
57      public LdapProtocolCodecFactory() 
58      {
59          this( LdapApiServiceFactory.getSingleton() );
60      }
61  
62      
63      /**
64       * 
65       * Creates a new instance of LdapProtocolCodecFactory.
66       *
67       * @param ldapApiService The associated LdapApiService instance
68       */
69      public LdapProtocolCodecFactory( LdapApiService ldapApiService ) 
70      {
71          ldapDecoder = new LdapProtocolDecoder();
72          ldapEncoder = new LdapProtocolEncoder( ldapApiService );
73      }
74      
75  
76      /**
77       * Get the LDAP decoder.
78       *
79       * @param session the IO session
80       * @return the decoder
81       */
82      @Override
83      public ProtocolDecoder getDecoder( IoSession session )
84      {
85          return ldapDecoder;
86      }
87  
88  
89      /**
90       * Get the LDAP encoder.
91       *
92       * @param session the IO session
93       * @return the encoder
94       */
95      @Override
96      public ProtocolEncoder getEncoder( IoSession session )
97      {
98          return ldapEncoder;
99      }
100 }