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 * https://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 statefull LDAP decoder */ 039 private LdapProtocolDecoder ldapDecoder; 040 041 /** The statefull LDAP edcoder */ 042 private LdapProtocolEncoder ldapEncoder; 043 044 045 /** 046 * Creates a new instance of LdapProtocolCodecFactory. 047 */ 048 public LdapProtocolCodecFactory() 049 { 050 this( LdapApiServiceFactory.getSingleton() ); 051 } 052 053 054 /** 055 * 056 * Creates a new instance of LdapProtocolCodecFactory. 057 * 058 * @param ldapApiService The associated LdapApiService instance 059 */ 060 public LdapProtocolCodecFactory( LdapApiService ldapApiService ) 061 { 062 ldapDecoder = new LdapProtocolDecoder(); 063 ldapEncoder = new LdapProtocolEncoder( ldapApiService ); 064 } 065 066 067 /** 068 * Get the LDAP decoder. 069 * 070 * @param session the IO session 071 * @return the decoder 072 */ 073 @Override 074 public ProtocolDecoder getDecoder( IoSession session ) 075 { 076 return ldapDecoder; 077 } 078 079 080 /** 081 * Get the LDAP encoder. 082 * 083 * @param session the IO session 084 * @return the encoder 085 */ 086 @Override 087 public ProtocolEncoder getEncoder( IoSession session ) 088 { 089 return ldapEncoder; 090 } 091}