410 likes | 532 Views
Index. Introduction to guasax framework: An overview Guasax container architecture Setting up the XML conf file Guasax program skeleton Hello world!, the guasax way Advanced features Versions , Roadmap and resources Summary. Introduction to guasax framework: An overview.
E N D
Index Introduction to guasax framework: An overview Guasax container architecture Setting up the XML conf file Guasax program skeleton Hello world!, the guasax way Advanced features Versions , Roadmap and resources Summary
Introduction to guasax framework: An overview
Introduction to guasax (1/4) Guasax is an ease of use programming framework to provide ordered and scalable Flex applications Life cycle of guasax framework is based in the MVC pattern to take on our program actions Guasax framework helps you to maintain your business logic tier highly decoupled from your presentation logic tier Guasax takes reflection and introspection techniques as well as IoC pattern to execute the operations which we have pointed at and to make a decision about itselves Guasax is not intrusive on your class model.You don’t have to extend your classes in framework classes to use it.
Introduction to guasax (2/4) Guasax is connected with others programming frameworks like Webwork 2.2.4 or Struts 2.0, also it implements some of the features quite similar to Cairngorm 2.1 Guasax is based in a configurable components container (Business Object) in which we declare any method to implement our logic business Inside our code we call to “actions”. An action belongs to a particular component that carries out the execution of an own method.Component is represented as a class called Business Object. Framework configuration feeds on an external XML configuration file.
Introduction to guasax (3/4) Guasax`s aims : Separate our application in presentation, data model, business classes and remote services tiers Standardization of new case use creation flow which resolves the “what I should do and where I should do it” dilemma according to a given way. Real reuse of code at functional component level. Provide the programmer with tools to perfom actions like enable/disable methods, define execution roles, build your own interceptors, redirect from one application view to another one,etc.
Introduction to guasax (4/4) Last introductory tip: Programming with guasax does NOT require to know all design patterns. Actually, one of guasax’s feature is that it has been programmed using the best practices, so that using the framework you are following good design practices too.
Guasax container architecture (1/7) Component container based architecture. A framework component is connected with an ActionScript (AS) class, which implements operations component. Through an external XML configuration file, invokable components and component operations (called actions) are declared During container initialization process, this classes (BO - business objects) are instanciated, acting then as a Singleton class. Internally, guasax mantains a components list and an actions list of each one too.
Guasax container architecture (3/7) • Each component stores actions list and a series of properties.Both of them are loaded from the xml file when we use them at first.Afterwards they are modificable at the container. • Each component has a BO type instance.This is created by reflection through the qualified class name declared in the XML file. • This instance is created only once, not in every action execution, saving instanciation time.
Guasax container architecture (4/7) • All the actions of a component are readed from the configuration file. • Each action is implemented in a BO class method. • So that, we can tell a component has actions • All of the actions from the component list have a reference to the BO component. This way, when an action is executed it can invoke to the object method which belongs. • Actions have a set of attributes which depending on its value will take a value or another
Guasax container architecture (5/7) • Other important guasax part are the services provided to easily invoke actions which we have declared. • Mainly we have: executeAction(actionName:String, params:Array): ResponseActionVO We execute an action passing an array of params which exactly matches with params of the destination method. executeActionWithView(actionName : String, params : Array, viewObjectArray : Array, viewMethodName: String, viewParams:Array): ResponseActionVO Quite similar to last method, but we can pass through an array of view objects and its method/s to invoke. Once the BO action has been executed, guasax will invoke that view method for us.
Guasax container architecture (6/7) • executeActionWithViewAfterService(actionName : String, params : Array, viewObjectArray : Array, viewMethodName: String, viewParams:Array): ResponseActionVO • Also quite similar to last, but if asynchronizly we call a remote service, the container instead of redirecting to a view defers it until we get the service response. • This way, when container redirects to a view to continue the program execution flow, the remote service has already finished. • Therefore we realised when we are programming that on the update method of the view we have got the remote service response.
Guasax container architecture (7/7) • In addition to previous service operations, through the container we are able to perform next operations: • findAction(actionId:String):ActionVO • findComponent(componentId:String):ComponentVO • setEnabledComponent(componentId:String,value:Boolean):void • isEnabledComponent(componentId:String):Boolean • setEnabledAction(actionId:String,value:Boolean):void • isEnabledAction(actionId:String):Boolean • setUserRole(userRole: String):void • getUserRole():String
Setting up the XML conf file(1/3) A guasax program is configured through a XML file. Here is an example:
Setting up the XML conf file (2/3) As we can notice in upper image the configuration file is composed by components and components are composed by actions. Components has a “className” attribute what specifies the class which implements. Action has a “method” attribute which points out the method to invoke when the action is requested. Components and actions can have an “enable” attribute which decides if it can be executed or not.When “enabled” overrides the actions flag. Actions enables you to define which role/s are allowed to execute a concrete action.The role can be assigned to the current user in the container.
Setting up the XML conf file (3/3) Actions also can declare different interceptor types (actions at the same time) Preinterceptor: Action/s we want to be executed BEFORE a given action. Interceptor: A single action to capture all the parameters, modifying them and passing through to a destination action with changed values. Postinterceptors: Action/s we want to be executed AFTER a given action.
Guasax program skeleton (1/4) First of all, we ought to declare a XML object which will point out to our XML application configuration file. For example: <mx:XML id="xmlfile" format="e4x|xml" source="/es/guasax/samples/helloworld/conf/guasax-conf.xml" /> If we are going to use remote services, we will declare a “<services:Services id="services" />” object.This object extends ServiceLocator class and declares the remote services we are going to use. This “services” object must be defined in our main.mxml application file We can use the creationComplete event and bind it to a function (e.g. init()) to load the framework configuration as this: GuasaxContainer.getInstance().parseConfFile(xmlfile);
Guasax program skeleton (2/4) The classes which will implement our business application logic are grouped according to its role The main roles we notice in the framework are: Value Objects Model Bussiness Objects Services Views Also, we can have all our internal classes necessaries to develop our business logic, util classes, etc. Inside “Views” we will group MXML files and support classes which are connected with them, filters, formatting functions, events, etc.
Guasax program skeleton (3/4) Normal life cycle of a guasax action uses to be the next one: Through the guasax container we execute an action, being able to pass a view objects array and a view method to execute. For example: executeActionWithView(actionName ,params, viewObjectArray , viewMethodName,viewParams): ResponseActionVO The container looks forward this action inside its component, and invokes it through a stored BO instance, passing all calling parameters. When BO method invokation finishes up, the container invokes view method passing as parameter the returned value. Also it is allowed to call the view method with no params, picking them from ModelLocator
Guasax program skeleton (4/4) Normal request life cycle diagram with all interacting elements:
Hello world!, the guasax way (step by step)
HolaMundoGuasax step by step(1/5) In this chapter we are going to view all necessary code and the basic directory skeleton to create the minimal program under guasax. First of all we are going to create a Flex project.In the main file we ought to carry on 3 tasks: Declare a XML configuration file. Init the framework through oncreation event Create at least one variable of the class which is going to be instaciated by reflection.This is a necessary task because the compiler MUST include all required information about these classes.Otherwise it will raise an exception.
HolaMundoGuasax step by step (2/5) Here we can see the project skeleton. We have the main application file called GuasaxHelloWorld.mxml. Also we have the HelloWorldBO which has all actions we are going to invoke. In conf directory, we have the Constants.as file in which we declare all constants to identify the name of the actions and the services We also have the guasax-conf.xml in which we declare all components and actions.
HolaMundoGuasax step by step (4/5) In the last screenshot we can see all the GuasaxHelloWorld.mxml file code where we start a guasax action through a button. We can realize in the init method in which we initiate the framework and the XML object in which we declare the xml configuration file
HolaMundoGuasax step by step (5/5) Finally we can see in this picture the HelloWorldBO class acting as a BO sayHello method is invokated by an action with the same name.(Note:It’s not necessary they both have the same name) This is only a demo example limited to show a message. You could invoke remote services and keep the results of them in the Model through ModelLocator
Advance features (1/6) We have talked in last chapters about the possibility of redirecting to a view after an action execution. Now, we are going to explain other features provided by guasax Enabling/Disabling actions and components Configuring role-based access control Building your own interceptors Component actions implemented by other component. Dispatched actions Executing a view object method.(A BO method is NOT neccesary)
Advance features (2/6) It´s posible to enable/disable and action or a component , forbidding its execution. Through setEnabledandisEnabledaccesors you can set/get its value. Using access roles you can declare for each action what roles can execute. When a user is logged into our application we can define his role in the container, then the container can allow or forbid the invokation of an action. Role declaration is optional Through interceptors you can configure differents behaviours for an action execution flow: Preinterceptor: Action/s we want to be executed BEFORE a given action. Interceptor: A single action to capture all the parameters, modifying them and passing through to a destination action with changed values. Postinterceptors: Action/s we want to be executed AFTER a given action.
Advance features (3/6) An example of preinterceptor could be to prepare a data retrieval or to check if we are logged into the system. An example of IN parameters interception could be to get an encrypted string and to desencrypt it. This way you can reuse this code several times. To finish, a postinterceptor example could be to trace a log in certain way. Interceptors advantage is to provide actions with certain behaviours without changing its code
Advance features (4/6) Other framework feature is the possibility to indicate to an action,through the XML configuration file, that the action is going to be executed will be another one Suppose you have a component which usually reads news from a system and when a new one comes an event is called to invoke a concrete guasax action. If we want to reuse this component in other application you can configure it in the XML configuration file, indicating in the action element in which action it will be delegated.
Advance features (5/6) Sometimes is needed to call a view method to perform an UI refresh, a transition, effects, etc. This kind of tasks don´t depends on a BO object or on a model update anyway. In this case, we used to carry out this update from ViewA to ViewB, dealing with scope problems It could be resolved having some kind of “workflowState” variable in our application model, changing its value and binding a ViewStack to it, for example.
Advance features(6/6) If you think it´s not the best way (personally we think that it´s a mistake to keep in your data model a view state value). We will be able to make a call to a view object method through guasax. We can use the ViewLocator class to store and to access in wherever part of our program to view objects.ViewLocator class works as an ordered by name view methods container, similar to a HashMap In this way, we can call guasax : GuasaxContainer.getInstance(). executeViewUpdate(ViewLocator.getInstance().getViewObject(“ID_VIEW”, “updateView”, viewParamsArray); Invoking the object method named as “updateView” retrieved from the ViewLocator
Versiones , roadmap and resources (1/2) Roadmap planned: At this moment guasax is in 0.9 Alpha version because it can be added a lot of new features. Beta 0.9, May 2007 Final Release, versión 1.0, End of June 2007
Versiones , roadmap and resources (2/2) Official web site www.guasax.com Blog http://guasax.wordpress.com Discussion group and mail-list http://groups.google.es/group/guasaxcoders/ SVN source repository and examples codehttp://code.google.com/p/guasax/source Wiki http://code.google.com/p/guasax/w/list Downloads and examples http://code.google.com/p/guasax/downloads
Sumary Guasax is an open source framework which pretends to help flex developers community to carry on good practices during program process design. Guasax purpose is to contribute to develop pretty ordered, robust, easier to maintain and scalable source code. Also, programmers can feel at homebehind the same development premises. The final guasax purpose is to provide a reusable components based development environment avoding to repeat the same code “again and again”, maintaining an ordered code.