Results 1 to 1 of 1

Thread: Diving a little deeper into the Vector problematic (partial solution)

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

    Default Diving a little deeper into the Vector problematic (solution included)

    UPDATED -- I needed to create a reference resolver as well...

    Hi again,

    I've been playing around with my little Vector problem a bit more and I think I have come to a, probably partial, solution.
    Turns out that this works fine:

    var className:String = "__AS3__.vec.Vector.<String>";
    var cls:Class = getDefinitionByName(className) as Class;
    var result:* = new cls();
    result.push('string1');
    result.push('string2');
    result.push('string3');

    So, given this, its possible to get a configuration like this working:
    Code:
    <object id="test" class="Object" singleton="false">
    	<property name="vectorprop">
    		<vector type="String">
    			<value>string1</value>
    			<value>string2</value>
    			<value>string3</value>
    			<value>string4</value>
    		</vector>
    	</property>
    </object>
    or, if you want to add object instances that are being created by the container:

    Code:
    <object id="test" class="Object" singleton="false">
    	<property name="vectorprop">
    		<vector type="com.myclasses.customtype">
    			<ref>ref1</ref>
    			<ref>ref2</ref>
    		</vector>
    	</property>
    </object>
    
    <object id="ref1" class="com.myclasses.customtype" />
    <object id="ref2" class="com.myclasses.customtype" />
    What I needed to do was create a new NodeParser and add an instance of this to the FlexXMLApplicationContext's parser.

    Too bad the parser in FlexXMLApplicationContext is protected, so I had to subclass it and add my NodeParser in its constructor. For the time being I've named my subclass Flex4XMLApplicationContext, which isn't completely appropriate, but bear with me...

    (Note to Christophe, perhaps the parser member should be made public? I don't know what the implications of this would be, but its just a suggestion...)

    UPDATE
    Alright, so a node parser wasn't enough. I also needed to create a custom referenceresolver to handle the actual creation of the property. The canResolve method seems a bit hacky in my implementation, but I don't know any other way to determine if the property is an arbitrary vector or not. Any suggestions are welcome.
    By the way, the new reference resolver gets added in the Flex4XMLApplicationContext constructor as well.
    UPDATE

    I have attached my nodeparser and referenceresolver classes and the FlexXMLApplicationContext subclass, so anyone who is interested in this can play around with it.
    These are just my preliminary findings, but I'm fairly confident this approach works for most use cases.

    P.S.
    Just for completist's sake, I've also added an enhanced prana-objects-0.7.xsd that adds definitions for the vector element.

    cheers and a happy new year to everyone,

    Roland
    Attached Files Attached Files
    Last edited by 666shooter; Jan 2nd, 2009 at 05:17 PM. Reason: updated the attached code to include my new referenceresolver class

Posting Permissions

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