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.dns.store.jndi;
21
22
23 import java.util.Set;
24
25 import org.apache.directory.server.core.DirectoryService;
26 import org.apache.directory.server.dns.DnsException;
27 import org.apache.directory.server.dns.messages.QuestionRecord;
28 import org.apache.directory.server.dns.messages.ResourceRecord;
29 import org.apache.directory.server.dns.store.RecordStore;
30
31
32 /**
33 * A DirectoryService-backed implementation of the RecordStore interface. This RecordStore uses
34 * the Strategy pattern to either serve records based on a single base DN or to lookup
35 * catalog mappings from directory configuration.
36 *
37 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38 * @version $Rev: 583592 $, $Date: 2007-10-10 21:49:37 +0200 (Mi, 10 Okt 2007) $
39 */
40 public class JndiRecordStoreImpl implements RecordStore
41 {
42 /**
43 * a handle on the searchh strategy
44 */
45 private final SearchStrategy strategy;
46
47
48 /**
49 * Creates a new instance of JndiRecordStoreImpl.
50 *
51 * @param catalogBaseDn base of catalog of searchDns
52 * @param searchBaseDn single search base for when there is no catalog
53 * @param directoryService DirectoryService backend for the searches.
54 */
55 public JndiRecordStoreImpl( String catalogBaseDn, String searchBaseDn, DirectoryService directoryService )
56 {
57
58 strategy = getSearchStrategy( catalogBaseDn, searchBaseDn, directoryService );
59 }
60
61
62 public Set<ResourceRecord> getRecords( QuestionRecord question ) throws DnsException
63 {
64 return strategy.getRecords( question );
65 }
66
67
68 private SearchStrategy getSearchStrategy( String catalogBaseDn, String searchBaseDn, DirectoryService directoryService )
69 {
70 if ( catalogBaseDn != null )
71 {
72 // build catalog from factory
73 return new MultiBaseSearch( catalogBaseDn, directoryService );
74 }
75
76 // use config for catalog baseDN
77 return new SingleBaseSearch( searchBaseDn, directoryService );
78 }
79 }