Calling a private method
class A{
private void x(){
System.out.println("x of A") ;
void y(){
System.out.println("y of A") ;
class B extends A{
private void x(){
System.out.println("x of B") ;
void y(){
System.out.println("y of B") ;
void xy(){
x() ;
y() ;
class Demo{
public static void main(String[] args){
B b1 = new B() ;
b1.xy() ;
o/p :
x of B
y of B
class A{
private void x(){
System.out.println("x of A") ;
void y(){
System.out.println("y of A") ;
void xy(){
x() ;
y() ;
class B extends A{
private void x(){
System.out.println("x of B") ;
void y(){
System.out.println("y of B") ;
class Demo{
public static void main(String[] args){
B b1 = new B() ;
b1.xy() ;
A b2 = new B() ;
b2.xy() ;
A a = new A() ;
a.xy() ;
o/p :
x of A
y of B
x of A
y of B
x of A
y of A
anyone plz explain the concept, how method x is called in abve 2 cases?????
thnx in advance.....
Edited by: rits on Sep 5, 2008 3:25 AM
Basically... this is using inheritance. The output shows which methods are/are not inherited from the superclass.
I'll edit this post after submitting it, and try to explain some concepts, then you should look at your code and try to figure it out.
First example
class Demo{
public static void main(String[] args){
B b1 = new B() ;
b1.xy() ; //Calls xy() method in B, and the xy() method calls x() and y()
Second example
class Demo{
public static void main(String[] args){
B b1 = new B() ;
b1.xy() ; //calls the method xy() in B [which is actually inherited from A], xy() method calls x() and y()
// the x() method is not inherited [private], so the one in A is used
// the y() method is inherited from A and is used here
A b2 = new B() ;
b2.xy() ; //calls the xy() method in A
// this is a little bit tricky though, as the label is of type A (the superclass), but the actual class is B
A a = new A() ;
a.xy() ; //calls the xy() method in A
// note that B is not used at all here
}But I'm reasonably new to this, and this isn't really straightforward, so I'd recommend waiting for someone else to confirm that I'm right before you try to understand what I'm saying ;)
Edited by: shano on Sep 5, 2008 3:50 AM
Similar Messages
-
How to call a private method in a JFrame
I have a Frame which has some properties like its size, bgcolor plus other parameters, as instance variables. There is a button on the Frame with the caption : "set properties". When one clicks on that button, a new frame should appear via which a user can change the values of the parameters of the main Frame (i.e size, bgcolor,..etc). The user would input the new values in the textfields or radio buttons that are on the new frame, and then click a submit button, which has to exist on the same NFrame. How can I do that so that when the submit button is pressed, the parameters values are updated and so is the display view ?
I made it this way : I created 2 classes, the main frame and the new Frame. I made the new Frame an instance variable of the main Frame. When the user clicks the " set properties" button on the main Frame, the new Frame is shown. The user enters new values for some of the parameters and clicks submit. The parameters in the new Frame are updated. UP TO HERE EVERYTHING WENT JUST FINE. Now, there is a private method in the main frame that changes the color, size, ...etc of the main frame according to the values stored in the instance variables color, size,...etc. THE QUESTION IS: How can the new Frame display the changes after the values have been updated ? That is, how can it call the "private" method in the main class?? Should the new class be a child class of the main class to be able to access it's private methods ??import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;
public class CallingHome
SkinMod skinMod;
JPanel panel;
public CallingHome()
// send reference so SkinMod can call methods in this class
skinMod = new SkinMod(this);
JButton change = new JButton("change properties");
change.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
skinMod.showDialog();
JPanel north = new JPanel();
north.add(change);
panel = new JPanel();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(north, "North");
f.getContentPane().add(panel);
f.setSize(300,100);
f.setLocation(200,200);
f.setVisible(true);
public void setBackground(Color color)
panel.setBackground(color);
panel.repaint();
public static void main(String[] args)
new CallingHome();
class SkinMod
CallingHome callHome;
Random seed;
JDialog dialog;
public SkinMod(CallingHome ch)
callHome = ch;
seed = new Random();
createDialog();
public void showDialog()
if(!dialog.isShowing())
dialog.setVisible(true);
private void createDialog()
JButton change = new JButton("change background");
change.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
callHome.setBackground(getColor());
dialog.dispose();
JPanel p = new JPanel();
p.add(change);
dialog = new JDialog();
dialog.getContentPane().add(p);
dialog.setSize(200,100);
dialog.setLocation(525,200);
private Color getColor()
return new Color(seed.nextInt(0xffffff));
} -
Calling package private method
Suppose you have a class called A:
org.blah.A
|
--org.blah.blahblah.B
(B extends A)
But class B is in another package than A
So if I do the following
A a = new A();
B b = (B) a;and if class B has package private methods how can I call them by downcasting to B? What is a work-around?Tutorial:
public is the most generous of the four modifiers. A public class, method, or variable may be used in any Java program without restriction.
private is the most restrictive of the modifiers. A private variable or method may only be used by an instance of the class that declares the item.
(read none) is the friend or default modifier. A class's default feature is available to any class in the same package.
protected vars and methods are available to all classes in the same package as the class that declares them. Moreover, they are available to subclasses of the declaring class even if the subclass resides in a different package. -
ABAP Objects: Calling private Methods
Hi,
i would choose an private Method of an global class (for example class: CL_GUI_ALV_GRID private Method: SEARCH_START) in a local class.
class lcl_test definition for testing.
private section.
methods test for testing.
data ref_alv type ref to cl_gui_alv_grid.
endclass.
class lcl_test implementation.
method for test.
create object ref_alv ...
* How to call a private Method?
call method ref_alv->search_start( ). "not possible!
endmethod.
endclass.
Is this possible?
Regards,
DamirDamir, of course you can call a private method of a class, if this class has made you a friend with the syntax element FRIENDS (available since Release 6.10). Here is a syntactically correct example, when my_method is a private class method:
REPORT test.
CLASS mytest DEFINITION FOR TESTING.
PRIVATE SECTION.
METHODS test FOR TESTING.
ENDCLASS.
CLASS myclass DEFINITION FRIENDS mytest.
PUBLIC SECTION.
CLASS-METHODS my_method.
ENDCLASS.
CLASS myclass IMPLEMENTATION.
METHOD my_method.
ENDMETHOD.
ENDCLASS.
CLASS mytest IMPLEMENTATION.
METHOD test.
CALL METHOD myclass=>my_method.
ENDMETHOD.
ENDCLASS.
If my_method is not a class method, then you need to create an object of the class first, whose methods you want to test.
Kind regards,
Michael Kraemer -
Error while usind Private Method of a global class
HI All..
I created a global class (ZLINE_GLOBAL) which has TOT_DATA private method. I have to call this private method in my report, I know that using Friend class we can do this.
But it is not working and showing the same error " METHOD "TOT_DATA" is unknown or Private or Public..
code i tried is
CLASS c2 DEFINITION DEFERRED.
CLASS ZLINE_GLOBAL DEFINITION FRIENDS c2.
PUBLIC SECTION.
METHODS : m1.
PRIVATE SECTION.
METHODS: m2.
ENDCLASS.
CLASS ZLINE_GLOBAL IMPLEMENTATION .
METHOD m1.
WRITE : 'Public Method C1'.
ENDMETHOD. "M1
METHOD m2.
WRITE : 'Private Method C1'.
ENDMETHOD.
ENDCLASS.
CLASS c2 DEFINITION FRIENDS ZLINE_GLOBAL. "my friends are here, allow them access to my (C2's) private components
PUBLIC SECTION.
METHODS :m3.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
METHOD m3.
DATA : obj TYPE REF TO ZLINE_GLOBAL.
CREATE OBJECT obj.
CALL METHOD obj->TOT_DATA. "here Iam calling Private method of global class
ENDMETHOD. "M3
ENDCLASS.
START-OF-SELECTION.
DATA obj_c2 TYPE REF TO c2.
CREATE OBJECT obj_c2.
obj_c2->m3( ).
can anybody help me on this..
MurthyHi Murthy,
Replace TOT_DATA with M2, you do not have any method by name "TOT_DATA" in your code.
CLASS c2 DEFINITION DEFERRED.
CLASS ZLINE_GLOBAL DEFINITION FRIENDS c2.
PUBLIC SECTION.
METHODS : m1.
PRIVATE SECTION.
METHODS: m2.
ENDCLASS.
CLASS ZLINE_GLOBAL IMPLEMENTATION .
METHOD m1.
WRITE : 'Public Method C1'.
ENDMETHOD. "M1
METHOD m2.
WRITE : 'Private Method C1'.
ENDMETHOD.
ENDCLASS.
CLASS c2 DEFINITION FRIENDS ZLINE_GLOBAL. "my friends are here, allow them access to my (C2's) private components
PUBLIC SECTION.
METHODS :m3.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
METHOD m3.
DATA : obj TYPE REF TO ZLINE_GLOBAL.
CREATE OBJECT obj.
CALL METHOD obj->M2. "here Iam calling Private method of global class
ENDMETHOD. "M3
ENDCLASS.
START-OF-SELECTION.
DATA obj_c2 TYPE REF TO c2.
CREATE OBJECT obj_c2.
obj_c2->m3( ).
Regards,
Chen -
Is it possible to override private methods??
class A {
private void print() {
System.out.println("Hello Super");
class B extends A{
public void print() {
System.out.println("Hello Sub");
class C {
public static void main(String args[]) {
A a=new B();
a.print();
According to overriding rules the sub class method should not be more restrictive than the super class method. SO we are making it public (From private).
So the above code is an example of overriding but when compiled it gives error.
Please explain why??Oh wait, I had a second look and compiled & ran your program. This is the error message:
A.java:16: print() has private access in A
a.print();
^
1 errorYou are trying to call a private method, so you get an error. You can't make private methods public by subclassing. -
Call Enterprise Bean (or Database) from private Method in Session-Bean
Hi Everybody,
I've a question regarding the possibility to call an dependency injected EJB in an private method of a session bean.
Imagine the following.
@Stateless
public class SomeBean implements SomeLocal{
@EJB
private AnotherLocal anotherBean;
/** Will be called from a web-app via delegate layer */
@TransactionAttribute(TransactionAttribute.RequiresNew)
public void someBusisnessMethod(){
String something = this.getSomeThing();
//Do more
private String getSomeThing(){
return anotherBean.aMethodWhichCallsTheEntityManager();
}I've to refactor code with uses such Call-Hierachy and I want to know whether this is a correct way? Somebody told me that such stuff should not be made, and I quess he told me an explanation, why not to do such stuff, but unfortunally I've forgotten that. Do someone have a suggestion why not to do this? Could it blow the application to hell? Is there any difference to the following code (The way I would have done it)?
@Stateless
public class SomeBean implements SomeLocal{
@EJB
private AnotherLocal anotherBean;
@Resource
private SessionContext sessionContext;
/** Will be called from a web-app via delegate layer */
@TransactionAttribute(TransactionAttribute.RequiresNew)
public void someBusisnessMethod(){
SomeLocal self = this.sessionContext.getBusinessObject(SomeLocal.class);
String something = self.getSomeThingBusinessMethod();
//Do more
@TransactionAttribute(TransactionAttribute.Required)
public String getSomeThingBusinessMethod(){
return anotherBean.aMethodWhichCallsTheEntityManager();
}Found the answer by myself....
Here it is if someone might have the same question:
http://stackoverflow.com/questions/3381002 or if the link may down sometime the content of the answer...
>
The motivation here is that most EJB implementations work on proxies. You wouldn't be too far off in thinking of it as old-school AOP. The business interface is implemented by the EJB container, quite often via a simple java.lang.reflect.Proxy, and this object is handed to everyone in the system who asks for the ejb via @EJB or JNDI lookup.
The proxy is hooked up to the container and all calls on it go directly to the container who will preform security checks, start/stop/suspend transactions, invoke interceptors, etc. etc. and then finally delegate the call to the bean instance -- and of course do any clean up required due to any exceptions thrown -- then finally hand the return value over through the proxy to the caller.
Calling this.foo() directly, or passing 'this' to a caller so they can make direct calls as well, will skip all of that and the container will be effectively cut out of the picture. The 'getBusinessObject(Class)' method allows the bean instance to essentially get a proxy to itself so it can invoke its own methods and make use of the container management services associated with it -- interceptors, transaction management, security enforcement, etc.
written by David Blevins -
How to call a set method from within a constructor
Hello,
I want to be able to call a set method from within a Scanner, to be used as the argument to pass to the Scanner (from a source file). Here's what i tried:
private void openFiles()
input = new Scanner( setSource );
and here is the set method:
public String setSource( String in )
source = in;
return source;
}obviously there will be more code in this method but i'm trying to tackle one problem at a time. Thanks in advance..The "String in" declaration says: "Nobody may ever invoke setSource() without specifying a certain String. The content of the String is known at run-time only."
In no place in your code you say the compiler: "I want the 'in' variable (actually, parameter) of method setSource() to contain the first arg which is passed to the application".
This is exactly the same mechanism allowing you to write "new Scanner" with something inside the two parentheses. -
How to call a java method in a Stored procedure
Hi.,
I was trying to call a method in a stored procedure
This was my procedure
CREATE OR REPLACE PROCEDURE proc_copy_file(sr_file VARCHAR2,dt_file VARCHAR2)
AS LANGUAGE JAVA
NAME 'FileCopy.copyfile(String,String)'; // calling a java method
/ this was my java method
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "FileCopy" as
import java.io.File;
import java.io.IOException;
import java.io.FileReader;
import java.io.FileWriter;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.FileImageOutputStream;
import java.security.AccessControlException;
public class FileCopy {
// Define variable(s).
private static int c;
private static File file1,file2;
private static FileReader inTextFile;
private static FileWriter outTextFile;
private static FileImageInputStream inImageFile;
private static FileImageOutputStream outImageFile;
// Define copyText() method.
public static void copyfile(String fromFile,String toFile) throws AccessControlException
// Create files from canonical file names.
file1 = new File(fromFile);
file2 = new File(toFile);
// Copy file(s).
try
// Define and initialize FileReader(s).
inTextFile = new FileReader(file1);
outTextFile = new FileWriter(file2);
// Read character-by-character.
while ((c = inTextFile.read()) != -1) {
outTextFile.write(c); }
// Close Stream(s).
inTextFile.close();
outTextFile.close(); }
catch (IOException e) {
System.out.println ("-------"); }
// return 1;
public static void main(String[] args){
switch(args.length){
case 0: System.out.println("File has not mentioned.");
System.exit(0);
case 1: System.out.println("Destination file has not mentioned.");
System.exit(0);
case 2: copyfile(args[0],args[1]);
System.exit(0);
default : System.out.println("Multiple files are not allow.");
System.exit(0);
};while i am executing this method i m getting error as
ORA-29531: NO METHOD COPYFILE IN CLASS FILECOPY
ORA-06512: AT "RMVER721.PROC_COPY_FILE", LINE 1could anyone help meLooks like it is a matter of not quite the same namespace for String object.
I can get it to work by the java source containing:
public static void copyfile(java.lang.String fromFile,java.lang.String toFile) throws AccessControlExceptionAnd the PL/SQL source:
NAME 'FileCopy.copyfile(java.lang.String,java.lang.String)'; // calling a java methodSeems like when you just use "String", then the namespace resolving in the java source is not the same as the namespace resolving in the PL/SQL?
Addendum:
You do not need to put java.lang.String in the java source, String will do (java.lang is by default "imported"?)
But in the PL/SQL source java.lang namespace prefix is needed - java.lang is not "imported" here.
Edited by: Kim Berg Hansen on Nov 23, 2011 1:07 PM -
Calling A Super Method Externally
Hi,
I would like to call an overridden method, a super method, of an object externally. I thought all I needed to do was:
1. get the java.lang.Class object of the super class where the original method was declared and implemented.
2. get the appropriate java.lang.reflect.Method object from the Class object.
3. override the java language protections on the Method object.
4. Call Method.invoke() with the instance of the subclass which I wanted to call the method on.
Unfortunately, when I got to step 4, I saw this in the documentation for Method.invoke:
"If the underlying method is an instance method, it is invoked using dynamic method lookup as documented in The Java Language Specification, Second Edition, section 15.12.4.4; in particular, overriding based on the runtime type of the target object will occur."
Is there any way to externally access the functionality of a super method implementation on a subclass that overrides it? It seems like there should be...
In case you are wondering, the reason I am doing this is I am trying to implement a deep clone method. However, I would like any class to be able to call the deep clone method by passing themselves as an argument to a static method -- that way you don't have to worry about subclasses inheritting clone or anything like that. The code would look something like this (however it seems that according to the docs, this would result in an infinite recursion because when the Object.clone() method is invoked, it would actually resolve to the MyDeepCloneableObject.clone() method (which would call the utility function, which would invoke the Object.clone() again etc. etc.)):
public class MyDeepCloneableObject implements Cloneable {
public Object clone() {
return ObjectUtil.deepClone(this);
public class ObjectUtil {
private static final Method OBJECT_CLONE_METHOD;
private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
static {
//Set the OBJECT_CLONE_METHOD
try {
OBJECT_CLONE_METHOD =
Object.class.getDeclaredMethod("clone", EMPTY_CLASS_ARRAY);
OBJECT_CLONE_METHOD.setAccessible(true);
} catch (NoSuchMethodException e) {
System.out.println(e.toString());
e.printStackTrace();
} catch (RuntimeException e) {
System.out.println(e.toString());
e.printStackTrace();
public static Object deepClone(Cloneable object, int levels) {
Object clone;
try {
clone = OBJECT_CLONE_METHOD.invoke(object, EMPTY_OBJECT_ARRAY);
} catch (IllegalAccessException e) {
System.out.println(e.toString());
e.printStackTrace();
return null;
} catch (InvocationTargetException e) {
System.out.println(e.toString());
e.printStackTrace();
return null;
} catch (RuntimeException e) {
System.out.println(e.toString());
e.printStackTrace();
return null;
// Use more reflection on fields of clone to implement deep clone
}In your example the clone method is not creating a clone, just returning a new instance of an object of the same type. In both cases the default shallow clone method should be implemented as follows:
public Object clone() {
//Call Object.clone()
return super.clone;
By doing so, any subclasses will also have their fields copied when clone() is called.
From the javadocs for Object.clone():
"The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable. Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation."
Now as to how the parent is supposed to know about fields in subclasses, the implementation of clone is implemented in a native method in Object, so the JVM can pretty much know anything about the subobject as long as it has a reference to it. Further, if I wanted to make my own implementation, I could using reflection:
public Object clone() {
// Get the runtime class of this object, note that the runtime class
// may be a subclass of the class in which this clone method is defined
Class objectClass = this.getClass();
//Get all of the fields in this class and it's super classes
List fieldsList = new ArrayList();
while (objectClass != null) {
Field[] fields = objectClass.getDeclaredFields();
for (int j =0; j < fields.length; j++) {
fieldsList.add(fields[j]);
objectClass = objectClass.getSuperClass();
//Now I can create a new instance of the runtime class and set
//all of its fields appropriately
However, I'm sure the JVM's implementation is far more efficient.
I have not benchmarked serialization. However, all the steps in my procedure would have to be done for serialization anyway (i.e. get list of all fields, instantiate equivalent field values and set them in the new object), but serialization also needs to convert everything to a byte representation and then parse it out again. Furthermore, serialization will perform a fully deep clone, where as I only want a one level deep clone (or two depending on how you think of it -- i.e. not a shallow copy of references (as Object.clone(0 does), but a copy of direct fields and containers (i.e. Maps and Collections in fields should be cloned, but not objects in the Maps and Collections). So if an object has a field which is a List and the List field contains 1 entry, and the object is cloned, then subsequent modifications to the List field in the cloned object are not reflected in the original object's List field and vice versa (i.e. the 1 entry is removed in the original , but remains in the clone's version of the List field). -
Creation of a static class with private methods
I'm new to java programming and am working on a project where I need to have a static class that does a postage calculation that must contain 2 private methods, one for first class and one for priority mail. I can't seem to figure out how to get the weight into the class to do the calculations or how to call the two private methods so that when one of my other classes calls on this class, it retrieves the correct postage. I've got all my other classes working correct and retrieving the information required. I need to use the weight from another class and return a "double". Help!!!
Here's my code:
* <p>Title: Order Control </p>
* <p>Description: Order Control Calculator using methods and classes</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Info 250, sec 001, T/TH 0930</p>
* @author Peggy Blake
* @version 1.0, 10/29/02
import javax.swing.*;
public class ShippingCalculator
static double firstClass, priorityMail;
//how do I get my weight from another class into this method to use??? not sure I understand how it works.
public static double ShippingCalculator(double weight)
String responseFirstClass;
double quantity, shippingCost;
double totalFirstClass, firstClass, priorityMail, totalShipping;
double priorityMail1 = 3.50d;//prioritymail fee up to 1 pound
double priorityMail2 = 3.95d;//prioritymail fee up to 2 pounds
double priorityMail3 = 5.20d;//prioritymail fee up to 3 pounds
double priorityMail4 = 6.45d;//prioritymail fee up to 4 pounds
double priorityMail5 = 7.70d;//prioritymail fee up to 5 pounds
quantity = 0d;//ititialization of quantity
// weight = 0d;//initialization of weight
// shippingCost = 0d;
//calculation of the number of items ordered..each item weights .75 ounces
quantity = (weight/.75);
if (quantity <= 30d)
//add 1 ounce to quantities that weigh less than 30 ounces
weight = (weight + 1);
else
//add 2 ounces to quantities that weigh more than 30 ounces
weight = (weight + 2);
if (weight > 80d)
//message to orderclerk ..order over 5 lbs, cannot process
JOptionPane.showMessageDialog(null, "Order exceeded 5 lbs, cannot process");
//exit system, do not process anything else
System.exit (0);
else
if (weight < 14d)
//send message to customer: ship firstclass or priority, y or n
responseFirstClass = JOptionPane.showInputDialog(null, "Ship first class? y or n?");
if (responseFirstClass.equals("y"))
//compute FirstClass shipping cost
totalFirstClass = ((weight - 1) * .23d) + .34d;
firstClass = totalFirstClass;
else
//compute PriorityMail cost for orders less than 14 ounces
priorityMail = (priorityMail1);
else
if (weight <=16d)
//compute totalshipping for orders up to 16 ounces
priorityMail = (priorityMail1);
else
if (weight <=32d)
//compute totalshipping for orders up to 32 ounces
priorityMail = (priorityMail2);
else
if (weight <=48d)
//compute totalshipping for orders up to 48 ounces
priorityMail = (priorityMail3);
else
if (weight <= 64d)
//compute totalshipping for orders up to 64 ounces
priorityMail = (priorityMail4);
else
//compute totalshipping for orders up to 80 ounces
priorityMail = (priorityMail5);
priorityMail = 0d;
firstClass = 0d;
firstClassMail ();
priorityMailCost ();
//I think this is where I should be pulling the two methods below into my code, but can't figure out how to do it.
shippingCost = priorityMail + firstClass;
return (shippingCost);
}//end method calculate shipping
private static double firstClassMail()//method to get first class ship cost
return (firstClass);
}//end method firstclass shipping
private static double priorityMailCost()//method to get priority mail cost
return (priorityMail);
}//end method priorityMail
}//end class shipping calculatorpublic class A {
public String getXXX () {
public class B {
A a = new A();
public void init () {
a.getXXX();
} -
Best practice for calling application module methods and plsql code
In my application I am experiencing problems with connection pooling, I seem to be using a lot of connections in my application when only a few users are using the system. As part of our application we need to call database procedures for business logic.
Our backing beans, call methods on the application module which in turn call a database procedure. For instance in the backing bean we have code like this to call the application module method.
// Calling Module to generate new examination/test.
CIGAppModuleImpl appMod = (CIGAppModuleImpl)Configuration.createRootApplicationModule("ky.gov.exam.model.CIGAppModule", "CIGAppModuleLocal");
String testId = appMod.createTest( userId, examId, centerId).toString();
AdfFacesContext.getCurrentInstance().getPageFlowScope().put("tid",testId);
// Close the call
System.out.println("Calling releaseRootApplicationModule remove");
Configuration.releaseRootApplicationModule(appMod, true);
System.out.println("Completed releaseRootApplicationModule remove");
return returnResult;
In the application module method we have the following code.
System.out.println("CIGAppModuleImpl: Call the database and use the value from the iterator");
CallableStatement cs = null;
try{
cs = getDBTransaction().createCallableStatement("begin ? := macilap.user_admin.new_test_init(?,?,?); end;", 0);
cs.registerOutParameter(1, Types.NUMERIC);
cs.setString(2, p_userId);
cs.setString(3, p_examId);
cs.setString(4, p_centerId);
cs.executeUpdate();
returnResult=cs.getInt(1);
System.out.println("CIGAppModuleImpl.createTest: Return Result is " + returnResult);
}catch (SQLException se){
throw new JboException(se);
finally {
if (cs != null) {
try {
cs.close();
catch (SQLException s) {
throw new JboException(s);
I have read in one of Steve Muench presentations (Oracle Fusion Applications Team' Best Practises) that calling the createRootApplicationModule method is a bad idea, and to call the method via the binding interface.
I am assuming calling the createRootApplicationModule uses much more resources and database connections that calling the method through the binding interface such as
BindingContainer bindings = getBindings();
OperationBinding ob = bindings.getOperationBinding("customMethod");
Object result = ob.execute()
Is this the case? Also is using getDBTransaction().createCallableStatement the best way of calling database procedures. Would it be better to expose plsql packages as webservices and then call them from the applicationModule. Is this more efficient?
Regards
OrlandoThanks Shay, this is now working.
I successfully got the binding to the application method in the pagedef.
I used the following code in my backing bean.
package view.backing;
import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;
public class Testdatabase {
private DCBindingContainer bindingContainer;
public void setBindingContainer (DCBindingContainer bc) {this.bindingContainer = bc;}
public DCBindingContainer getBindingContainer() {return bindingContainer;}
public static String validateUser()
// Calling Module to validate user and return user role details.
System.out.println("Getting Binding Container from Home Backing Bean");
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
System.out.println("Obtain binding");
OperationBinding operationBinding = bindings.getOperationBinding("calldatabase");
System.out.println("Set username parameter");
operationBinding.getParamsMap().put("p_userId",userId);
System.out.println("Set password parameter");
operationBinding.getParamsMap().put("p_testId",examId);
Object result = operationBinding.execute();
System.out.println("Obtain result");
String userRole = result.toString();
System.out.println("Result is "+userRole);
} -
Code to call friends class method
Hello,
Please can someone help me with friends class method call. in global classes
Thanks
Megh
Moderator message: please search for available information/documentation before asking.
Edited by: Thomas Zloch on Nov 2, 2010 5:29 PMWhat is your exact problem?
The class whose private and protected section you want to use, needs declaration of its friends. You do it in Friends tabstrip. All these classes are allowed then to access these "hiden" sections from outside of the class. Below example how it works with local classes. For global ones the principle stays the same
CLASS lcl_main DEFINITION DEFERRED.
CLASS lcl_other DEFINITION FRIENDS lcl_main. "only LCL_MAIN can use may hiden sections
PROTECTED SECTION.
METHODS prot_meth.
PRIVATE SECTION.
METHODS priv_meth.
ENDCLASS.
CLASS lcl_other IMPLEMENTATION.
METHOD prot_meth.
WRITE / 'This is protected method of class lcl_other'.
ENDMETHOD. "prot_meth
METHOD priv_meth.
WRITE / 'This is private method of class lcl_other'.
ENDMETHOD. "priv_meth
ENDCLASS.
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
METHODS call_friends_methods.
PRIVATE SECTION.
DATA mr_my_friend TYPE REF TO lcl_other.
ENDCLASS.
CLASS lcl_main IMPLEMENTATION.
METHOD call_friends_methods.
CREATE OBJECT mr_my_friend.
mr_my_friend->prot_meth( ).
mr_my_friend->priv_meth( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA gr_main TYPE REF TO lcl_main.
CREATE OBJECT gr_main.
gr_main->call_friends_methods( ).
Regards
Marcin -
Private methods Importing parameter cannot be changed error
Hi Guys,
I have this scenario where I have a private method inside a class which is having an error "Field SAPMF02K cannot be changed".
here is the code for the private method call.
call method create_bdc_dynpro
importing IM_PROGRAM = 'SAPMF02K'
IM_DYNPRO = '0100'.
code of the method
data: wa_bdcdata type bdcdata.
CLEAR wa_bdcdata.
wa_bdcdata-program = im_program.
wa_bdcdata-dynpro = im_dynpro.
wa_bdcdata-dynbegin = at_true.
APPEND wa_bdcdata to at_bdcdata.
Hope you can help
Thanks!Howdy,
I think you have your importing/exporting the wrong way round.
The method call should be:
call method create_bdc_dynpro
exporting IM_PROGRAM = 'SAPMF02K'
IM_DYNPRO = '0100'.
And of course in the method definition they should be importing parameters.
Cheers
Alex -
How to call a private attribute from a funcion module?
Guys,
I am trying to call a private attribute but of course it does not recognize the attribute. I am not very familiar with ABAP Objects, so i need some help on this. What is the solution as i need to get values from the fields which are inside the private attribute of the class CL_HRPA_INFOTYPE_CONTAINER. The private attribute name is a_primary_record.
Any help will be appreciated.
Thanks
NahmanHi Sushanth,
We save the text not as fields in a ztable directly but as a text.Please check the format below since it is based on a working code....
first you need to create a text in s010 transaction...
there should be some key based on which you plan to save the text..imagine it is Purchase order then..PO+item numner is always unique.eg:0090010(900PO/item10).so in the code you can append these two and they will be unique..so you can always retrieve them,overwrite,save them anytime you need
**************data declarations
TYPES: BEGIN OF TY_EDITOR,
EDIT(254) TYPE C,
END OF TY_EDITOR.
data: int_line type table of tline with header line.
data: gw_thead like thead.
data: int_table type standard table of ty_editor.
****************fill header..from SO10 t-code..when you save you need the unique key..youfill it here and pass it in save_text function module
GW_THEAD-TDNAME = loc_nam. " unique key for the text -> our unique key to identify the text
GW_THEAD-TDID = 'ST'. " Text ID from SO10
GW_THEAD-TDSPRAS = SY-LANGU. "current language
GW_THEAD-TDOBJECT = 'ZXXX'. "name of the text object created in SO10
*To Read from Container and get data to int_table
CALL METHOD EDITOR ->GET_TEXT_AS_R3TABLE
IMPORTING
TABLE = int_table
EXCEPTIONS
ERROR_DP = 1
ERROR_CNTL_CALL_METHOD = 2
ERROR_DP_CREATE = 3
POTENTIAL_DATA_LOSS = 4
others = 5.
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop data from int_table and save to int_line-tdline appending it.
*save the text
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
HEADER = GW_THEAD
TABLES
LINES = InT_LINE
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
OBJECT = 4
OTHERS = 5.
IF SY-SUBRC 0.
ENDIF.
*To pass to Container
CALL METHOD EDITOR ->SET_TEXT
hope that the above sample with helps you solve the problem
Please check and revert,
Reward if helpful
Regards
Byju
Maybe you are looking for
-
My HP2840 laser jet All-InOne has been telling me for 6 months that I need a new drum. I was waiting until I saw an issue with my print quality (which I never had a problem) and now my printer will not work unless I replace the drum. A friend told me
-
Unable to disable 20gb iPod 'enable disk use' Disc in iTunes7
Hello, i got this problem, when i connected my old 20gb iPod on to my computer which now has iTunes 7 installed i wont be able to turn off "Enable disc use" check button. Why? Resetting the iPod wont help, restoring the software to iPod wont solve th
-
Adode Photoshop Album Starter Edition Lock Out
HI I have been using a very old product for years called Adobe Photoshop Album Starter Edition 3.2, however it has locked me out of my old photos of my children. Does anyone know how to get in to access old photos as it is saying it is past registrat
-
Vertical Scrolling problem in Safari
I'm currently having an odd vertical scrolling problem in Safari. This issue is not reproduced in Chrome or Firefox. I've been able to reproduce this issue doing something very simple: I have a browser wide rectangle with a solid color. Beneath that
-
I am trying to convert a file to PDF and get the message that it is taking to long to process. How do I convert larger files?