directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1004472 - in /directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config: ConfigPartitionReader.java beans/ beans/JournalBean.java beans/TcpTransportBean.java beans/TransportBean.java beans/UdpTransportBean.java
Date Mon, 04 Oct 2010 22:59:49 GMT
Author: elecharny
Date: Mon Oct  4 22:59:48 2010
New Revision: 1004472

URL: http://svn.apache.org/viewvc?rev=1004472&view=rev
Log:
o Created some beans to store the configuration read from the ldif files.
o Added methods to read the Ldif config into beans before instanciating the real objects

Added:
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/JournalBean.java
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TcpTransportBean.java
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TransportBean.java
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/UdpTransportBean.java
Modified:
    directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java

Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java?rev=1004472&r1=1004471&r2=1004472&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
(original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
Mon Oct  4 22:59:48 2010
@@ -57,6 +57,10 @@ import java.util.TreeSet;
 import javax.naming.directory.SearchControls;
 
 import org.apache.directory.server.changepw.ChangePasswordServer;
+import org.apache.directory.server.config.beans.JournalBean;
+import org.apache.directory.server.config.beans.TcpTransportBean;
+import org.apache.directory.server.config.beans.TransportBean;
+import org.apache.directory.server.config.beans.UdpTransportBean;
 import org.apache.directory.server.core.DefaultDirectoryService;
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.authn.AuthenticationInterceptor;
@@ -1246,58 +1250,83 @@ public class ConfigPartitionReader
         return transports.toArray( new Transport[]
             {} );
     }
-
-
-    //This will suppress PMD.AvoidUsingHardCodedIP warnings in this class
-    @SuppressWarnings("PMD.AvoidUsingHardCodedIP")
-    public Transport createTransport( Entry transportEntry ) throws Exception
+    
+    
+    public TransportBean readTransport( Entry transportEntry ) throws Exception
     {
-        Transport transport = null;
+        TransportBean transportBean = null;
 
         EntryAttribute ocAttr = transportEntry.get( OBJECT_CLASS_AT );
 
         if ( ocAttr.contains( ConfigSchemaConstants.ADS_TCP_TRANSPORT ) )
         {
-            transport = new TcpTransport();
+            transportBean = new TcpTransportBean();
         }
         else if ( ocAttr.contains( ConfigSchemaConstants.ADS_UDP_TRANSPORT ) )
         {
-            transport = new UdpTransport();
+            transportBean = new UdpTransportBean();
         }
 
-        transport.setPort( getInt( ConfigSchemaConstants.ADS_SYSTEM_PORT, transportEntry
) );
+        transportBean.setPort( getInt( ConfigSchemaConstants.ADS_SYSTEM_PORT, transportEntry
) );
         EntryAttribute addressAttr = transportEntry.get( ConfigSchemaConstants.ADS_TRANSPORT_ADDRESS
);
 
         if ( addressAttr != null )
         {
-            transport.setAddress( addressAttr.getString() );
+            transportBean.setAddress( addressAttr.getString() );
         }
         else
         {
-            transport.setAddress( "0.0.0.0" );
+            transportBean.setAddress( "0.0.0.0" );
         }
 
         EntryAttribute backlogAttr = transportEntry.get( ConfigSchemaConstants.ADS_TRANSPORT_BACKLOG
);
 
         if ( backlogAttr != null )
         {
-            transport.setBackLog( Integer.parseInt( backlogAttr.getString() ) );
+            transportBean.setBackLog( Integer.parseInt( backlogAttr.getString() ) );
         }
 
         EntryAttribute sslAttr = transportEntry.get( ConfigSchemaConstants.ADS_TRANSPORT_ENABLE_SSL
);
 
         if ( sslAttr != null )
         {
-            transport.setEnableSSL( Boolean.parseBoolean( sslAttr.getString() ) );
+            transportBean.setEnableSSL( Boolean.parseBoolean( sslAttr.getString() ) );
         }
 
         EntryAttribute nbThreadsAttr = transportEntry.get( ConfigSchemaConstants.ADS_TRANSPORT_NBTHREADS
);
 
         if ( nbThreadsAttr != null )
         {
-            transport.setNbThreads( Integer.parseInt( nbThreadsAttr.getString() ) );
+            transportBean.setNbThreads( Integer.parseInt( nbThreadsAttr.getString() ) );
+        }
+
+        return transportBean;
+    }
+
+
+    //This will suppress PMD.AvoidUsingHardCodedIP warnings in this class
+    @SuppressWarnings("PMD.AvoidUsingHardCodedIP")
+    public Transport createTransport( Entry transportEntry ) throws Exception
+    {
+        Transport transport = null;
+
+        TransportBean transportBean = readTransport( transportEntry );
+        
+        if ( transportBean instanceof TcpTransportBean )
+        {
+            transport = new TcpTransport();
+        }
+        else if ( transportBean instanceof UdpTransportBean )
+        {
+            transport = new UdpTransport();
         }
 
+        transport.setPort( transportBean.getPort() );
+        transport.setAddress( transportBean.getAddress() );
+        transport.setBackLog( transportBean.getBackLog() );
+        transport.setEnableSSL( transportBean.isSSLEnabled() );
+        transport.setNbThreads( transportBean.getNbThreads() );
+
         return transport;
     }
 
@@ -1324,40 +1353,65 @@ public class ConfigPartitionReader
 
         return cl;
     }
-
-
-    public Journal createJournal( DN journalDN ) throws Exception
+    
+    
+    /**
+     * Load the Journal configuration
+     * 
+     * @param journalDN The DN which contains the journal configuration
+     * @return A bean containing the journal configuration
+     * @throws Exception If there is somethng wrong in the configuration
+     */
+    public JournalBean readJournal( DN journalDN ) throws Exception
     {
-        long id = configPartition.getEntryId( journalDN );
-        Entry jlEntry = configPartition.lookup( id );
+        JournalBean journalBean = new JournalBean();
 
-        Journal journal = new DefaultJournal();
-        JournalStore store = new DefaultJournalStore();
-
-        store.setFileName( getString( ConfigSchemaConstants.ADS_JOURNAL_FILENAME, jlEntry
) );
+        long id = configPartition.getEntryId( journalDN );
+        Entry entry = configPartition.lookup( id );
+        
+        journalBean.setFileName( entry.get( ConfigSchemaConstants.ADS_JOURNAL_FILENAME ).getString()
);
 
-        EntryAttribute jlWorkDirAttr = jlEntry.get( ConfigSchemaConstants.ADS_JOURNAL_WORKINGDIR
);
+        EntryAttribute workingDirAttr = entry.get( ConfigSchemaConstants.ADS_JOURNAL_WORKINGDIR
);
 
-        if ( jlWorkDirAttr != null )
+        if ( workingDirAttr != null )
         {
-            store.setWorkingDirectory( jlWorkDirAttr.getString() );
+            journalBean.setWorkingDir( workingDirAttr.getString() );
         }
+        
+        EntryAttribute rotationAttr = entry.get( ConfigSchemaConstants.ADS_JOURNAL_ROTATION
);
 
-        EntryAttribute jlRotAttr = jlEntry.get( ConfigSchemaConstants.ADS_JOURNAL_ROTATION
);
-
-        if ( jlRotAttr != null )
+        if ( rotationAttr != null )
         {
-            journal.setRotation( Integer.parseInt( jlRotAttr.getString() ) );
+            journalBean.setRotation( Integer.parseInt( rotationAttr.getString() ) );
         }
+        
+        EntryAttribute enabledAttr = entry.get( ConfigSchemaConstants.ADS_JOURNAL_ENABLED
);
 
-        EntryAttribute jlEnabledAttr = jlEntry.get( ConfigSchemaConstants.ADS_JOURNAL_ENABLED
);
-
-        if ( jlEnabledAttr != null )
+        if ( enabledAttr != null )
         {
-            journal.setEnabled( Boolean.parseBoolean( jlEnabledAttr.getString() ) );
+            journalBean.setEnabled( Boolean.parseBoolean( enabledAttr.getString() ) );
         }
+        
+        return journalBean;
+    }
+
+
+    public Journal createJournal( DN journalDN ) throws Exception
+    {
+        JournalBean journalBean = readJournal( journalDN );
+        
+        Journal journal = new DefaultJournal();
+
+        journal.setRotation( journalBean.getRotation() );
+        journal.setEnabled( journalBean.isEnabled() );
+
+        JournalStore store = new DefaultJournalStore();
+
+        store.setFileName( journalBean.getFileName() );
+        store.setWorkingDirectory( journalBean.getWorkingDir() );
 
         journal.setJournalStore( store );
+        
         return journal;
     }
 

Added: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/JournalBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/JournalBean.java?rev=1004472&view=auto
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/JournalBean.java
(added)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/JournalBean.java
Mon Oct  4 22:59:48 2010
@@ -0,0 +1,124 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you 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.directory.server.config.beans;
+
+/**
+ * A class used to store the Journal configuration.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class JournalBean 
+{
+    /** The journal file name */
+    private String fileName;
+    
+    /** The journal working directory */
+    private String workingDir;
+    
+    /** The journal rotation */
+    private int rotation;
+    
+    /** Tells if the journal is enabled */
+    private boolean enabled;
+
+    /**
+     * Create a new JournalBean instance
+     */
+    public JournalBean()
+    {
+        // Default to infinite
+        rotation = 0;
+        
+        // Not enabled by default
+        enabled = false;
+    }
+    
+    
+    /**
+     * @return the fileName
+     */
+    public String getFileName() 
+    {
+        return fileName;
+    }
+
+    
+    /**
+     * @param fileName the fileName to set
+     */
+    public void setFileName( String fileName ) 
+    {
+        this.fileName = fileName;
+    }
+
+    
+    /**
+     * @return the workingDir
+     */
+    public String getWorkingDir() 
+    {
+        return workingDir;
+    }
+
+    
+    /**
+     * @param workingDir the workingDir to set
+     */
+    public void setWorkingDir( String workingDir ) 
+    {
+        this.workingDir = workingDir;
+    }
+
+    
+    /**
+     * @return the rotation
+     */
+    public int getRotation() 
+    {
+        return rotation;
+    }
+
+    
+    /**
+     * @param rotation the rotation to set
+     */
+    public void setRotation( int rotation ) 
+    {
+        this.rotation = rotation;
+    }
+
+    
+    /**
+     * @return the enabled
+     */
+    public boolean isEnabled() 
+    {
+        return enabled;
+    }
+
+    
+    /**
+     * @param enabled the enabled to set
+     */
+    public void setEnabled( boolean enabled ) 
+    {
+        this.enabled = enabled;
+    }
+}

Added: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TcpTransportBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TcpTransportBean.java?rev=1004472&view=auto
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TcpTransportBean.java
(added)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TcpTransportBean.java
Mon Oct  4 22:59:48 2010
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you 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.directory.server.config.beans;
+
+/**
+ * A class used to store the TCP Transport configuration.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TcpTransportBean extends TransportBean
+{
+    /**
+     * Create a new TransportBean instance
+     */
+    public TcpTransportBean()
+    {
+        super();
+    }
+}

Added: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TransportBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TransportBean.java?rev=1004472&view=auto
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TransportBean.java
(added)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TransportBean.java
Mon Oct  4 22:59:48 2010
@@ -0,0 +1,146 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you 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.directory.server.config.beans;
+
+/**
+ * A class used to store the Transport configuration.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TransportBean 
+{
+    /** The server address */
+    private String address;
+    
+    /** The port number */
+    private int port = -1;
+
+    /** A flag set if SSL is enabled */
+    private boolean sslEnabled = false;
+    
+    /** The default backlog queue size */
+    protected static final int DEFAULT_BACKLOG_NB = 50;
+    
+    /** The default number of threads */
+    protected static final int DEFAULT_NB_THREADS = 3;
+
+    /** The number of threads to use for the IoAcceptor executor */
+    private int nbThreads = DEFAULT_NB_THREADS;
+    
+    /** The backlog for the transport services */
+    private int backlog = DEFAULT_BACKLOG_NB;
+    
+
+    /**
+     * Create a new TransportBean instance
+     */
+    public TransportBean()
+    {
+    }
+
+    
+    /**
+     * @param port the port to set
+     */
+    public void setPort( int port ) 
+    {
+        this.port = port;
+    }
+
+    
+    /**
+     * @return the port
+     */
+    public int getPort() 
+    {
+        return port;
+    }
+
+    
+    /**
+     * @param address the address to set
+     */
+    public void setAddress( String address ) {
+        this.address = address;
+    }
+
+    
+    /**
+     * @return the address
+     */
+    public String getAddress() {
+        return address;
+    }
+    
+    
+    /**
+     * @return <code>true</code> id SSL is enabled for this transport
+     */
+    public boolean isSSLEnabled()
+    {
+        return sslEnabled;
+    }
+    
+    
+    /**
+     * Enable or disable SSL
+     * @param sslEnabled if <code>true</code>, SSL is enabled.
+     */
+    public void setEnableSSL( boolean sslEnabled )
+    {
+        this.sslEnabled = sslEnabled;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public int getNbThreads() 
+    {
+        return nbThreads;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void setNbThreads( int nbThreads )
+    {
+        this.nbThreads = nbThreads;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public int getBackLog()
+    {
+        return backlog;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void setBackLog( int backLog )
+    {
+        this.backlog = backLog;
+    }
+}

Added: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/UdpTransportBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/UdpTransportBean.java?rev=1004472&view=auto
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/UdpTransportBean.java
(added)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/UdpTransportBean.java
Mon Oct  4 22:59:48 2010
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you 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.directory.server.config.beans;
+
+/**
+ * A class used to store the UDP Transport configuration.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class UdpTransportBean extends TransportBean
+{
+    /**
+     * Create a new TransportBean instance
+     */
+    public UdpTransportBean()
+    {
+        super();
+    }
+}



Mime
View raw message