changeset 8:ff1e55a2171f

Refactored.
author Mikhail Kryshen <mikhail@kryshen.net>
date Sun, 01 Nov 2009 05:41:39 +0300
parents ca0b81d28307
children a3321ea9b33f
files src/kryshen/catalina/startup/HomesUserConfig.java src/kryshen/catalina/startup/HomesUserDatabase.java src/kryshen/catalina/startup/PasswdUserConfig.java src/kryshen/catalina/startup/UserConfig.java src/kryshen/catalina/startup/UserDatabase.java
diffstat 5 files changed, 122 insertions(+), 248 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/kryshen/catalina/startup/HomesUserConfig.java	Sun Nov 01 05:41:39 2009 +0300
@@ -0,0 +1,76 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package kryshen.catalina.startup;
+
+import java.io.File;
+
+/**
+ *
+ * @author Mikhail Kryshen
+ */
+public class HomesUserConfig extends UserConfig {
+
+    /**
+     * The directory name to be searched for within each user home directory.
+     */
+    private String directoryName = "public_webapps";
+    /**
+     * The base directory containing user home directories.
+     */
+    private String homeBase = null;
+
+    public String getDirectoryName() {
+        return directoryName;
+    }
+
+    /**
+     * Set the directory name for user web applications.
+     *
+     * @param directoryName The new directory name
+     */
+    public void setDirectoryName(String directoryName) {
+        this.directoryName = directoryName;
+    }
+
+    /**
+     * Return the base directory containing user home directories.
+     */
+    public String getHomeBase() {
+        return homeBase;
+    }
+
+    /**
+     * Set the base directory containing user home directories.
+     *
+     * @param homeBase The new base directory
+     */
+    public void setHomeBase(String homeBase) {
+        this.homeBase = homeBase;
+    }
+
+    @Override
+    protected void deployUserApps() {
+        File homeBaseFile = new File(homeBase);
+
+        if (!homeBaseFile.exists() || !homeBaseFile.isDirectory()) {
+            host.getLogger().error("Invalid home base.");
+            return;
+        }
+
+        String[] homes = homeBaseFile.list();
+
+        for (String name : homes) {
+            File home = new File(homeBaseFile, name);
+            
+            if (!home.isDirectory() /* || !home.canExecute() */) {
+                continue;
+            }
+
+            File base = new File(home, directoryName);
+            deployUserApps(name, base);
+        }
+    }
+}
--- a/src/kryshen/catalina/startup/HomesUserDatabase.java	Sun Nov 01 04:25:39 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-/*
- * 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 kryshen.catalina.startup;
-
-
-import java.io.File;
-import java.util.Collections;
-import java.util.Iterator;
-
-/**
- * Implementation of the <code>UserDatabase</code> interface
- * lists all users by their home directories found in the specified
- * base directory.
- *
- * @author Mikhail Kryshen
- */
-
-public final class HomesUserDatabase implements UserDatabase {
-
-    /**
-     * Iterates over users with accessible home directories.
-     */
-    private class UserIterator implements Iterator<User> {
-        final File homeBase;
-        final String[] homes;
-
-        User next;
-        int index = 0;
-
-        UserIterator(File homeBase) {
-            this.homeBase = homeBase;
-            this.homes = homeBase.list();
-
-            findNext();
-        }
-
-        /**
-         * Find the next accessible home directory in the list and
-         * create appropriate User to be returned by <code>next()</code>.
-         */
-        void findNext() {
-            next = null;
-
-            while (next == null && index < homes.length) {
-                final String name = homes[index];
-                final File home = new File(homeBase, name);               
-
-                index++;
-                
-                if (!home.isDirectory() /* || !home.canExecute() */) {
-                    continue;
-                }
-
-                next = new User() {
-                    public String getName() {
-                        return name;
-                    }
-
-                    public File getHome() {
-                        return home;
-                    }
-                };                
-            }
-        }
-
-        public boolean hasNext() {
-            return next != null;
-        }
-
-        public User next() {
-            User current = next;
-            findNext();
-            return current;
-        }
-
-        public void remove() {
-            throw new UnsupportedOperationException("Not supported.");
-        }
-    }
-
-    /**
-     * The UserConfig listener with which we are associated.
-     */
-    private UserConfig userConfig = null;
-
-    /**
-     * Return the UserConfig listener with which we are associated.
-     */
-    public UserConfig getUserConfig() {
-        return (this.userConfig);
-    }
-
-    /**
-     * Set the UserConfig listener with which we are associated.
-     *
-     * @param userConfig The new UserConfig listener
-     */
-    public void setUserConfig(UserConfig userConfig) {
-        this.userConfig = userConfig;
-    }
-
-    /**
-     * Returns Iterator for the list of users.
-     */
-    public Iterator<User> iterator() {
-        File homeBase = new File(userConfig.getHomeBase());
-
-        if (!homeBase.exists() || !homeBase.isDirectory()) {
-            // PENDING: throw Exception instead?
-            return Collections.<User>emptyList().iterator();
-        }
-
-        return new UserIterator(homeBase);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/kryshen/catalina/startup/PasswdUserConfig.java	Sun Nov 01 05:41:39 2009 +0300
@@ -0,0 +1,40 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package kryshen.catalina.startup;
+
+/**
+ *
+ * @author Mikhail Kryshen
+ */
+public class PasswdUserConfig extends UserConfig {
+
+    private static final String PASSWD_DATABASE = "passwd";
+
+    /**
+     * Command for retrieving passwd database.
+     */
+    private String getent = "getent";
+
+    /**
+     * Get command for retrieving passwd database.
+     */
+    public String getGetent() {
+        return getent;
+    }
+
+    /**
+     * Set command for retrieving passwd database.
+     */
+    public void setGetent(String getent) {
+        this.getent = getent;
+    }
+
+    @Override
+    protected void deployUserApps() {
+        // TODO
+    }
+
+}
--- a/src/kryshen/catalina/startup/UserConfig.java	Sun Nov 01 04:25:39 2009 +0300
+++ b/src/kryshen/catalina/startup/UserConfig.java	Sun Nov 01 05:41:39 2009 +0300
@@ -7,87 +7,11 @@
  *
  * @author Mikhail Kryshen
  */
-public class UserConfig extends HostConfig {
-
-    /**
-     * The directory name to be searched for within each user home directory.
-     */
-    private String directoryName = "public_webapps";
-
-    /**
-     * The base directory containing user home directories.
-     */
-    private String homeBase = null;
-
-    /**
-     * The Java class name of the user database class we should use.
-     */
-    private String userClass =
-            "org.apache.catalina.startup.PasswdUserDatabase";
-
-    /**
-     * Return the directory name for user web applications.
-     */
-    public String getDirectoryName() {
-        return (this.directoryName);
-    }
-
-    /**
-     * Set the directory name for user web applications.
-     *
-     * @param directoryName The new directory name
-     */
-    public void setDirectoryName(String directoryName) {
-        this.directoryName = directoryName;
-    }
-
-    /**
-     * Return the base directory containing user home directories.
-     */
-    public String getHomeBase() {
-        return (this.homeBase);
-    }
-
-    /**
-     * Set the base directory containing user home directories.
-     *
-     * @param homeBase The new base directory
-     */
-    public void setHomeBase(String homeBase) {
-        this.homeBase = homeBase;
-    }
-
-    /** 
-     * Return the user database class name for this component. 
-     */
-    public String getUserClass() {
-        return (this.userClass);
-    }
-
-    /** 
-     * Set the user database class name for this component. 
-     */
-    public void setUserClass(String userClass) {
-        this.userClass = userClass;
-    }
+public abstract class UserConfig extends HostConfig {
 
     @Override
     protected void deployApps() {       
-        // Load the user database object for this host
-        UserDatabase database = null;
-        try {
-            Class clazz = Class.forName(userClass);
-            database = (UserDatabase) clazz.newInstance();
-            database.setUserConfig(this);
-        } catch (Exception e) {
-            host.getLogger().error(sm.getString("userConfig.database"), e);
-            return;
-        }
-
-        // Deploy the web application (if any) for each defined user
-        for (UserDatabase.User user : database) {
-            deployUserApps(user.getName(), user.getHome());
-        }
+        deployUserApps();
     }
 
     @Override
@@ -96,16 +20,15 @@
                 ("deployApps(String) is not supported.");
     }
 
-    protected void deployUserApps(String user, File home) {
-        File base = new File(home, directoryName);
+    protected abstract void deployUserApps();
 
+    protected void deployUserApps(String user, File base) {
         if (!base.exists() || !base.isDirectory() || !base.canRead()) {
             return;
         }
 
-// TODO: deployWARs
-//        // Deploy WARs, and loop if additional descriptors are found
-//        deployWARs(appBase, appBase.list());
+        // TODO: deployWARs
+        // deployWARs(appBase, appBase.list());
 
         // Deploy expanded folders
         deployDirectories(user, base, base.list());
--- a/src/kryshen/catalina/startup/UserDatabase.java	Sun Nov 01 04:25:39 2009 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-package kryshen.catalina.startup;
-
-import java.io.File;
-import java.util.Iterator;
-
-/**
- *
- * @author Mikhail Kryshen
- */
-public interface UserDatabase extends Iterable<UserDatabase.User> {
-
-    interface User {
-        String getName();
-
-        File getHome();
-    }
-
-    /**
-     * Return the UserConfig listener with which we are associated.
-     */
-    UserConfig getUserConfig();
-
-    /**
-     * Set the UserConfig listener with which we are associated.
-     *
-     * @param userConfig The new UserConfig listener
-     */
-    void setUserConfig(UserConfig userConfig);
-
-    /**
-     * Returns Iterator for the list of users.
-     */
-    Iterator<User> iterator();
-}