Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Method execution problem in java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 12-03-2010
Member
 
Join Date: Mar 2010
Posts: 198
Method execution problem in java

Hello,
I have a problem of inheritance which disturbs me because it challenges one from my understanding of java, I hope someone will give me an explanation. Within my team, we have a framework based on which several applications depend, a class is abstract, and each application must be classified under this class. The method getApplicationName () returns normally the application name, defined in a configuration file. So now I have something that works but is ugly, and I do not understand why the simple version does not work. If someone has an explanation. Any help on this is highly appreciated. Thanks in advance.
__________________
www.techarena.in
Reply With Quote
  #2  
Old 12-03-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Method execution problem in java

Hello,
See if the following code helps you. Here is the code that I have created check out if it helps.
Code:
Public String appnm() {
	return approp().getName();
}
 
Protected static ApplicationProperties approp(){
		
	if (proper == null){
		WebApplicationContext cnt = WebApplicationContextUtils.getWebApplicationContext(ServletContext);
proper = ApplicationProperties)cnt.getBean("proper");
	}
	return proper;
}
Reply With Quote
  #3  
Old 12-03-2010
Member
 
Join Date: Mar 2010
Posts: 198
Re: Method execution problem in java

Hello,
This is my updated code, have a look at it
Code:
abstcnt ctx = abstcntt.getCurrentContext(request);
ctx.getapp();
And I use this
Code:
appcnt ctx =(appcnt)abstcnt.getCurrentContext(request);
ctx.getApplicationName();
Code:
And also this
abstcnt tmpCtx = abstcnt.getCurrentContext(request);
Method mth = Class.Class.forName(tmpCtx.getClass().getName()).getMethod("getApplicationName", null);
out.print(mth.invoke(tmpCtx, null));
__________________
www.techarena.in
Reply With Quote
  #4  
Old 12-03-2010
Member
 
Join Date: Nov 2009
Posts: 447
Re: Method execution problem in java

Hello,
Please check the following code I have modified it, see if this works now.
Code:
<% = abstcnt.getCurrentContext(request).getApplicationName()%>
--
<%
abstcnt tpcx = abstcnt.getCurrentContext(request);
Method mth = Class.Class.forName(tpcx.getClass().getName()).getMethod("getApplicationName", null);
out.print(mth.invoke(tpcx, null));
%>
Reply With Quote
  #5  
Old 12-03-2010
Member
 
Join Date: Nov 2009
Posts: 331
Re: Method execution problem in java

Hello,
In my opinion on your application server you are always the old version of the superclass, ie one where getapp() is static and the new version of the subclass which contains an instance method getapp(). So when you compile the following code:
Code:
abstcnt.getCurrentContext(request).getapp()
The compiler sees only the superclass, and as for his method getapp() is static. It generates a call to the static method (and thus without inheritance mechanism).
Reply With Quote
  #6  
Old 12-03-2010
Member
 
Join Date: Nov 2009
Posts: 335
Re: Method execution problem in java

Hello,
I think the getapp() was static at the parent class, the name of the application was the same for all users of an application. Now, you removed the static level of the superclass, thus redefining the method in subclasses. Each user can have a different application name, as it is stored in context, which is related to the session. I think you get the point I am trying to explain here.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Method execution problem in java"
Thread Thread Starter Forum Replies Last Post
Problem in using random method in java Gunner 1 Software Development 5 13-02-2010 02:22 AM
What is method overriding and method overloading in java beelow Software Development 3 17-11-2009 08:20 AM
Problem with my java method manjava Software Development 3 17-11-2009 06:15 AM
How to validate form field before execution of a servlet service method Quattro Portable Devices 3 11-09-2009 04:28 PM
Java: How can I call one method in another method? biohazard 76 Software Development 3 16-07-2009 08:12 PM


All times are GMT +5.5. The time now is 03:43 AM.