This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Do I interface with another class or just call it with a constructor? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Do I interface with another class or just call it with a constructor?" Watch "Do I interface with another class or just call it with a constructor?" New topic
Author

Do I interface with another class or just call it with a constructor?

Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
First let me say, thank you very much for having this place for Java Greenhorns and to the *many* who help answer questions.

I am very new and in charge of tying up loose ends behind consultants.

I am trying to determine what server I am on based on method written by the team like this:



This should return a boolean value. The class this method is in is called WebStoreContext..

I have tried to get the boolean value by using this.. I should note when I do it does find getProdServer() as an available choice in JBOSS DEV STUDIO


I have also tried:



But there is no true *Interface* class for WebStoreContext.java

What do I need to show further or do in next in order to get the boolean value?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi Dan,

The constructor path isn't going to work, I'm sure, because you don't want a new WebStoreContext -- you want one particular WebStoreContext, the one that's all configured already. WHat you need to find out it how to get access to that one particular WebStoreContext. Now, I don't know if that's part of an in-house framework, or some COTS framework, or what. But you'd think that the point of this class was to provide global access to those methods, so there must be some way to get ahold of it. Maybe it's stored in the session, or the server context? Do you have any examples or information on this framework?


[Jess in Action][AskingGoodQuestions]
Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
There is another file in the same package as WebStoreContext.java, it is WebStoreContextStaticAccessor.java. Not sure if it plays a role and if I need to use this like an interface.

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Ah, that looks like it, indeed. So it looks like you should just call the static method to get the instance of that class, and then call the other method on it -- like this:

boolean boolProd = WebStoreContextStaticAccessor.getWebStoreContext().getProdServer();

This assumes that something, somewhere, calls "init()" for you. I'd guess that's why that "@Create" annotation is there. Tough to learn Java when there's so much other black magic going on as well, isn't it!
Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
That did the trick!!

Yes it has been difficult going at it all at once. Check this out. Java, EJB3, Hibernate, SEAM, JSF, Facelets, RichFaces -- all at once!! he


Sure appreciate the help. Thanks much.
Dan Acuff
Ranch Hand

Joined: Jul 13, 2009
Posts: 62
By the way. Is WebStoreContextStaticAccessor.java just a class file that was created to access WebStoreContext and it's methods?

Is this common in Java Programming? Does it have a name?

If anyone could explain more about it, it would be helpful in me learning architecture principals.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do I interface with another class or just call it with a constructor?