You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2010/09/16 15:10:25 UTC
svn commit: r997737 - in
/directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server:
AbstractLayout.java InstallationLayout.java InstanceLayout.java
Author: pamarcelot
Date: Thu Sep 16 13:10:24 2010
New Revision: 997737
URL: http://svn.apache.org/viewvc?rev=997737&view=rev
Log:
Shared common code into an AbstractLayer class.
Added:
directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/AbstractLayout.java
Modified:
directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/InstallationLayout.java
directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/InstanceLayout.java
Added: directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/AbstractLayout.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/AbstractLayout.java?rev=997737&view=auto
==============================================================================
--- directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/AbstractLayout.java (added)
+++ directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/AbstractLayout.java Thu Sep 16 13:10:24 2010
@@ -0,0 +1,222 @@
+package org.apache.directory.server;
+
+
+/*
+ * 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.
+ *
+ */
+
+import java.io.File;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Convenience class to encapsulate paths to various directories and files within
+ * an layout.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class AbstractLayout
+{
+ /** The logger*/
+ private final static Logger log = LoggerFactory.getLogger( AbstractLayout.class );
+
+ /** The required directories */
+ private File[] requiredDirectories = new File[0];
+
+ /** The required files */
+ private File[] requiredFiles = new File[0];
+
+ /** The directory */
+ private File directory;
+
+
+ /**
+ * Creates a new instance of AbstractLayout.
+ *
+ * @param directory
+ * the directory
+ */
+ protected AbstractLayout( File directory )
+ {
+ this.directory = directory;
+ }
+
+
+ /**
+ * Creates a new instance of AbstractLayout.
+ *
+ * @param directoryPath
+ * the path to the directory
+ */
+ protected AbstractLayout( String directoryPath )
+ {
+ this.directory = new File( directoryPath );
+ }
+
+
+ /**
+ * Gets the installation directory.
+ *
+ * @return
+ * the installation directory
+ */
+ protected File getDirectory()
+ {
+ return directory;
+ }
+
+
+ /**
+ * Gets the required directories.
+ *
+ * @return
+ * the required directories
+ */
+ public File[] getRequiredDirectories()
+ {
+ return requiredDirectories;
+ }
+
+
+ /**
+ * Gets the required files.
+ *
+ * @return
+ * the required files
+ */
+ public File[] getRequiredFiles()
+ {
+ return requiredFiles;
+ }
+
+
+ /**
+ * Creates the required directories (if they don't already exist).
+ */
+ public void mkdirs()
+ {
+ for ( File requiredDirectory : requiredDirectories )
+ {
+ if ( !requiredDirectory.exists() )
+ {
+ requiredDirectory.mkdirs();
+ }
+ }
+ }
+
+
+ /**
+ * Sets the required directories.
+ *
+ * @param requiredDirectories
+ * an array of required directories
+ */
+ protected void setRequiredDirectories( File[] requiredDirectories )
+ {
+ this.requiredDirectories = requiredDirectories;
+ }
+
+
+ /**
+ * Sets the required files.
+ *
+ * @param requiredFiles
+ * an array of required files
+ */
+ protected void setRequiredFiles( File[] requiredFiles )
+ {
+ this.requiredFiles = requiredFiles;
+ }
+
+
+ /**
+ * Verifies the installation by checking required directories and files.
+ */
+ public void verifyInstallation()
+ {
+ log.debug( "Verifying required directories" );
+
+ // Verifying required directories
+ for ( File requiredDirectory : requiredDirectories )
+ {
+ // Exists?
+ if ( !requiredDirectory.exists() )
+ {
+ String message = "The required '" + requiredDirectory + " directory does not exist!";
+ log.error( message );
+ throw new IllegalStateException( message );
+ }
+
+ // Directory?
+ if ( requiredDirectory.isFile() )
+ {
+ String message = "'" + requiredDirectory + "' is a file when it should be a directory.";
+ log.error( message );
+ throw new IllegalStateException( message );
+ }
+
+ // Writable?
+ if ( !requiredDirectory.canWrite() )
+ {
+ String message = "'" + requiredDirectory
+ + "' is write protected from the current user '"
+ + System.getProperty( "user.name" ) + "'";
+ log.error( message );
+ throw new IllegalStateException( message );
+ }
+ }
+
+ log.debug( "Required directories verification finished successfully." );
+
+ log.debug( "Verifying required files" );
+
+ // Verifying required files
+ for ( File requiredFile : requiredFiles )
+ {
+ // Exists?
+ if ( !requiredFile.exists() )
+ {
+ String message = "The required'" + requiredFile + "' file does not exist!";
+ log.error( message );
+ throw new IllegalStateException( message );
+ }
+
+ // File?
+ if ( requiredFile.isDirectory() )
+ {
+ String message = "'" + requiredFile + "' is a directory when it should be a file.";
+ log.error( message );
+ throw new IllegalStateException( message );
+ }
+
+ // Writable?
+ if ( !requiredFile.canRead() )
+ {
+ String message = "'" + requiredFile + "' is not readable by the current user '"
+ + System.getProperty( "user.name" ) + "'.";
+ log.error( message );
+ throw new IllegalStateException( message );
+ }
+ }
+
+ log.debug( "Required files verification finished successfully." );
+ }
+}
Modified: directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/InstallationLayout.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/InstallationLayout.java?rev=997737&r1=997736&r2=997737&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/InstallationLayout.java (original)
+++ directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/InstallationLayout.java Thu Sep 16 13:10:24 2010
@@ -1,4 +1,6 @@
package org.apache.directory.server;
+
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -19,13 +21,8 @@ package org.apache.directory.server;
*
*/
-
-
import java.io.File;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* Convenience class to encapsulate paths to various directories and files within
@@ -33,32 +30,8 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class InstallationLayout
+public class InstallationLayout extends AbstractLayout
{
- /** The logger*/
- private final static Logger log = LoggerFactory.getLogger( InstallationLayout.class );
-
- /** The required directories */
- private File[] requiredDirectories = new File[]
- {
- getInstallationDirectory(),
- getBinDirectory(),
- getConfDirectory(),
- getLibDirectory()
- };
-
- /** The required files */
- private File[] requiredFiles = new File[]
- {
- getScriptFile(),
- getWrapperFile(),
- getWrapperConfigurationFile()
- };
-
- /** The installation directory */
- private File installationDirectory;
-
-
/**
* Creates a new instance of InstallationLayout.
*
@@ -67,7 +40,8 @@ public class InstallationLayout
*/
public InstallationLayout( File installationDirectory )
{
- this.installationDirectory = installationDirectory;
+ super( installationDirectory );
+ init();
}
@@ -79,7 +53,34 @@ public class InstallationLayout
*/
public InstallationLayout( String installationDirectoryPath )
{
- this.installationDirectory = new File( installationDirectoryPath );
+ super( installationDirectoryPath );
+ init();
+ }
+
+
+ /**
+ * Initializes the InstallationLayout.
+ */
+ private void init()
+ {
+ // The required directories
+ File[] requiredDirectories = new File[]
+ {
+ getInstallationDirectory(),
+ getBinDirectory(),
+ getConfDirectory(),
+ getLibDirectory()
+ };
+ setRequiredDirectories( requiredDirectories );
+
+ // The required files
+ File[] requiredFiles = new File[]
+ {
+ getScriptFile(),
+ getWrapperFile(),
+ getWrapperConfigurationFile()
+ };
+ setRequiredFiles( requiredFiles );
}
@@ -115,7 +116,7 @@ public class InstallationLayout
*/
public File getInstallationDirectory()
{
- return installationDirectory;
+ return getDirectory();
}
@@ -189,93 +190,4 @@ public class InstallationLayout
{
return new File( getBinDirectory(), "wrapper" );
}
-
-
- /**
- * Creates the required directories (if they don't already exist).
- */
- public void mkdirs()
- {
- for ( File requiredDirectory : requiredDirectories )
- {
- if ( !requiredDirectory.exists() )
- {
- requiredDirectory.mkdirs();
- }
- }
- }
-
-
- /**
- * Verifies the installation by checking required directories and files.
- */
- public void verifyInstallation()
- {
- log.debug( "Verifying required directories" );
-
- // Verifying required directories
- for ( File requiredDirectory : requiredDirectories )
- {
- // Exists?
- if ( !requiredDirectory.exists() )
- {
- String message = "The required '" + requiredDirectory + " directory does not exist!";
- log.error( message );
- throw new IllegalStateException( message );
- }
-
- // Directory?
- if ( requiredDirectory.isFile() )
- {
- String message = "'" + requiredDirectory + "' is a file when it should be a directory.";
- log.error( message );
- throw new IllegalStateException( message );
- }
-
- // Writable?
- if ( !requiredDirectory.canWrite() )
- {
- String message = "'" + requiredDirectory
- + "' is write protected from the current user '"
- + System.getProperty( "user.name" ) + "'";
- log.error( message );
- throw new IllegalStateException( message );
- }
- }
-
- log.debug( "Required directories verification finished successfully." );
-
- log.debug( "Verifying required files" );
-
- // Verifying required files
- for ( File requiredFile : requiredFiles )
- {
- // Exists?
- if ( !requiredFile.exists() )
- {
- String message = "The required'" + requiredFile + "' file does not exist!";
- log.error( message );
- throw new IllegalStateException( message );
- }
-
- // File?
- if ( requiredFile.isDirectory() )
- {
- String message = "'" + requiredFile + "' is a directory when it should be a file.";
- log.error( message );
- throw new IllegalStateException( message );
- }
-
- // Writable?
- if ( !requiredFile.canRead() )
- {
- String message = "'" + requiredFile + "' is not readable by the current user '"
- + System.getProperty( "user.name" ) + "'.";
- log.error( message );
- throw new IllegalStateException( message );
- }
- }
-
- log.debug( "Required files verification finished successfully." );
- }
}
Modified: directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/InstanceLayout.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/InstanceLayout.java?rev=997737&r1=997736&r2=997737&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/InstanceLayout.java (original)
+++ directory/apacheds/branches/apacheds-apacheds-2.0/service/src/main/java/org/apache/directory/server/InstanceLayout.java Thu Sep 16 13:10:24 2010
@@ -1,4 +1,6 @@
package org.apache.directory.server;
+
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -19,13 +21,8 @@ package org.apache.directory.server;
*
*/
-
-
import java.io.File;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* Convenience class to encapsulate paths to various directories and files within
@@ -33,35 +30,12 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class InstanceLayout
+public class InstanceLayout extends AbstractLayout
{
- /** The logger*/
- private final static Logger log = LoggerFactory.getLogger( InstanceLayout.class );
-
+ // Static final fields for system property names
private static final String LOG_DIR = "apacheds.log.dir";
private static final String RUN_DIR = "apacheds.run.dir";
- /** The required directories */
- private File[] requiredDirectories = new File[]
- {
- getInstanceDirectory(),
- getConfDirectory(),
- getLogDirectory(),
- getPartitionsDirectory(),
- getRunDirectory()
- };
-
- /** The required files */
- private File[] requiredFiles = new File[]
- {
- getWrapperConfigurationFile(),
- getLogConfigurationFile() /*,
- getApacheDsConfigurationLdifFile() */// TODO re-activate this when possible.
- };
-
- /** The instance directory */
- private File instanceDirectory;
-
/**
* Creates a new instance of InstanceLayout.
@@ -71,7 +45,8 @@ public class InstanceLayout
*/
public InstanceLayout( File instanceDirectory )
{
- this.instanceDirectory = instanceDirectory;
+ super( instanceDirectory );
+ init();
}
@@ -83,7 +58,35 @@ public class InstanceLayout
*/
public InstanceLayout( String instanceDirectoryPath )
{
- this.instanceDirectory = new File( instanceDirectoryPath );
+ super( instanceDirectoryPath );
+ init();
+ }
+
+
+ /**
+ * Initializes the InstanceLayout.
+ */
+ private void init()
+ {
+ // The required directories
+ File[] requiredDirectories = new File[]
+ {
+ getInstanceDirectory(),
+ getConfDirectory(),
+ getLogDirectory(),
+ getPartitionsDirectory(),
+ getRunDirectory()
+ };
+ setRequiredDirectories( requiredDirectories );
+
+ // The required files
+ File[] requiredFiles = new File[]
+ {
+ getWrapperConfigurationFile(),
+ getLogConfigurationFile() /*,
+ getApacheDsConfigurationLdifFile() */// TODO re-activate this when possible.
+ };
+ setRequiredFiles( requiredFiles );
}
@@ -157,7 +160,7 @@ public class InstanceLayout
*/
public File getInstanceDirectory()
{
- return instanceDirectory;
+ return getDirectory();
}
@@ -195,93 +198,4 @@ public class InstanceLayout
{
return new File( getConfDirectory(), "config.ldif" );
}
-
-
- /**
- * Creates the required directories (if they don't already exist).
- */
- public void mkdirs()
- {
- for ( File requiredDirectory : requiredDirectories )
- {
- if ( !requiredDirectory.exists() )
- {
- requiredDirectory.mkdirs();
- }
- }
- }
-
-
- /**
- * Verifies the installation by checking required directories and files.
- */
- public void verifyInstallation()
- {
- log.debug( "Verifying required directories" );
-
- // Verifying required directories
- for ( File requiredDirectory : requiredDirectories )
- {
- // Exists?
- if ( !requiredDirectory.exists() )
- {
- String message = "The required '" + requiredDirectory + " directory does not exist!";
- log.error( message );
- throw new IllegalStateException( message );
- }
-
- // Directory?
- if ( requiredDirectory.isFile() )
- {
- String message = "'" + requiredDirectory + "' is a file when it should be a directory.";
- log.error( message );
- throw new IllegalStateException( message );
- }
-
- // Writable?
- if ( !requiredDirectory.canWrite() )
- {
- String message = "'" + requiredDirectory
- + "' is write protected from the current user '"
- + System.getProperty( "user.name" ) + "'";
- log.error( message );
- throw new IllegalStateException( message );
- }
- }
-
- log.debug( "Required directories verification finished successfully." );
-
- log.debug( "Verifying required files" );
-
- // Verifying required files
- for ( File requiredFile : requiredFiles )
- {
- // Exists?
- if ( !requiredFile.exists() )
- {
- String message = "The required'" + requiredFile + "' file does not exist!";
- log.error( message );
- throw new IllegalStateException( message );
- }
-
- // File?
- if ( requiredFile.isDirectory() )
- {
- String message = "'" + requiredFile + "' is a directory when it should be a file.";
- log.error( message );
- throw new IllegalStateException( message );
- }
-
- // Writable?
- if ( !requiredFile.canRead() )
- {
- String message = "'" + requiredFile + "' is not readable by the current user '"
- + System.getProperty( "user.name" ) + "'.";
- log.error( message );
- throw new IllegalStateException( message );
- }
- }
-
- log.debug( "Required files verification finished successfully." );
- }
}