Importance of Context Object in Parsley

Context is the heart of Parsley Framework which keep every other part/object of the framework alive. So any object, which want to live in Parsley environment, should be linked with its Context. Any object which is not linked to context is not actually live for Parsley, as no body part can live without supply from heart.

Above is the artistic definition. The technical point is that, context is the object where Parsley framework keeps all the information for all linked objects. Context is the single shared object among all the components, and parts of the Parsley. So if any part of parsley needs any object, it can ask the single shared context for the object. Similarly, context is important in initialization and un-initialization of objects and manage their life cycle events as well.

So context is the storage of all the live objects in Parsley framework. Any object can be asked from the context at anytime during execution.

And the object, which is not in context, is not live for Parsley.

Now Parsley features are available to the objects only which are live i.e. if their existence is known to Parsley framework. For example, only those objects can dispatch and consume the events which are live for parsley. Similarly dependency injection will also work till the object is in context. Many a times, developers face the problem like their object is either not dispatching the event or not consuming the event, a major debug point can be to ensure that this object is still in context of Parsley. Objects can be released from Parsley context due to various reasons like

  • Dynamic commands releases from context as soon as these get the result or error from service call.
  • View objects releases from the context as soon as their parent window gets closed

So be careful for the object life cycle and always code to consume all the events before the un-initialization of the objects.

What is XML

XML is a strong and flexible language.

As soon as we read the word ‘language’, most of the persons, new to XML, consider it as some programming language and start wondering what all we can create using XML language.

But Friends, XML is not a programming language but it is a language. Language means a way of communication which can communicate the intended message to the other partners, which can make them understand what we want to say. It is like any other language which used to have a grammar to write and read the messages.

XML works in similar fashion. It does have its own protocol i.e. defined set of rules (grammar) that how one should write and read the messages using XML. 

Tips for E-Mail Communication

Here are a few points which may be helpful for mail communication:

  • Subject of the mail should be chosen wisely. 
    1. It should explain the motive of mail, i.e. receiver should understand from the subject itself that why this mail is here and what would the purpose, and even sometime, what is the expected from her.
    2. It should not be too big
    3. It should not be generic like Hi , until you don’t have any other choice after much thinking.
  • Mail should be started with formal salutation. It put the reader in good mood with the start of the letter. Like
    1. Hi/Hello - If you interact quite often
    2. Dear Mr/Ms - More formal communication
  • Writing a name directly to start the mail is not always recommended i.e.
    1. 'Name'
      1. Please do the work as discussed.

Use of Prepared Statement and Stored Procedure

What is the use of Prepared Statement or Stored Procedure? When should we use simple statement, prepared statement or stored procedure?

To understand the answer for above questions, we first need to understand that how database systems manage and execute the query. When we ask database system to execute any query, there are few steps in execution. Major steps are

  • Parsing of query
  • Compilation
  • Execution
Database system parses the supplied query; hence break it to the tokens to understand what is being supplied. Compilation step process the parsed tokens and create the execution structure which can be database specific. Mostly these are the expressions which evaluate the query tokens during execution. For example:

Flex/Parsley - Use AsyncToken to return asynchronous response from Service

In Flex application, we need to manage the asynchronous responses from the service to the commands. The approach to manage this scenario is:

  • Create a AsyncToken in Service method
  • Return it to the command
  • Retain it with service for the time when we shall get the result
  • As we get the result in result handler of service, use AsyncToken to return the result to command.
  • Get the responders form the AsyncToken responders array and hand over the result or fault to these. 
  • The result or fault will be communicated to the Command result or error handler methods.
Here point is that how AsyncToken will get the responder for command. The process under the hood is that as Service return the AsyncToken to Command, and command return the same object further. Parsley framework will capture the return value, create a Responder with Command's result and fault methods and add it to the AsyncToken. So when we are accessing the first responder from AsyncToken, this is the same responder which Parsley has added automatically.

AsyncToken.responders[0].result(resultObject);

Or

AsyncToken.responders[0].fault(faultObject);

Keep in mind, if you are not returning the AsyncToken from the service and hence from the Command, and if the command is dynamic; Parsley will remove the Command reference from the context as soon as control will return from the execute method. Otherwise it will retain it till it gets the result or fault call on AsyncToken>responder.

Another point is that any object in Parsley is not able to capture the event if it has already been removed from the context. So any object should be alive with Parsley context to be a part of framework and to be managed by Parsley, only then it will be eligible for the events and other facilities. 

Dynamic Commands with Parsley

Parsley provides dynamic commands feature where it creates a new instance of command on triggering of a matching event. Dynamic commands means the command instances which will be created dynamically by Parsley at runtime, whenever it finds any event in the system matching with 'selector' attribute of the command.

So instance of the dynamic command is dependent on the system state. If at anytime, the required event has been fired, the parsley will create the instance of corresponding Command and will handover the event to it. 

Dynamic Commands can be singleton or non-singleton. This behavior can be controlled by setting  'singleton' attribute with configuration file while defining the Dynamic Commands. In case of singleton commands, Parsley retain the instance of Dynamic Command once it is generated and always hand over the event to same instance. However for non-singleton command, Parsley creates a new instance of Command every time it gets a matching event. 

One should use 'selector', 'execute', 'error', 'result', and 'singleton' attributes while defining the dynamic commands with configuration file. Alternative approach is to write these tags in code file on the methods. We found that sometime 'error' tag specified with code file is not working properly, hence we followed the configuration file approach. 

Execute function of the command can return 'void', 'AsyncToken' or a 'Task'. We assume that command is interacting with service for some database interaction or for business logic. 
  • void - If service is not returning anything, return type can be void for command execute method. 
  • AsyncToken - If it is returning a asynchronous response, an AsyncToken should be returned. It will invoke the command result and fault handlers whenever it will get the result. 
  • Task - If we want to execute some task on command result, one can return the Task object which can perform the required task. 

MVCS Design implementation in Flex and/or Parsley - II

This is in continuation of the last blog for MVCS implementation using Flex and Parsley.

We have discussed various design for various layers in MVCS. Another approach is:

  • View are having reference of Presentation Model. Better to inject the PM using Parsley DI, however as per requirement, these can be instantiated using constructor also. 
  • Commands are having reference of Service. Services are injected using DI. 
  • Commands are dynamic and non-singleton in nature, and hence every event will result in creation of a new command. Parsley framework will automatically create a new command for every event, and hand over the event to it.
  • View can interact with commands using events, and can pass the PM to commands by putting it in Event. 
  • As commands are non-singleton and existing one per event, so now commands can retain the instance of PM till these get the response back from asynchronous service request in result handler. In result handler, command can use the retained PM and update the state of the PM and hence of the view.
  • Command can interact with view or Model using events. However Model and View need to put the check for the events to filter out the events targeted for other UI of same type.It can be done by putting a check for the PM, as command are having the instance of PM, so same can be passed to view or model with event to filter the required event. 
This design considers all the features given by Parsley and Flex and provide flexibility in terms of interaction among layers.


New version of Expression Engine Released - 2.3

  1. Support for ternary operator
  2. Support for XML expressions, using Xalan XPath
    1. XML Expressions are returning only String type value. 
    2. We can change it to some specific type like Number, String etc in future depending upon data or we should provide some type casting function
  3. Added more test cases 


For Download: http://xpressionengine.blogspot.com/p/downloads.html

New version of Expression Engine Released - 2.2


New version of 'XpressionEngine' has been released at 





Release notes: 
  • Support for more math functions
  • Bitwise operators
  • Change precendence of operators - http://en.wikipedia.org/wiki/Order_of_operations
  • Change '=' operator with '=='
 

MVCS Design implementation in Flex and/or Parsley

Here are varioius approaches to implement MVCS design using Flex and Parsley. MVCS - Model View Controller and Service. MVCS contains one more layer, called as Service. Service is used to contain business logic. It can be on client side or at server side, depending upon the application architecture. (Refer for MVC definition



Here we are defining MVCS from Flex and Parsley perspective.Following MVCS, there can be various kind of layers and interaction.

Layers and Flow of control
  • View
    • MXML and View Logic
    • Interacts with Presentation Model for data
    • May Interact with Commands for action implementation
  • Presentation Model
    • Contains data state for view, may contains data transfer object from Service
    • May interact directly with services for data related operations
    • Or can have interaction channel with Commands to have update for data 
    • Injected in View as stateless object
  • Commands
    • Contains view logic to act upon various user action from UI
    • Helps to break the UI logic in various objects which acts based on the action
    • Interact with Services for data related operations or Business Logic
    • May update the presentation model for data state
    • Can act as singleton stateless objects and linked with event mechanism 
    • Or view can have their reference as per architecture preference
  • Service
    • Contains business logic and data related operations
    • Can be on server side and may be implemented in various language like PHP or Java etc
    • Can be on client side in case of desktop application, can use assql like MySQL connector to interact with database
    • Service Delegates generally injected in Commands or Presentation Model using DI
Now there are many interaction models between these four layers depending upon overall application architecture or architect preference.