Your SlideShare is downloading. ×
Christophe Spring Actionscript Flex Java Exchange
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Christophe Spring Actionscript Flex Java Exchange

2,006
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,006
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Spring ActionScript
    ChristopheHerreman
  • 2. Agenda
    What is Spring ActionScript
    The IoC container
    Configuration
    MVC Architecture
    Demo
    Q&A
  • 3. What is Spring ActionScript(1/2)
    Inversion of Control (IoC) forActionScript 3.0
    Flash/Flex/AIR/Pure AS3
    IoC container
    Tailoredarchitectures (noprescriptivestructure)
  • 4. What is Spring ActionScript(2/2)
    Started as anin-houselibrary
    Formerlyknown as the Pranaframework
    Incubated as a Spring Extension project
    Upcoming release 1.0 (1.0RC1)
    AS3Commons: Lang, Logging, Reflect, …
  • 5. The IoC Container (1/2)
    = Object Factory
    Creates and assembles objects
    Centralizeddependency management
    Spring AS: configuration via XML or MXML
  • 6. The IoC Container (2/2)
    Object (bean): object managed and/orcreatedby the container
    Object Factory: factorythatcreates and managesobjects
    factory.getObject(“myObject”)
    Object Definition: blueprintforan object
    Application Context: smarter Object Factory
  • 7. Configuration(1/9)
    MXML Configuration
    // AppContext.mxml file, compiledinto the application
    <Objects>
    <app:ApplicationModelid=“appModel” />
    <app:ApplicationControllerid=“appController” applicationModel=“{appModel}”/>
    </Objects>
  • 8. Configuration(2/9)
    MXML Configuration: loading
    var context:MXMLApplicationContext = newMXMLApplicationContext();
    context.addConfig(AppContext);
    context.addEventListener(Event.COMPLETE, context_completeHandler);
    context.load();
    function context_completeHandler(event:Event):void {
    varappModel:ApplicationModel = context.getObject(“appModel”);
    varappController:ApplicationController = context.getObject(“appController”);
    }
  • 9. Configuration(3/9)
    MXML Configuration: alternativeapproach
    // AppContext.mxml file, compiledinto the application
    <Objects>
    <Object id=“appModel” clazz=“{ApplicationModel}”/>
    <Object id=“appController” clazz=“{ApplicationController}”>
    <Property name=“applicationModel” ref=“appModel”/>
    </Object>
    </objects>
  • 10. Configuration(4/9)
    MXML Configuration: pros
    Editor support
    Simple to use
  • 11. Configuration(5/9)
    MXML Configuration: cons
    Compiledinto the application
    Explicitdeclaration: limited to singletons, noexternalreferences, no prototypes -> use Spring AS MXML dialect
  • 12. Configuration(6/9)
    XML Configuration
    // externalcontext.xml, loadedonapplicationstartup
    <objects>
    <object id=“appModel” class=“com.domain.app.ApplicationModel”/>
    <object id=“appController” class=“com.domain.app.ApplicationController”>
    <property name=“applicationModel” ref=“appModel”/>
    </object>
    </objects>
  • 13. Configuration(7/9)
    XML Configuration: loading
    var context:XMLApplicationContext = newXMLApplicationContext();
    context.addConfigLocation(“context.xml”);
    context.addEventListener(Event.COMPLETE, context_completeHandler);
    context.load();
    function context_completeHandler(event:Event):void {
    var appModel:ApplicationModel = context.getObject(“appModel”);
    var appController:ApplicationController = context.getObject(“appController”);
    }
  • 14. Configuration(8/9)
    XML Configuration: pros
    Richer dialect than MXML config
    Usablefornon-Flexprojects
    No need to recompile (in some cases)
    Familiar to Spring Java users
  • 15. Configuration(9/9)
    XML Configuration: cons
    Classes need to becompiledinto the app, noclassloading (!)
    No editor support, only XSD
  • 16. MVC Architecture(1/3)
    No realprescriptivearchitecture
    Do youreallyneedone?
    Rollyourownbecauseone does NOT fit all
    Many MVC architectures out there:
    Cairngorm (2), PureMVC, Mate, …
    … Spring AS wants to support them (seeextensions)
  • 17. MVC Architecture(2/3)
    Spring AS MVC ingredients
    Operation API
    Event Bus
    Autowiring
    Recommendations
    Presentation Model (Fowler)
    LayeredArchitecture (DDD – Evans)
  • 18. MVC Architecture(3/3)
    LayeredArchitecture (DDD – Evans)
  • 19. The Operation API (1/7)
    Asynchronousbehavior in Flash Player: loadingexternal resources, RMI, sqlite, Webservices, HTTPServices, …
    No threading API
    Many different APIs: AsyncToken, Responders, Callbacks, Events… we need a unifiedapproach!
  • 20. The Operation API (2/7)
    Problem: a user repository (or service)
    interface IUserRepository {
    functiongetUser(id:int): ???
    }
    What does the getUsermethod return? AsyncToken (Flex/RemoteObject), User (In memory), void (events)
  • 21. The Operation API (3/7)
    Spring AS solution: return anIOperation
    interface IUserRepository {
    functiongetUser(id:int):IOperation;
    }
    Cannowbeused in anyActionScript 3 context and easilymockedfortesting
  • 22. The Operation API (4/7)
    In Spring AS, an “operation” is used to indicateanasynchronousexecution
    IOperation interface with “complete” and “error” events
    IProgressOperationwith “progress” event
    OperationQueuebundlesoperations (a compositeoperation)
  • 23. The Operation API (5/7)
    Defininganoperation:
    public classGetUserOperationextendsAbstractOperation {
    functionGetUserOperation(remoteObject:RemoteObject, id:String) {
    vartoken:AsyncToken = remoteObject.getUser(id);
    token.addResponder(newResponder(resultHandler, faultHandler));
    }
    private functionresultHandler(event:ResultEvent):void {
    dispatchCompleteEvent(User(event.result));
    }
    private functionfaultHandler(event:FaultEvent):void {
    dispatchErrorEvent(event.fault);
    }
    }
  • 24. The Operation API (6/7)
    Usage:
    varoperation:IOperation = newGetUserOperation(remoteObject, 13);
    operation.addCompleteListener(function(event:OperationEvent):void {
    var user:User = event.result;
    });
    operation.addErrorListener(function(event:OperationEvent):void {
    Alert.show(event.error, “Error”);
    });
  • 25. The Operation API (7/7)
    A progressoperation:
    varoperation:IOperation = newSomeProgressOperation(param1, param2);
    operation.addCompleteListener(function(event:OperationEvent):void {
    });
    operation.addErrorListener(function(event:OperationEvent):void {
    });
    operation.addProgressListener(function(event:OperationEvent):void {
    var op:IProgressOperation = IProgressOperation(event.operation);
    trace(“Progress:” + op.progress + “, total: “ + op.total);
    });
  • 26. The Event Bus (1/4)
    Publish/subscribeevent system
    Usedforglobalapplicationevents
    Promotesloosecoupling
    Works withstandard Flash Events; noneed to subclass Spring AS base classes
  • 27. The Event Bus (2/4)
    Listening/subscribing to events:
    // listen for all events
    EventBus.addListener(listener:IEventBusListener);
    functiononEvent(event:Event):void {
    }
    // listen forspecificevents
    EventBus.addEventListener(“anEvent”, handler);
    functionhandler(event:Event):void {
    }
  • 28. The Event Bus (3/4)
    Dispatching/publishingevents:
    // dispatchstandardevent
    EventBus.dispatchEvent(newEvent(“someEvent”));
    // dispatchcustomevent
    classUserEventextendsEvent {
    ...
    }
    EventBus.dispatchEvent(newUserEvent(UserEvent.DELETE, user));
  • 29. The Event Bus (4/4)
    Routing events:
    <object id="routeEventsProcessor" class="org.springextensions.actionscript.ioc.factory.config.RouteEventsMetaDataPostProcessor"/>
    [RouteEvents]
    Public classMyClass {}
    or…
    [RouteEvents(events=“eventA,eventB”)]
    Public classMyClass {}
  • 30. Autowiring(1/2)
    Auto DependencyInjection via metadata
    Autowireby type, name, constructor, autodetect
    Works forobjectsmanagedby the container and for view components
    Be careful: magic happens, noexplicitconfiguration
  • 31. Autowiring(2/2)
    Annotate a propertywith [Autowired]
    classUserController {
    [Autowired]
    public var userRepository:IUserRepository;
    }
    [Autowired(name=“myObject“, property=“prop”)]
  • 32. The Container (1/5)
    Object references
    <object id=“me” class=“Person”/>
    <object id=“john” class=“Person”>
    <property name=“buddy" ref=“me“ />
    </object>
  • 33. The Container (2/5)
    PropertyPlaceholderConfigurerer
    Loadsexternalproperties
    Properties: (server.properties)
    host=172.16.34.4
    port=8081
    contex-root=myapp
    Config:
    <object class=“org.springextensions.actionscript.ioc.factory.config.PropertyPlaceholderConfigurer”>
    <property name=“location” value=“server.properties”/>
    </object>
    <object id=“userRemoteObject” class=“mx.rpc.remoting.mxml.RemoteObject”>
    <property name="endpoint" value="http://${host}:${port}/${context- root}/messagebroker/amf" />
    </object>
  • 34. The Container (3/5)
    Parentdefinitions / abstract definitions
    <object id="remoteObject" class="mx.rpc.remoting.mxml.RemoteObject" abstract="true">
    <property name="endpoint" value="http://${host}:${port}/${context-root}/messagebroker/amf" />
    <property name="showBusyCursor" value="true" />
    </object>
    <object id=“userRemoteObject" parent="remoteObject">
    <property name="destination" value=“userService" />
    </object>
  • 35. The Container (4/5)
    Object definition scopes
    Singleton (default): sameinstance is returnedoneachrequest
    Prototype: newinstance is returned
    <object id=“mySingleton” class=“MyClass”/>
    <object id=“myPrototype” class=“MyClass” scope=“prototype”/>
    or…
    <object id=“myPrototype” class=“MyClass” singleton=“false”/>
  • 36. The Container (5/5)
    Lazyinitializedobjects
    Singletonsthat are notinstantiatedwhen the container starts
    <object id=“myLazyObject” class=“MyClass”
    lazy-init=“true”/>
  • 37. And there is more…
    Module support
    XML namespaces (rpc, messaging, util, …)
    Task API
    Service base classes
    Container extensionpoints (factory post processors, object post processors, custom metadata handlers, …)
    Workingon: testing support, AOP, …
  • 38. Summary
    Dependency Management
    Loosecoupling, type to interfaces
    Usewithotherframeworks
    Spring mentality: provide choice
    Promote best practices
  • 39. DEMO
    A sample application
  • 40. Thanksforyourattention!
    www.herrodius.com
    info@herrodius.com
    www.springactionscript.org
    www.as3commons.org