• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB that extends Properties cant create interface  RSS feed

 
Dan Fow
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a newbie to JEE and EJB's so forgive me if this is a stupid question.

I want to have an EJB that extends the java.util.Properties class however, it is my understanding that I need to have an interface for the Bean that I inject. Properties does not have an interface so I don't know how to expose the Properties methods in my beans interface.

How can I create a Bean that extends Properties and has an interface that also exposes the Properties methods (without having to rewrite all of them myself)?

is there a way to create a bean without an interface?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a way to create a bean without an interface?


Yes, it's possible in EJB3.1. Which version are you using? And which application server.

I want to have an EJB that extends the java.util.Properties class


I haven't seen a bean having to extend Properties, but I guess I don't know the details about your application.
 
Dan Fow
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using JBoss AS6, but trying to stay as container-agnostic as possible, might as well ask if that is possible though?

I'm using the JBoss default EJB version so I think that is an alpha of EJB 3.1.1 (could be wrong though).

As far as extending Properties goes, my main concern is being able to extend any class, seems kind of odd if using ejb's prevents you from using inheritance, could just be me not understanding something though?
 
Dan Fow
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, could you point me to a tutorial or just tell me the trick to making a bean without an interface? Everytime I've tried the server throws a bunch of exceptions.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan Fow wrote:Using JBoss AS6, but trying to stay as container-agnostic as possible, might as well ask if that is possible though?

Yes, EJB 3.1 is a spec implemented by various vendors (including JBoss AS 6). So the "no-interface view" introduced in EJB3.1 spec is app server agnostic.
Dan Fow wrote:
I'm using the JBoss default EJB version so I think that is an alpha of EJB 3.1.1 (could be wrong though).

JBoss AS 6 implements EJB 3.1 spec.


As far as extending Properties goes, my main concern is being able to extend any class, seems kind of odd if using ejb's prevents you from using inheritance, could just be me not understanding something though?

You can extend any class for the bean. EJB spec just mandates that you expose the appropriate methods either via explicit (business) interfaces or starting EJB3.1 the "no-interface view" allows you to expose all public methods of a bean without having to explicitly implement any interface.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan Fow wrote:Also, could you point me to a tutorial or just tell me the trick to making a bean without an interface? Everytime I've tried the server throws a bunch of exceptions.


http://community.jboss.org/wiki/EJB31inAS600M2
 
Valentin Floarea
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan Fow wrote:I'm a newbie to JEE and EJB's so forgive me if this is a stupid question.

I want to have an EJB that extends the java.util.Properties class however, it is my understanding that I need to have an interface for the Bean that I inject. Properties does not have an interface so I don't know how to expose the Properties methods in my beans interface.

How can I create a Bean that extends Properties and has an interface that also exposes the Properties methods (without having to rewrite all of them myself)?

is there a way to create a bean without an interface?


If I correctly understand, you want to expose the methods from java.util.Properties as EJB methods. Why do you need this? First, the EJB rules restrict the use of java.io package in the EJBs and some methods from Properties class use a couple of classes included in this package. Second, you cannot create stateless bean extending the Properties class because the stateless bean does not maintain the conversational state. So when you add a property you don't know the instance where that property will be added (usually the servers keep in memory several instances of a bean). You could use a stateful bean, but I don't see the benefit over a simple instantiation of the Property class. You should use EJBs when you need services provided by the container (e.g. transactions, security, pooling,....).

Anyway, for the sake of illustration you could accomplish your task using EJB 3.0 too. You could define an interface containing the signature of the public methods from the Properties class. Your bean has to implement this interface and extend the Properties class, but not provide any implementation for the methods defined in the interface (the bean will inherit these methods). But again, this is against the rules and the purpose of the EJBs.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!