|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwt.load.GenericFileLoader
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."
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.
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:
Developer
and Demo
classes will be
reparented with this class. This should have no impacts on clients
of these classes.
Installer
class will be reparented, its behavior will
be moved up into this class, and it's static methods will be
deprectated but they will be retained for compatibility with
un-refactored clients of the Installer class.
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", ","); } }
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 |
private String loaderType_
private String mapFileName_
private boolean promptBeforeLoadingFile_
private String userAdminName_
private Hashtable commandLineArgs_
Constructor Detail |
public GenericFileLoader(String loader_type, String[] main_args) throws IOException
loader_type
- a descriptive name for the loader (e.g. Demo, Developer)main_args
- the args from the main method
IOException
- if there is an IOException looking up the default administrator name from the properties filesLoadFromFile
public GenericFileLoader(String loader_type) throws IOException
loader_type
- a descriptive name for the loader (e.g. Demo, Developer)
IOException
- if there is an IOException looking up the default administrator name from the properties filesMethod Detail |
public final void setMapFileName(String map_file_name)
public final void setPromptBeforeLoadingFile(boolean prompt)
private boolean promptBeforeLoadingFile()
private String getMapFileName()
private static String identifyAdministrator() throws IOException
IOException
public static Hashtable argsToHashtable(String[] args)
This method does not cope with flags that aren't followed by an accompanying value. So the string "-a -b foo" is not valid.
public void execute() throws Exception
Exception
#addDirective
protected final void showHeader(String title)
protected final boolean promptForYesNo(String question_fragment) throws WTException
Currently delegates to Installer.promptForYesNo
WTException
Installer.promptForYesNo(java.lang.String)
protected final void load(String question_fragment, String file_name, String delimiter) throws Exception
Exception
protected final void loadRequiredData() throws Exception
Currently delegates to Installer.loadRequired
Exception
Installer.loadRequired(java.util.Hashtable)
protected abstract void loadFiles() throws Exception
Exception
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |