directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r328196 - in /directory/protocol-providers/ntp/trunk: project.xml src/java/org/apache/ntp/NtpConfiguration.java
Date Tue, 25 Oct 2005 00:26:51 GMT
Author: erodriguez
Date: Mon Oct 24 17:26:46 2005
New Revision: 328196

URL: http://svn.apache.org/viewcvs?rev=328196&view=rev
Log:
Consolidated configuration from NTP OSGi bundle to protocol provider.

Added:
    directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java 
 (with props)
Modified:
    directory/protocol-providers/ntp/trunk/project.xml

Modified: directory/protocol-providers/ntp/trunk/project.xml
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/project.xml?rev=328196&r1=328195&r2=328196&view=diff
==============================================================================
--- directory/protocol-providers/ntp/trunk/project.xml (original)
+++ directory/protocol-providers/ntp/trunk/project.xml Mon Oct 24 17:26:46 2005
@@ -94,6 +94,12 @@
       <url>http://slf4j.org/nlog4j</url>
     </dependency>
     <dependency>
+      <!-- required to load Configuration and LDIFs -->
+      <groupId>directory</groupId>
+      <artifactId>apacheds-main</artifactId>
+      <version>0.9.3-SNAPSHOT</version>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>

Added: directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java?rev=328196&view=auto
==============================================================================
--- directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java (added)
+++ directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java Mon
Oct 24 17:26:46 2005
@@ -0,0 +1,122 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+
+package org.apache.ntp;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ldap.server.DirectoryService;
+import org.apache.ldap.server.configuration.Configuration;
+import org.apache.ldap.server.configuration.ConfigurationException;
+
+public class NtpConfiguration extends Configuration
+{
+    /** the prop key const for the port */
+    public static final String NTP_PORT_KEY = "ntp.port";
+
+    /** the default port */
+    private static final String NTP_DEFAULT_PORT = "123";
+
+    private static final String SERVICE_PID = "service.pid";
+    private static final String PID = "org.apache.ntp";
+    private static final String name = "Apache NTP Service";
+
+    private Map configuration = new HashMap();
+
+    /**
+     * Creates a new instance with default settings.
+     */
+    public NtpConfiguration()
+    {
+        this( getDefaultConfig() );
+    }
+
+    /**
+     * Creates a new instance with default settings that operates on the
+     * {@link DirectoryService} with the specified ID.
+     */
+    public NtpConfiguration( String instanceId )
+    {
+        this( getDefaultConfig() );
+        setInstanceId( instanceId );
+    }
+
+    public NtpConfiguration( Map properties )
+    {
+        if ( properties == null )
+        {
+            configuration = getDefaultConfig();
+        }
+        else
+        {
+            configuration.putAll( properties );
+        }
+
+        int port = getPort();
+
+        if ( port < 1 || port > 0xFFFF )
+        {
+            throw new ConfigurationException( "Invalid value:  " + NTP_PORT_KEY + "=" + port
);
+        }
+    }
+
+    public static Map getDefaultConfig()
+    {
+        Map defaults = new HashMap();
+
+        defaults.put( SERVICE_PID, PID );
+        defaults.put( NTP_PORT_KEY, NTP_DEFAULT_PORT );
+
+        return defaults;
+    }
+
+    public boolean isDifferent( Dictionary config )
+    {
+        int port = getPort();
+
+        if ( port == Integer.parseInt( (String) config.get( NTP_PORT_KEY ) ) )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public int getPort()
+    {
+        String key = NTP_PORT_KEY;
+
+        if ( configuration.containsKey( key ) )
+        {
+            return Integer.parseInt( get( key ) );
+        }
+
+        return Integer.parseInt( NTP_DEFAULT_PORT );
+    }
+
+    private String get( String key )
+    {
+        return (String) configuration.get( key );
+    }
+}

Propchange: directory/protocol-providers/ntp/trunk/src/java/org/apache/ntp/NtpConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message