PaP
Class XMLFileUtil

java.lang.Object
  |
  +--PaP.XMLFileUtil

public class XMLFileUtil
extends java.lang.Object

XMLFileUtil is utility class for reading from or writing to XML-files. The parseXXX methods are methods implemented for parsing files with a specific syntax, same as the writeXXX methods are implemented for writing content to a file with a syntax that the parseXXX methods can understand.

The class can parse the files RoleList.xml, SessionDescriptions.xml or UserProfiles.xml, or other files with equivalent syntax of either one of the three mentionded files. The class can also write content to files with a syntax equivalent of either SessionDescriptions.xml or UserProfiles.xml. One of the methods can parse a line with Name-Value pairs delimited by white space and the '=' character. Finally, the main() method can be used to validate files with a syntax equivalent of either one of the three files listed above.

Version:
1.0 - 01.05.02
Author:
Lars Erik Liljebäck

Field Summary
private  int ACTOR_MODUS
           
private  int APPLICATION_MODUS
           
 boolean debuggingEnabled
           
private  int HEADER_MODUS
           
private  int ROLESESSION_MODUS
           
private  int USER_MODUS
           
 
Constructor Summary
XMLFileUtil()
          Creates a new XMLFileUtil.
 
Method Summary
private  void dbg(java.lang.String dbg)
          Writes a debug string to the console if debugging is enabled.
 java.lang.String hashtable2String(java.util.Hashtable ht)
          Gets the content from the specified Hashtable and creates a string of it.
static void main(java.lang.String[] args)
          Used for debugging purposes as well as for validating a file.
 java.util.Hashtable parseActorStateLine(java.lang.String line)
          Parses the specified string and divides it into tokens according to white space.
 java.util.ArrayList parseRoleList(java.lang.String filename)
          Parses a file containing a list of Roles.
 java.util.ArrayList parseSessionDescriptions(java.lang.String filename)
          Parses a file containing a list of sessiondescriptions.
 java.util.ArrayList parseUserProfiles(java.lang.String filename)
          Parses a file containing a list of userprofiles.
private static void showSyntax()
          Shows the correct syntax to the user.
 void writeSessionsToFile(java.util.ArrayList sessions, java.lang.String filename)
          Writes the content of the specified ArrayList containing Session-objects to the specified file.
 void writeUserProfilesToFile(java.util.ArrayList users, java.lang.String filename)
          Writes the content of the specified ArrayList containing UserProfile-objects to the specified file.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

HEADER_MODUS

private final int HEADER_MODUS

USER_MODUS

private final int USER_MODUS

APPLICATION_MODUS

private final int APPLICATION_MODUS

ACTOR_MODUS

private final int ACTOR_MODUS

ROLESESSION_MODUS

private final int ROLESESSION_MODUS

debuggingEnabled

public boolean debuggingEnabled
Constructor Detail

XMLFileUtil

public XMLFileUtil()
Creates a new XMLFileUtil.
Method Detail

hashtable2String

public java.lang.String hashtable2String(java.util.Hashtable ht)
Gets the content from the specified Hashtable and creates a string of it. The syntax of the string is: = = etc. This method is used in the method writeSessionsToFile() since the state of actorinstances in Session-objects can be in the form of either a string or a Hashtable.
Parameters:
ht - The Hashtable to be converted to a string.
The - string form of the hashtable.

parseActorStateLine

public java.util.Hashtable parseActorStateLine(java.lang.String line)
Parses the specified string and divides it into tokens according to white space. Then each of those tokens is divided into name-value pairs according to the '=' charachter since each token should be on the form [name]=[value]. Each such pair is added to a Hashtable which is returned.
Parameters:
line - The string to be parsed.
Returns:
Hashtable with the name-value pairs from the parsed string.

parseRoleList

public java.util.ArrayList parseRoleList(java.lang.String filename)
                                  throws java.lang.Exception
Parses a file containing a list of Roles. This method is intended to be used by either a UserAgent or a VisitorAgent and the content is shown in either a UserWindow or a VisitorWindow. The user can through them select one of the roles in the list and plugin an actor with the selected role.

As the name implies the list contains a set of roles where each role has five parameters; PlayName, Version, RoleName, PlugInLocation and ForVisitors. RoleName is the name of a role belonging to the specified version of the specified play. PlugInLocation specifies where the actor can be plugged in (on the user's node or on the Director's node). Finally, ForVisitors specifies if a user logged in as a visitor can plugin the role. This field is used so that one do not need one RoleList for a UserAgent and one RoleList for a VisitorAgent.
Parameters:
filename - The name of the file to be parsed.
Returns:
ArrayList with String arrays where each array contains the information listed for each role.
Throws:
java.lang.Exception - if something goes wrong.

parseSessionDescriptions

public java.util.ArrayList parseSessionDescriptions(java.lang.String filename)
                                             throws java.lang.Exception
Parses a file containing a list of sessiondescriptions. This method is inteded to be used by the Director who calls it after he is plugged in to restore his SessionBase. A sessiondescription contains information used to restore an actor's state. This consists of the name of the actor's role, the name of the play the role belongs to and the play's version. Other information saved is the name of the actor, a list of the actor's RoleSessions and the state of the actor. The SessionDescriptions tags and the Session tags marks the start and end of the file, and the start and end of a session, respectively.
Parameters:
filename - The name of the file to be parsed.
Returns:
ArrayList of Session-objects where each Session-object contains the information listed in a user's sessiondescription.
Throws:
java.lang.Exception - if something goes wrong.

parseUserProfiles

public java.util.ArrayList parseUserProfiles(java.lang.String filename)
                                      throws java.lang.Exception
Parses a file containing a list of userprofiles. The file is intended to be used by the Director who calls it after he is plugged in to restore his UserProfileBase. A userprofile contains the username and password of each of the users belonging to the PaP domain that the Director administrates. In addition it contains some properties used by the UserWindow to show User mobility. A UserProfile-object is created for each user listed and the user's usernames, passwords and properties are added to it. The UserProfile-objects are then added to an ArrayList which is returned.
Parameters:
filename - The name of the file to be parsed.
Returns:
An ArrayList with all the UserProfile-objects created.
Throws:
java.lang.Exception - if something goes wrong.

writeSessionsToFile

public void writeSessionsToFile(java.util.ArrayList sessions,
                                java.lang.String filename)
                         throws java.lang.Exception
Writes the content of the specified ArrayList containing Session-objects to the specified file. Each Session-object contains a username and a list of actorinstances. An actorinstance is a set of information about an actor that has been suspended. It is needed in order to be able to resume him in the state he was when he was suspended. The content of each of the objects is retrieved and written consequtively to the file by using an XML oriented syntax. The file can be validated by using the main() method in this class. Write: java PaP.XMLFileUtil -sd to validate the file. The file is then read and the content is written to the console.
Parameters:
sessions - ArrayList with the Session-objects to be saved.
filename - The name of the file to write to.
Throws:
java.lang.Exception - if something goes wrong.

writeUserProfilesToFile

public void writeUserProfilesToFile(java.util.ArrayList users,
                                    java.lang.String filename)
                             throws java.lang.Exception
Writes the content of the specified ArrayList containing UserProfile-objects to the specified file. Each UserProfile-object contains a username, a password and a set of properties used by the UserWindow to show User mobility. The content of each of the objects is retrieved and written consequtively to the file by using an XML oriented syntax. The file can be validated by using the main() method in this class. Write: java PaP.XMLFileUtil -up to validate the file. The file is then read and the content is written to the console.
Parameters:
users - ArrayList with the UserProfile-objects to be saved.
filename - The name of the file to write to.
Throws:
java.lang.Exception - if something goes wrong.

dbg

private void dbg(java.lang.String dbg)
Writes a debug string to the console if debugging is enabled.
Parameters:
dbg - The debug string.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Used for debugging purposes as well as for validating a file. Just write java PaP.XMLFileUtil to get the syntax written to the console.

showSyntax

private static void showSyntax()
Shows the correct syntax to the user.