You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2003/06/25 16:37:08 UTC
cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ac Item.java ItemManager.java UserManager.java RoleManager.java GroupManager.java
andreas 2003/06/25 07:37:08
Modified: src/java/org/apache/lenya/cms/ac ItemManager.java
UserManager.java RoleManager.java GroupManager.java
Added: src/java/org/apache/lenya/cms/ac Item.java
Log:
changed contract: items must not have a (publication, configuration) constructor, but implement the Item interface
Revision Changes Path
1.7 +37 -36 cocoon-lenya/src/java/org/apache/lenya/cms/ac/ItemManager.java
Index: ItemManager.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/ItemManager.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ItemManager.java 25 Jun 2003 08:56:32 -0000 1.6
+++ ItemManager.java 25 Jun 2003 14:37:07 -0000 1.7
@@ -51,7 +51,6 @@
import java.io.File;
import java.io.FileFilter;
-import java.lang.reflect.Constructor;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
@@ -59,45 +58,50 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import org.apache.lenya.cms.publication.Publication;
import org.apache.log4j.Category;
/**
+ * Abstract superclass for classes that manage items loaded from configuration files.
* @author egli
- *
- *
+ * @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
*/
public abstract class ItemManager {
- static final Category log = Category.getInstance(ItemManager.class);
+ private static final Category log = Category.getInstance(ItemManager.class);
public static final String PATH =
"config" + File.separator + "ac" + File.separator + "passwd";
private Set items = null;
- private Publication publication = null;
+ private File configurationDirectory;
/**
* Create a new ItemManager
*
- * @param publication where the items are fetched from
+ * @param configurationDirectory where the items are fetched from
* @throws AccessControlException if the item manager cannot be instantiated
*/
- protected ItemManager(Publication publication)
+ protected ItemManager(File configurationDirectory)
throws AccessControlException {
+
+ assert configurationDirectory != null;
+
+ if (!configurationDirectory.exists()
+ || !configurationDirectory.isDirectory()) {
+ throw new AccessControlException(
+ "The directory [" + configurationDirectory.getAbsolutePath()
+ + "] does not exist!");
+ }
- this.publication = publication;
+ this.configurationDirectory = configurationDirectory;
- File groupDir = new File(publication.getDirectory(), PATH);
- if (!groupDir.exists() || !groupDir.isDirectory()) {
- // throw new Execption();
- }
- File[] itemFiles = groupDir.listFiles(getFileFilter());
+ File[] itemFiles = configurationDirectory.listFiles(getFileFilter());
items = new HashSet();
Configuration config = null;
for (int i = 0; i < itemFiles.length; i++) {
DefaultConfigurationBuilder builder =
new DefaultConfigurationBuilder();
try {
+ assert itemFiles[i].exists();
config = builder.buildFromFile(itemFiles[i]);
} catch (Exception e) {
String errorMsg =
@@ -116,12 +120,9 @@
log.error(errorMsg);
throw new AccessControlException(errorMsg, e);
}
- Object item = null;
+ Item item = null;
try {
- Class[] constructorClasses = { Publication.class, Configuration.class };
- Constructor constructor = Class.forName(klass).getConstructor(constructorClasses);
- Object[] arguments = { publication, config };
- item = constructor.newInstance(arguments);
+ item = (Item) Class.forName(klass).newInstance();
} catch (Exception e) {
String errorMsg =
"Exception when trying to instanciate: "
@@ -133,6 +134,15 @@
log.error(errorMsg);
throw new AccessControlException(errorMsg, e);
}
+ item.setConfigurationDirectory(configurationDirectory);
+ try {
+ item.configure(config);
+ } catch (ConfigurationException e) {
+ String errorMsg =
+ "Exception when trying to configure: "
+ + klass;
+ throw new AccessControlException(errorMsg, e);
+ }
items.add(item);
}
}
@@ -165,13 +175,13 @@
items.remove(item);
}
- /**
- * Get the path where the items are located.
- *
- * @return a <code>File</code>
- */
- public File getPath() {
- return new File(publication.getDirectory(), PATH);
+ /**
+ * Get the directory where the items are located.
+ *
+ * @return a <code>File</code>
+ */
+ public File getConfigurationDirectory() {
+ return configurationDirectory;
}
/**
@@ -181,14 +191,5 @@
*/
protected abstract FileFilter getFileFilter();
- /**
- * Items are attached to a publication. Get the publication
- * to which the items are attached to.
- *
- * @return a <code>Publication</code>
- */
- public Publication getPublication() {
- return publication;
- }
}
1.8 +10 -11 cocoon-lenya/src/java/org/apache/lenya/cms/ac/UserManager.java
Index: UserManager.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/UserManager.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- UserManager.java 24 Jun 2003 16:50:10 -0000 1.7
+++ UserManager.java 25 Jun 2003 14:37:07 -0000 1.8
@@ -55,7 +55,6 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.lenya.cms.publication.Publication;
import org.apache.log4j.Category;
/**
@@ -75,30 +74,30 @@
/**
* Create a UserManager
*
- * @param publication for which the UserManager should be instanciated.
+ * @param configurationDirectory for which the UserManager should be instanciated.
* @throws AccessControlException if the UserManager could not be
* instantiated.
*/
- protected UserManager(Publication publication)
+ protected UserManager(File configurationDirectory)
throws AccessControlException {
- super(publication);
+ super(configurationDirectory);
}
/**
* Describe <code>instance</code> method here.
*
- * @param publication a <code>Publication</code> value
+ * @param configurationDirectory a directory
* @return an <code>UserManager</code> value
* @exception AccessControlException if an error occurs
*/
- public static UserManager instance(Publication publication)
+ public static UserManager instance(File configurationDirectory)
throws AccessControlException {
- assert publication != null;
- if (!instances.containsKey(publication))
- instances.put(publication, new UserManager(publication));
- return (UserManager) instances.get(publication);
+ assert configurationDirectory != null && configurationDirectory.isDirectory();
+ if (!instances.containsKey(configurationDirectory))
+ instances.put(configurationDirectory, new UserManager(configurationDirectory));
+ return (UserManager) instances.get(configurationDirectory);
}
/**
1.3 +58 -56 cocoon-lenya/src/java/org/apache/lenya/cms/ac/RoleManager.java
Index: RoleManager.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/RoleManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RoleManager.java 24 Jun 2003 16:50:10 -0000 1.2
+++ RoleManager.java 25 Jun 2003 14:37:07 -0000 1.3
@@ -55,7 +55,6 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.lenya.cms.publication.Publication;
import org.apache.log4j.Category;
/**
@@ -63,37 +62,73 @@
*
*
*/
-public class RoleManager extends ItemManager {
- private static Category log = Category.getInstance(RoleManager.class);
+public final class RoleManager extends ItemManager {
+ private static Category log = Category.getInstance(RoleManager.class);
protected static final String SUFFIX = ".rml";
private static Map instances = new HashMap();
- /**
- * Create a RoleManager
- *
- * @param publication for which the RoleManager is to be created
- * @throws AccessControlException if the RoleManager could not be instantiated
- */
- protected RoleManager(Publication publication)
- throws AccessControlException {
- super(publication);
- }
-
/**
- * Return the <code>RoleManager</code> for this publication.
+ * Return the <code>RoleManager</code> for this configuration directory.
* The <code>RoleManager</code> is a singleton.
*
- * @param publication the <code>Publication</code> for which the RoleManager is requested.
- * @return a <code>RoleManager</code>
+ * @param configurationDirectory the directory for which the RoleManager is requested.
* @throws AccessControlException if the <code>RoleManager<code> could not be instantiated
*/
- public static RoleManager instance(Publication publication)
- throws AccessControlException {
- if (!instances.containsKey(publication))
- instances.put(publication, new RoleManager(publication));
- return (RoleManager) instances.get(publication);
+ protected RoleManager(File configurationDirectory)
+ throws AccessControlException {
+ super(configurationDirectory);
+ }
+
+ /**
+ * Returns the role manager for this configuration directory.
+ * @param configurationDirectory The configuration directory.
+ * @return A role manager.
+ * @throws AccessControlException when something went wrong.
+ */
+ public static RoleManager instance(File configurationDirectory)
+ throws AccessControlException {
+ if (!instances.containsKey(configurationDirectory))
+ instances.put(configurationDirectory, new RoleManager(configurationDirectory));
+ return (RoleManager) instances.get(configurationDirectory);
+ }
+
+ /**
+ * Get the role for the given roleName
+ *
+ * @param roleName the name of the role requested
+ * @return a <code>Role</code> or null if no role with the given name found
+ */
+ public Role getRole(String roleName) {
+ Role role = null;
+ Iterator iter = getRoles();
+ while (iter.hasNext()) {
+ Role element = (Role) iter.next();
+ if (element.getName().equals(roleName)) {
+ role = element;
+ }
+ }
+ if (role == null) {
+ throw new IllegalArgumentException("Role '" + roleName + "' not found!");
+ }
+ return role;
+ }
+
+
+ /**
+ * Get a file filter for role files
+ *
+ * @return a <code>FileFilter</code>
+ */
+ protected FileFilter getFileFilter() {
+ FileFilter filter = new FileFilter() {
+
+ public boolean accept(File pathname) {
+ return (pathname.getName().endsWith(SUFFIX));
+ }
+ };
+ return filter;
}
/**
@@ -121,39 +156,6 @@
*/
public void remove(Role role) {
super.remove(role);
- }
-
- /**
- * Get the role for the given roleName
- *
- * @param roleName the name of the role requested
- * @return a <code>Role</code> or null if no role with the given name found
- */
- public Role getRole(String roleName) {
- Role role = null;
- Iterator iter = getRoles();
- while (iter.hasNext()) {
- Role element = (Role) iter.next();
- if (element.getName().equals(roleName)) {
- role = element;
- }
- }
- return role;
- }
-
- /**
- * Get a file filter for role files
- *
- * @return a <code>FileFilter</code>
- */
- protected FileFilter getFileFilter() {
- FileFilter filter = new FileFilter() {
-
- public boolean accept(File pathname) {
- return (pathname.getName().endsWith(SUFFIX));
- }
- };
- return filter;
}
}
1.4 +13 -12 cocoon-lenya/src/java/org/apache/lenya/cms/ac/GroupManager.java
Index: GroupManager.java
===================================================================
RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac/GroupManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GroupManager.java 24 Jun 2003 16:50:10 -0000 1.3
+++ GroupManager.java 25 Jun 2003 14:37:07 -0000 1.4
@@ -55,7 +55,6 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.lenya.cms.publication.Publication;
import org.apache.log4j.Category;
/**
@@ -63,37 +62,39 @@
*
*
*/
-public class GroupManager extends ItemManager {
- static private Category log = Category.getInstance(GroupManager.class);
+public final class GroupManager extends ItemManager {
+ private static Category log = Category.getInstance(GroupManager.class);
protected static final String SUFFIX = ".gml";
private static Map instances = new HashMap();
+
/**
* Create a GroupManager
*
- * @param publication for which the GroupManager is to be created
+ * @param configurationDirectory for which the GroupManager is to be created
* @throws AccessControlException if no GroupManager could be instanciated
*/
- protected GroupManager(Publication publication)
+ private GroupManager(File configurationDirectory)
throws AccessControlException {
- super(publication);
+ super(configurationDirectory);
}
/**
* Return the <code>GroupManager</code> for the given publication.
* The <code>GroupManager</code> is a singleton.
*
- * @param publication for which the GroupManager is requested
+ * @param configurationDirectory for which the GroupManager is requested
* @return a <code>GroupManager</code>
* @throws AccessControlException if no GroupManager could be instanciated
*/
- public static GroupManager instance(Publication publication)
+ public static GroupManager instance(File configurationDirectory)
throws AccessControlException {
- if (!instances.containsKey(publication))
- instances.put(publication, new GroupManager(publication));
- return (GroupManager) instances.get(publication);
+ assert configurationDirectory != null;
+ if (!instances.containsKey(configurationDirectory))
+ instances.put(configurationDirectory, new GroupManager(configurationDirectory));
+ return (GroupManager) instances.get(configurationDirectory);
}
/**
1.1 cocoon-lenya/src/java/org/apache/lenya/cms/ac/Item.java
Index: Item.java
===================================================================
/*
* $Id
* <License>
* The Apache Software License
*
* Copyright (c) 2002 lenya. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. All advertising materials mentioning features or use of this software must
* display the following acknowledgment: "This product includes software developed
* by lenya (http://www.lenya.org)"
*
* 4. The name "lenya" must not be used to endorse or promote products derived from
* this software without prior written permission. For written permission, please
* contact contact@lenya.org
*
* 5. Products derived from this software may not be called "lenya" nor may "lenya"
* appear in their names without prior written permission of lenya.
*
* 6. Redistributions of any form whatsoever must retain the following acknowledgment:
* "This product includes software developed by lenya (http://www.lenya.org)"
*
* THIS SOFTWARE IS PROVIDED BY lenya "AS IS" WITHOUT ANY WARRANTY EXPRESS OR IMPLIED,
* INCLUDING THE WARRANTY OF NON-INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTI-
* BILITY AND FITNESS FOR A PARTICULAR PURPOSE. lenya WILL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY YOU AS A RESULT OF USING THIS SOFTWARE. IN NO EVENT WILL lenya BE LIABLE
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR LOST PROFITS EVEN IF lenya HAS
* BEEN ADVISED OF THE POSSIBILITY OF THEIR OCCURRENCE. lenya WILL NOT BE LIABLE FOR ANY
* THIRD PARTY CLAIMS AGAINST YOU.
*
* Lenya includes software developed by the Apache Software Foundation, W3C,
* DOM4J Project, BitfluxEditor and Xopus.
* </License>
*/
package org.apache.lenya.cms.ac;
import java.io.File;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
/**
* An item can be initialized from a configuration.
* @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
*/
public interface Item {
/**
* Sets the configuration directory of this item.
* @param configurationDirectory The configuration directory.
*/
void setConfigurationDirectory(File configurationDirectory);
/**
* Configures this item.
* @param configuration The configuration.
* @throws ConfigurationException when something went wrong.
*/
void configure(Configuration configuration) throws ConfigurationException;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org