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.server.ldap;
21
22
23 import org.apache.directory.server.core.DirectoryService;
24 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
25 import org.apache.directory.shared.asn1.codec.Asn1CodecDecoder;
26 import org.apache.directory.shared.asn1.codec.Asn1CodecEncoder;
27 import org.apache.directory.shared.ldap.message.MessageDecoder;
28 import org.apache.directory.shared.ldap.message.MessageEncoder;
29 import org.apache.directory.shared.ldap.message.spi.BinaryAttributeDetector;
30 import org.apache.directory.shared.ldap.schema.AttributeType;
31 import org.apache.mina.filter.codec.ProtocolCodecFactory;
32 import org.apache.mina.filter.codec.ProtocolDecoder;
33 import org.apache.mina.filter.codec.ProtocolEncoder;
34
35
36 /**
37 * An LDAP BER Decoder/Encoder factory implementing {@link ProtocolCodecFactory}.
38 *
39 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
40 * @version $Rev$
41 */
42 final class LdapProtocolCodecFactory implements ProtocolCodecFactory
43 {
44 /** the directory service for which this factor generates codecs */
45 final private DirectoryService directoryService;
46
47
48 /**
49 * Creates a new instance of LdapProtocolCodecFactory.
50 *
51 * @param directoryService the {@link DirectoryService} for which this
52 * factory generates codecs.
53 */
54 public LdapProtocolCodecFactory( DirectoryService directoryService )
55 {
56 this.directoryService = directoryService;
57 }
58
59
60 /*
61 * (non-Javadoc)
62 * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getEncoder()
63 */
64 public ProtocolEncoder getEncoder()
65 {
66 return new Asn1CodecEncoder( new MessageEncoder() );
67 }
68
69
70 /*
71 * (non-Javadoc)
72 * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getDecoder()
73 */
74 public ProtocolDecoder getDecoder()
75 {
76 return new Asn1CodecDecoder( new MessageDecoder( new BinaryAttributeDetector()
77 {
78 public boolean isBinary( String id )
79 {
80 AttributeTypeRegistry attrRegistry = directoryService.getRegistries().getAttributeTypeRegistry();
81 try
82 {
83 AttributeType type = attrRegistry.lookup( id );
84 return ! type.getSyntax().isHumanReadable();
85 }
86 catch ( Exception e )
87 {
88 return false;
89 }
90 }
91 }) );
92 }
93 }