Results 1 to 3 of 3

Thread: Object with interfaces

  1. #1
    Join Date
    Feb 2009
    Posts
    21

    Default Object with interfaces

    Hello,

    Im having a problem loading a as class that implements an interface. this should be straightforward but what im doing wrong here:

    spring-actionscript.xml

    Code:
    <object id="configurl" class="com.buspinoy.utils.config.BPConfiguration">
        	<property name="userUploadUrl" value="helloworld" />
        </object>
    the AS class...

    Code:
    package com.buspinoy.utils.config
    {
    	
    	public class BPConfiguration implements Configuration
    	{
    		private var _userUploadUrl:String;
    		
    		public function BPConfiguration()
    		{
    			
    		}
    
    		public function set userUploadUrl(url:String):void
    		{
    			this._userUploadUrl = url;
    		}
    		
    		public function get userUploadUrl():String
    		{
    			return this._userUploadUrl;
    		}
    	}
    }
    the interface...

    Code:
    package com.buspinoy.utils.config
    {
    	public interface Configuration
    	{
    		function get userUploadUrl():String;
    		
    	}
    }
    here is the trace....

    Error: A class with the name 'com.buspinoy.utils.config.BPConfiguration' could not be found.
    at as3reflect::ClassUtils$/forName()
    at org.springextensions.actionscript.ioc.factory.supp ort:efaultListableObjectFactory/getObjectNamesForType()
    at org.springextensions.actionscript.context.support: :XMLApplicationContext/registerObjectPostProcessors()
    at org.springextensions.actionscript.context.support: :XMLApplicationContext/afterParse()
    at org.springextensions.actionscript.ioc.factory.xml: :XMLObjectFactory/_doParse()

    ...do i need to updagrade something? but when i remove the interface it works properly.

    Thanks a lot.
    Cheers?

  2. #2
    Join Date
    Apr 2008
    Posts
    13

    Default

    Did you add the classes to your code?

    see this http://forum.springsource.org/showthread.php?t=67539

  3. #3

    Default interfaces and ioc

    If you're trying to load applicationContext.xml class instances, for classes that have interfaces, you need to tell the Flex compiler to include the classes. One way to accomplish this is to explicitly cast the object to the class and set it to an interface variable. In the example below, TestService is the interface and TestServiceImpl is the class that implements it.

    Code:
    private var testService:TestService;
    
    private function initializeApplication():void 
    {
      applicationContext = 
        new FlexXMLApplicationContext("applicationContext.xml");
      applicationContext.addEventListener(
        Event.COMPLETE, applicationContextLoaded);
      applicationContext.load();
    }
    			
    private function applicationContextLoaded(event:Event):void 
    {
      testService = TestServiceImpl(applicationContext.getObject("testService"));
    }
    Another option is to create an empty class that contains Frame metadata. I place this class at the base of my source tree (at the same level as applicationContext.xml and main.mxml). This will tell the compiler to include our TestServiceImpl implementation class.

    Code:
    package
    {
      [Frame(extraClass="com.examples.TestServiceImpl")]
      internal final class ApplicationContextClassImports {}
    }
    You need to create a reference to this empty class within main.mxml.

    Code:
    <mx:Script>
      // applicationContext.xml class imports (do not delete)
      private var applicationContextClassImports:ApplicationContextClassImports;
    </mx:Script>
    After that, you should be able to cast the applicationContext object using the interface instead of the implementation class.

    Code:
    // see example code at the top of this post for the rest
    		
    private function applicationContextLoaded(event:Event):void 
    {
      // cast using the interface this time
      testService = TestService(applicationContext.getObject("testService"));
    }

Posting Permissions

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