SlideShare a Scribd company logo
Context &
Dependency Injection
A Cocktail of Guice and Seam, the
missing ingredients for Java EE 6




           Werner Keil
           21/04/2011
Without Dependency Injection
Explicit Constructor
class Stopwatch {
     final TimeSource timeSource;
     Stopwatch () {
       timeSource = new AtomicClock(...);
     }
     void start() { ... }
     long stop() { ... }
}



www.catmedia.us                             2
Without Dependency Injection
Using a Factory
class Stopwatch {
     final TimeSource timeSource;
     Stopwatch () {
       timeSource =
  DefaultTimeSource.getInstance();
     }
     void start() { ... }
     long stop() { ... }
}                   Somewhat like in java.util.Calendar
www.catmedia.us                                       3
Without Dependency Injection
Mock Data
void testStopwatch() {
   TimeSource original = DTS.getInstance();
     DefaultTimeSource.setInstance(new
  MockTimeSource());
     try {
     Stopwatch sw = new Stopwatch();
        ...
     } finally {
       DTS.setInstance(original);
     }
}
www.catmedia.us                               4
With Dependency Injection
@Inject
class Stopwatch {
      final TimeSource timeSource;
      @Inject Stopwatch(TimeSource timeSource)
  {
        this.timeSource = TimeSource;
      }
      void start() { ... }
      long stop() { ... }
    }


www.catmedia.us                             5
JSR-330
Definition
 @Inject
      Identifies injectable constructors, methods, and fields .
       This works for both static and non-static elements.
 @Qualifier
      Identifies qualifier annotations to declare binding types of
       your API
 @Named
      A name (string) based qualifier
      Others may be declared application - or domain-specific
www.catmedia.us                                                       6
JSR-330
Implementation
 @Provider
      Provides instances of an (injectable) type. Allows
                 Retrieving multiple instances.
                 Lazy or optional retrieval of an instance.
                 Breaking circular dependencies.
                 Abstracting scope
 @Singleton
      Identifies a type that the injector only instantiates once.
      See the well-known Design Pattern

www.catmedia.us                                                      7
DEMO




www.catmedia.us          8
JSR-330
Configuration
1. Minimal but usable API: A small API surface seems
   more important than making it as convenient as
   possible for clients. There are only two methods in
   the proposed API that could be considered
   convenience, added because they seemed to pull
   their weight
      InjectionConfigurer.inject and InjectionSpec.inject(Object)
2. Builder-style API: so-called "fluent APIs“
     •      Open to other styles.
www.catmedia.us                                                      9
JSR-330
Configuration (2)
3. Abstract classes instead of interfaces: 2 main types
      (InjectionConfigurer and InjectionSpec) are abstract classes
       instead of interfaces.
      This allows new methods to be added later in a binary-
       compatible way.
4. Separate configuration API
     •      The API does not specify how an instance of
            InjectionConfigurer is obtained.
     •      Otherwise we have to standardize the injector API
            itself, something outside of the stated scope of JSR-330.
www.catmedia.us                                                         10
JSR-330
Configuration (3)
5. Names are different from Guice's configuration API:
   This is mostly
 to keep this separate from existing configuration APIs,
   but also so
 that new concepts (like "Binding") don't have to be
   defined.



www.catmedia.us                                        11
More about JSR-330, see
      http://code.google.com/p/atinject
                        or
http://jcp.org/en/jsr/summary?id=330



www.catmedia.us                           12
Formerly known as WebBeans…




www.catmedia.us                   13
JSR-299
Services
 The lifecycle and interactions of stateful components
  bound to well-defined lifecycle contexts, where the
  set of contexts is extensible
 A sophisticated, type safe dependency injection
  mechanism, including a facility for choosing between
  various components that implement the same Java
  interface at deployment time
 An event notification model

www.catmedia.us                                       14
JSR-299
Services (2)
 Integration with the Unified Expression Language (EL),
  allowing any component to be used directly within a
  JSF or JSP page
 The ability to decorate injected components
 A web conversation context in addition to the three
  standard web contexts defined by the Java Servlets
  specification
 An SPI allowing portable extensions to integrate
  cleanly with the Java EE environment
www.catmedia.us                                       15
• Sophisticated,
• Type Safe,
• Dependency
  Injection,…




www.catmedia.us    16
IN MEMORIAM
Pietro Ferrero Jr.




                  11 September 1963 – 18 April 2011

www.catmedia.us                                       17
JSR-299
Bean Attributes
   A (nonempty) set of bean types
   A (nonempty) set of bindings
   A scope
   A deployment type
   Optionally, a bean EL name
   A set of interceptor bindings
   A bean implementation

www.catmedia.us                      18
JSR-299
Context
• A custom implementation of Context may be
  associated with a scope type by calling
  BeanManager.addContext().

public void addContext(Context context);




www.catmedia.us                               19
JSR-299
Context (2)
• BeanManager.getContext() retrieves an active context
  object associated with the a given scope:

public Context getContext(Class<? extends
  Annotation> scopeType);


→ Context used in a broader meaning than some other
 parts of Java (Enterprise)

www.catmedia.us                                     20
JSR-299
Restricted Instantiation
@SessionScoped
public class PaymentStrategyProducer {
  private PaymentStrategyType
  paymentStrategyType;

    public void setPaymentStrategyType(
      PaymentStrategyType type) {
       paymentStrategyType = type;
    }
www.catmedia.us                           21
JSR-299
Restricted Instantiation (2)
@Produces PaymentStrategy
  getPaymentStrategy(@CreditCard
  PaymentStrategy creditCard,
@Cheque PaymentStrategy cheque,
@Online PaymentStrategy online) {
   switch (paymentStrategyType) {
        case CREDIT_CARD: return creditCard;
        case CHEQUE: return cheque;
[…]

www.catmedia.us                            22
JSR-299
Restricted Instantiation (3)
[…]
         case ONLINE: return online;
         default: throw new
    IllegalStateException();
       }
    }
}




www.catmedia.us                        23
JSR-299
Event Observer
• Then the following observer method will always be
  notified of the event:
• public void afterLogin(@Observes
  LoggedInEvent event) { ... }


• Whereas this observer method may or may not be
  notified, depending upon the value of user.getRole():
• public void afterAdminLogin(@Observes
  @Role("admin") LoggedInEvent event) { ... }

www.catmedia.us                                       24
JSR-299
Event Binding
• As elsewhere, binding types may have annotation
  members:
@BindingType
@Target(PARAMETER)
@Retention(RUNTIME)
public @interface Role {
  String value();
}
www.catmedia.us                                     25
JSR-299
Event Binding (2)
 Actually @Role could extend @Named from JSR-330
 JSRs here potentially not consequently streamlined…?




www.catmedia.us                                     26
JSR-299
Portable Extensions
public interface Bean<T>
extends Contextual<T> {
  public Set<Type> getTypes();
  public Set<Annotation>
  getBindings();
  public Class<? extends Annotation>
                      getScopeType();


www.catmedia.us                         27
JSR-299
Portable Extensions (2)
    public Class<? extends Annotation>

     getDeploymentType();
  public String getName();
  public Class<?> getBeanClass();
  public boolean isNullable();
public Set<InjectionPoint>
  getInjectionPoints();
}
www.catmedia.us                          28
DEMO




www.catmedia.us          31
More about JSR-299, see
       http://www.seamframework.org/
                            JCP
 http://jcp.org/en/jsr/summary?id=299
                   or
http://www.developermarch.com/devel
  opersummit/sessions.html#session66
                       (cancelled ;-/)
www.catmedia.us               32
Further Reading
     • Java.net
       http://www.java.net/
     • Java™ EE Patterns and Best Practices
       http://kenai.com/projects/javaee-patterns /




www.catmedia.us                                  33
Thank you!
                  Contact & Questions
                    jcp@catmedia.us
                        Twitter
                      @wernerkeil


www.catmedia.us                         34

More Related Content

What's hot

Java 7: Quo vadis?
Java 7: Quo vadis?Java 7: Quo vadis?
Java 7: Quo vadis?
Michal Malohlava
 
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
Arun Gupta
 
CDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptorCDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptor
Caelum
 
12 hibernate int&cache
12  hibernate int&cache12  hibernate int&cache
12 hibernate int&cache
thirumuru2012
 
Advanced Hibernate Notes
Advanced Hibernate NotesAdvanced Hibernate Notes
Advanced Hibernate Notes
Kaniska Mandal
 
Sql full tutorial
Sql full tutorialSql full tutorial
Sql full tutorial
Mozaaic Cyber Security
 
RIBs - Fragments which work
RIBs - Fragments which workRIBs - Fragments which work
RIBs - Fragments which work
Dmitry Zaytsev
 
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUGThe Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
Arun Gupta
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2
Matt Raible
 
Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018
Luciano Mammino
 
spring-tutorial
spring-tutorialspring-tutorial
spring-tutorial
Arjun Shanka
 
Deployment
DeploymentDeployment
Whats New In Java Ee 6
Whats New In Java Ee 6Whats New In Java Ee 6
Whats New In Java Ee 6
Stephan Janssen
 
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
Fwdays
 
Framework Engineering Revisited
Framework Engineering RevisitedFramework Engineering Revisited
Framework Engineering Revisited
YoungSu Son
 
14 hql
14 hql14 hql
Android Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingAndroid Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and Testing
Yongjun Kim
 
12 global fetching strategies
12 global fetching strategies12 global fetching strategies
12 global fetching strategies
thirumuru2012
 
ZooKeeper Recipes and Solutions
ZooKeeper Recipes and SolutionsZooKeeper Recipes and Solutions
ZooKeeper Recipes and Solutions
Jeff Smith
 

What's hot (19)

Java 7: Quo vadis?
Java 7: Quo vadis?Java 7: Quo vadis?
Java 7: Quo vadis?
 
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
 
CDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptorCDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptor
 
12 hibernate int&cache
12  hibernate int&cache12  hibernate int&cache
12 hibernate int&cache
 
Advanced Hibernate Notes
Advanced Hibernate NotesAdvanced Hibernate Notes
Advanced Hibernate Notes
 
Sql full tutorial
Sql full tutorialSql full tutorial
Sql full tutorial
 
RIBs - Fragments which work
RIBs - Fragments which workRIBs - Fragments which work
RIBs - Fragments which work
 
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUGThe Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2
 
Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018Unbundling the JavaScript module bundler - DublinJS July 2018
Unbundling the JavaScript module bundler - DublinJS July 2018
 
spring-tutorial
spring-tutorialspring-tutorial
spring-tutorial
 
Deployment
DeploymentDeployment
Deployment
 
Whats New In Java Ee 6
Whats New In Java Ee 6Whats New In Java Ee 6
Whats New In Java Ee 6
 
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
 
Framework Engineering Revisited
Framework Engineering RevisitedFramework Engineering Revisited
Framework Engineering Revisited
 
14 hql
14 hql14 hql
14 hql
 
Android Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and TestingAndroid Jetpack: ViewModel and Testing
Android Jetpack: ViewModel and Testing
 
12 global fetching strategies
12 global fetching strategies12 global fetching strategies
12 global fetching strategies
 
ZooKeeper Recipes and Solutions
ZooKeeper Recipes and SolutionsZooKeeper Recipes and Solutions
ZooKeeper Recipes and Solutions
 

Viewers also liked

Implement Dependency Injection in Java
Implement Dependency Injection in JavaImplement Dependency Injection in Java
Implement Dependency Injection in Java
Geng-Dian Huang
 
Dependency Injection in Spring in 10min
Dependency Injection in Spring in 10minDependency Injection in Spring in 10min
Dependency Injection in Spring in 10min
Corneil du Plessis
 
Spring beans
Spring beansSpring beans
Spring beans
Roman Dovgan
 
Spring and dependency injection
Spring and dependency injectionSpring and dependency injection
Spring and dependency injection
Steve Ng
 
Dependency injection
Dependency injectionDependency injection
Dependency injection
Mindfire Solutions
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 

Viewers also liked (6)

Implement Dependency Injection in Java
Implement Dependency Injection in JavaImplement Dependency Injection in Java
Implement Dependency Injection in Java
 
Dependency Injection in Spring in 10min
Dependency Injection in Spring in 10minDependency Injection in Spring in 10min
Dependency Injection in Spring in 10min
 
Spring beans
Spring beansSpring beans
Spring beans
 
Spring and dependency injection
Spring and dependency injectionSpring and dependency injection
Spring and dependency injection
 
Dependency injection
Dependency injectionDependency injection
Dependency injection
 
Spring Core
Spring CoreSpring Core
Spring Core
 

Similar to Context and Dependency Injection

Java EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSFJava EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSF
Jiayun Zhou
 
CDI @javaonehyderabad
CDI @javaonehyderabadCDI @javaonehyderabad
CDI @javaonehyderabad
Prasad Subramanian
 
Spring training
Spring trainingSpring training
Spring training
TechFerry
 
Javaee6 Overview
Javaee6 OverviewJavaee6 Overview
Javaee6 Overview
Carol McDonald
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheCon
os890
 
New Features of JSR 317 (JPA 2.0)
New Features of JSR 317 (JPA 2.0)New Features of JSR 317 (JPA 2.0)
New Features of JSR 317 (JPA 2.0)
Markus Eisele
 
jRecruiter - The AJUG Job Posting Service
jRecruiter - The AJUG Job Posting ServicejRecruiter - The AJUG Job Posting Service
jRecruiter - The AJUG Job Posting Service
Gunnar Hillert
 
Gnizr Architecture (for developers)
Gnizr Architecture (for developers)Gnizr Architecture (for developers)
Gnizr Architecture (for developers)
hchen1
 
CDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE DevelopmentCDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE Development
Saltmarch Media
 
Context and Dependency Injection 2.0
Context and Dependency Injection 2.0Context and Dependency Injection 2.0
Context and Dependency Injection 2.0
Brian S. Paskin
 
Spring Performance Gains
Spring Performance GainsSpring Performance Gains
Spring Performance Gains
VMware Tanzu
 
S313937 cdi dochez
S313937 cdi dochezS313937 cdi dochez
S313937 cdi dochez
Jerome Dochez
 
Dependency injection in iOS
Dependency injection in iOSDependency injection in iOS
Dependency injection in iOS
IuriiMozharovskyi
 
Spring framework core
Spring framework coreSpring framework core
Spring framework core
Taemon Piya-Lumyong
 
Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
Fermin Galan
 
Java EE 6
Java EE 6Java EE 6
Java EE 6
Geert Pante
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf
DeoDuaNaoHet
 
Jakarta EE and MicroProfile - EclipseCon 2020
Jakarta EE and MicroProfile - EclipseCon 2020Jakarta EE and MicroProfile - EclipseCon 2020
Jakarta EE and MicroProfile - EclipseCon 2020
Josh Juneau
 
DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)
Hendrik Ebbers
 
How to not shoot yourself in the foot when working with serialization
How to not shoot yourself in the foot when working with serializationHow to not shoot yourself in the foot when working with serialization
How to not shoot yourself in the foot when working with serialization
PVS-Studio
 

Similar to Context and Dependency Injection (20)

Java EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSFJava EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSF
 
CDI @javaonehyderabad
CDI @javaonehyderabadCDI @javaonehyderabad
CDI @javaonehyderabad
 
Spring training
Spring trainingSpring training
Spring training
 
Javaee6 Overview
Javaee6 OverviewJavaee6 Overview
Javaee6 Overview
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheCon
 
New Features of JSR 317 (JPA 2.0)
New Features of JSR 317 (JPA 2.0)New Features of JSR 317 (JPA 2.0)
New Features of JSR 317 (JPA 2.0)
 
jRecruiter - The AJUG Job Posting Service
jRecruiter - The AJUG Job Posting ServicejRecruiter - The AJUG Job Posting Service
jRecruiter - The AJUG Job Posting Service
 
Gnizr Architecture (for developers)
Gnizr Architecture (for developers)Gnizr Architecture (for developers)
Gnizr Architecture (for developers)
 
CDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE DevelopmentCDI and Seam 3: an Exciting New Landscape for Java EE Development
CDI and Seam 3: an Exciting New Landscape for Java EE Development
 
Context and Dependency Injection 2.0
Context and Dependency Injection 2.0Context and Dependency Injection 2.0
Context and Dependency Injection 2.0
 
Spring Performance Gains
Spring Performance GainsSpring Performance Gains
Spring Performance Gains
 
S313937 cdi dochez
S313937 cdi dochezS313937 cdi dochez
S313937 cdi dochez
 
Dependency injection in iOS
Dependency injection in iOSDependency injection in iOS
Dependency injection in iOS
 
Spring framework core
Spring framework coreSpring framework core
Spring framework core
 
Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
 
Java EE 6
Java EE 6Java EE 6
Java EE 6
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf
 
Jakarta EE and MicroProfile - EclipseCon 2020
Jakarta EE and MicroProfile - EclipseCon 2020Jakarta EE and MicroProfile - EclipseCon 2020
Jakarta EE and MicroProfile - EclipseCon 2020
 
DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)DataFX 8 (JavaOne 2014)
DataFX 8 (JavaOne 2014)
 
How to not shoot yourself in the foot when working with serialization
How to not shoot yourself in the foot when working with serializationHow to not shoot yourself in the foot when working with serialization
How to not shoot yourself in the foot when working with serialization
 

More from Werner Keil

Securing eHealth, eGovernment and eBanking with Java - DWX '21
Securing eHealth, eGovernment and eBanking with Java - DWX '21Securing eHealth, eGovernment and eBanking with Java - DWX '21
Securing eHealth, eGovernment and eBanking with Java - DWX '21
Werner Keil
 
OpenDDR and Jakarta MVC - JavaLand 2021
OpenDDR and Jakarta MVC - JavaLand 2021OpenDDR and Jakarta MVC - JavaLand 2021
OpenDDR and Jakarta MVC - JavaLand 2021
Werner Keil
 
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
Werner Keil
 
OpenDDR and Jakarta MVC - Java2Days 2020 Virtual
OpenDDR and Jakarta MVC - Java2Days 2020 VirtualOpenDDR and Jakarta MVC - Java2Days 2020 Virtual
OpenDDR and Jakarta MVC - Java2Days 2020 Virtual
Werner Keil
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 Virtual
Werner Keil
 
JCON 2020: Mobile Java Web Applications with MVC and OpenDDR
JCON 2020: Mobile Java Web Applications with MVC and OpenDDRJCON 2020: Mobile Java Web Applications with MVC and OpenDDR
JCON 2020: Mobile Java Web Applications with MVC and OpenDDR
Werner Keil
 
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
Werner Keil
 
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
Werner Keil
 
Money, Money, Money, can be funny with JSR 354 (DWX 2019)
Money, Money, Money, can be funny with JSR 354 (DWX 2019)Money, Money, Money, can be funny with JSR 354 (DWX 2019)
Money, Money, Money, can be funny with JSR 354 (DWX 2019)
Werner Keil
 
NoSQL: The first New Jakarta EE Specification (DWX 2019)
NoSQL: The first New Jakarta EE Specification (DWX 2019)NoSQL: The first New Jakarta EE Specification (DWX 2019)
NoSQL: The first New Jakarta EE Specification (DWX 2019)
Werner Keil
 
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR DayHow JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
Werner Keil
 
JNoSQL: The Definitive Solution for Java and NoSQL Databases
JNoSQL: The Definitive Solution for Java and NoSQL DatabasesJNoSQL: The Definitive Solution for Java and NoSQL Databases
JNoSQL: The Definitive Solution for Java and NoSQL Databases
Werner Keil
 
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL DatabasesEclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
Werner Keil
 
Physikal - Using Kotlin for Clean Energy - KUG Munich
Physikal - Using Kotlin for Clean Energy - KUG MunichPhysikal - Using Kotlin for Clean Energy - KUG Munich
Physikal - Using Kotlin for Clean Energy - KUG Munich
Werner Keil
 
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
Werner Keil
 
Performance Monitoring for the Cloud - Java2Days 2017
Performance Monitoring for the Cloud - Java2Days 2017Performance Monitoring for the Cloud - Java2Days 2017
Performance Monitoring for the Cloud - Java2Days 2017
Werner Keil
 
Eclipse Science F2F 2016 - JSR 363
Eclipse Science F2F 2016 - JSR 363Eclipse Science F2F 2016 - JSR 363
Eclipse Science F2F 2016 - JSR 363
Werner Keil
 
Java2Days - Security for JavaEE and the Cloud
Java2Days - Security for JavaEE and the CloudJava2Days - Security for JavaEE and the Cloud
Java2Days - Security for JavaEE and the Cloud
Werner Keil
 
Apache DeviceMap - Web-Dev-BBQ Stuttgart
Apache DeviceMap - Web-Dev-BBQ StuttgartApache DeviceMap - Web-Dev-BBQ Stuttgart
Apache DeviceMap - Web-Dev-BBQ Stuttgart
Werner Keil
 
The First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
The First IoT JSR: Units of Measurement - JUG Berlin-BrandenburgThe First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
The First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
Werner Keil
 

More from Werner Keil (20)

Securing eHealth, eGovernment and eBanking with Java - DWX '21
Securing eHealth, eGovernment and eBanking with Java - DWX '21Securing eHealth, eGovernment and eBanking with Java - DWX '21
Securing eHealth, eGovernment and eBanking with Java - DWX '21
 
OpenDDR and Jakarta MVC - JavaLand 2021
OpenDDR and Jakarta MVC - JavaLand 2021OpenDDR and Jakarta MVC - JavaLand 2021
OpenDDR and Jakarta MVC - JavaLand 2021
 
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
How JSR 385 could have Saved the Mars Climate Orbiter - Zurich IoT Day 2021
 
OpenDDR and Jakarta MVC - Java2Days 2020 Virtual
OpenDDR and Jakarta MVC - Java2Days 2020 VirtualOpenDDR and Jakarta MVC - Java2Days 2020 Virtual
OpenDDR and Jakarta MVC - Java2Days 2020 Virtual
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 Virtual
 
JCON 2020: Mobile Java Web Applications with MVC and OpenDDR
JCON 2020: Mobile Java Web Applications with MVC and OpenDDRJCON 2020: Mobile Java Web Applications with MVC and OpenDDR
JCON 2020: Mobile Java Web Applications with MVC and OpenDDR
 
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
How JSR 385 could have Saved the Mars Climate Orbiter - JFokus 2020
 
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
Money, Money, Money, can be funny with JSR 354 (Devoxx BE)
 
Money, Money, Money, can be funny with JSR 354 (DWX 2019)
Money, Money, Money, can be funny with JSR 354 (DWX 2019)Money, Money, Money, can be funny with JSR 354 (DWX 2019)
Money, Money, Money, can be funny with JSR 354 (DWX 2019)
 
NoSQL: The first New Jakarta EE Specification (DWX 2019)
NoSQL: The first New Jakarta EE Specification (DWX 2019)NoSQL: The first New Jakarta EE Specification (DWX 2019)
NoSQL: The first New Jakarta EE Specification (DWX 2019)
 
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR DayHow JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
How JSR 385 could have Saved the Mars Climate Orbiter - Adopt-a-JSR Day
 
JNoSQL: The Definitive Solution for Java and NoSQL Databases
JNoSQL: The Definitive Solution for Java and NoSQL DatabasesJNoSQL: The Definitive Solution for Java and NoSQL Databases
JNoSQL: The Definitive Solution for Java and NoSQL Databases
 
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL DatabasesEclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
Eclipse JNoSQL: The Definitive Solution for Java and NoSQL Databases
 
Physikal - Using Kotlin for Clean Energy - KUG Munich
Physikal - Using Kotlin for Clean Energy - KUG MunichPhysikal - Using Kotlin for Clean Energy - KUG Munich
Physikal - Using Kotlin for Clean Energy - KUG Munich
 
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
Physikal - JSR 363 and Kotlin for Clean Energy - Java2Days 2017
 
Performance Monitoring for the Cloud - Java2Days 2017
Performance Monitoring for the Cloud - Java2Days 2017Performance Monitoring for the Cloud - Java2Days 2017
Performance Monitoring for the Cloud - Java2Days 2017
 
Eclipse Science F2F 2016 - JSR 363
Eclipse Science F2F 2016 - JSR 363Eclipse Science F2F 2016 - JSR 363
Eclipse Science F2F 2016 - JSR 363
 
Java2Days - Security for JavaEE and the Cloud
Java2Days - Security for JavaEE and the CloudJava2Days - Security for JavaEE and the Cloud
Java2Days - Security for JavaEE and the Cloud
 
Apache DeviceMap - Web-Dev-BBQ Stuttgart
Apache DeviceMap - Web-Dev-BBQ StuttgartApache DeviceMap - Web-Dev-BBQ Stuttgart
Apache DeviceMap - Web-Dev-BBQ Stuttgart
 
The First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
The First IoT JSR: Units of Measurement - JUG Berlin-BrandenburgThe First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
The First IoT JSR: Units of Measurement - JUG Berlin-Brandenburg
 

Recently uploaded

GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 

Recently uploaded (20)

GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 

Context and Dependency Injection

  • 1. Context & Dependency Injection A Cocktail of Guice and Seam, the missing ingredients for Java EE 6 Werner Keil 21/04/2011
  • 2. Without Dependency Injection Explicit Constructor class Stopwatch { final TimeSource timeSource; Stopwatch () { timeSource = new AtomicClock(...); } void start() { ... } long stop() { ... } } www.catmedia.us 2
  • 3. Without Dependency Injection Using a Factory class Stopwatch { final TimeSource timeSource; Stopwatch () { timeSource = DefaultTimeSource.getInstance(); } void start() { ... } long stop() { ... } } Somewhat like in java.util.Calendar www.catmedia.us 3
  • 4. Without Dependency Injection Mock Data void testStopwatch() { TimeSource original = DTS.getInstance(); DefaultTimeSource.setInstance(new MockTimeSource()); try { Stopwatch sw = new Stopwatch(); ... } finally { DTS.setInstance(original); } } www.catmedia.us 4
  • 5. With Dependency Injection @Inject class Stopwatch { final TimeSource timeSource; @Inject Stopwatch(TimeSource timeSource) { this.timeSource = TimeSource; } void start() { ... } long stop() { ... } } www.catmedia.us 5
  • 6. JSR-330 Definition  @Inject  Identifies injectable constructors, methods, and fields . This works for both static and non-static elements.  @Qualifier  Identifies qualifier annotations to declare binding types of your API  @Named  A name (string) based qualifier  Others may be declared application - or domain-specific www.catmedia.us 6
  • 7. JSR-330 Implementation  @Provider  Provides instances of an (injectable) type. Allows  Retrieving multiple instances.  Lazy or optional retrieval of an instance.  Breaking circular dependencies.  Abstracting scope  @Singleton  Identifies a type that the injector only instantiates once.  See the well-known Design Pattern www.catmedia.us 7
  • 9. JSR-330 Configuration 1. Minimal but usable API: A small API surface seems more important than making it as convenient as possible for clients. There are only two methods in the proposed API that could be considered convenience, added because they seemed to pull their weight  InjectionConfigurer.inject and InjectionSpec.inject(Object) 2. Builder-style API: so-called "fluent APIs“ • Open to other styles. www.catmedia.us 9
  • 10. JSR-330 Configuration (2) 3. Abstract classes instead of interfaces: 2 main types  (InjectionConfigurer and InjectionSpec) are abstract classes instead of interfaces.  This allows new methods to be added later in a binary- compatible way. 4. Separate configuration API • The API does not specify how an instance of InjectionConfigurer is obtained. • Otherwise we have to standardize the injector API itself, something outside of the stated scope of JSR-330. www.catmedia.us 10
  • 11. JSR-330 Configuration (3) 5. Names are different from Guice's configuration API: This is mostly  to keep this separate from existing configuration APIs, but also so  that new concepts (like "Binding") don't have to be defined. www.catmedia.us 11
  • 12. More about JSR-330, see http://code.google.com/p/atinject or http://jcp.org/en/jsr/summary?id=330 www.catmedia.us 12
  • 13. Formerly known as WebBeans… www.catmedia.us 13
  • 14. JSR-299 Services  The lifecycle and interactions of stateful components bound to well-defined lifecycle contexts, where the set of contexts is extensible  A sophisticated, type safe dependency injection mechanism, including a facility for choosing between various components that implement the same Java interface at deployment time  An event notification model www.catmedia.us 14
  • 15. JSR-299 Services (2)  Integration with the Unified Expression Language (EL), allowing any component to be used directly within a JSF or JSP page  The ability to decorate injected components  A web conversation context in addition to the three standard web contexts defined by the Java Servlets specification  An SPI allowing portable extensions to integrate cleanly with the Java EE environment www.catmedia.us 15
  • 16. • Sophisticated, • Type Safe, • Dependency Injection,… www.catmedia.us 16
  • 17. IN MEMORIAM Pietro Ferrero Jr. 11 September 1963 – 18 April 2011 www.catmedia.us 17
  • 18. JSR-299 Bean Attributes  A (nonempty) set of bean types  A (nonempty) set of bindings  A scope  A deployment type  Optionally, a bean EL name  A set of interceptor bindings  A bean implementation www.catmedia.us 18
  • 19. JSR-299 Context • A custom implementation of Context may be associated with a scope type by calling BeanManager.addContext(). public void addContext(Context context); www.catmedia.us 19
  • 20. JSR-299 Context (2) • BeanManager.getContext() retrieves an active context object associated with the a given scope: public Context getContext(Class<? extends Annotation> scopeType); → Context used in a broader meaning than some other parts of Java (Enterprise) www.catmedia.us 20
  • 21. JSR-299 Restricted Instantiation @SessionScoped public class PaymentStrategyProducer { private PaymentStrategyType paymentStrategyType; public void setPaymentStrategyType( PaymentStrategyType type) { paymentStrategyType = type; } www.catmedia.us 21
  • 22. JSR-299 Restricted Instantiation (2) @Produces PaymentStrategy getPaymentStrategy(@CreditCard PaymentStrategy creditCard, @Cheque PaymentStrategy cheque, @Online PaymentStrategy online) { switch (paymentStrategyType) { case CREDIT_CARD: return creditCard; case CHEQUE: return cheque; […] www.catmedia.us 22
  • 23. JSR-299 Restricted Instantiation (3) […] case ONLINE: return online; default: throw new IllegalStateException(); } } } www.catmedia.us 23
  • 24. JSR-299 Event Observer • Then the following observer method will always be notified of the event: • public void afterLogin(@Observes LoggedInEvent event) { ... } • Whereas this observer method may or may not be notified, depending upon the value of user.getRole(): • public void afterAdminLogin(@Observes @Role("admin") LoggedInEvent event) { ... } www.catmedia.us 24
  • 25. JSR-299 Event Binding • As elsewhere, binding types may have annotation members: @BindingType @Target(PARAMETER) @Retention(RUNTIME) public @interface Role { String value(); } www.catmedia.us 25
  • 26. JSR-299 Event Binding (2)  Actually @Role could extend @Named from JSR-330  JSRs here potentially not consequently streamlined…? www.catmedia.us 26
  • 27. JSR-299 Portable Extensions public interface Bean<T> extends Contextual<T> { public Set<Type> getTypes(); public Set<Annotation> getBindings(); public Class<? extends Annotation> getScopeType(); www.catmedia.us 27
  • 28. JSR-299 Portable Extensions (2) public Class<? extends Annotation> getDeploymentType(); public String getName(); public Class<?> getBeanClass(); public boolean isNullable(); public Set<InjectionPoint> getInjectionPoints(); } www.catmedia.us 28
  • 30. More about JSR-299, see http://www.seamframework.org/ JCP http://jcp.org/en/jsr/summary?id=299 or http://www.developermarch.com/devel opersummit/sessions.html#session66 (cancelled ;-/) www.catmedia.us 32
  • 31. Further Reading • Java.net http://www.java.net/ • Java™ EE Patterns and Best Practices http://kenai.com/projects/javaee-patterns / www.catmedia.us 33
  • 32. Thank you! Contact & Questions jcp@catmedia.us Twitter @wernerkeil www.catmedia.us 34