001: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.channels.groupsmanager;
007:
008: import java.util.HashMap;
009: import java.util.Set;
010:
011: /**
012: * A class designed to decouple a request for an action to be performed from the
013: * class responsible for the action. Also centralizes authorization for commands.
014: * @author Don Fracapane
015: * @version $Revision: 34756 $
016: */
017: public class GroupsManagerCommandFactory implements
018: GroupsManagerConstants {
019: protected static HashMap BINDINGS = new java.util.HashMap(16);
020: protected static boolean INITIALIZED = false;
021:
022: /**
023: * Lazily initialize the static variables.
024: * Binds a hasmap name to an instance of a command object
025: */
026: public static void init() {
027: if (INITIALIZED) {
028: return;
029: }
030: try {
031: BINDINGS.put("Add", Class.forName(
032: COMMANDS_PACKAGE + ".AddMembers").newInstance());
033: BINDINGS.put("Permissions", Class.forName(
034: COMMANDS_PACKAGE + ".AssignPermissions")
035: .newInstance());
036: BINDINGS.put("Cancel", Class.forName(
037: COMMANDS_PACKAGE + ".CancelSelection")
038: .newInstance());
039: BINDINGS.put("Collapse", Class.forName(
040: COMMANDS_PACKAGE + ".CollapseGroup").newInstance());
041: BINDINGS.put("Create", Class.forName(
042: COMMANDS_PACKAGE + ".CreateGroup").newInstance());
043: BINDINGS.put("Delete", Class.forName(
044: COMMANDS_PACKAGE + ".DeleteGroup").newInstance());
045: BINDINGS.put("Done", Class.forName(
046: COMMANDS_PACKAGE + ".DoneWithSelection")
047: .newInstance());
048: BINDINGS.put("Lock", Class.forName(
049: COMMANDS_PACKAGE + ".EditGroup").newInstance());
050: BINDINGS.put("Expand", Class.forName(
051: COMMANDS_PACKAGE + ".ExpandGroup").newInstance());
052: BINDINGS.put("Search", Class.forName(
053: COMMANDS_PACKAGE + ".Search").newInstance());
054: BINDINGS
055: .put("Highlight", Class.forName(
056: COMMANDS_PACKAGE + ".HighlightGroup")
057: .newInstance());
058: BINDINGS.put("Remove", Class.forName(
059: COMMANDS_PACKAGE + ".RemoveMember").newInstance());
060: BINDINGS.put("Deselect", Class.forName(
061: COMMANDS_PACKAGE + ".SelectMembers").newInstance());
062: BINDINGS.put("Select", Class.forName(
063: COMMANDS_PACKAGE + ".SelectMembers").newInstance());
064: BINDINGS.put("Unlock", Class.forName(
065: COMMANDS_PACKAGE + ".UnlockGroup").newInstance());
066: BINDINGS.put("Update", Class.forName(
067: COMMANDS_PACKAGE + ".UpdateGroup").newInstance());
068: BINDINGS
069: .put("ShowProperties", Class.forName(
070: COMMANDS_PACKAGE + ".ShowProperties")
071: .newInstance());
072: BINDINGS
073: .put("HideProperties", Class.forName(
074: COMMANDS_PACKAGE + ".HideProperties")
075: .newInstance());
076: } catch (Exception e) {
077: Utility.logMessage("ERROR",
078: "GroupsManagerCommandFactory::init(): \n" + e, e);
079: }
080: INITIALIZED = true;
081: }
082:
083: /**
084: * Returns the instance of a command object bound to a name.
085: * @param name
086: * @return IGroupsManagerCommand
087: */
088: public static IGroupsManagerCommand get(String name) {
089: init();
090: String cmdsString = "";
091: String[] keys = getKeys();
092: for (int i = 0; i < keys.length; i++) {
093: cmdsString = cmdsString + keys[i] + "|";
094: }
095: Utility.logMessage("DEBUG",
096: "GroupsManagerCommandFactory::get(): Command keys = : "
097: + cmdsString);
098: Utility.logMessage("DEBUG",
099: "GroupsManagerCommandFactory::get(): about to get command: "
100: + name);
101: return (IGroupsManagerCommand) BINDINGS.get(name);
102: }
103:
104: /**
105: * Returns the names of the bound command objects. Used for debugging.
106: * @return String[]
107: */
108: public static String[] getKeys() {
109: init();
110: Set keyset = BINDINGS.keySet();
111: return (String[]) keyset.toArray(new String[0]);
112: }
113: }
|