Section 10: Framework components

In this section, we will look at the various components in the OTC framework.

The OTC framework consists of the below components -

  1. OTC Script Compiler,
  2. Source-code generator,
  3. Token Metadata (TMD) registry,
  4. Indexer, and
  5. Executor.

There are 4 steps in all and all 4 has to be invoked on a DEV-cum-unittest box. However, while promoting to other environments such as the QA or PROD, the framework will automatically execute only the last 2 steps. The 4 steps are -

  1. OTC Script compilation,
  2. Source-code generation and compilation,
  3. TMD registration,
  4. Execution

  1. Step One : Compile OTC Script files
    The first phase is to compile the OTC Script files. The OTC Script compiler has 5 subcomponents which are the typical components in any compiler -
    • The Lexicalizer,
    • The Syntax checker,
    • The Semantics checker
    • The Token metadata (TMD) generator - akin to intermediate code generator
    • The Source Code Generator.

    The TMD files are created in this step and are used during source-code generation and during execution step.

    During source-code generation, there are several subcomponents that kicks in to generate object-conversion source-code. As already mentioned the generated source-code are placed in the folder as explained in next section "OTC Configuration". If you have not configured a location then the default location would be the "${OTC_HOME}/src" folder.

    To compile the OTCS files, do the following –
    OtcsCompiler otcsCompiler = OtcsCompilerImpl.getInstance();
    otcsCompiler.compile(); 

    As already mentioned the OTC-Compiler will look for the "*.otcs" files under "${OTC_HOME}/unittest" folder

  2. Step Two : TMD Registration
    This TMD-Registration step is automatically invoked by the OTC-Executor upon initialization and hence is not required to be explicitly invoked.

    TMD is part of the OTC's internals and so the details of the TMD is not required.

  3. Step Three : The Executor
    In this step, the Executor internally will first try to retrieve the registered TMD set. If it finds them, it will invoke the 'Indexer' subcomponent passing the source object if applicable. The 'Indexer' indexes all the collections if present (i.e. arrays, lists and maps). After the Indexer completes, the Executor finally invokes the compiled executable. This is the only step you will have to invoke every time you want to perform an object-conversion.

    There are 2 methods with different method signatures to invoke the executor.

    If the OTCS file consists of values only, (meaning there is no source object used) and so the parameters would be only 3 as shown below -
    Method signature: 
    	copyFromLiterals(String namespace, Class<T> targetClz, Map<String, Object> data)
    
    Ex:-
    	OtcExecutor otcExecutor = OtcExecutorImpl.getInstance();
    	otcExecutor.copyFromLiterals("com.example", Passenger.class, null); 

    If the OTCS file uses a source-object (copy-values command inclusive) then the format is as given in the below example -
    Method signature:
    	copyFromSource(String namespace, S source-object, Class<T> targetClz, Map<String, Object> data);
    
    Ex:-
    	OtcExecutor otcExecutor = OtcExecutorImpl.getInstance();
    	otcExecutor.copyFromSource(null, employee-object, Passenger.class, data); 

    Please note that 'null' can be passed for the first and the last parameters which are the package-name and the Map parameters.