001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.ldap.codec.protocol.mina; 021 022 023import org.apache.directory.api.ldap.codec.api.LdapApiService; 024import org.apache.directory.api.ldap.codec.api.LdapApiServiceFactory; 025import org.apache.mina.core.session.IoSession; 026import org.apache.mina.filter.codec.ProtocolCodecFactory; 027import org.apache.mina.filter.codec.ProtocolDecoder; 028import org.apache.mina.filter.codec.ProtocolEncoder; 029 030 031/** 032 * The factory used to create the LDAP encoder and decoder. 033 * 034 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 035 */ 036public class LdapProtocolCodecFactory implements ProtocolCodecFactory 037{ 038 /** The tag stored into the session if we want to set a max PDU size */ 039 public static final String MAX_PDU_SIZE = "MAX_PDU_SIZE"; 040 041 /** The LdapDecoder key */ 042 public static final String LDAP_DECODER = "LDAP_DECODER"; 043 044 /** The LdapEncoder key */ 045 public static final String LDAP_ENCODER = "LDAP_ENCODER"; 046 047 /** The statefull LDAP decoder */ 048 private LdapProtocolDecoder ldapDecoder; 049 050 /** The statefull LDAP edcoder */ 051 private LdapProtocolEncoder ldapEncoder; 052 053 054 /** 055 * Creates a new instance of LdapProtocolCodecFactory. 056 */ 057 public LdapProtocolCodecFactory() 058 { 059 this( LdapApiServiceFactory.getSingleton() ); 060 } 061 062 063 /** 064 * 065 * Creates a new instance of LdapProtocolCodecFactory. 066 * 067 * @param ldapApiService The associated LdapApiService instance 068 */ 069 public LdapProtocolCodecFactory( LdapApiService ldapApiService ) 070 { 071 ldapDecoder = new LdapProtocolDecoder(); 072 ldapEncoder = new LdapProtocolEncoder( ldapApiService ); 073 } 074 075 076 /** 077 * Get the LDAP decoder. 078 * 079 * @param session the IO session 080 * @return the decoder 081 */ 082 @Override 083 public ProtocolDecoder getDecoder( IoSession session ) 084 { 085 return ldapDecoder; 086 } 087 088 089 /** 090 * Get the LDAP encoder. 091 * 092 * @param session the IO session 093 * @return the encoder 094 */ 095 @Override 096 public ProtocolEncoder getEncoder( IoSession session ) 097 { 098 return ldapEncoder; 099 } 100}