SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
Web Beans, the RI of JSR-299

          Pete Muir
 JBoss, a division of Red Hat
Road Map



Background
Concepts
Status




               2
Java EE 6

• The EE 6 web profile removes most of the “cruft” that
  has developed over the years
  -   mainly the totally useless stuff like web services, EJB 2 entity beans,
      etc
  -   some useful stuff like JMS is also missing, but vendors can include it
      if they like
• EJB 3.1 - a whole bunch of cool new functionality!
• JPA 2.0 - typesafe criteria query API, many more O/R
  mapping options
• JSF 2.0 - don’t need to say much more!
• Bean Validation 1.0 - annotation-based validation API
• Servlet 3.0 - async support, better support for
  frameworks
• Standard global JNDI names
• Contexts and Dependency Injection for Java EE
                                                                                3
Goals

• JSR-299 defines a unifying dependency injection
  and contextual lifecycle model for Java EE 6
  -   a completely new, richer dependency management
      model
  -   designed for use with stateful objects
  -   integrates the “web” and “transactional” tiers
  -   makes it much easier to build applications using JSF
      and EJB together
  -   includes a complete SPI allowing third-party
      frameworks to integrate cleanly in the EE 6
      environment




                                                             4
What can be injected?


• Pre-defined by the specification:
  -   (Almost) any Java class
  -   EJB session beans
  -   Objects returned by producer methods
  -   Java EE resources (Datasources, JMS topics/
      queues, etc)
  -   Persistence contexts (JPA EntityManager)
  -   Web service references
  -   Remote EJBs references
• Plus anything else you can think of!
  -   An SPI allows third-party frameworks to introduce
      new kinds of things

                                                          5
Loose coupling

• Events, interceptors and decorators enhance the
  loose-coupling that is inherent in this model:
  -   event notifications decouple event producers from
      event consumers
  -   interceptors decouple technical concerns from business
      logic
  -   decorators allow business concerns to be
      compartmentalized




                                                           6
Going beyond the spec

• Web Beans provides extra integrations
  -   Tomcat/Jetty support
  -   Wicket support
  -   ???
• and features which can be used in any JSR-299
  environment
  -   jBPM integration
  -   log injection (choose between log4j and jlr, parameter
      interpolation
  -   Seam2 bridge
  -   Spring bridge



                                                               7
Seam 3?

• Use the JSR-299 core
• Provide a development environment
  -   JBoss Tools
  -   Seam-gen (command line tool)
• include a set of modules for any container which
  includes JSR-299
  -   Seam Security
  -   Reporting (Excel/PDF)
  -   Mail
  -   etc.




                                                     8
Road Map



Background
Concepts
Status




               9
Essential ingrediants

•   API types
•   Binding annotations
•   Scope
•   Deployment type
•   A name (optional)
•   Interceptor bindings
•   The implementation




                                    10
Simple Example



public class Hello {                    Any Java Bean can use
   public String hello(String name) {   these services
      return quot;helloquot; + name;
   }
}
                                         So can EJBs
@Stateless
public class Hello {
   public String hello(String name) {
      return quot;helloquot; + name;
   }



                                                                11
Simple Example



public class Printer {                  @Current is the default
                                        (built in) binding type
    @Current Hello hello;

    public void hello() {
       System.out.println( hello.hello(quot;worldquot;) );
    }
}




                                                                  12
Constructor injection



public class Printer {
                                          Mark the constructor to be called by
   private Hello hello;                   the container @Initializer

    @Initializer
    public Printer(Hello hello) { this.hello=hello; }

    public void hello() {
       System.out.println( hello.hello(quot;worldquot;) );
    }                              Constructors are injected by default;
}                                          @Current is the default binding type




                                                                                 13
Web Bean Names


                                          By default not available through EL.
@Named(quot;helloquot;)
public class Hello {
   public String hello(String name) {
      return quot;helloquot; + name;
   }
}                        If no name is specified, then a
                               default name is used. Both these
@Named                         beans have the same name

public class Hello {
   public String hello(String name) {
       return quot;helloquot; + name;
   }

                                                                                 14
JSF Page




<h:commandButton value=“Say Hello”
                 action=“#{hello.hello}”/>


                                     Calling an action on a bean
                                     through EL




                                                                   15
Binding Types

• A binding type is an annotation that lets a client
  choose between multiple implementations of an
  API at runtime
  -   Binding types replace lookup via string-based names
  -   @Current is the default binding type




                                                            16
Define a binding type



public
                                       Creating a binding type is
@BindingType
                                       really easy!
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
@interface Casual {}




                                                                17
Using a binding type


                                 We also specify the @Casual binding
@Casual                          type. If no binding type is specified on
                                 a bean, @Current is assumed
public class Hi extends Hello {
   public String hello(String name) {
      return quot;hiquot; + name;
   }
}




                                                                     18
Using a binding type

                                       Here we inject the Hello
                                       bean, and require an
                                       implementation which is
public class Printer {
                                       bound to @Casual
   @Casual Hello hello;
   public void hello() {
      System.out.println( hello.hello(quot;JBossquot;) );
   }
}




                                                              19
Deployment Types

• A deployment type is an annotation that
  identifies a deployment scenario
  -   Deployment types may be enabled or disabled,
      allowing whole sets of beans to be easily enabled or
      disabled at deployment time
  -   Deployment types have a precedence, allowing
      different implementations of an API to be chosen
  -   Deployment types replace verbose XML configuration
      documents
• Default deployment type: Production




                                                             20
Create a deployment type



public
@DeploymentType
@Retention(RUNTIME)
@Target({TYPE, METHOD})
@interface Espanol {}




                                      21
Using a deployment type



                                         Same API, different
@Espanol
                                         implementation
public class Hola extends Hello {

    public String hello(String name) {
       return quot;hola quot; + name;
    }

}




                                                               22
Enabling deployment types



<Beans>
  <Deploy>
    <Standard />
    <Production>
    <i8ln:Espanol>
                         A strongly ordered list of enabled
  </Deploy>              deployment types. Notice how everything
</Beans>                 is an annotation and so typesafe!




Only Web Bean implementations which have enabled
deployment types will be deployed to the container


                                                                   23
Scopes and Contexts

• Extensible context model
  -   A scope type is an annotation, can write your own
      context implementation and scope type annotation
• Dependent scope, @Dependent
• Built-in scopes:
  -   Any servlet - @ApplicationScoped, @RequestScoped,
      @SessionScoped
  -   JSF requests - @ConversationScoped
• Custom scopes




                                                          24
Scopes



@SessionScoped                         Session scoped
public class Login {
   private User user;
   public void login() {
      user = ...;
   }
   public User getUser() { return user; }
}




                                                        25
Scopes



public class Printer {                  No coupling between scope
                                        and use of implementation
    @Current Hello hello;
    @Current Login login;

    public void hello() {
       System.out.println(
          hello.hello( login.getUser().getName() ) );
    }
}




                                                              26
Conversation context


@ConversationScoped                    Conversation has the same
                                       semantics as in Seam
public class ChangePassword {
   @UserDatabase EntityManager em;
   @Current Conversation conversation;
   private User user;
   public User getUser(String userName) {
      conversation.begin();                    Conversation is
      user = em.find(User.class, userName); demarcated by the
                                               application
   }
   public User setPassword(String password) {
      user.setPassword(password);
      conversation.end();
   }
}
                                                               27
Producer methods

• Producer methods allow control over the
  production of a bean where:
  -   the objects to be injected are not managed instances
  -   the concrete type of the objects to be injected may
      vary at runtime
  -   the objects require some custom initialization that is
      not performed by the bean constructor




                                                               28
Producer methods



@SessionScoped
public class Login {
   private User user;
   public void login() {
      user = ...;
   }

    @Produces
    User getUser() { return user; }
}




                                      29
Producer methods



                                             Producer method can a
@SessionScoped                               scope (otherwise inherited
                                             from the declaring
public class Login {
                                             component)
   private User user;

  @Produces @RequestScoped @LoggedIn         Producer method can have
  User getUser() { return user; }            a binding type


  @Produces
  String getWelcomeMessage(@Current Hello hello) {
     return hello.hello(user);
                                      You can inject parameters
  }


                                                                      30
Producer methods



public class Printer {
   @Current Hello hello;
   @Current User user;                 Much better, no
   public void hello() {               dependency on Login!

      System.out.println(
         hello.hello( user.getName() ) );
   }
}




                                                              31
Producer Fields




• Simpler alternative to Producer methods
 @SessionScoped                          Similar to outjection
                                         in Seam
 public class Login {

    @Produces @LoggedIn @RequestScoped
    private User user;

    public void login() {
       user = ...;
    }


                                                                 32
Disposal Method



    • Clean up after a producer method
public class UserDatabaseEntityManager {

     @Produces @UserDatabase
     EntityManager create(EntityManagerFactory emf) {
        return emf.createEntityManager();
                                               Same binding types
     }           Same API type


     void close(@Disposes @UserDatabase EntityManager em) {
     em.close();
     }
}
                                                               33
Java EE Resources

•    To inject Java EE resources, persistence contexts, web
    service references, remote EJB references, etc, we use a
    special kind of producer field declaration:


     public class PricesTopic {
        @Produces @Prices
        @Resource(name=quot;java:global/env/jms/Pricesquot;)
        Topic pricesTopic;
     }

     public class UserDatabasePersistenceContext {
        @Produces @UserDatabase
        @PersistenceContext
        EntityManager userDatabase;
     }
                                                               34
Events

Event producers raise events that are then delivered
to event observers by the Web Bean manager.
-   not only are event producers decoupled from
    observers; observers are completely decoupled from
    producers
-   observers can specify a combination of quot;selectorsquot; to
    narrow the set of event notifications they will receive
-   observers can be notified immediately, or can specify
    that delivery of the event should be delayed until the
    end of the current transaction




                                                              35
Event producer

                          Inject an instance of Event. Additional binding
                          types can be specified to narrow the event
public class Hello {      consumers called. API type specified as a
                          parameter on Event
    @Casual Event<Greeting> casualHello;

    public void hello(String name) {
       casualHello.fire( new Greeting(quot;hello quot; + name) );
    }
                          “Fire” an event, the
}                         producer will be
                          notified




                                                                            36
Event consumer


                               Observer methods, take the API
public class Printer {         type and additional binding types


    void onHello(@Observes @Casual Greeting greeting,
                 @Current User user) {
       System.out.println(user + “ “ + greeting);
    }

}                                     Additional parameters can
                                      be specified and will be
                                      injected by the container




                                                                   37
Specialization

• Allows a bean with a higher precedence
  deployment to completely replace a bean with a
  lower precedence
    -    even producer methods, observer methods etc.



@Mock                                       A @Mock deployment
                                            type for testing
@Specializes
public class MockLogin extends Login {

        @Produces
        User getUser() { return new DummyUser(); }
}

                                                                 38
Road Map



Background
Concepts
Status




               39
JSR-299

• Public Review Draft 2 published
• Currently working on EE6 integration
• Web Beans “Book” (a less formal guide to
  JSR299)
  -   http://www.seamframework.org/WebBeans
• Send feedback to jsr-299-comments@jcp.org




                                              40
Web Beans

• The Reference implementation
  -   Feature complete preview of second public review
      draft. Download it, try it out, give feedback!
  - http://seamframework.org/Download
• Integrated into:
  -   JBoss 5.1.0.CR1 and above
  -   GlassFish V3 build 46 and above
• Available as an addon for:
  -   Tomcat 6.0.x
  -   Jetty 6.1.x




                                                         41
Q&A




http://in.relation.to/Bloggers/Pete

http://www.seamframework.org/WebBeans

http://jcp.org/en/jsr/detail?id=299




                                        42

Más contenido relacionado

La actualidad más candente

[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cooljavablend
 
Using Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformUsing Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformArun Gupta
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCIMC Institute
 
Contexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformContexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformBozhidar Bozhanov
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans Fabrizio Giudici
 
企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践Jacky Chi
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Arun Gupta
 
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Understanding
Understanding Understanding
Understanding Arun Gupta
 
Groovy, Transforming Language
Groovy, Transforming LanguageGroovy, Transforming Language
Groovy, Transforming LanguageUehara Junji
 
Ajax Tags Advanced
Ajax Tags AdvancedAjax Tags Advanced
Ajax Tags AdvancedAkramWaseem
 
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011Alexander Klimetschek
 
JBoss AS Upgrade
JBoss AS UpgradeJBoss AS Upgrade
JBoss AS Upgradesharmami
 
JavaScript
JavaScriptJavaScript
JavaScriptSunil OS
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenThorsten Kamann
 
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용Sungchul Park
 
Groovy Power Features
Groovy Power FeaturesGroovy Power Features
Groovy Power FeaturesPaul King
 
[스프링/Spring교육학원,자바교육,근로자교육,실업자교육추천학원_탑크리에듀]#6.스프링프레임워크 & 마이바티스 (Spring Framew...
[스프링/Spring교육학원,자바교육,근로자교육,실업자교육추천학원_탑크리에듀]#6.스프링프레임워크 & 마이바티스 (Spring Framew...[스프링/Spring교육학원,자바교육,근로자교육,실업자교육추천학원_탑크리에듀]#6.스프링프레임워크 & 마이바티스 (Spring Framew...
[스프링/Spring교육학원,자바교육,근로자교육,실업자교육추천학원_탑크리에듀]#6.스프링프레임워크 & 마이바티스 (Spring Framew...탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Types of Dependency Injection in Spring
Types of Dependency Injection in SpringTypes of Dependency Injection in Spring
Types of Dependency Injection in SpringSunil kumar Mohanty
 

La actualidad más candente (20)

[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool[Strukelj] Why will Java 7.0 be so cool
[Strukelj] Why will Java 7.0 be so cool
 
Using Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformUsing Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 Platform
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVC
 
Contexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformContexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platform
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
 
Jersey and JAX-RS
Jersey and JAX-RSJersey and JAX-RS
Jersey and JAX-RS
 
企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践企业级软件的组件化和动态化开发实践
企业级软件的组件化和动态化开发实践
 
Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5Java EE 7: Boosting Productivity and Embracing HTML5
Java EE 7: Boosting Productivity and Embracing HTML5
 
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
Understanding
Understanding Understanding
Understanding
 
Groovy, Transforming Language
Groovy, Transforming LanguageGroovy, Transforming Language
Groovy, Transforming Language
 
Ajax Tags Advanced
Ajax Tags AdvancedAjax Tags Advanced
Ajax Tags Advanced
 
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
 
JBoss AS Upgrade
JBoss AS UpgradeJBoss AS Upgrade
JBoss AS Upgrade
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
 
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용
스프링 코어 강의 2부 - Java 구성을 활용한 스프링 코어 사용
 
Groovy Power Features
Groovy Power FeaturesGroovy Power Features
Groovy Power Features
 
[스프링/Spring교육학원,자바교육,근로자교육,실업자교육추천학원_탑크리에듀]#6.스프링프레임워크 & 마이바티스 (Spring Framew...
[스프링/Spring교육학원,자바교육,근로자교육,실업자교육추천학원_탑크리에듀]#6.스프링프레임워크 & 마이바티스 (Spring Framew...[스프링/Spring교육학원,자바교육,근로자교육,실업자교육추천학원_탑크리에듀]#6.스프링프레임워크 & 마이바티스 (Spring Framew...
[스프링/Spring교육학원,자바교육,근로자교육,실업자교육추천학원_탑크리에듀]#6.스프링프레임워크 & 마이바티스 (Spring Framew...
 
Types of Dependency Injection in Spring
Types of Dependency Injection in SpringTypes of Dependency Injection in Spring
Types of Dependency Injection in Spring
 

Similar a Introduction To Web Beans

Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Ray Ploski
 
Php Development With Eclipde PDT
Php Development With Eclipde PDTPhp Development With Eclipde PDT
Php Development With Eclipde PDTBastian Feder
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James NelsonGWTcon
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)Montreal JUG
 
Dive into Play Framework
Dive into Play FrameworkDive into Play Framework
Dive into Play FrameworkMaher Gamal
 
Ejb3 1 Overview Glassfish Webinar 100208
Ejb3 1 Overview Glassfish Webinar 100208Ejb3 1 Overview Glassfish Webinar 100208
Ejb3 1 Overview Glassfish Webinar 100208Eduardo Pelegri-Llopart
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascriptrajivmordani
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Bastian Feder
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGuillaume Laforge
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLsintelliyole
 
What's New In Apache Lenya 1.4
What's New In Apache Lenya 1.4What's New In Apache Lenya 1.4
What's New In Apache Lenya 1.4nobby
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGuillaume Laforge
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundryrajdeep
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 

Similar a Introduction To Web Beans (20)

Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6Introduction to CDI and DI in Java EE 6
Introduction to CDI and DI in Java EE 6
 
Os Haase
Os HaaseOs Haase
Os Haase
 
Php Development With Eclipde PDT
Php Development With Eclipde PDTPhp Development With Eclipde PDT
Php Development With Eclipde PDT
 
S313937 cdi dochez
S313937 cdi dochezS313937 cdi dochez
S313937 cdi dochez
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)
 
Dive into Play Framework
Dive into Play FrameworkDive into Play Framework
Dive into Play Framework
 
Ejb3 1 Overview Glassfish Webinar 100208
Ejb3 1 Overview Glassfish Webinar 100208Ejb3 1 Overview Glassfish Webinar 100208
Ejb3 1 Overview Glassfish Webinar 100208
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascript
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009
 
CDI @javaonehyderabad
CDI @javaonehyderabadCDI @javaonehyderabad
CDI @javaonehyderabad
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
Play 2.0
Play 2.0Play 2.0
Play 2.0
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
What's New In Apache Lenya 1.4
What's New In Apache Lenya 1.4What's New In Apache Lenya 1.4
What's New In Apache Lenya 1.4
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundry
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Play framework
Play frameworkPlay framework
Play framework
 

Más de Eduardo Pelegri-Llopart

Pelegri Desarrollando en una nueva era de software
Pelegri   Desarrollando en una nueva era de software Pelegri   Desarrollando en una nueva era de software
Pelegri Desarrollando en una nueva era de software Eduardo Pelegri-Llopart
 
Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015Eduardo Pelegri-Llopart
 
The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015Eduardo Pelegri-Llopart
 
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...Eduardo Pelegri-Llopart
 
What is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts YouWhat is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts YouEduardo Pelegri-Llopart
 
Ehcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEhcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEduardo Pelegri-Llopart
 

Más de Eduardo Pelegri-Llopart (20)

Juggling at freenome
Juggling   at freenomeJuggling   at freenome
Juggling at freenome
 
Csumb capstone-fall2016
Csumb capstone-fall2016Csumb capstone-fall2016
Csumb capstone-fall2016
 
Digital activitymanagement
Digital activitymanagementDigital activitymanagement
Digital activitymanagement
 
Progress next iot_pelegri
Progress next iot_pelegriProgress next iot_pelegri
Progress next iot_pelegri
 
Pelegri Desarrollando en una nueva era de software
Pelegri   Desarrollando en una nueva era de software Pelegri   Desarrollando en una nueva era de software
Pelegri Desarrollando en una nueva era de software
 
Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015Market trends in IT - exchange cala - October 2015
Market trends in IT - exchange cala - October 2015
 
The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015The impact of IOT - exchange cala - 2015
The impact of IOT - exchange cala - 2015
 
IOT - Presentation to PEP @ Progress
IOT - Presentation to PEP @ ProgressIOT - Presentation to PEP @ Progress
IOT - Presentation to PEP @ Progress
 
Node.js as an IOT Bridge
Node.js as an IOT BridgeNode.js as an IOT Bridge
Node.js as an IOT Bridge
 
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
What is IoT and how Modulus and Pacific can Help - Featuring Node.js and Roll...
 
What is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts YouWhat is the Internet of Things and How it Impacts You
What is the Internet of Things and How it Impacts You
 
Community Update 25 Mar2010 - English
Community Update 25 Mar2010 - EnglishCommunity Update 25 Mar2010 - English
Community Update 25 Mar2010 - English
 
GlassFish Community Update 25 Mar2010
GlassFish Community Update 25 Mar2010GlassFish Community Update 25 Mar2010
GlassFish Community Update 25 Mar2010
 
Glass Fish Portfolio C1 West V3.Mini
Glass Fish Portfolio C1 West V3.MiniGlass Fish Portfolio C1 West V3.Mini
Glass Fish Portfolio C1 West V3.Mini
 
Virtual Box Aquarium May09
Virtual Box Aquarium May09Virtual Box Aquarium May09
Virtual Box Aquarium May09
 
Ehcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEhcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage Patterns
 
OpenDS Primer Aquarium
OpenDS Primer AquariumOpenDS Primer Aquarium
OpenDS Primer Aquarium
 
Fuji Overview
Fuji OverviewFuji Overview
Fuji Overview
 
Nuxeo 5.2 Glassfish
Nuxeo 5.2 GlassfishNuxeo 5.2 Glassfish
Nuxeo 5.2 Glassfish
 
OpenSSO Deployments
OpenSSO DeploymentsOpenSSO Deployments
OpenSSO Deployments
 

Último

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Introduction To Web Beans

  • 1. Web Beans, the RI of JSR-299 Pete Muir JBoss, a division of Red Hat
  • 3. Java EE 6 • The EE 6 web profile removes most of the “cruft” that has developed over the years - mainly the totally useless stuff like web services, EJB 2 entity beans, etc - some useful stuff like JMS is also missing, but vendors can include it if they like • EJB 3.1 - a whole bunch of cool new functionality! • JPA 2.0 - typesafe criteria query API, many more O/R mapping options • JSF 2.0 - don’t need to say much more! • Bean Validation 1.0 - annotation-based validation API • Servlet 3.0 - async support, better support for frameworks • Standard global JNDI names • Contexts and Dependency Injection for Java EE 3
  • 4. Goals • JSR-299 defines a unifying dependency injection and contextual lifecycle model for Java EE 6 - a completely new, richer dependency management model - designed for use with stateful objects - integrates the “web” and “transactional” tiers - makes it much easier to build applications using JSF and EJB together - includes a complete SPI allowing third-party frameworks to integrate cleanly in the EE 6 environment 4
  • 5. What can be injected? • Pre-defined by the specification: - (Almost) any Java class - EJB session beans - Objects returned by producer methods - Java EE resources (Datasources, JMS topics/ queues, etc) - Persistence contexts (JPA EntityManager) - Web service references - Remote EJBs references • Plus anything else you can think of! - An SPI allows third-party frameworks to introduce new kinds of things 5
  • 6. Loose coupling • Events, interceptors and decorators enhance the loose-coupling that is inherent in this model: - event notifications decouple event producers from event consumers - interceptors decouple technical concerns from business logic - decorators allow business concerns to be compartmentalized 6
  • 7. Going beyond the spec • Web Beans provides extra integrations - Tomcat/Jetty support - Wicket support - ??? • and features which can be used in any JSR-299 environment - jBPM integration - log injection (choose between log4j and jlr, parameter interpolation - Seam2 bridge - Spring bridge 7
  • 8. Seam 3? • Use the JSR-299 core • Provide a development environment - JBoss Tools - Seam-gen (command line tool) • include a set of modules for any container which includes JSR-299 - Seam Security - Reporting (Excel/PDF) - Mail - etc. 8
  • 10. Essential ingrediants • API types • Binding annotations • Scope • Deployment type • A name (optional) • Interceptor bindings • The implementation 10
  • 11. Simple Example public class Hello { Any Java Bean can use public String hello(String name) { these services return quot;helloquot; + name; } } So can EJBs @Stateless public class Hello { public String hello(String name) { return quot;helloquot; + name; } 11
  • 12. Simple Example public class Printer { @Current is the default (built in) binding type @Current Hello hello; public void hello() { System.out.println( hello.hello(quot;worldquot;) ); } } 12
  • 13. Constructor injection public class Printer { Mark the constructor to be called by private Hello hello; the container @Initializer @Initializer public Printer(Hello hello) { this.hello=hello; } public void hello() { System.out.println( hello.hello(quot;worldquot;) ); } Constructors are injected by default; } @Current is the default binding type 13
  • 14. Web Bean Names By default not available through EL. @Named(quot;helloquot;) public class Hello { public String hello(String name) { return quot;helloquot; + name; } } If no name is specified, then a default name is used. Both these @Named beans have the same name public class Hello { public String hello(String name) { return quot;helloquot; + name; } 14
  • 15. JSF Page <h:commandButton value=“Say Hello” action=“#{hello.hello}”/> Calling an action on a bean through EL 15
  • 16. Binding Types • A binding type is an annotation that lets a client choose between multiple implementations of an API at runtime - Binding types replace lookup via string-based names - @Current is the default binding type 16
  • 17. Define a binding type public Creating a binding type is @BindingType really easy! @Retention(RUNTIME) @Target({TYPE, METHOD, FIELD, PARAMETER}) @interface Casual {} 17
  • 18. Using a binding type We also specify the @Casual binding @Casual type. If no binding type is specified on a bean, @Current is assumed public class Hi extends Hello { public String hello(String name) { return quot;hiquot; + name; } } 18
  • 19. Using a binding type Here we inject the Hello bean, and require an implementation which is public class Printer { bound to @Casual @Casual Hello hello; public void hello() { System.out.println( hello.hello(quot;JBossquot;) ); } } 19
  • 20. Deployment Types • A deployment type is an annotation that identifies a deployment scenario - Deployment types may be enabled or disabled, allowing whole sets of beans to be easily enabled or disabled at deployment time - Deployment types have a precedence, allowing different implementations of an API to be chosen - Deployment types replace verbose XML configuration documents • Default deployment type: Production 20
  • 21. Create a deployment type public @DeploymentType @Retention(RUNTIME) @Target({TYPE, METHOD}) @interface Espanol {} 21
  • 22. Using a deployment type Same API, different @Espanol implementation public class Hola extends Hello { public String hello(String name) { return quot;hola quot; + name; } } 22
  • 23. Enabling deployment types <Beans> <Deploy> <Standard /> <Production> <i8ln:Espanol> A strongly ordered list of enabled </Deploy> deployment types. Notice how everything </Beans> is an annotation and so typesafe! Only Web Bean implementations which have enabled deployment types will be deployed to the container 23
  • 24. Scopes and Contexts • Extensible context model - A scope type is an annotation, can write your own context implementation and scope type annotation • Dependent scope, @Dependent • Built-in scopes: - Any servlet - @ApplicationScoped, @RequestScoped, @SessionScoped - JSF requests - @ConversationScoped • Custom scopes 24
  • 25. Scopes @SessionScoped Session scoped public class Login { private User user; public void login() { user = ...; } public User getUser() { return user; } } 25
  • 26. Scopes public class Printer { No coupling between scope and use of implementation @Current Hello hello; @Current Login login; public void hello() { System.out.println( hello.hello( login.getUser().getName() ) ); } } 26
  • 27. Conversation context @ConversationScoped Conversation has the same semantics as in Seam public class ChangePassword { @UserDatabase EntityManager em; @Current Conversation conversation; private User user; public User getUser(String userName) { conversation.begin(); Conversation is user = em.find(User.class, userName); demarcated by the application } public User setPassword(String password) { user.setPassword(password); conversation.end(); } } 27
  • 28. Producer methods • Producer methods allow control over the production of a bean where: - the objects to be injected are not managed instances - the concrete type of the objects to be injected may vary at runtime - the objects require some custom initialization that is not performed by the bean constructor 28
  • 29. Producer methods @SessionScoped public class Login { private User user; public void login() { user = ...; } @Produces User getUser() { return user; } } 29
  • 30. Producer methods Producer method can a @SessionScoped scope (otherwise inherited from the declaring public class Login { component) private User user; @Produces @RequestScoped @LoggedIn Producer method can have User getUser() { return user; } a binding type @Produces String getWelcomeMessage(@Current Hello hello) { return hello.hello(user); You can inject parameters } 30
  • 31. Producer methods public class Printer { @Current Hello hello; @Current User user; Much better, no public void hello() { dependency on Login! System.out.println( hello.hello( user.getName() ) ); } } 31
  • 32. Producer Fields • Simpler alternative to Producer methods @SessionScoped Similar to outjection in Seam public class Login { @Produces @LoggedIn @RequestScoped private User user; public void login() { user = ...; } 32
  • 33. Disposal Method • Clean up after a producer method public class UserDatabaseEntityManager { @Produces @UserDatabase EntityManager create(EntityManagerFactory emf) { return emf.createEntityManager(); Same binding types } Same API type void close(@Disposes @UserDatabase EntityManager em) { em.close(); } } 33
  • 34. Java EE Resources • To inject Java EE resources, persistence contexts, web service references, remote EJB references, etc, we use a special kind of producer field declaration: public class PricesTopic { @Produces @Prices @Resource(name=quot;java:global/env/jms/Pricesquot;) Topic pricesTopic; } public class UserDatabasePersistenceContext { @Produces @UserDatabase @PersistenceContext EntityManager userDatabase; } 34
  • 35. Events Event producers raise events that are then delivered to event observers by the Web Bean manager. - not only are event producers decoupled from observers; observers are completely decoupled from producers - observers can specify a combination of quot;selectorsquot; to narrow the set of event notifications they will receive - observers can be notified immediately, or can specify that delivery of the event should be delayed until the end of the current transaction 35
  • 36. Event producer Inject an instance of Event. Additional binding types can be specified to narrow the event public class Hello { consumers called. API type specified as a parameter on Event @Casual Event<Greeting> casualHello; public void hello(String name) { casualHello.fire( new Greeting(quot;hello quot; + name) ); } “Fire” an event, the } producer will be notified 36
  • 37. Event consumer Observer methods, take the API public class Printer { type and additional binding types void onHello(@Observes @Casual Greeting greeting, @Current User user) { System.out.println(user + “ “ + greeting); } } Additional parameters can be specified and will be injected by the container 37
  • 38. Specialization • Allows a bean with a higher precedence deployment to completely replace a bean with a lower precedence - even producer methods, observer methods etc. @Mock A @Mock deployment type for testing @Specializes public class MockLogin extends Login { @Produces User getUser() { return new DummyUser(); } } 38
  • 40. JSR-299 • Public Review Draft 2 published • Currently working on EE6 integration • Web Beans “Book” (a less formal guide to JSR299) - http://www.seamframework.org/WebBeans • Send feedback to jsr-299-comments@jcp.org 40
  • 41. Web Beans • The Reference implementation - Feature complete preview of second public review draft. Download it, try it out, give feedback! - http://seamframework.org/Download • Integrated into: - JBoss 5.1.0.CR1 and above - GlassFish V3 build 46 and above • Available as an addon for: - Tomcat 6.0.x - Jetty 6.1.x 41