Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:45:03+00:00 2026-06-09T20:45:03+00:00

I am wondering if it is possible to accomplish the following using EJB3. I

  • 0

I am wondering if it is possible to accomplish the following using EJB3.

I have the following interface:

interface DateParser {
    Date parseDate(String input);
    String getType();
}

Then I have several implementations of said interface that handle different formats based on the information given in the getType method. When my bean starts up it creates a Set of implementations of DateParser and when it needs to parse a date, it iterates over the set to see which one matches. If one matches it uses that one to parse the date. If none match, then it applies a default strategy. I would like to get away from instantiating these delegates because every time I add a new strategy it requires a code change in the bean making it a huge mess.

I would much prefer to have the container inject all of the implementations it finds at deployment. Is there a reasonable way to accomplish this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:45:05+00:00Added an answer on June 9, 2026 at 8:45 pm

    Implementation of this interface should be regular classes, not beans. EJB are meant to be business services. Parsing date is IMHO a responsabiltiy that is too fine-grained for a bean.

    I would much prefer to have the container inject all of the
    implementations it finds at deployment.

    I don’t think there is standard way to do that. I see only two options to dynamically fill the set with the instances:

    1. Use an external configuration files with list of class names. Reach each class name and instantiate one instance reflectively (Class.forName, Class.newInstance). Then add it to the set.

    2. Iterate over all classes in the class path, identifiy those that are implementation of DateParser. Then instantiate it reflectively, and add it to the set. Note that iterating over loadable classes is kind of tricky, see this answer.

    it requires a code change in the bean making it a huge mess.

    That should require a code change in a class, but not the bean itself. The bean should delegate the creation of the set, the identification of the parser, etc. to another class, IMHO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering if is possible to have a responsive layout without using CSS3. Are
I was wondering if the following is possible. I have a BASH script that
I was wondering what would be a good way to accomplish the following using
Say I have a textbox in HTML using the following code: <input type=text name=text
I am wondering if its possible to have a an (||)or or (&&)and operator
I was wondering if the following migration is possible with Django south and still
I'm wondering if something is possible in Java String A = UPDATE blah set
I'm wondering how I can accomplish the effect in figure 1. What I have
I was wondering if there's a way to accomplish the following: In my project,
I was wondering ( if possible ) if there was a program/tool/utility that when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.