企業管理 > Windchill 資料載入 > Creating Load Methods > Creating New Methods for Loading
Creating New Methods for Loading
You may need to create a new method or class for a new Windchill loader. Any modifications should be performed in the csvmapfile.dtd, and information about the new loader class and its corresponding method should be registered in the csvmapfile.txt. It is important that you update the csvmapfile.txt so it remains synchronized with the DTD.
* 
The source code for the LoadDoc and LoadPart loaders is available for customization. You can create new methods for loading by editing this source code. Refer to the appropriate section below.
About Load Methods
All the methods that are called by the load framework follow the same signature:
public static boolean myMethod (HashTable nv, HashTable cmd_line, Vector v)
The method returns true if the function is successful, and false if it is not. The parameters are as follows:
nv parameter—A hash table of the attribute names from the map file as the keys and the corresponding strings from one line of the data file as the value.
cmd_line parameter—A hash table of the extra attributes from the command line (parameters that are not defined in the interface). This allows substitution of values from the command line into the data file at runtime.
return_objects parameter—A vector of the objects created or worked upon by the createNewClass method. After the object is manipulated, add it to the vector. For example:
return_objects.addElement(doc);
This vector is used to return more informative messages to the command line. If the object that was manipulated by this method does not implement getIdentity, or if that information would not be useful in a message to the command line, a string should be added to the return_object instead. For example:
String msg = "Type = Content Item, Identity =
" + appData.getFileName();
return_objects.addElement(msg);
Resolving Data
There is a utility that resolves the data from the data file and the data from the command line. For example, to retrieve a value for the new attribute that was added for NewClass, use the following:
String my_attribute = LoadServerHelper.getValue("my_new_attribute",
nv,cmd_line,LoadServerHelper.REQUIRED);
The first parameter is the string from the map file. The last parameter is used to indicate if the field is required, not required, or a blank value is acceptable.
If the field is required or the load should fail, use LoadServerHelper.REQUIRED and check if the return value is null. LoadServerHelper.getValue generates an error message if the value is required and the field value is null or an empty string.
If the field is not required and you want the return set to null for no value or empty strings, use LoadServerHelper.NOT_REQUIRED.
If you want to know the difference between no value being given for a field and an empty string, use LoadServerHelper.BLANK_OKAY. The BLANK_OKAY option returns null if the attribute is not found in the hash table, meaning there could be a format issue with the map and data files. The blank okay option returns the message: “If the attribute is found in the hash table but the value was blank, which, depending on the attribute, could be okay.”
Additional Utilities within a Method
The following are utilities or helper methods for use within a method:
The LoadServerHelper.getTargetContainer() method can be used to get a target container for a load. This is the container specified in the load file set, or, if using LoadFromFile, it is specified using the -CONT_PATH command line option.
If no container was specified, it will display a warning message and try to use the Exchange container.
The LoadServerHelper.getTargetDomain() method can be used to get a target domain for a load. The input file may specify the domain path as follows:
Full path (/System)—It looks in the target container and then in Exchange.
Container qualified path ([/]/System)—If the container is a parent organization for the target container, you can use [/Org] for container path part.
Domain name (System)—For migration purposes, it also supports use of the domain name. If the domain name is a special domain, it will return this domain. Otherwise, it will return the domain with the root parent in the Exchange container.
The LoadServerHelper.changePrincipal(user) method can be used to change the effective user for a set of actions. This can be used only if the user who was authenticated for this session is a member of the administrative group. After processing one line of data, the load utility sets the participant (formerly called a principal) back to the original one if the method it called changed the participant.
The LoadServerHelper.removeCacheValue(MY_KEY) method and LoadServerHelper.setCacheValue(MY_KEY,my_object) method can be used to cache objects between calls to a specific method or calls to different methods. The load utility calls one method per line in the data file. Loading documents and then loading multiple content files into a document is one example of first creating a document, caching it, and returning to the load. The load then reads in the next data line, which is a content line.
The LoadContent method retrieves the cached data as follows:
ContentHolder contentHolder =
(ContentHolder)LoadServerHelper.getCacheValue(CURRENT_CH_KEY);
This method adds the content file to the document. If you are creating an object that can hold content (files and URLs) and you want to load multiple content items on lines following the object in the data file, you must cache the object using the following constant:
private static String CURRENT_CH_KEY = "Current ContentHolder";
If you want to cache an object for another reason, you must create a unique key string. It is recommended that you clear your cached object at the beginning of the next create so that if the create fails, the next operation depending on it fails and does not corrupt other data. The cache of all objects is cleared after the last data line is processed.
* 
The cache does not clear items by itself. If you cache lots of items with different keys and run the method multiple times through a load file, this limits the size of your load file because you can run out of memory.
Creating a Document Class
PTC supports two types of customization of the document class: a type and a subtype.
If you add a subtype or global attributes to WTDocument, the existing load methods do not require any customization. However, if you add a type customization to WTDocument, a new load method is required.
To customize wt.doc.LoadDoc to work with new modeled subclasses of WTDocument, search LoadDoc for the factory method that creates the new instance of the Document.
The statement is as follows:
document = WTDocument.newWTDocument in the constructDocument method
Change this statement to handle the new modeled class. You must also search for the applyHardAttributes method and add the setting of any modeled attributes.
* 
wt.doc.LoadDoc can handle loading out-of-sequence iterations and versions. For information about the beginCreateWTDocument class, see the JavaDoc.
Creating a Part Class
PTC supports two types of customization of the part class: a type and a subtype.
If you add a subtype or global attributes to WTPart, the existing load methods do not require any customization. However, if you add a type customization to WTPart, a new load method is required.
To customize wt.part.LoadPart to work with new modeled subclasses of WTPart, search LoadPart for the factory method that creates the new instance of the part.
The statement is as follows:
part = WTPart.newWTPart in the constructPart method
Change this statement to handle the new modeled class. You must also search for the applyHardAttributes method and add the setting of any modeled attributes.
* 
wt.part.LoadPart can handle loading out-of-sequence iterations and versions. For information about the beginCreateWTPart class, see the JavaDoc.
這是否有幫助?