wt.load
Class GenericFileLoader

java.lang.Object
  extended bywt.load.GenericFileLoader

public abstract class GenericFileLoader
extends Object

A first small step toward refactoring the load classes invoked from the console. The goal is to make them cleaner, remove some of their design idiosyncracies, and reduce the amount of code that each new type of loader needs to contain. This should facilitate easier creation of new loaders with reduced "cut-and-paste reuse."

History

This abstract class was introduced in the R4.0 maintenance branch to include some new files in the first DSU. It currently implements most of its behavior by delegating to the Installer class. It offers the benefit of some smaller method parameter lists be storing these parameters in the class itself.

Future Direction

The remainder of the refactoring will be made in the R5.0 development branch shortly after the first R4.0 DSU. These are the planned actions:

Example Usage

This is an example demonstrates how to re-implement wt.load.Developer via this loader implementation.

 public class Developer
 	extends GenericFileLoader
 {
    public static void main(String[] args)
    {
       int return_code = 0;
       try
       {
          System.out.println("Welcome to Database setup for Developers.");
          System.out.println("You will be presented with a series of prompts.");
          new Developer().execute();
       }
       catch(Throwable t)
       {
          System.err.println("Unexpected error: ");
          t.printStackTrace();
          return_code = -1;
       }
       System.exit(return_code);
    }
  
    private Developer()
       throws IOException
    {
       super("Developer");
    }
  
    protected void loadFiles()
       throws Exception
    {
       if(promptForYesNo("Install Windchill base data"))
          loadRequiredData();

       // include developer data
       showHeader("Windchill developer data. Step 1 of 1");
       load("developers personal file devuser.csv", "devuser.csv", ",");
    }
 }
 

See Also:
wt.load.Demo, wt.load.Developer, Installer

Field Summary
private  Hashtable commandLineArgs_
           
private  String loaderType_
           
private  String mapFileName_
           
private  boolean promptBeforeLoadingFile_
           
private  String userAdminName_
           
 
Constructor Summary
GenericFileLoader(String loader_type)
          Create an instance without any special arguments.
GenericFileLoader(String loader_type, String[] main_args)
          Create an instance using the specified main arguments.
 
Method Summary
static Hashtable argsToHashtable(String[] args)
          Convert command line args to a hashtable containing the flag names as keys and the following value as args.
 void execute()
          Restarts the method server, authenticate as the administrator, then load each file in succession.
private  String getMapFileName()
          Provide threadsafe access to the map file name.
private static String identifyAdministrator()
          Looks up the administrator from wt.properties
protected  void load(String question_fragment, String file_name, String delimiter)
          This method is used as a wrapper for the installService.runFileLoader() method.
protected abstract  void loadFiles()
          Implementations by subclasses should specify the steps in the load process.
protected  void loadRequiredData()
          Load the base required data.
private  boolean promptBeforeLoadingFile()
          Provide thread safe access to the boolean.
protected  boolean promptForYesNo(String question_fragment)
          Prompt for a yes or no response on the supplied string.
 void setMapFileName(String map_file_name)
          Change the map file name for this loader.
 void setPromptBeforeLoadingFile(boolean prompt)
          Specify whether to prompt before loading files or not.
protected  void showHeader(String title)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loaderType_

private String loaderType_

mapFileName_

private String mapFileName_

promptBeforeLoadingFile_

private boolean promptBeforeLoadingFile_

userAdminName_

private String userAdminName_

commandLineArgs_

private Hashtable commandLineArgs_
Constructor Detail

GenericFileLoader

public GenericFileLoader(String loader_type,
                         String[] main_args)
                  throws IOException
Create an instance using the specified main arguments. These arguments will be passed to and interpreted by LoadFromFile.

Parameters:
loader_type - a descriptive name for the loader (e.g. Demo, Developer)
main_args - the args from the main method
Throws:
IOException - if there is an IOException looking up the default administrator name from the properties files
See Also:
LoadFromFile

GenericFileLoader

public GenericFileLoader(String loader_type)
                  throws IOException
Create an instance without any special arguments.

Parameters:
loader_type - a descriptive name for the loader (e.g. Demo, Developer)
Throws:
IOException - if there is an IOException looking up the default administrator name from the properties files
Method Detail

setMapFileName

public final void setMapFileName(String map_file_name)
Change the map file name for this loader.


setPromptBeforeLoadingFile

public final void setPromptBeforeLoadingFile(boolean prompt)
Specify whether to prompt before loading files or not.


promptBeforeLoadingFile

private boolean promptBeforeLoadingFile()
Provide thread safe access to the boolean.


getMapFileName

private String getMapFileName()
Provide threadsafe access to the map file name.


identifyAdministrator

private static String identifyAdministrator()
                                     throws IOException
Looks up the administrator from wt.properties

Throws:
IOException

argsToHashtable

public static Hashtable argsToHashtable(String[] args)
Convert command line args to a hashtable containing the flag names as keys and the following value as args.

Design Notes

This method does not cope with flags that aren't followed by an accompanying value. So the string "-a -b foo" is not valid.


execute

public void execute()
             throws Exception
Restarts the method server, authenticate as the administrator, then load each file in succession. Files are loaded in the order added via addDirective(). When complete the user is prompted whether or not to restart the method server to flush caches.

Throws:
Exception
See Also:
#addDirective

showHeader

protected final void showHeader(String title)

promptForYesNo

protected final boolean promptForYesNo(String question_fragment)
                                throws WTException
Prompt for a yes or no response on the supplied string.

Note

Currently delegates to Installer.promptForYesNo

Throws:
WTException
See Also:
Installer.promptForYesNo(java.lang.String)

load

protected final void load(String question_fragment,
                          String file_name,
                          String delimiter)
                   throws Exception
This method is used as a wrapper for the installService.runFileLoader() method.

Throws:
Exception

loadRequiredData

protected final void loadRequiredData()
                               throws Exception
Load the base required data.

Note

Currently delegates to Installer.loadRequired

Throws:
Exception
See Also:
Installer.loadRequired(java.util.Hashtable)

loadFiles

protected abstract void loadFiles()
                           throws Exception
Implementations by subclasses should specify the steps in the load process. This method will be called after the method server is restarted and after authenticating as admin. After it is complete, the user will be given the option to restarts the servers.

Throws:
Exception