Results 1 to 5 of 5

Thread: Spring Container in Flex

  1. #1
    Join Date
    Jan 2006
    Posts
    26

    Default Spring Container in Flex

    Hi ,
    Iam a user of spring framework, indeed a lover of spring framework. Recently i started working on Flex for my front end. I found a open source framework for Flex, Cairngorm quite useful. However being a spring lover, I would like to know is there any spring container in flex? Or any developement going on in that front?

  2. #2
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    What prevents you to integrate Flex and Java (found that with most trivial Google search)? One of the links on that page is Using Flex with Spring.

    Jörg

  3. #3
    Join Date
    Jan 2006
    Posts
    26

    Default

    I think iam not clear in my question.

    The architecture of my project is as below
    Flex UI using Cairngorm --> OpenAMF remoting --> Spring Framework (Java Biz Services).

    What i wanted is a spring-framework in flex for flex. Which replaces cairngorm.

    Spring framework already have their product in .NET and Java. I wanted to ask is there any Spring-Framework for flex in flex.

  4. #4
    Join Date
    Jan 2006
    Posts
    26

    Default

    Can anyone validate this code, This is a very basic code to startwith a spring like framework for flex. If there is anyone out there working on springframework in flex, please highlight. Iam very new to flex and trying to make a framework like spring, which can integrate to flex framework like Cairngorm.


    BeanFactory.as
    ---------------
    package com.fw.core
    {

    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.utils.*;

    import mx.logging.ILogger;
    import mx.logging.Log;
    import flash.system.ApplicationDomain;

    public class BeanFactory
    {
    private var log:ILogger = Log.getLogger( "com.fw.core.BeanFactory" );
    private var appDom:ApplicationDomain = null;
    private var beansXML:XML = new XML();
    private var urlLoader:URLLoader = null;
    private var beansictionary = new Dictionary();
    private var beansPropsToInjectictionary = new Dictionary();

    private const ID:String = "id";
    private const NAME:String = "name";
    private const CLASS:String = "class";
    private const BEANPROPERTIES:String = "beanProperties";


    public function BeanFactory(config:Array,appDom:ApplicationDomain) {
    this.appDom = appDom;
    for(var i:int=0;i<config.length;i++){
    log.info( "@BeanFactory..Parsing.." + String(config[i]) );
    //Currently only one spring bean config file is supported
    parseXML( BeanContext.getInstance().getBeanProperties().getP roperty(BeanProperties.FLEX_APPROOT)
    + String(config[i]) );
    break;
    }
    }

    public function parseXML(xmlUrl:String):void{
    var urlReq:URLRequest = new URLRequest(xmlUrl);
    urlLoader = new URLLoader(urlReq);
    urlLoader.addEventListener(Event.COMPLETE,xmlLoade d);
    }

    public function xmlLoaded(evt:Event):void{
    beansXML = XML(urlLoader.data);
    //log.info("..Parsed XML:" + beansXML );
    initialize();
    }

    public function initialize():void{
    //Add the remote connection as the framework bean
    validateBeanIdsUniqueness();
    validateBeanPropertiesUniqueness();
    createBeans();
    injectDependentBeans();
    debugBeans("finally");
    }

    public function validateBeanIdsUniqueness():void{

    for each (var bean:XML in beansXML.bean){
    var id:String = bean.attribute(ID);

    if( id.length < 3 ) {
    throw new BeanFactoryException(
    BeanFactoryException.ERR_BEANID_INVALID);
    }

    //log.info(id);
    var ids:Array = new Array();

    if( ids.indexOf(id) == -1 ){
    ids.push(id);
    beans[id]=bean;
    }else{
    throw new BeanFactoryException(
    BeanFactoryException.ERR_DUPLICATE_BEANID,id);
    }
    }

    }

    public function validateBeanPropertiesUniqueness():void{

    for each ( var bean:XML in beans){
    var props:Array = new Array();
    for each (var prop:XML in bean.property){
    var propName:String = prop.attribute(NAME);
    log.info( "@validateBeanPropertiesUniqueness: " + bean.attribute(ID) + "." + propName + " DepBean:[" + prop.toString() + "]" );
    if( props.indexOf(propName) == -1 ){
    props.push( [propName,prop.toString()] );
    }else{
    throw new BeanFactoryException(
    BeanFactoryException.ERR_DUPLICATE_PROPERTY
    ,bean.attribute(ID),propName);
    }
    }
    beansPropsToInject[ bean.attribute(ID).toString() ] = props;
    }
    }

    public function createBeans():void{
    for each ( var bean:XML in beans){
    var className:String = bean.attribute(CLASS);
    var beanClass:Class = Class( appDom.getDefinition(className) );
    //var beanClass:Class = Class( getDefinitionByName(className) );
    log.info("@createBeans:" + bean.attribute(ID) + "-->" + getQualifiedClassName( beanClass ) );
    var id:String = bean.attribute(ID);
    beans[id] = new beanClass();
    }
    }

    public function injectDependentBeans():void{

    for ( var beanId:String in beans){
    var obj:Object = beans[beanId];
    var classInfo:XML = describeType(obj);
    var props:Array = beansPropsToInject[beanId];

    for ( var i:int=0;i<props.length;i++){

    var propName:String = props[i][0];
    var depBeanName:String = props[i][1];

    var isProperyMatched:Boolean = false;
    for each (var a:XML in classInfo..accessor) {

    if( a.@name == propName ){
    if ( (a.@access == "writeonly") || (a.@access == "readwrite") ) {
    log.info( "@injectDependentBeans: Injecting Bean " + depBeanName + " to " + beanId + "." + a.@name + " type(" + a.@type +")" );
    var childBean:Object = null;
    if( (depBeanName == BEANPROPERTIES) &&
    ( a.@type == getQualifiedClassName(BeanProperties) ) ){
    log.info( "@@injectDependentBeans: Inject BeanProperties From BeanContext " ) ;
    childBean = BeanContext.getInstance().getBeanProperties();
    }else{
    childBean = getBean(depBeanName);
    }

    beans[beanId][a.@name] = childBean;
    isProperyMatched = true;
    break;
    }//Can the property injected?
    }//Is the property to be injected?

    }//All properties of the bean

    if(!isProperyMatched){
    throw new BeanFactoryException(
    BeanFactoryException.ERR_BEAN_PROPERTY_NOT_FOUND,[beanId,props[i]]);
    }
    }//Properties to be injected

    }
    }

    public function getBean(id:String):Object{
    if( beans[id] == null ){
    throw new BeanFactoryException(BeanFactoryException.ERR_BEAN _NOT_FOUND,id);
    }
    return beans[id];
    }

    private function debugBeans(flag:String=""):void{
    log.info(".........................Bean Container." + flag + "...................");
    for ( var beanId:String in beans){
    log.info(beanId + " = " + beans[beanId] + " = " + getQualifiedClassName(beans[beanId]) );
    }
    log.info("........................End Bean Container.." + flag + "..................");
    }

    }
    }


    -------------------
    Spring dtd
    -------------------
    <!ELEMENT bean ( property* ) >
    <!ATTLIST bean class NMTOKEN #REQUIRED >
    <!ATTLIST bean id NMTOKEN #REQUIRED >

    <!ELEMENT beans ( bean+ ) >

    <!ELEMENT property ( #PCDATA ) >
    <!ATTLIST property name NMTOKEN #REQUIRED >


    -------------------
    Sample xml
    -------------------
    <!DOCTYPE beans SYSTEM "flex-spring-container.dtd">
    <beans>

    <bean id="testCommand" class="com.test.commands.TestCommand" >
    <property name="testBO">testBO</property>
    </bean>

    <bean id="testBO" class="com.test.business.TestBO" >
    <property name="remoteConnection">remoteConnection</property>
    </bean>

    <bean id="remoteConnection" class="com.fw.rmi.RemoteConnection" >
    <property name="beanProperties">beanProperties</property>
    </bean>

    </beans>

  5. #5

    Default Spring ActionScript

    There is a Spring-like container for ActionScript (and thus Flex) called Spring ActionScript. Currently it's in the Spring Extensions incubator, and is described here: http://www.springsource.org/extensio...ctionscript-as

Posting Permissions

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