Assembler¶
The module contains the assembler to construct loaders and entities based on the configuration and register to a particular locator.
XML Schema¶
Note
This is the master specification document for the configuration.
The schema is defined as followed:
# Base
<imagination>
(ENTITY|FACTORIZATION|CALLABLE)*
</imagination>
##########
# Entity #
##########
ENTITY = <entity id="ENTITY_ID"
class="ENTITY_CLASS"
(tags="...")?
(interceptable="(false|true)")?
>
(CONSTRUCTOR_PARAMETER)*
(INTERCEPTION)*
</entity>
FACTORIZATION = <factorization
id="CREATED_ENTITY_ID"
with="FACTORY_ENTITY_ID"
call="FACTORY_ENTITY_METHOD"
>
(CONSTRUCTOR_PARAMETER)*
</factorization>
CALLABLE = <callable
id="CREATED_ENTITY_ID"
method="IMPORTABLE_PATH_TO_CALLABLE"
static="(true|false)"
>
(CONSTRUCTOR_PARAMETER)*
</callable>
# Initial Parameter
INITIAL_PARAMETER = CONSTRUCTOR_PARAMETER
# Constructor's parameter and initial parameter
CONSTRUCTOR_PARAMETER = <param type="PARAMETER_TYPE" name="PARAMETER_NAME">
(PARAMETER_VALUE|ENTITY_ID|CLASS_IDENTIFIER|ENTRY_ITEM*)
</param>
ENTRY_ITEM = <item( name="DICT_KEY")? type="DATA_TYPE">DATA_VALUE</item>
# See the section "Parameter Types" for PARAMETER_TYPE.
#########
# Event #
#########
EVENT=(before|pre|post|after)
INTERCEPTION = <interception EVENT="REFERENCE_ENTITY_IDENTIFIER"
do="REFERENCE_ENTITY_METHOD"
with="THIS_ENTITY_METHOD"
>
(INITIAL_PARAMETER)*
</interception>
where:
ENTITY_IDis the identifier of the entity.ENTITY_CLASSis the fully-qualified class name of the entity. (e.g.tori.service.rdb.EntityService)CREATED_ENTITY_IDis the factorized entity ID. (Added in Imagination 1.9)FACTORY_ENTITY_IDis the factory entity ID. (Added in Imagination 1.9)FACTORY_ENTITY_METHODis the factory method. (Added in Imagination 1.9)optionis the option of the entity whereENTITY_OPTIONScan have one or more of:factory-mode: always fork the instance of the given class.no-interuption: any methods of the entity cannot be interrupted.
REFERENCE_ENTITY_IDENTIFIERis the reference’s entity identifierREFERENCE_ENTITY_METHODis the reference’s method nameTHIS_ENTITY_METHODis this entity’s method nameEVENTis where theREFERENCE_ENTITY_METHODis intercepted.beforeis an event before the execution of the method of the reference (reference method) regardless to the given arguments to the reference method.preis an event on pre-contact of the reference method and concerning about the arguments given to the reference method. The method of the entity (the intercepting method) takes the same paramenter as the reference method.postis an event on post-contact of the reference method and concerning about the result returned by the reference method. The intercepting method for this event takes only one parameter which is the result from the reference method or any previous post-contact interceptors.afteris an event after the execution of the reference method regardless to the result reterned by the reference method.
Parameter Types¶
| Type Name | Data Type |
|---|---|
| unicode | Unicode (default) |
| bool | Boolean (bool) [1] |
| float | Float (float) |
| int | Integer (int) |
| class | Class reference [2] |
| entity | imagination.entity.Entity [3] |
| set | Python’s Set (set) |
| list | Python’s List (list) |
| tuple | Python’s Tuple (tuple) |
| dict | Python’s Dictionary (dict) |
Footnotes
| [1] | Only any variations (letter case) of the word ‘true’ or ‘false’ are considered as a valid boolean value. |
| [2] | The module and package specified as the value of <param> is loaded
when Assembler.load() is executed. |
| [3] | The encapsulated instance of the entity specified as the value of
<param> is instantiated when Assembler.load()
is executed or when the instance is given with a proxy (imagination.proxy.Proxy). |
Example¶
<?xml version="1.0" encoding="utf-8"?>
<imagination>
<entity id="alpha" class="dummy.lazy_action.Alpha">
<param type="entity" name="accompany">beta</param>
<interception before="charlie" do="cook" with="order">
<param type="unicode" name="item">egg and becon</param>
</interception>
<interception pre="charlie" do="repeat" with="confirm"/>
<interception before="charlie" do="serve" with="speak_to_accompany">
<param type="str" name="context">watch your hand</param>
</interception>
<interception before="charlie" do="serve" with="wash_hands"/>
<interception after="me" do="eat" with="speak">
<param type="str" name="context">merci</param>
</interception>
</entity>
<entity id="beta" class="dummy.lazy_action.Beta"/>
<entity id="charlie" class="dummy.lazy_action.Charlie"/>
</imagination>
API¶
-
class
imagination.helper.data.Interception(event, actor, intercepted_action, handler, handling_action)[source]¶ Event Interception
Parameters: - event (str) – the event type
- actor (str) – the ID of the actor
- intercepted_action (str) – the intercepted method
- handler (str) – the ID of the handler (interceptor)
- handling_action (str) – the handing (intercepting) method
-
class
imagination.helper.data.ParameterPackage(largs=None, kwargs=None)[source]¶ Parameter Package represents the parameter of arguments as a list and a dictionary to any callable objects (e.g., constructor and methods).
Parameters: - largs (list) – a list of arguments
- kwargs (dict) – a dictionary of arguments
-
class
imagination.helper.data.Transformer(locator)[source]¶ Data transformer
Parameters: locator (imagination.locator.Locator) – the entity locator