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 */
020
021 package org.apache.directory.server.dns.store.jndi;
022
023
024 import java.util.Set;
025
026 import javax.naming.directory.DirContext;
027 import javax.naming.ldap.LdapName;
028
029 import org.apache.directory.server.core.CoreSession;
030 import org.apache.directory.server.core.DirectoryService;
031 import org.apache.directory.server.core.jndi.ServerLdapContext;
032 import org.apache.directory.server.dns.DnsException;
033 import org.apache.directory.server.dns.messages.QuestionRecord;
034 import org.apache.directory.server.dns.messages.ResourceRecord;
035 import org.apache.directory.server.dns.messages.ResponseCode;
036 import org.apache.directory.server.dns.store.jndi.operations.GetRecords;
037 import org.apache.directory.server.i18n.I18n;
038 import org.apache.directory.server.protocol.shared.ServiceConfigurationException;
039 import org.slf4j.Logger;
040 import org.slf4j.LoggerFactory;
041
042
043 /**
044 * A JNDI-backed search strategy implementation. This search strategy searches a
045 * single base DN for resource records.
046 *
047 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
048 * @version $Rev: 925887 $, $Date: 2010-03-21 22:36:55 +0200 (Sun, 21 Mar 2010) $
049 */
050 public class SingleBaseSearch implements SearchStrategy
051 {
052 /**
053 * the LOG for this class
054 */
055 private static final Logger LOG = LoggerFactory.getLogger( SingleBaseSearch.class );
056
057 private final DirContext ctx;
058
059
060 SingleBaseSearch( String searchBaseDn, DirectoryService directoryService )
061 {
062 try
063 {
064 CoreSession session = directoryService.getSession();
065 ctx = new ServerLdapContext( directoryService, session, new LdapName( searchBaseDn ) );
066 } catch ( Exception e )
067 {
068 throw new ServiceConfigurationException( I18n.err( I18n.ERR_649, searchBaseDn ), e );
069 }
070
071 }
072
073
074 public Set<ResourceRecord> getRecords( QuestionRecord question ) throws DnsException
075 {
076 try
077 {
078
079 return new GetRecords( question ).execute( ctx, null );
080 }
081 catch ( Exception e )
082 {
083 LOG.debug( "Unexpected error retrieving DNS records.", e );
084 throw new DnsException( ResponseCode.SERVER_FAILURE );
085 }
086 }
087
088
089 }