Initializing Parsley Framework and Dynamic Short Lived Objects

Parsley framework needs the configuration file for its initalization. This configuration can be written in tradition mxml file or using a xml file. Parsley API provides different configuration builders for initializing the configuration from these files, like FlexContextBuilder and XmlContextBuilder etc. So step to initialize the Parsley are:

  • Create configuration file either in mxml file or in xml file
  • Call appropraiate API by using the above file
    • FlexContextBuilder.build() or
    • XmlContextBuilder.build() etc
  • The build method will always return a context object. 
Generally we need  not to use the context object directly. Parsley itself manage the creation of objects and their relations through injection by using the declared configuration. However in some situations, we may need to interact with the API, like if we are extending the framework for some custom requirement, or for creating the application test environment etc.

Once we build the configuration, the Parsley environment is ready with the context and other configurations mentioned with configuration file. Now suppose if we are preparing a test case and want to fire the events from it so that respective command can be executed based on these events. Here the requirement is to attach the test case object to Parsley context, so that test case object gets the support of event mechanism from Parsley. The way to attach the object with Parsley is to add the object in context. 

Generally for short lived objects, we should use Dynamic Context. Dynamic Context should always be created from default context, so that it can be wired with the other application context. 

dynamicContext as DynamicContext = Context.createDynamicContext();

Now add the test object to this dynamic context. This can be done in setup of the test case. We should consider to remove the object from context after execution of the test methods. Code will be as:

dynamicContext.addObject(testCase);

Now the test case object is linked with Parsley and hence live for Parsley. Now it can participate in all life cycle events and operations of the Parsley like event firing and management. 

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 '=='