method ZIF_DPX_GUINEA_PIG~WATER.
data LT_PARAMS type ABAP_PARMBIND_TAB.
data LS_PARAM type ABAP_PARMBIND.
data LT_EXCPTS type ABAP_EXCPBIND_TAB.
data LS_EXCPT type ABAP_EXCPBIND.
data LV_RC type SYSUBRC.
LS_PARAM-NAME = 'IV_LITRES_PROVIDED'.
LS_PARAM-KIND = CL_ABAP_OBJECTDESCR=>EXPORTING.
get reference of IV_LITRES_PROVIDED into LS_PARAM-VALUE.
insert LS_PARAM into table LT_PARAMS.
if RV_LITRES_CONSUMED is requested.
LS_PARAM-NAME = 'RV_LITRES_CONSUMED'.
LS_PARAM-KIND = CL_ABAP_OBJECTDESCR=>RECEIVING.
get reference of RV_LITRES_CONSUMED into LS_PARAM-VALUE.
insert LS_PARAM into table LT_PARAMS.
endif.
LS_EXCPT-NAME = 'DYSENTERY'.
LS_EXCPT-VALUE = 1.
insert LS_EXCPT into table LT_EXCPTS.
MR_HANDLER->INVOKE(
exporting
IR_PROXY = ME
IV_METHOD_NAME = 'ZIF_DPX_GUINEA_PIG~WATER'
IT_EXCEPTIONS = LT_EXCPTS
importing
EV_RC = LV_RC
changing
CT_PARAMETERS = LT_PARAMS ).
case LV_RC.
when 1.
raise DYSENTERY.
when others.
endcase.
endmethod.
As we have noted previously, the above
coding resembles that needed for making a dynamic method call:
All in all, no great surprises here (I
hope). Now we only have to figure out the XSLT templates to produce the code.
Encouraged by this success, we can now
tackle the last missing piece, i.e. generating the code for methods RAISE_EVENT
and RAISE_STATIC_EVENT of our interface ZIF_DP_PROXY. As before,
we start with an overview of the code we want to produce. However, to keep
things interesting (and to have an example that exhibits all relevant
features), this time we will concern ourselves with a dynamic proxy class that
implements ZIF_DPX_CLOCK as well as ZIF_DPX_GUINEA_PIG. The
pertinent parts of this ill-conceived chimera’s implementation are listed below:
class LCL_PROXY
definition inheriting from ZCL_DP_PROXY_BASE.
public section.
interfaces ZIF_DP_PROXY.
interfaces ZIF_DPX_CLOCK.
interfaces ZIF_DPX_GUINEA_PIG.
interfaces ZIF_DPX_SIMULATED_OBJECT.
private section.
class-methods RAISE_EVENT_1
importing
INCREMENT type ANY.
methods RAISE_EVENT_2.
methods RAISE_EVENT_3.
endclass.
class LCL_PROXY
implementation.
method ZIF_DP_PROXY~RAISE_EVENT.
data LV_METHOD_NAME type ABAP_METHNAME.
case IV_EVENT_NAME.
when 'ZIF_DPX_CLOCK~TICKED'.
LV_METHOD_NAME = 'RAISE_EVENT_1'.
when 'ZIF_DPX_GUINEA_PIG~HUNGRY'.
LV_METHOD_NAME = 'RAISE_EVENT_2'.
when 'ZIF_DPX_GUINEA_PIG~THIRSTY'.
LV_METHOD_NAME = 'RAISE_EVENT_3'.
when others.
raise exception type ZCX_DP_UNDEF_EVNT_EXCEPTION
exporting
NAME = IV_EVENT_NAME.
endcase.
call method ME->(LV_METHOD_NAME)
parameter-table
CT_PARAMETERS.
endmethod.
method ZIF_DP_PROXY~RAISE_STATIC_EVENT.
data LV_METHOD_NAME type ABAP_METHNAME.
case IV_EVENT_NAME.
when 'ZIF_DPX_CLOCK~TICKED'.
LV_METHOD_NAME = 'RAISE_EVENT_1'.
when others.
raise exception type ZCX_DP_UNDEF_EVNT_EXCEPTION
exporting
NAME = IV_EVENT_NAME.
endcase.
call method (LV_METHOD_NAME)
parameter-table
CT_PARAMETERS.
endmethod.
...
method RAISE_EVENT_1.
raise event ZIF_DPX_CLOCK~TICKED
exporting
INCREMENT = INCREMENT.
endmethod.
method RAISE_EVENT_2.
raise event ZIF_DPX_GUINEA_PIG~HUNGRY.
endmethod.
method RAISE_EVENT_3.
raise event ZIF_DPX_GUINEA_PIG~THIRSTY.
endmethod.
endclass.
The methods we provide for triggering the
proxy’s events expect the associated parameters in the by now familiar
parameter table format suitable for a dynamic method call. We take advantage of
this circumstance and raise the events through dedicated private methods (RAISE_EVENT_*)
with a compatible parameter signature which we call dynamically ourselves, thus
leaving the unenviable task of extracting the event’s parameters from the
appropriate entries in CT_PARAMETERS to the ABAP runtime. Apart from
this trick, the rest of the code is rather unremarkable:
Not to squander the rest of your goodwill,
I will not tax your patience again by a piecemeal revelation of the templates
required to generate the above code. Instead, you get the complete XSL
transformation that is used in the current incarnation of the dynamic proxy
framework: