EJB loading configuration files and singletons


EJB design: EJB loading configuration files and singletons

  1. EJB loading configuration files and singletons (1 messages)

    Hello, I understand that singletons are not recommended. I would like to know how generally to deal with this type of issue. Lets say I have a server that processes xml messages in some way. I have a java singleton that read the config.xml file on startup and initializes dataStructures to contain mapping between the xml message tag name for each request and the classes to handle such a request. My stateless session beans accesses that singleton to retrieve the correct processor for the request. Is this the wrong way of doing it. Should I instead of a singleton create a regular class that reads the configuration files even though it should be a singleton. or should I hard code a map in my stateless bean that contains mapping from xmlTagNameToJNDIName and use JNDI to retrieve appropriate classes? Also a question about regular IO. I also read that IO is not recommended? If this is true is it only in the bean class or can a bean have a reference to a plain java object that does IO. Thanks a lot for your help,
  2. Hard Coding is never a better option! If you just want a class which reads the xml file and fills up datastructure at the t=initial phase, then having singletons won't pose problems because you will be just treating the class as the repository.Or you can have a regular class with static methods to retrieve the mappings. cheers, http://www.javaicillusion.blogspot.com/