UserList Example
/////////////////////////////////////////////////////////////////////////
//
// User list example. This program lists all of the users in a given
// group.
//
// Command syntax:
// UserListExample system group
//
/////////////////////////////////////////////////////////////////////////
//
// This source is an example of AS/400 Toolbox for Java "UserList".
// IBM grants you a nonexclusive license to use this as an example
// from which you can generate similar function tailored to
// your own specific needs.
//
// This sample code is provided by IBM for illustrative purposes
// only. These examples have not been thoroughly tested under all
// conditions. IBM, therefore, cannot guarantee or imply
// reliability, serviceability, or function of these programs.
//
// All programs contained herein are provided to you "AS IS"
// without any warranties of any kind. The implied warranties of
// merchantablility and fitness for a particular purpose are
// expressly disclaimed.
//
// AS/400 Toolbox for Java
// (C) Copyright IBM Corp. 1997, 1998
// All rights reserved.
// US Government Users Restricted Rights -
// Use, duplication, or disclosure restricted
// by GSA ADP Schedule Contract with IBM Corp.
//
/////////////////////////////////////////////////////////////////////////
import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*;
import java.util.Enumeration;
public class UserListExample
{
public static void main (String[] args)
{
// If a system and group were not specified, then display
// help text and exit.
if (args.length != 2)
{
System.out.println("Usage: UserListExample system group");
return;
}
try
{
// Create an AS400 object. The system name was passed
// as the first command line argument.
AS400 system = new AS400 (args[0]);
// The group name was passed as the second command line
// argument.
String groupName = args[1];
// Create the user list object.
UserList userList = new UserList (system);
// Get a list of the users in the given group.
userList.setUserInfo (UserList.MEMBER);
userList.setGroupInfo (groupName);
Enumeration enum = userList.getUsers ();
// Iterate through the list and print out the
// users' names and descriptions.
while (enum.hasMoreElements ())
{
User u = (User) enum.nextElement ();
System.out.println ("User name: " + u.getName ());
System.out.println ("Description: " + u.getDescription ());
System.out.println ("");
}
}
catch (Exception e)
{
System.out.println ("Error: " + e.getMessage ());
}
System.exit (0);
}
}