📄 commandexecute.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.//// $Id: CommandExecute.java,v 1.19 2000/10/28 16:55:20 daniela Exp $package org.ozoneDB.tools;import org.ozoneDB.DxLib.*;import org.ozoneDB.core.*;import org.ozoneDB.util.*;import java.io.*;/** * This class implements the user dialog of all admin functions. In/output * comes/goes to the specified IODevice which might be terminal or AWT or * other GUI. * * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision: 1.19 $Date: 2000/10/28 16:55:20 $ */public class CommandExecute { IODevice device; AdminMessPort messPort; AdminRemote commPort; public CommandExecute( IODevice dev ) { device = dev; } public void open( String host, int port ) throws IOException { messPort = new AdminMessPort( device, host, port ); commPort = new AdminRemote( host, port ); } public void close() throws IOException { messPort.close(); commPort.close(); } public void message( String mess ) { device.message( mess ); } public boolean invalidCommand( String[] com, int c, String usage ) { if (com.length < c + 1) { message( "\n*** To few arguments! ***" ); message( "usage: " + com[0] + " " + usage + "\n" ); return true; } return false; } public boolean execute( String[] com ) { try { // newgroup if (com[0].equals( "newgroup" ) || com[0].equals( "ng" )) { if (invalidCommand( com, 2, "<groupName> <id>" )) { return true; } commPort.newGroup( com[1], Integer.valueOf( com[2] ) ); message( "Group '" + com[1] + "' added." ); } else if (com[0].equals( "newuser" ) || com[0].equals( "nu" )) { // newuser if (invalidCommand( com, 2, "<user> <id>" )) { return true; } commPort.newUser( com[1], Integer.valueOf( com[2] ) ); message( "User '" + com[1] + "' added." ); } else if (com[0].equals( "usertogroup" ) || com[0].equals( "u2g" )) { // user to group if (invalidCommand( com, 2, "<user> <group>" )) { return true; } commPort.addUserToGroup( com[1], com[2] ); message( "User '" + com[1] + "' added to group '" + com[2] + "'." ); } else if (com[0].equals( "rmuserfromgroup" ) || com[0].equals( "ufg" )) { // remove user from group if (invalidCommand( com, 2, "<user> <group>" )) { return true; } if (device.request( "Really remove user '" + com[1] + "' from group '" + com[2] + "' ? (y/n) " )) { commPort.removeUserFromGroup( com[1], com[2] ); message( "User '" + com[1] + "' removed from group '" + com[2] + "'." ); } } else if (com[0].equals( "showgroups" ) || com[0].equals( "sg" )) { // show all groups DxCollection groups = commPort.allGroups(); if (groups.isEmpty()) { message( "No groups found." ); return true; } message( "" ); for (DxIterator it = groups.iterator(); it.next() != null;) { Group grp = (Group)it.object(); // message ("-----------------------------"); message( "group name: " + grp.name() ); message( " id: " + grp.id() ); message( " user count: " + grp.usersCount() ); DxIterator it2 = grp.userIDs().iterator(); int c = 1; String line = " users: "; while (it2.next() != null) { line = line + ", " + it2.object().toString(); if (c++ % 6 == 0) { line = ""; message( line ); } } message( line ); } } else if (com[0].equals( "showusers" ) || com[0].equals( "su" )) { // show all users DxCollection users = commPort.allUsers(); if (users.isEmpty()) { message( "No users found." ); return true; } message( "" ); for (DxIterator it = users.iterator(); it.next() != null;) { User user = (User)it.object(); // message ("-----------------------------"); message( "user name: " + user.name() ); message( " id: " + user.id() ); // DxIterator it2 = user.groups().iterator(); // int c = 1; // String line = " groups: "; // while (it2.next() != null) { // line = line + ", " + it2.object().toString(); // if ((c++ % 6) == 0) { // line = ""; // message (line); // } // } // message (line); } } else if (com[0].equals( "rmgroup" ) || com[0].equals( "rg" )) { // remove group if (invalidCommand( com, 1, "<group>" )) { return true; } if (device.request( "Really remove group '" + com[1] + "' ? (y/n) " )) { commPort.removeGroup( com[1] ); message( "Group '" + com[1] + "' removed." ); } } else if (com[0].equals( "rmuser" ) || com[0].equals( "ru" )) { // remove user if (invalidCommand( com, 1, "<user>" )) { return true; } if (device.request( "Really remove user '" + com[1] + "' ? (y/n) " )) { commPort.removeUser( com[1] ); message( "User '" + com[1] + "' removed." ); } } else if (com[0].equals( "cssize" ) || com[0].equals( "cs" )) { // cluster (space) size if (invalidCommand( com, 2, "<cluster space size> <cluster size>" )) { return true; } int csSize = Integer.parseInt( com[1] ); int clSize = Integer.parseInt( com[2] ); if (csSize >= clSize) { commPort.setCSSizes( Integer.valueOf( com[1] ), Integer.valueOf( com[2] ) ); } else { message( "ClusterSpace size cannot be smaller than cluster size!" ); } } else if (com[0].equals( "shutdown" ) || com[0].equals( "sd" )) { // shutdown if (device.request( "Really shutdown database ? (y/n) " )) { message( "Shutdown database ..." ); commPort.shutdown(); // FIXME: these methods cause admin tool to hang // close(); return false; } } else if (com[0].equals( "quit" ) || com[0].equals( "q" )) { // quit message( "Closing connection ..." ); commPort.close(); // FIXME: these methods cause admin tool to hang // device.close(); // messPort.close(); return false; } else if (com[0].equals( "help" ) || com[0].equals( "?" )) { // help message( "newgroup, ng - adds a group to the database" ); message( "newuser, nu - adds a user to the database" ); message( "usertogroup, u2g - adds a user to a group" ); message( "rmuserfromgroup, ufg - removes a user from a group" ); message( "rmgroup, rm - removes a group from the database" ); message( "rmuser, ru - removes a user from the database" ); message( "showgroups, sg - shows all groups" ); message( "showusers, su - shows all users" ); // message ("cssize, cs - sets the clusterspace and cluster size"); message( "shutdown, sd - shutdown the database" ); message( "quit, q - quit the AdminTool\n" ); } else { message( "Unknown command '" + com[0] + "'! Try 'help' !" ); } } catch (NumberFormatException e) { message( "Number has wrong format!" ); } catch (Exception e) { message( e.getMessage() ); } return true; } public DxSet commands() { DxSet comms = new DxHashSet(); comms.add( "newgroup" ); comms.add( "newuser" ); comms.add( "usertogroup" ); comms.add( "rmuserfromgroup" ); comms.add( "rmgroup" ); comms.add( "showgroups" ); comms.add( "showusers" ); comms.add( "rmuser" ); comms.add( "cssize" ); comms.add( "shutdown" ); comms.add( "quit" ); comms.add( "help" ); return comms; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -