001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: /* $Id: FileGroupManager.java 485769 2006-12-11 17:41:23Z andreas $ */
020:
021: package org.apache.lenya.ac.file;
022:
023: import java.io.File;
024: import java.util.HashMap;
025: import java.util.Map;
026:
027: import org.apache.avalon.framework.logger.Logger;
028: import org.apache.lenya.ac.AccessControlException;
029: import org.apache.lenya.ac.AccreditableManager;
030: import org.apache.lenya.ac.Group;
031: import org.apache.lenya.ac.GroupManager;
032: import org.apache.lenya.ac.Item;
033:
034: /**
035: * File-based group manager.
036: */
037: public final class FileGroupManager extends FileItemManager implements
038: GroupManager {
039:
040: private static Map instances = new HashMap();
041:
042: /**
043: * Ctor.
044: * @param mgr The accreditable manager.
045: */
046: private FileGroupManager(AccreditableManager mgr) {
047: super (mgr);
048: }
049:
050: /**
051: * Return the <code>GroupManager</code> for the given publication. The
052: * <code>GroupManager</code> is a singleton.
053: * @param mgr The accreditable manager.
054: * @param configurationDirectory for which the GroupManager is requested
055: * @param logger The logger.
056: * @return a <code>GroupManager</code>
057: * @throws AccessControlException if no GroupManager could be instanciated
058: */
059: public static FileGroupManager instance(AccreditableManager mgr,
060: File configurationDirectory, Logger logger)
061: throws AccessControlException {
062: assert configurationDirectory != null;
063:
064: if (!instances.containsKey(configurationDirectory)) {
065: FileGroupManager manager = new FileGroupManager(mgr);
066: manager.enableLogging(logger);
067: manager.configure(configurationDirectory);
068: instances.put(configurationDirectory, manager);
069: }
070:
071: return (FileGroupManager) instances.get(configurationDirectory);
072: }
073:
074: /**
075: * Get all groups
076: *
077: * @return an array of groups.
078: */
079: public Group[] getGroups() {
080: Item[] items = super .getItems();
081: Group[] groups = new Group[items.length];
082: for (int i = 0; i < groups.length; i++) {
083: groups[i] = (Group) items[i];
084: }
085: return groups;
086: }
087:
088: /**
089: * @see org.apache.lenya.ac.GroupManager#add(java.lang.String)
090: */
091: public Group add(String id) throws AccessControlException {
092: Group group = new FileGroup(this , getLogger(), id);
093: super .add(group);
094: return group;
095: }
096:
097: /**
098: * Remove a group from this manager
099: *
100: * @param group the group to be removed
101: * @throws AccessControlException when the notification failed.
102: */
103: public void remove(Group group) throws AccessControlException {
104: super .remove(group);
105: }
106:
107: /**
108: * Get the group with the given group name.
109: *
110: * @param groupId the id of the requested group
111: * @return a <code>Group</code> or null if there is no group with the
112: * given name
113: */
114: public Group getGroup(String groupId) {
115: return (Group) getItem(groupId);
116: }
117:
118: protected static final String SUFFIX = ".gml";
119:
120: /**
121: * @see org.apache.lenya.ac.file.FileItemManager#getSuffix()
122: */
123: protected String getSuffix() {
124: return SUFFIX;
125: }
126:
127: }
|