Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: stage autowiring without XML (Flex 4.5, SAS 1.2-SNAPSHOT)

  1. #1
    Join Date
    Aug 2010
    Posts
    14

    Default stage autowiring without XML (Flex 4.5, SAS 1.2-SNAPSHOT)

    hello all,

    although it [1], [2] reads like using a FlexXMLApplicationContext and a ClassScannerObjectFactoryPostProcessor with Autowired/Inject annotations is enough to setup stage autowiring I can't get it to work without adding a XML to FlexXMLApplicationContext like below:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <objects xsi:schemaLocation="http://www.springactionscript.org/schema/objects http://www.springactionscript.org/schema/objects/spring-actionscript-objects-1.0.xsd"
             xmlns="http://www.springactionscript.org/schema/objects"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
      <object id="stageAutowirer" class="org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor"/>
    
    </objects>
    Is there a way to use stage autowiring without XML?

    Thanks,
    O.

    [1] "The FlexXMLApplicationContext take care all by itself of creating the necessary objects to facilitate stage wiring." (2.1.2.21)

    [2] "IStageProcessor implementation that is created by default by the FlexXMLApplicationContext to perform autowiring and dependency injection on stage components." in DefaultAutowiringStageProcessor

  2. #2
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default ...

    Hey there,

    this information in the docs is slightly out of date, I'm afraid, my apologies for this.
    Since a while it is requried to add the stage processor explicitly, that way people can choose to completely ignore stage processing.

    You can add the DefaultAutowiringStageProcessor manually like this:

    Code:
    var processor:DefaultAutowiringStageProcessor = new DefaultAutowiringStageProcessor(applicationContext);
    FlexStageProcessorRegistry.getInstance().registerStageProcessor("autowirer", processor, processor.objectSelector);
    Hope that helps,

    cheers,

    Roland

  3. #3
    Join Date
    Aug 2010
    Posts
    14

    Default

    hi Roland,

    it doesn't work for me:
    Code:
    [TIMESTAMP] DEBUG - FlexStageProcessorRegistry - FlexStageProcessorRegistry didn't find appropriate stage processors for document 'application0', retrieving application processors instead
    cheers,
    O.

  4. #4
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default hmmm

    hm, sorry to hear that,

    would it be possible for you to post a small sample application here that demonstrates the problem? I think I'll be able to easily figure out what is going wrong that way.

    Thanks a lot in advance!

    cheers,

    Roland

  5. #5
    Join Date
    Aug 2010
    Posts
    14

    Default

    hey Roland,

    here is the sample application: https://github.com/oliverlietz/sas-samples

    To break the application uncomment lines 58 and 59 in EdisApplication and remove stageAutowirer from context.xml.

    cheers,
    O.
    Last edited by oliverlietz; Aug 14th, 2011 at 10:49 AM.

  6. #6
    Join Date
    Aug 2010
    Posts
    14

    Default

    upgraded to 2.0-SNAPSHOT but still not able to drop the XML. Roland, can you take a look?

    Thanks,
    O.

  7. #7
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default :)

    Hey there,

    I was wondering when you'd make a comment about this Hehe, no, right now v2.0 will also not work with this scenario.
    I'm still thinking of an elegant solution, that's why it isn't supported yet. Here is my problem, if you're using the metadata based configuration
    you add the [Component] metadata to you project classes to have them turned into object definitions.
    But, if you want an object definition for an existing framework class, this is impossible right now.

    So, I was thinking about perhaps implementing some kind of [Configuration] metadata. Imagine you can add object definition like this:

    Code:
    [Configuration]
    public class configClass {
    
      public var autowireProcessor: DefaultAutowireProcessor;
    
      public var eventHandlerProcessor: EventHandlerMetadataProcessor;
    
    }
    This configClass itself will NEVER be instantiated, it is simply used as placeholder to define the metadata. Upon initializing the container will look for classes
    with the [Component] anootation, but also for [Configuration] annotations. If found, it iterates over the the properties of the Class, uses the name
    of the property as the object definition's id and the type of the property as the definition's class.

    One extra problem, something that you guys might be able to help with is how to inject properties and declare method invocations for these classes...

    Please help us out and think with us!

    cheers!

    Roland

  8. #8
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default

    Hey again,

    alright, I think I came to a quite elegant solution, and quite straightforward too I think. To configure properties and method invocations on classes where you do not have access to the source code (so you can't add the metadata directly into the source).
    You could do something like this:

    Code:
    [Configuration]
    public class configClass {
    
      [Property(name="autowireOnce",value="false")]
      [Property(name="objectDefinitionResolver",ref="myObjectDefinitionResolver")]
      [Component(scope="singleton")]
      public var autowireStageProcessor: DefaultAutowiringStageProcessor;
    
      [Component(scope="singleton",lazyInit="true")]
      public var eventHandlerProcessor:EventHandlerMetadataProcessor;
    
      [Invoke(name="myMethod",args="stringValue")]
      [Component(scope="singleton",lazyInit="true",initMethod="initResolver")]
      public var myObjectDefinitionResolver:CustomObjectDefinitionResolver;
    
    }
    What do you think? I think I'll go ahead and implement it this way, unless someone has some clear objections against this?

    cheers,

    Roland
    Last edited by 666shooter; Sep 18th, 2011 at 03:25 PM.

  9. #9
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default beta sample

    Hi again,

    I've put up some sample apps on the beta site for Spring AS 2.0. There is also a sample app that demonstrates the new metadata driven configuration:

    http://beta.springactionscript.org/s...data/Main.html

    It has 'View Source' enabled, so you can check out the how and why in the sources.

    I hope this is to your liking, let me know what you think!

    cheers,

    Roland

  10. #10
    Join Date
    Aug 2010
    Posts
    14

    Default

    Roland,

    thank you. I switched my sample app to annotated configuration class. It works
    However I'm still interested in completely dropping external configuration and solve it with one or two lines of code as described in your first answer.

    For now switching from Halo to Spark and from a custom framework to SAS, the use of a new state machine lib and of course the broken SAS Maven build prevent me from digging deeper into SAS (expect patches coming to JIRA).
    In a best-case scenario, adding spring-actionscript-core (or spring-actionscript-flex) to a pom should be enough. But as you can see I have to do a lot of configuration in my poms to get a working build and swf.

    cheers,
    O.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •