 | Level: Intermediate Mark Goossen, Software Engineer, IBM
17 Sep 2007 This article shows how to use Java technology to access the
IBM® Rational® RequisitePro® Extensibility Interface. It also
explains how to use the Java™ Native Interface (JNI) libraries that are
installed with RequisitePro.
Note: This article expands upon a previous one titled "An introduction to Rational RequisitePro extensibility."
Tips for using Java in RequisitePro
The libraries that comprise the RequisitePro API are COM libraries. The focus of this article is on one library, ReqPro.dll, which is the most frequently used. One way of accessing this library from Java is to use the RJCB (Rational Java-COM Bridge) technology. The RJCB tool generates Java class proxies and C++ bridge libraries that can access the COM DLL files through the Java™ Native Interface (JNI). You can find more information on the RJCB tool, plus a download that you can use to generate a Java bridge for any COM library, on the Integrate COM and Java components page on IBM® developerWorks®.
Figure 1. Java-COM bridge
It is not necessary to generate your own Java bridge for the extensibility interface, because RequisitePro includes everything that you need to access the API.
Your Java class path needs to contain the RJCB Java runtime and proxies libraries. These are installed with RequisitePro in the following locations:
-
<install location>\Rational\common\RJCB.jar
-
<install location>\Rational\RequisitePro\lib\proxies.jar
The required RJCB runtime and bridge DLL files are also installed and registered with RequisitePro. These do not need to be in your Java class path, but you can find them in these locations:
-
<install location>\Rational\RequisitePro\common\RJCB.dll
-
<install location>\Rational\RequisitePro\bin\ReqProBridge.dll
Note:
Before the 7.0 release, these libraries were only installed with Rational RequisiteWeb.
Documentation
The attached rpxdoc.zip archive file contains the Javadoc tool, which will help determine the appropriate RequisitePro Extensibility Interface methods to use (see Downloads).
You might also need to use traditional methods of accessing COM inline help. This is especially helpful when you are trying to better resolve the arguments of a method. Some information is lost during the generation of Java classes. This includes the conversion of COM enum arguments to Java int variables and the default values for what were optional arguments in COM. To see the original declaration in a COM object browser, use any Microsoft® development tool that can reference a COM library.
Code examples
Open a project
_Application RPX = new Application();
String path =
"C:\\Program Files\\Rational\\RequisitePro\\Projects\\" +
"Project 1\\Project 1.RQS";
String username = "admin";
String password = "";
_Project project = RPX.OpenProject(
path,
enumOpenProjectOptions.eOpenProjOpt_RQSFile,
username,
password,
enumProjectFlags.eProjFlag_Normal,
enumRelatedProjectOptions.eRelatedProjOption_ConnectNone);
|
Create a requirement type and attribute
definitions
_ReqType reqType = project.getReqTypes().Add(
"Product Feature", //name
"FEAT", //prefix
enumReqStyles.eReqStyles_Normal,
enumReqColors.eReqColors_Auto,
1, //initial req number
"", //description
null, //must contain
false); //allow external refs
///create a text attribute
_Attr attr1 = reqType.getAttrs().Add(
"Contact",
0, //displayRank
true, //autoSuspect
enumAttrDataTypes.eAttrDataTypes_Text,
null, //defaultValue
false); //required
//create a list attribute
_Attr attr2 = reqType.getAttrs().Add(
"Priority",
0, //displayRank
true, //autoSuspect
enumAttrDataTypes.eAttrDataTypes_List,
null, //defaultValue
false); //required
_ListItem listItem1 = attr2.getListItems().Add(
0, //rank
"High",
true); //default
_ListItem listItem2 = attr2.getListItems().Add(
1, //rank
"Low",
false); //default
project.Save();
|
Create a package at the root level
_RootPackage rootPack = project.GetRootPackage(false);
com.rational.reqpro.rpx.Package pack = new com.rational.reqpro.rpx.Package(
rootPack.CreatePackage(
"new package",
"",
enumPackageTypes.ePackageType_Empty));
|
Create a requirement in a package
_Requirement newReq = project.CreateRequirement(
"new req",
"the text",
"FEAT",
enumReqTypesLookups.eReqTypesLookups_Prefix,
"", //sVersionLabel
"", //sVersionReason As String
new Integer(0), //vParentReqLookupValue
enumRequirementLookups.eReqLookup_Empty);
newReq.Save();
pack.AddElement(newReq, enumPackageLookups.ePackageLookup_Object,
enumElementTypes.eElemType_Requirement);
|
Get a requirement and update attribute
values
_Requirement existingReq = project.GetRequirement("FEAT1",
enumRequirementLookups.eReqLookup_Tag,
enumRequirementsWeights.eReqWeight_Medium,
enumRequirementFlags.eReqFlag_Empty);
//update a text attribute
_AttrValue attrVal = existingReq.getAttrValue("Contact",
enumAttrValueLookups.eAttrValueLookup_Label);
attrVal.setText(String.valueOf("Bob"));
//update a list attribute
attrVal = existingReq.getAttrValue("Priority",
enumAttrValueLookups.eAttrValueLookup_Label);
_ListItemValue listItemVal = attrVal.getListItemValue("Low",
enumListItemValueLookups.eListItemValueLookup_Text);
listItemVal.setSelected(true);
existingReq.Save();
|
Create a relationship between two
requirements
//by default, changes to relationships will not create a new revision of a requirement
project.setLogRelationshipRevisions(true);
_Requirement req1 = project.CreateRequirement("new req 1",
"", "FEAT",
enumReqTypesLookups.eReqTypesLookups_Prefix, null, null, 0,
enumRequirementLookups.eReqLookup_Empty);
_Requirement req2 = project.CreateRequirement("new req 2", "", "FEAT",
enumReqTypesLookups.eReqTypesLookups_Prefix, null, null,
0, enumRequirementLookups.eReqLookup_Empty);
_Relationship rel = req2.getTracesTo().Add(
req1.getKey(),enumRequirementLookups.eReqLookup_Key,
null, //the requirement is not in an external project
enumRelatedProjectLookups.eRelProjLookup_Empty,
false); //suspect state
req1.Save();
req2.Save();
|
Close a project
project.CloseProject();;
ComObjectProxy obj = (ComObjectProxy) RPX;
obj.release();
RPX= null;
|
Download | Description | Name | Size | Download method |
|---|
| Java archive and Javadoc tool | rpxdoc.zip | 1,649KB | HTTP |
|---|
Resources Learn
- Read
An introduction to Rational RequisitePro extensibility, (developerWorks, November 2007), which explains more about how RequisitePro can easily be extended to help support your project's process. This article demonstrates how to quickly get started with scripts that you can use to customize this requirements management tool..
- The article by the creators of the IBM Java-COM bridge technology, Integrate COM and Java components, (developerWorks, November 2004) describes how this tool simplifies the job and also provides an evolutionary approach to migrating applications from COM to the Java platform. The authors explain its basics and present a sample application that leverages its capabilities. .
- Learn how you can use the included APIs to extend the capabilities of Rational RequisitePro in IBM author Sharoon Kuriyala's article: "Project administration using IBM Rational RequisitePro."
- Visit the
Rational software area on developerWorks
for technical resources and best practices for Rational Software Delivery Platform
products.
- In the
Architecture area on developerWorks,
get the resources you need to advance your skills in the architecture arena.
- Subscribe to the
developerWorks Rational zone newsletter.
Keep up with developerWorks Rational content. Every other week, you'll
receive updates on the latest technical resources and best practices for the
Rational Software Delivery Platform.
- Subscribe to the
Rational Edge newsletter
for articles on the concepts behind effective software development.
- Subscribe to the
IBM developerWorks newsletter,
a weekly update on the best of developerWorks tutorials, articles, downloads,
community activities, webcasts and events.
- Browse the
technology bookstore
for books on these and other technical topics.
Get products and technologies
Discuss
About the author  | |  | Mark Goossen is a software engineer with IBM Rational, with over ten years of application development experience. His focus is on the design and development of requirement definition and management tools. |
Rate this page
|  |