Develop code using Java API
You can develop Java™ API-based stand-alone applications or Java API-based extension points or Java API-based web services.
Java API programming pattern
When you are programming through the Java API, you generally follow a programming pattern. The pattern involves obtaining a context, obtaining a manager from the context, obtaining a Java API entity object, and modifying the object and saving it.
- Obtaining a context
- To access IBM® Product Master entities and methods, the
Java code must first obtain a PIMContext. You can obtain a
PIMContext in two ways:
- You can obtain a fresh context by providing the username, password, and company information to
the API:
PIMContextFactory.getContext(user name, password, company name)
. This method is used when you are writing stand-alone Java API applications or unsecured web services. - If the Java API code is running in an already
authenticated context (for example, an extension point implementation class that runs within the Product Master application or a secure web service, where
authentication information was provided when the web service was started), you can obtain the
existing context through the API:
PIMContextFactory.getCurrentContext()
. Using this approach removes the over head of creating extra contexts.
- You can obtain a fresh context by providing the username, password, and company information to
the API:
- Obtaining a manager from the context
- After the context is available, you can retrieve from the context a Java API manager object that corresponds to the entity. For example, a manager
for the catalog can be obtained by using the Java API.
CatalogManager ctgManager = context.getCatalogManager();
- Obtaining a Java API entity object
- After manager for an entity is obtained from the context, you can access the entity itself. For
example, a catalog object can be obtained from the catalog manager by using the Java API.
Catalog catalog = ctgManager.getCatalog("my catalog");
- Modifying the object and saving it
- The entity object that you obtained from the manager class can be modified by using the APIs
that are available within the object itself. After the modifications are done, you save them to the
database with the save() method. For example, a catalog object that is obtained from the catalog
manager can be modified and saved by using the Java
API.
catalog.addSecondaryHierarchy(hierarchy);
catalog.save();
Java API and Rational Software Architect
You can use IDEs like RSA (Rational® Software Architect) to develop your application and resolve Java compilation errors from the application.