directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r519816 - in /directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns: DnsConfiguration.java DnsServer.java store/SingleBaseSearch.java
Date Mon, 19 Mar 2007 03:37:29 GMT
Author: erodriguez
Date: Sun Mar 18 20:37:28 2007
New Revision: 519816

URL: http://svn.apache.org/viewvc?view=rev&rev=519816
Log:
Clean-up of DNS protocol configuration.
o  Enhancements to support Spring.
o  Removal of all code related to map-based configuration.
o  Some parameter names standardized with other protocol providers.
o  Enhancement to lazy-load search base DN.

Modified:
    directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsConfiguration.java
    directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsServer.java
    directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SingleBaseSearch.java

Modified: directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsConfiguration.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsConfiguration.java?view=diff&rev=519816&r1=519815&r2=519816
==============================================================================
--- directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsConfiguration.java
(original)
+++ directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsConfiguration.java
Sun Mar 18 20:37:28 2007
@@ -20,17 +20,12 @@
 package org.apache.directory.server.dns;
 
 
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.configuration.ConfigurationException;
-import org.apache.directory.server.protocol.shared.LoadStrategy;
 import org.apache.directory.server.protocol.shared.ServiceConfiguration;
 
 
 /**
+ * Contains the configuration parameters for the DNS protocol provider.
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
@@ -38,117 +33,23 @@
 {
     private static final long serialVersionUID = 6943138644427163149L;
 
-    /** the default port */
-    private static final String DEFAULT_IP_PORT = "53";
+    /** The default IP port. */
+    private static final int IP_PORT_DEFAULT = 53;
 
-    /** the default pid */
-    private static final String DEFAULT_PID = "org.apache.dns";
+    /** The default service pid. */
+    private static final String SERVICE_PID_DEFAULT = "org.apache.dns";
 
-    /** the default name */
-    private static final String DEFAULT_NAME = "Apache DNS Service";
-
-    /** the default prefix */
-    private static final String DEFAULT_PREFIX = "dns.";
+    /** The default service name. */
+    private static final String SERVICE_NAME_DEFAULT = "Apache DNS Service";
 
 
     /**
-     * Creates a new instance with default settings.
+     * Creates a new instance of DnsConfiguration.
      */
     public DnsConfiguration()
     {
-        this( getDefaultConfig(), LoadStrategy.LDAP );
-    }
-
-
-    /**
-     * Creates a new instance with default settings that operates on the
-     * {@link DirectoryService} with the specified ID.
-     */
-    public DnsConfiguration(String instanceId)
-    {
-        this( getDefaultConfig(), LoadStrategy.LDAP );
-        setInstanceId( instanceId );
-    }
-
-
-    public DnsConfiguration( Map<String, String> properties )
-    {
-        this( properties, LoadStrategy.LDAP );
-    }
-
-
-    public DnsConfiguration( Map<String, String> properties, int strategy )
-    {
-        if ( properties == null )
-        {
-            configuration = getDefaultConfig();
-        }
-        else
-        {
-            loadProperties( DEFAULT_PREFIX, properties, strategy );
-        }
-
-        int port = getPort();
-
-        if ( port < 1 || port > 0xFFFF )
-        {
-            throw new ConfigurationException( "Invalid value:  " + IP_PORT_KEY + "=" + port
);
-        }
-    }
-
-
-    public static Map<String, String> getDefaultConfig()
-    {
-        Map<String, String> defaults = new HashMap<String, String>();
-
-        defaults.put( SERVICE_PID, DEFAULT_PID );
-        defaults.put( IP_PORT_KEY, DEFAULT_IP_PORT );
-
-        return defaults;
-    }
-
-
-    public boolean isDifferent( Dictionary config )
-    {
-        int port = getPort();
-
-        if ( port == Integer.parseInt( ( String ) config.get( IP_PORT_KEY ) ) )
-        {
-            return false;
-        }
-
-        return true;
-    }
-
-
-    public String getName()
-    {
-        return DEFAULT_NAME;
-    }
-
-
-    public int getPort()
-    {
-        String key = IP_PORT_KEY;
-
-        if ( configuration.containsKey( key ) )
-        {
-            return Integer.parseInt( get( key ) );
-        }
-
-        return Integer.parseInt( DEFAULT_IP_PORT );
-    }
-
-
-    public int getBufferSize()
-    {
-        String key = BUFFER_SIZE_KEY;
-
-        if ( configuration.containsKey( key ) )
-        {
-            return Integer.parseInt( get( key ) );
-        }
-
-        return DEFAULT_BUFFER_SIZE;
+        super.setIpPort( IP_PORT_DEFAULT );
+        super.setServicePid( SERVICE_PID_DEFAULT );
+        super.setServiceName( SERVICE_NAME_DEFAULT );
     }
 }

Modified: directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsServer.java?view=diff&rev=519816&r1=519815&r2=519816
==============================================================================
--- directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsServer.java
(original)
+++ directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/DnsServer.java
Sun Mar 18 20:37:28 2007
@@ -34,6 +34,9 @@
 
 
 /**
+ * A wrapper encapsulating configuration, a MINA IoAcceptor, and a RecordStore
+ * to implement a complete DNS server. 
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
@@ -48,14 +51,22 @@
 
     private IoHandler handler;
 
-    public DnsServer(DnsConfiguration config, IoAcceptor acceptor, RecordStore store)
+
+    /**
+     * Creates a new instance of DnsServer.
+     *
+     * @param config
+     * @param acceptor
+     * @param store
+     */
+    public DnsServer( DnsConfiguration config, IoAcceptor acceptor, RecordStore store )
     {
         this.config = config;
         this.acceptor = acceptor;
         this.store = store;
 
-        String name = config.getName();
-        int port = config.getPort();
+        String name = config.getServiceName();
+        int port = config.getIpPort();
 
         try
         {
@@ -80,11 +91,11 @@
 
     public void destroy()
     {
-        acceptor.unbind( new InetSocketAddress( config.getPort() ) );
+        acceptor.unbind( new InetSocketAddress( config.getIpPort() ) );
 
-        acceptor= null;
+        acceptor = null;
         handler = null;
 
-        log.debug( "{} has stopped listening on port {}", config.getName(), new Integer(
config.getPort() ) );
+        log.debug( "{} has stopped listening on port {}", config.getServiceName(), new Integer(
config.getIpPort() ) );
     }
 }

Modified: directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SingleBaseSearch.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SingleBaseSearch.java?view=diff&rev=519816&r1=519815&r2=519816
==============================================================================
--- directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SingleBaseSearch.java
(original)
+++ directory/apacheds/branches/apacheds-sasl-branch/protocol-dns/src/main/java/org/apache/directory/server/dns/store/SingleBaseSearch.java
Sun Mar 18 20:37:28 2007
@@ -51,24 +51,20 @@
     private static final Logger log = LoggerFactory.getLogger( SingleBaseSearch.class );
 
     private DirContext ctx;
+    private Hashtable<String, Object> env;
+    private InitialContextFactory factory;
 
 
-    SingleBaseSearch(DnsConfiguration config, InitialContextFactory factory)
+    SingleBaseSearch( DnsConfiguration config, InitialContextFactory factory )
     {
-        Hashtable env = new Hashtable( config.toJndiEnvironment() );
+        env = new Hashtable<String, Object>( config.toJndiEnvironment() );
         env.put( Context.INITIAL_CONTEXT_FACTORY, config.getInitialContextFactory() );
-        env.put( Context.PROVIDER_URL, config.getEntryBaseDn() );
+        env.put( Context.PROVIDER_URL, config.getSearchBaseDn() );
+        env.put( Context.SECURITY_AUTHENTICATION, config.getSecurityAuthentication() );
+        env.put( Context.SECURITY_CREDENTIALS, config.getSecurityCredentials() );
+        env.put( Context.SECURITY_PRINCIPAL, config.getSecurityPrincipal() );
 
-        try
-        {
-            ctx = ( DirContext ) factory.getInitialContext( env );
-        }
-        catch ( NamingException ne )
-        {
-            log.error( ne.getMessage(), ne );
-            String message = "Failed to get initial context " + ( String ) env.get( Context.PROVIDER_URL
);
-            throw new ConfigurationException( message, ne );
-        }
+        this.factory = factory;
     }
 
 
@@ -80,6 +76,20 @@
 
     private Object execute( ContextOperation operation ) throws Exception
     {
+        if ( ctx == null )
+        {
+            try
+            {
+                ctx = ( DirContext ) factory.getInitialContext( env );
+            }
+            catch ( NamingException ne )
+            {
+                log.error( ne.getMessage(), ne );
+                String message = "Failed to get initial context " + ( String ) env.get( Context.PROVIDER_URL
);
+                throw new ConfigurationException( message, ne );
+            }
+        }
+
         return operation.execute( ctx, null );
     }
 }



Mime
View raw message