
You can implement your own callable objects with the GP design time API. The interface allows you to define input, output and configuration parameters for the callable object, as well as result states and exceptions.
Callable object types are resolved with the IGPCallableObjectTypeManager . Types are defined by a type name. You can retrieve the type, if you know the type name. For example, type name com.sap.gp.wd corresponds to type Web Dynpro Application.
You need to specify a category for the newly-created callable object. For this purpose, you can create a new category or provide the Id of an existing one.
| Creating a Callable Object of Type Web Dynpro Application |
|---|
importjava.util.Locale; importcom.sap.caf.eu.gp.process.dt.api.IGPDesigntimeUpdateManager; importcom.sap.caf.eu.gp.process.dt.api.IGPDesigntimeManager; importcom.sap.caf.eu.gp.process.api.IGPCategory; importcom.sap.caf.eu.gp.process.api.GPProcessFactory; importcom.sap.caf.eu.gp.co.type.api.IGPCallableObjectTypeManager; importcom.sap.caf.eu.gp.co.type.api.IGPCallableObjectType; importcom.sap.caf.eu.gp.co.api.IGPCallableObject; importcom.sap.caf.eu.gp.exception.api.GPBaseException; Localelocale = Locale.getDefault(); // get user info IUserloggedUser = WDClientUser.getCurrentUser().getSAPUser(); IGPUserContext userContext = GPContextFactory.getContextManager().createUserContext(loggedUser); // instantiate the design time update manager .. // find category "test" in the root category String catName ="test"; IGPCategory cat =null; IGPDesigntimeManagerdtManager = GPProcessFactory.getDesigntimeManager(); IGPCategoryroot = dtManager.getRootCategory(userContext); IGPCategory[]subs = root.getSubCategories(); for(int i = 0; i < subs.length; i++) { if (subs[i].resolveTitle(locale).equals(catName)) {cat = subs[i]; } } StringcoTitle = "Title"; StringcoDescription = "Description"; StringcoType = "com.sap.gp.wd"; try{// resolve the callable object type IGPCallableObjectTypeManagercoTypeManager = GPCallableObjectTypeFactory.getCallableObjectTypeManager(); IGPCallableObjectType wdCoType = coTypeManager.getCallableObjectType(coType); // create the callable object IGPCallableObject co = manager.createCallableObject( wdCoType, locale, coTitle, coDescription, cat.getID() ); }catch (GPBaseException e) {// handle GP exception } |
The following types of multiplicity are supported:
| Singleton | 0_1 (at most one) |
|---|---|
| 1_1 (exactly one) | |
| List |
0_N (any number of occurrences) |
|
1_N (at least one) |
| Populating the Input Parameters Structure |
|---|
importcom.sap.caf.eu.gp.structure.api.IGPStructureInfo; importcom.sap.caf.eu.gp.structure.api.IGPAttributeInfo; importcom.sap.caf.eu.gp.exception.api.GPEngineException; importcom.sap.caf.eu.gp.exception.api.GPInvocationException; try{// obtain copy of the input parameter structure of our object IGPStructureInfo input = co.getInputParameters(); IGPAttributeInfo attr = null; // add attribute of type date, its multiplicity is by default 0_1 attr = input.addAttribute("param_input_date", IGPAttributeInfo.BASE_DATE);// define string attribute and make it required attr = input.addAttribute("param_input_string", IGPAttributeInfo.BASE_STRING);attr.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_1_1); // define a list of doubles attr = input.addAttribute("param_input_double", IGPAttributeInfo.BASE_DOUBLE);attr.setMultiplicity(IGPAttributeInfo.MULITIPLICITY_0_N); //define a substructure IGPStructureInfo subStruct = input.addStructure("sub_structure");// additionally define the substructure... // at the end, save the changes co.setInputParameters(input); } catch (GPEngineException e) {// internal exception occurred when getting or setting the input parameters } catch (GPInvocationException e) {// invalid parameters were passed by defining attribute or sub-structure } |
You may use the same logic to populate the output parameters structure:
// obtain copy of the output parameter structure IGPStructureInfooutput = co.getOutputParameters(); // add substructures and attributes ... // save the changes co.setOutputParameters(output); |
To define result states, exceptions and other configuration parameters, use the IGPPhysicalCallableObject associated with the callable object.
The physical callable object stores technical information about the object that should be invoked during action execution. This includes:
| Defining Result States, Exceptions and Configuration Properties |
|---|
importcom.sap.caf.eu.gp.co.api.IGPPhysicalCallableObject; IGPPhysicalCallableObjectpco = co.resolvePhysicalCallableObject(); try{// set two result states: complete and incomplete pco.addResultState("COMPLETE", "complete"); pco.addResultState("INCOMPLETE", "incomplete");// define an exception pco.addProcessException("EXCEPTION", "exception");// set configuration property pco.setConfigProperty("property", "value");// make the input view of the object visible when the object is created, edited and displayed (for all purposes) pco.setInputViewVisible(true,VIEW_VISIBILITY_PURPOSE_ALL); } catch (GPInvocationException e) {// invalid parameters were passed } |
Once a new callable object has been created, it is locked for editing by other users until it has been saved and released.
| Saving and Releasing a Callable Object |
|---|
IGPCallableObjectco = null; try{// open callable object or create a new one ... // make some changes... ... // save it manager.save(co); }catch (GPBaseException e) {// handle error } finally{if (co != null) manager.release(co); } |
Once you have created a callable object, you can: