DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. Stars the new Stripes framework extension for full stack development

Stars the new Stripes framework extension for full stack development

Hussachai Puripunpinyo user avatar by
Hussachai Puripunpinyo
·
Apr. 28, 11 · News
Like (0)
Save
Tweet
Share
601 Views

Join the DZone community and get the full member experience.

Join For Free
I'm happy to announce the new Stripes framework extension, Stars!
Stars and Stripes is the perfect couple to get the job done.

The benefit of using Stars

  • Be able to change the service provider easily (Just a few line of configurations)
  • Be able to reuse existing knowledge because you can use target framework's native annotations which you are already familiar with such as @EJB, @Autowired, etc.
  • Small footprint and lightweight.

Features

  • Stars enhances existing ActionBean classes by providing dependency injection capability.
  • JSR 250's annotations @PostConstruct, @PreDestroy and @Resource
  • Spring integration - @Autowired annotation support and Spring callback interfaces such as InitializingBean, DisposableBean, ApplicationContextAware, BeanFactoryAware.
  • EJB integration - @EJB annotation support.
  • For Java Persistence API - @PersistenceUnit, @PersistenceContext with multiple persistence units support. Transaction type support depends on configuration and service provider.
  • Bootstrap class with dependency injection support
  • Built-in service container called Stars local service which supports annotation configuration as well. For example @Service, @ServiceBean It's easy to configure and customize.
  • Useful taglibs
  • The below snippet show how to implement bootstrap and use annotation in Stars.
    Stars does not manage transaction for Bootstrap class even you're using Stars local service,
    so you have to manage your own transaction. I use @SkipInjectionError to mark the bootstrap class
    in order to avoid injection error blocks the bootstrap job.
    Injection error?
    Yes! because Stars supports multiple service providers and therefore fail to inject the missing resource.
    In this example, if you run the web application in Java EE container managed environment, the UserTransaction
    resource will be avaiable; otherwise the resource will be missing. That's why @SkipInjectionError comes into play.
    Why Stars does not set the null value to attribute for unavailable resource instead of throwing error?
    The answer is Fail-fast

    BugzookyBootstrap.java
    @SkipInjectionError
    public class BugzookyBootstrap implements StarsBootstrap {

    @PersistenceContext
    private EntityManager em;

    @Resource
    private UserTransaction userTx;

    @Override
    public void execute(ServletContext servletContext) throws Exception {
    if(ServiceProvider.isEjb(servletContext)){
    userTx.begin();
    }else{
    if(!em.getTransaction().isActive())
    em.getTransaction().begin();
    }
    ...
    Another example is using DI in Stripes ActionBean class
    The below snippet show how to inject service instance to ActionBean's attribute using
    annotation configuration. There are 3 annotations for 3 types of service provider- Stars local service,
    Spring, and EJB respectively. The amazing feature of Stars, you can change service provider easily
    by changing a few line of configuration (No code change!!!). It means that the below ActionBean can
    use 3 difference types of service by just changing a few configurations without code changing.
    That's cool, isn't it.
    MultiBugActionBean.java
    @UrlBinding("/bugzooky/multiBug.action")
    public class MultiBugActionBean extends BugzookyActionBean {

    @Service(impl=BugManagerImpl.class)
    @Autowired
    @EJB
    private BugManager bugManager;
    ...

    You can download it here http://code.google.com/p/stars/
Stripes (framework) Framework Web Service Dependency injection Annotation

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Connecting Your Devs' Work to the Business
  • How and Why You Should Start Automating DevOps
  • Top 5 PHP REST API Frameworks
  • Memory Debugging: A Deep Level of Insight

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: