Example: Adding an Attribute to <Part> by Extending the Renderer
The default output for the Part XML element is shown in the figure Default Part XML Element Structure. The Map element in the default response meta information file is shown in the Example: Adding an Attribute to <Part> section of this document.
The new <Part> element now has an additional child element, <Team>.
The modified Map and MapInformation elements of the response meta information file will take the form shown below:
<esi:Map id="ESINewPart">
<esi:attributeMapping sourceAttribute="obid">ObjectID</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="xxxx" defaultValue="com.ptc.windchill.esi.Part">Class</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="modifier">LastChangedBy</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="number">Number</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="xxxx">StartEffectivity</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="xxxx">EndEffectivity</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="xxxx">StartSerialNumberEffectivity</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="xxxx">EndSerialNumberEffectivity</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="xxxx">StartLotNumberEffectivity</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="xxxx">EndLotNumberEffectivity</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="xxxx">SerialNumberEffectivityCxtPartNumber</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="xxxx">LotNumberEffectivityCxtPartNumber</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="defaultUnit">DefaultUnit</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="name">Name</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="partType">PartType</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="source">Source</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="state.state">State</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="view" plantSpecificAttribute="true">View</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="storageLocation" plantSpecificAttribute="true">StorageLocation</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="phantom">IsPhantom</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="versionInfo.identifier.versionId">Version</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="iterationInfo.identifier.iterationId">Iteration</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="PreviousVersion">PreviousVersion</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="genericType">IsConfigurable</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="collapsible">IsCollapsible</esi:attributeMapping>
<esi:attributeMapping sourceAttribute="team">Team</esi:attributeMapping>
</esi:Map>
<esi:MapInformation id="ESIPartInfo">
<esi:typedef>wt.part.WTPart</esi:typedef>
<esi:elementMetaName>Part</esi:elementMetaName>
<esi:keyAttribute>Number</esi:keyAttribute>
<esi:keyAttribute>Version</esi:keyAttribute>
<esi:keyAttribute>PreviousVersion</esi:keyAttribute>
<esi:keyAttribute>View</esi:keyAttribute>
<esi:keyAttribute>StorageLocation</esi:keyAttribute>
<esi:mapRef>ESINewPart</esi:mapRef>
</esi:MapInformation>
The response meta information file with the above described changes is located in <Windchill>/codebase/com/ptc/windchill/esi/examples/ESIResponseMetaInfoExample2.xml.
The Windchill ESI mapper generates the following output if the file ESIResponseMetaInfoExample2.xml were used:
Customized Part XML Element Structure – Example 2
The mapper may not be able to obtain the required data since a WTPart object does not have an attribute called team. As a result, activating the modified version of the response meta information file results in an empty <Team> element in the ESI response. This could be fixed by either extending WTPart to include the team attribute, or by extending Windchill ESI’s ESIWTPartRenderer class to fill in the empty team value. The class Example2MyRenderer shows how to extend the class ESIWTPartRenderer. The source code for the class is located in
<Windchill>/codebase/com/ptc/windchill/esi/examples/Example2MyRenderer.java.
These are the contents of the sample file:
package com.ptc.windchill.esi.examples;
import com.infoengine.object.factory.Att; import com.infoengine.object.factory.Element;
import com.ptc.windchill.esi.esipart.ESIWTPartRenderer; import com.ptc.windchill.esi.rnd.ESIRendererException; import java.util.Collection;
import wt.eff.Eff; import wt.part.WTPart;
public class Example2MyRenderer extends ESIWTPartRenderer {
// This example method will adjust the mapper to return a value for the attribute "Team". If the attribute "Team" is found
// and the value is null or empty, then this method will update the value.
protected Element adjustPartElement( Element elem,
String group, WTPart part, Eff [] effs,
Collection targets )
throws ESIRendererException {
Att att = elem.getAtt("Team"); // get the attribute "Team" from the mapper output
if ( att != null ) // verify that the attribute exists in the mapper
{
// Check to see if the value of "Team" is null or is empty.
if ( att.getValue() == null || att.getValue().toString().trim().equals(""))
{
// Get the value for "Team" from the part object and use it to set
// the value for the "Team" attribute in the mapper output. att.setValue(part.getTeamName());
}
}
return elem;
}
}
Consider the following:
The package statement ensures that the output of the java compiler is written to the correct directory.
The java import statements are required because of the inheritance of the class and the arguments to the adjustElement() method.
The if statement, if ( att != null ) allows the mapper to control the presence of the team attribute. It does so by attempting to obtain the Att object whose name is Team from the mapper output. If there is no attributeMapping entry with the value Team in the relevant Map element of the response meta information file, the result of the attempt to obtain the Att object will be null.
The if statement, if ( att.getValue() == null || att.getValue().toString().trim().equals("")) checks to see if the mapper was able to obtain the desired data. If the data was obtained, nothing is done. This is the recommended way to override the behavior of the mapper.
You can compile and run the example by doing the following:
Launch the Windchill shell from within the <Windchill> directory that was defined when you installed Windchill with this command:
bin/windchill shell
Use the java compiler to compile the class
javac -d ./codebase ./codebase/com/ptc/windchill/esi/examples/*.java
Use the Manage Distribution UI to bring up the Edit Distribution Target (or the New Distribution Target) dialogue, and edit the value of the ESI Response Meta Information File Path field to point to the file ESIResponseMetaInfoExample2.xml. Click OK to save the changes and have the edited (or the newly created) distribution target associated to the part being released.
* 
The above described procedure causes Windchill ESI services to use the example response meta information file when rendering parts. This changes the structure of the ESI response for GetPart, GetBOM, GetECN, GetProcessPlan and GetPromotionRequest. Changing the structure causes the XML schemas in Windchill and the EAI software components to become out of synch. If you make a change to the response meta information file, you must modify the XML schema as described in the Create/Modify XML Schema section of this document. You must also modify the EAI software components to use the new schema. See the XML schemas section of this document for details.
The following XML document serves as an input to the xconfmanager command to activate the new part renderer class:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Configuration SYSTEM "xconf.dtd">
<Configuration targetFile="codebase/service.properties">
<!-- The ESIRenderer entries for use by com.windchill.esi.rnd.ESIRendererFactory -->
<Service context="default" name="com.ptc.windchill.esi.rnd.ESIRenderer">
<Option cardinality="duplicate" requestor="wt.part.WTPart" serviceClass="com.ptc.windchill.esi.examples.Example2MyRenderer"/>
</Service>
</Configuration>
The file is located in
<Windchill>/codebase/com/ptc/windchill/esi/examples/Example2.service.properties.xconf.
The following command propagates the changes specified in the file to the file
<Windchill>/codebase/service.properties:
xconfmanager –i
codebase/com/ptc/windchill/esi/examples/Example2.service.properties.xconf –p
The XML schema definition for the Windchill ESI response that is generated when the customized response meta information file is used is located in
<Windchill>/codebase/com/ptc/windchill/esi/examples/Example2.xsd.
The Windchill ESI response that is generated when the customized response meta information file is used is located in <Windchill>/codebase/com/ptc/windchill/esi/examples/Example2.xml.
* 
Besides extending the VDB builder and any of the ESI renderers, it is possible to extend the ESI response generator and ESI service implementations. See the ESIResponseGenerator and StandardESIService sections for more information.
Was this helpful?