The Source for Java Technology Collaboration
User: Password:



Lorenzo Puccetti

Lorenzo Puccetti's Blog

A Dynamic Language For Bean Factory

Posted by unoinpiu on November 30, 2006 at 12:47 PM | Comments (5)

A Dynamic Language For BeanFactory

A Dynamic Language For BeanFactory.

One of the things I like the most about the Spring-IOC-container is its non-intrusiveness. I can write my classes, test them and then, only when I come to assemble them, use Spring. For this final step, I use the XmlBeanFactory (the most commonly used implementation of the BeanFactory) and write an xml file like this:

<beans>
   <bean id="timerService" class="foo.core.TimerService"/>
   <bean id="locationService" class="foo.core.LocationService" />
   <bean id="currencyExchangeService" class="foo.core.CurrencyExchangeService">
      <property name="currencies">
         <set>
<value>EUR</value>
<value>GBP</value>
<value>USD</value>
         </set>
      </property>
   </bean>
   <bean id="serviceManager" class="foo.core.ServiceManager">
      <property name="services">
         <set>
<ref bean="timerService" />
<ref bean="locationService" />
<ref bean="currencyExchangeService" />
         </set>
      </property>
   </bean>
   <bean id="encoder" class="foo.core.Encoder">
      <property name="mode" value="UTF-8"/>
   </bean>
   <bean id="server" class="foo.core.Server">
       <property name="host" value="localhost" />
       <property name="port" value="9999" />
       <property name="encoder" ref="encoder" />
       <property name="serviceManager" ref="serviceManager" />
   </bean>
</beans>

This file is generally easy to understand and mantain. Besides the Spring-IDE makes my job easier and there are several articles on best practices on how to write a Spring xml file.

Yet, I can't stop wondering about a new BeanFactory which uses one of the many scripting languages for java to make this job simpler (and to an extent more natural). Let me give you an example. If I were to use Rhino (popular javascript engine for java) my configuration file could look like this:

var timerService = new foo.core.TimerService();
var locationService = new foo.core.LocationService();
var currencyExchangeService = new foo.core.CurrencyExchangeService();
{  // curly brackets ensure an unreachable scope for 'set'.
   var set = new HashSet()
   set.add("EUR");
   set.add("GBP")
   set.add("USD")
   currencyExchangeService.add(set)
}
var serviceManager = new foo.core.ServiceManager();
{  // curly brackets ensure an unreachable scope for 'set'.
   var set = new HashSet()
   set.addtimerService );
   set.addlocationService )
   set.addcurrencyExchangeService )
   currencyExchangeService.add(set)
}
var encoder = new foo.core.Encoder();
encoder.setMode(
"UTF-8");
var server = new foo.core.Server()
server.setHost("localhost");
server.setPort(9999);
server.setEncoder(encoder);
server.setServiceManager(serviceManager);

// 'native' objects could be used to indicate the scope of the beans
__scriptFactory.setBeanScope(server,"SINGLETON")


It is your call to think which approach reads better.

Of course, writing this RhinoScriptBeanFactory would present new challenges. For example, we should probably limit the scripting capabilities neither to have conditional statements nor loops but allow just that bit of functionality that encourages the Dependency Injection pattern and nothing more.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • I think if you're going to do this, at least make it more natural, like:

    server.host="localhost";
    server.port=9999

    and so on.

    Unfortunately, javascript doesn't have the concept of a set, as such, but a bit of guessed coercion like this might be nicer:

    currencyExchange.add(["EUR","GBP","USD"]);

    ie. convert the javascript array to a Set.

    Personally, I prefer the XML format though. Stops anyone who has to support it later from wondering what on earth you've done :-)

    Posted by: goron on November 30, 2006 at 01:33 PM

  • Just had a thought.... given that Rhino supports E4X (although IIRC, not the bundled one with Java SE 6), you could mix the two styles up :-)

    Posted by: goron on November 30, 2006 at 01:39 PM

  • Have a look at this blog entry by Rod Johnson: http://blog.interface21.com/main/2006/11/28/a-java-configuration-option-for-spring/. Does exactly what you want in pure Java - which means you can use any standard IDE to great effect instead of inventing yet another syntax.

    Posted by: pcholakov on November 30, 2006 at 08:34 PM

  • Have a look at this blog entry by Rod Johnson: http://blog.interface21.com/main/2006/11/28/a-java-configuration-option-for-spring/. You can use your favourite Java IDE instead of inventing a new syntax.

    Posted by: pcholakov on November 30, 2006 at 08:35 PM

  • Have a look at this blog entry by Rod Johnson: http://blog.interface21.com/main/2006/11/28/a-java-configuration-option-for-spring/. You can use your favourite Java IDE instead of inventing a new syntax.


    acrobat
    ad-aware ad-aware
    adulte
    amateur
    amateur2
    amatrice
    anal
    antivirus
    antivirus-gratuit
    anus
    ares
    asian
    asiatique
    ass
    astuce
    auto
    avatar
    avatars
    baise
    bebe
    beurette
    bikini
    bisexuel
    bite
    black
    blague
    blagues
    blonde
    boob
    brune
    carte
    carte2
    carte3
    cartes
    cartes2
    cartes3
    celebrite
    chaleur
    chanson-gratuit


    chansons-gratuit
    charme
    chat-gratuit
    cheat
    cinema
    clip-gratuit
    clitoris
    clone
    cochon
    code-jeu
    coquin
    couille
    couple
    cul
    cul-gratuit
    diaporama
    diaporamas
    divx
    divx-gratuit
    download
    ecran-de-veille
    ecran-de-veille-gratuit
    ecrans-de-veille
    edonkey
    emoticone
    emoticone-gratuit
    emoticones
    emule
    emule-gratuit
    enculer
    enfant
    erotique
    erotiques
    erotisme
    etudiante
    exhibitionniste
    f1-rallye
    familiale
    famille


    fellation
    femme
    femme2
    fesse
    fetiche
    fetichisme
    film
    film2
    film-gratuit
    film-porno-gratuit
    films
    film-x-gratuit
    firefox
    fond-d-ecran
    fond-d-ecran-gratuit
    fonds-d-ecran
    football
    gay
    gay-gratuit
    girl
    golf
    gratuit
    gratuit2
    gratuit3
    gratuite
    gratuite2
    gratuite3
    gros
    grosse
    gros-sein-gratuit
    hard
    hardcore
    hentai-gratuit
    histoire
    homosexuel
    horoscope
    horoscope-gratuit
    horoscopes
    hot

    humour
    icone
    icq
    illusion
    image
    image2
    image-humour
    jeu
    jeu2
    jeu-adulte-gratuit
    jeu-de-voiture-gratuit
    jeu-enfant-gratuit
    jeu-gratuit
    jeu-gratuit-cadeaux
    jeune
    jeu-pc-gratuit
    jeu-video-gratuit
    jeux
    jeux2
    kazaa
    kazaa-gratuit
    latinas
    lesbian
    lesbienne
    limewire
    lingerie
    logiciel
    logiciel2
    logiciel-gratuit
    logiciels
    logiciels2
    logiciels-gratuit
    manga
    massage
    mature
    messenger
    messenger-gratuit
    models
    morpheus


    movie
    mp3-gratuit
    msn
    msn-gratuit
    mure
    music-gratuite
    musique-gratuite
    musiques-gratuites
    nero
    nero-gratuit
    noire
    nu
    nude
    nudiste
    orgasme
    orgie
    parole-gratuit
    paroles-gratuit
    partition
    partitions
    penis
    photo
    photo2
    photo-gay-gratuit
    photo-porno-gratuit
    photo-sexe-gratuit
    photo-sex-gratuit
    pied
    pipe
    poitrine
    porn
    porn-gratuit
    porno
    porno2
    pornographie
    porno-gratuit
    pps-ppt
    programme
    pussy

    rasee
    real-player
    recette
    recettes
    rousse
    sado
    safari
    salope
    sex
    sex2
    sexe
    sexe2
    sexe-amateur-gratuit
    sexe-gratuit
    sex-gratuit
    sex-gratuit-beurette
    sexuelle
    sexy
    shareaza
    skype
    sms-gratuit
    sodomie
    soluce
    solution-jeu
    spectacle
    sport
    sportive
    spybot
    suce
    suceuse
    sudoku-gratuit
    tarot
    tarot-gratuit
    tatouage
    tatouages
    teen
    tele
    telechargement
    telechargement2

    telechargement-antivirus
    telechargement-chanson
    telechargement-chansons
    telechargement-divx
    telechargement-emule
    telechargement-film
    telechargement-film-gratuit
    telechargement-gratuit
    telechargement-kazaa
    telechargement-logiciel
    telechargement-logiciel-gratuit
    telechargement-logiciels
    telechargement-messenger
    telechargement-movie
    telechargement-mp3
    telechargement-msn
    telechargement-music
    telechargement-musique
    telechargement-nero
    telechargement-parole
    telechargement-paroles
    telechargement-porn
    telechargement-porno
    telechargement-sex
    telechargement-sexe
    telechargement-x
    telechargement-xxx
    telecharger
    telecharger2
    telecharger3
    telecharger-antivirus
    telecharger-antivirus2
    telecharger-chanson
    telecharger-chansons
    telecharger-divx
    telecharger-emule
    telecharger-film
    telecharger-gratuit
    telecharger-jeu-gratuit


    telecharger-kazaa
    telecharger-logiciel
    telecharger-logiciels
    telecharger-messenger
    telecharger-movie
    telecharger-mp3
    telecharger-msn
    telecharger-music
    telecharger-musique
    telecharger-nero
    telecharger-parole
    telecharger-paroles
    telecharger-porn
    telecharger-porno
    telecharger-sex
    telecharger-sexe
    telecharger-x
    telecharger-xxx
    television
    tennis
    tit
    toon
    tourisme
    touristique
    tout-gratuit
    traducteur-gratuit
    transsexuelle
    truc
    tuning
    tv
    vacances
    video

    video2
    video-comique
    video-gratuit
    video-porno
    video-porno2
    video-porno-gratuit
    videos
    videos2
    videos-comiques
    video-sexe-gratuit
    video-sex-gratuit
    video-x-gratuit
    vlc
    voiture
    voyage
    voyager
    voyeur
    wallpaper
    webcam
    winamp
    winmx
    winrar
    winzip
    x
    x2
    x-gratuit
    xxx
    xxx-gratuit
    yoga

    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841

    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149

    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37

    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90

    porno1
    porno2
    porno3
    porno4
    porno5
    porno6
    porno7
    porno8
    porno9
    porno10
    porno11
    porno12
    porno13
    porno14
    porno15
    porno16
    porno17
    porno18
    porno19
    porno20
    porno21
    porno22
    porno23
    porno24
    porno25
    porno26
    porno27
    porno28
    porno29
    porno30

    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62

    1-shareaza
    2-skype
    3-sms-gratuit
    4-sodomie
    5-soluce
    6-spectacle
    7-sport
    8-sportive
    9-sportive
    10-sportive
    11-spybot
    12-suce
    13-suceuse
    14-sudoku-gratuit
    15-tarot-gratuit
    16-tarot
    17-tatouage
    18-tatouages
    19-teen
    20-tele
    21-telechargement-antivirus
    23-telechargement-chansons
    22-telechargement-chanson
    24-telechargement-divx
    25-telechargement-emule
    26-telechargement-film-gratuit
    27-telechargement-film
    28-telechargement-gratuit
    29-telechargement-kazaa
    30-telechargement-logiciel-gratuit
    31-telechargement-logiciel
    32-telechargement-logiciels
    33-telechargement-messenger
    34-telechargement-movie
    36-telechargement-msn
    35-telechargement-mp3
    37-telechargement-music
    38-telechargement-musique
    39-telechargement-nero
    40-telechargement-parole
    41-telechargement-paroles
    42-telechargement-porn
    43-telechargement-porno
    44-telechargement-sex
    45-telechargement-sexe
    46-telechargement-x
    47-telechargement-xxx
    48-telechargement
    49-telechargement
    50-telecharger-antivirus
    51-telecharger-antivirus
    52-telecharger-chanson
    53-telecharger-chansons
    54-telecharger-divx
    55-telecharger-emule
    56-telecharger-film
    57-telecharger-gratuit
    58-telecharger-jeu-gratuit
    59-telecharger-xxx
    60-telecharger-movie
    61-telecharger-sex
    62-telecharger-nero
    63-telecharger-sexe
    64-telecharger-parole
    65-telecharger-paroles
    66-telecharger-porno
    67-telecharger-x
    68-telecharger-messenger
    69-telecharger-music


    1-telecharger
    2-telecharger
    3-telecharger
    4-telecharger-logiciel
    5-telecharger-logiciels
    6-telecharger-mp3
    7-telecharger-msn
    8-telecharger-musique
    9-telecharger-porn
    10-television
    11-tennis
    12-tit
    13-toon
    14-tourisme
    15-touristique
    16-tout-gratuit
    18-transsexuelle
    17-traducteur-gratuit
    19-truc
    20-tuning
    21-tv
    22-vacances
    23-video
    24-video
    25-video-comique
    26-video-gratuit
    27-video-porno
    28-video-porno
    29-video-porno-gratuit
    30-videos
    31-videos-comiques
    32-video-sexe-gratuit
    33-video-sex-gratuit
    34-video-x-gratuit
    35-vlc
    36-voiture
    37-voyage
    38-voyager
    39-voyeur
    40-wallpaper
    41-webcam
    42-winamp
    43-winmx
    44-winrar
    45-winzip
    46-x
    47-x
    48-x-gratuit
    49-xxx
    50-xxx-gratuit
    51-yoga

    Posted by: juanjuanmak on April 01, 2007 at 11:25 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds