Calling a method in an owning object

I have an application that involves an object (B) that is a member (not a sub-class) of another object (A). Within the owned object (B) I want to call up a method from the owning object A. E.g I would like to do something like this:
class A
object B; // B is a member of A
methodX( )
class B
owner.methodX( ); // invoke the methodX that is a member of object A.
Is this possible and how can i do it?

No, there is no implicit reference to an "owning" object. Think about the following code:
class Parent {
  Child child
  Parent(Child child) { this.child = child; }
  void doSomething() {}
class Child {
class Test {
public static void main(String[] args) {
   Child child = new Child();
   Parent p1 = new Parent(child);
   Parent p2 = new Parent(child);
}So the two instances of Parent both have a reference to the same instance of Child. Which one is the "owner"?
You'll have to explicitly give your "child" object a reference to the "owner" object in order to call methods on it

Similar Messages

  • Calling a method that returns an object Array

    Hello.
    During a JNICALL , I wish to call a method which returns an object array.
    ie my java class has a method of the form
    public MyObject[] getSomeObjects(String aString){
    MyObject[] theObjects=new MyObject[10];
    return theObjects
    Is there an equivalent to (env)->CallObjectMethod(...
    which returns a jobjectArray instead of a jobject, and if not could somebody suggest a way around this.
    Thanks,
    Neil

    I believe an array oj jobjects is also a jobject. You can then cast it to another class.

  • How to call the method of a Business Object?

    Hi,
    Can someone guide me how to call the method of a business object?
    For example, I want to use the method SalesDocument.Copy of the Business Object VBAK. How can I do that? If you are familiar with any similar scenario please help.
    Regards,
    Renjith Michael.

    Hi
    double click on the copy  and
    go to abap tab
    there u can get functionmodule name
    u can call that
    Rewards if helpful

  • Calling parent method from within child object

    Hello,
    A quick question! Is it possible to call a method in a parent object from within a child object.By child object I mean an object that was instantiated within the parent object.
    Thanks.

    A quick question! Is it possible to call a method in a
    parent object from within a child object.By child
    object I mean an object that was instantiated within
    the parent object.Since you are using ambiguous terminology, it would be much better if you provided a small sample of your code to avoid confusion. I am guessing that you are actually talking about an inner class when you say child class.
    If that is correct, then you can do something like this:
    class Parent {
      void foo() {}
      void bar() {}
      class Child {
        void foo() {}
        void test() {
          bar(); // No conflicts, just call the Parent method
          Parent.this.foo(); // Use explicit qualification to avoid conflicts.

  • Calling a method from a UICommand Object

    How do I call an action method from a UICommand object?
    I create a HtmlCommandLink in my backing bean, and I think I should be setting the action, but with what? The method takes a MethodBinding but I can't find much detail on how to get that. I just want to call a method like linkAction1_action() in the example below, but you cannot pass a method.
    public class Page1 extends AbstractPageBean {
      private HtmlPanelGroup panel = new HtmlPanelGroup();
      public HtmlPanelGroup getPanel() {
        return panel;
      public void setPanel(HtmlPanelGroup panel) {
        this.panel = panel;
      public Page1() {
        HtmlCommandLink link = new HtmlCommandLink();
        link.setAction(/* what do I put here */);
        this.panel.getChildren().add(link);
      public String linkAction1_action() {
        return "GoBack";
    }

    OK. A couple days later and I am able to answer my
    own question. Anyway, I will lay it out there for
    anyone interested. This worked for me...
    public class Page1 extends AbstractPageBean {
    private HtmlPanelGroup panel = new HtmlPanelGroup();
    public HtmlPanelGroup getPanel() {
    return panel;
    public void setPanel(HtmlPanelGroup panel) {
    this.panel = panel;
    public Page1() {
    HtmlCommandLink link = new HtmlCommandLink();
    link.setAction(
    FacesContext.getCurrentInstance()
    .getApplication()
    .createMethodBinding("#{Page1.linkAction1_action}",
    new Class[0]));
    this.panel.getChildren().add(link);
    public String linkAction1_action() {
    return "GoBack";
    Since you're setting the action from within the Page1 object, why don't you create a method binding manually? This will be much more performant that using the application to create and EL-based binding.
    Try:
    link.setAction(new MethodBinding()
          public Object invoke(FacesContext facesContext, Object[] objects) throws EvaluationException, MethodNotFoundException
            return linkAction1_action();
          public Class getType(FacesContext facesContext) throws MethodNotFoundException
            return String.class;
    });Note that you also avoid any naming convention - you do not require your Page1 object to be configured as a managed bean "Page1".

  • RMI server calling a method on a client object ?

    Hi All,
    I am writing a client - server application and my intention is to use RMI for comunication.
    When the client has to retrive datas from the server it's easy, but let's suppose that the server has to inform the client about some updates about the data, how can I do that?
    I do not want the client keeping calling methods on the server to see if there is something of new :(
    Is there some way to pass an OutputStream to the client, so when the server writes someting, the client reads it ? ( the client should have a thread which keeps reading)
    Or maybe I could pass a reference of a client class to the server so when the server needs to inform the client, it calls a method on this class?
    thanks, Fab

    The client can be a Remote Object to, passed as a remote reference when calling the server.
    Basically all you'll have to do is "register" the client on the serverside.
    Your serverside class would the have a:
    register(RemoteClient client) method.
    The server could the use this remote reference for callbacks.
    So, all you have to do is declare the Remote Interface for the client and implement it, and the call the servers myRemoteServer.register(this).
    If you've already implemented the server, it's a peace of cake to enhance your client.

  • Generic approach to call a method for any business object

    My requirement is to call the DISPLAY method of a business object when I have the objectType and objectId.
    Say I have BUS2012 and Id 4500001111, now I want to call a method which invoke the DISPLAY method for this object with objectId (say ME_DISPLAY_PURCHASE_DOCUMENT for purchase order). I even have the key fields for the business object.
    Is it possible ?
    Thanks in advance !
    Ruhi Hira

    Hi Ruhi,
               Yes you can call the method for display.Before we can do that we need to fix the procedure for the calling of the method.If you want to call it programitically or you want to call it in task builder or you want to use it as a activity in the work item.we can check for the BUSXXXXXX what ever number is there and we can also check for the activity type pre defined by SAP for it.If suppose you dont have the activity we can create the method for the BOR object type using SWO1.May be it helps your query.
    Have a best day ahead.

  • Calling a method on a remote object to ping the server

    I need a generic way of pinging a server to check if it is still there. Assuming I don't know the methods defined in the remote interface of the server, one way to achieve this would be to invoke one of the Object methods on the server and catch any exceptions. To do this I could call invoke on the RemoteRef interface, but this requires the opnum of the method, and I don't know what these are for the Object methods. Can anyone help, or suggest a better method for pinging the server ?
    William
    For example:
    // my remote service
    Remote service;
    // obtain remote ref
    RemoteRef ref = ((RemoteObject) service).getRef();
    // invoke Object method e.g. hashCode
    ref.invoke( ... );

    if you mean a real ping like windows/unix send from the ping command then it can not be done from jave. you can either connect to the echo port and test it that way or you would have to make a native call.

  • Calling Java Method on an Object?????

    It is quite clear how to call a method that passes an argument in Express i.e.
    <invoke name='methodName' class='com.waveset.ui.ClassName'>
    <ref>argument</ref>
    </invoke>
    Essentially this is the same as calling
    methodName( argument );
    How is is possible to call a method in a class that operates on the object i.e.
    object.methodName( );
    i.e.
    com.waveset.object.GenericObject has a method called toMap( ) which returns the GenericObject back as a Map.
    A User View is a GenericObject so how do you call a method on the User object i.e.
    <ref>user</ref>.someMethod( ); or user.toMap( ); rather than
    <invoke name='toMap' class='com.waveset.object.GenericObject'>
    <ref>user</ref>
    </invoke>
    This will not work because there is no method called toMap that takes a GenericObject as a argument.
    I can't find any documentation that addresses this issue.

    The invoke tag is handled differently depending on its arguments.
    <invoke name='methodName' class='com.something'>
       <ref>someVariable</ref>
    </invoke>is calling static method methodName on class com.something and passes someVariable as an argument
    If you leave the class name out of the invoke, it calls the method on the first variable within the tag (the object). The remaining variables act as arguments to the method.
    Here's a trivial example. It creates a HashMap and then performs a 'get' on one of its keys (name)
    <invoke name='get'>
        <new class='java.util.HashMap'>
            <map>
                 <s>name</s>
                 <s>Darth Vader</s>
                 <s>type</s>
                 <s>villain</s>
            </map>
        </new>
        <s>name</s>
    </invoke>Here's a more complex example:
    <new class='com.waveset.object.Resource'>
         <invoke name='toXml'>
                <invoke name='getObject' class='com.waveset.ui.FormUtil'>
                       <ref>:display.session</ref>
                       <s>Resource</s>
                       <s>Active Directory Resource Adapter</s>
                </invoke>
         </invoke>
    </new>This calls the static getObject method returns a com.waveset.object.PersistentObject, which in turn has toXML invoked on it (returning a java.lang.String serialized version of the object) which is then used as the argument for constructing a com.waveset.object.Resource object.
    Jason

  • Calling abstract method from method, where is functional code

    HI All
    I'm trying to find the actual code that is responsible for the play() method to play sound of Applet or of AudioClip. I looked in the source files and found that the two are circle-refering to each other. Audio clip is an interface so it doesnt specify any code for how the method play() should work. That should be left to the classes that implement it. But the play(URL) method of Applet refers to the the AudioClips method:public void play(URL url) {
    AudioClip clip = getAudioClip(url);
    if (clip != null) {
    clip.play();
    So where is the real code for the method?
    This seems to be very normal because almost all methods in Applet where refering to interfaces like AppletContext an AppletStub.
    How does this work? Can anybody explain?

    This is a design-pattern called "factory-method". The factory-method (here getAudioClip(URL)) has a return value of an interface but really returns an object of a class implementing this interface. The user can call this factory-method and then call the methods of the returned object without knowing wich class this methods implements. If you want to change the implementing class later, you only have to build a new class and to change the factory-method - but the code of the "user" will not change.

  • Drag & Drop, call a method if list changes.

    Hi there,
    I have two spark lists,backed up by Array Collections, both of which accept drag & drop either to move objects between them or to reorder within the lists. I have a method which is called on drop which resets some properties of the object to 0, this works as expected...
    protected function list_dragDropHandler(event:DragEvent):void
         if(event.action != DragManager.NONE)
              var item:Object = event.dragSource.dataForFormat("itemsByIndex")[0];
              item.someProperty = 0;
                    item.someOtherProperty = 0;
    What I would like to do is only call this method only when the objects are moved to another list, currently it is called when I reorder within the same list too, could someone please point me in the right direction with this?
    Many Thanks,
    J.

    Ned,
    Thanks for your prompt reply, you gave me the idea I needed here. As I'm dragging things about by their item renderers a creationComplete is fired when they end up in new places, I used a mouseDown event (This happens when one drags, it's as good an event as any to use I guess) to grab the current list and I compare that to the list I get when creationComplete fires. These are stored in the object and compared by the dragDrop event handler...
    Probably an inelegant take on what you were suggesting, but it works...
    J.

  • Getting an error when calling the method of the bean

    Hi,
    I have the following problem:
    From my action class I'm calling a method on EJB through Business Object and getting the following error:
    org.apache.struts.action.RequestProcessor Unhandled Exception thrown: class gov.nyc.fisa.wbas.exceptions.ServerException
    [3/6/08 13:53:44:700 EST] 1acdd938 WebGroup E SRVE0026E: [Servlet Error]-[SERVER EXCEPTION CALLING searchBenefitGroups() METHOD ]: gov.nyc.fisa.wbas.exceptions.ServerException: SERVER EXCEPTION CALLING searchBenefitGroups() METHOD
    The following are parts of my code:
    In Action Class:
    BenefitGroupBO bo = new BenefitGroupBO();
    BenefitGroupsColView cView = new BenefitGroupsColView();
    try{
        cView = bo.searchBenefitGroups(transferObject,true);
    catch (ServerException e){
        throw new ServerException("SERVER EXCEPTION CALLING searchFunds() METHOD ",e);
    In Business Object:
    private BenefitGroupImpl benGrpImpl = null;
        try{
               System.out.println("1. BenefitGroupBO - searchBenefitGroups()");
               collectionView = benGrpImpl.searchBenefitGroups(transferObject, isSearch);
               System.out.println("2. BenefitGroupBO - searchBenefitGroups()");
    catch (RemoteException e){
                throw new ServerException("Remote exception calling BenefitGroupImplBean: searchBenefitGroups()", e);
    .....It never executes the second print statement in the method
    In Remote Interface:
    public BenefitGroupsColView searchBenefitGroups(BenefitGroupVO transferObject, boolean isSearch)
                                                                           throws ServerException, java.rmi.RemoteException;
    In the EJB
    public BenefitGroupsColView searchBenefitGroups(BenefitGroupVO transferObject, boolean isSearch){
                                                                        throws ServerException                
             System.out.println("1. BenefitGroupImplBean - searchBenefitsGroups() method");
             BenefitGroupsColView collectionView = new BenefitGroupsColView();
             System.out.println("2. BenefitGroupImplBean - searchBenefitsGroups() method");
              return collectionView;
    .....It never executes first Print statement in that method and I do not think it ever goes into the actual EJB class.
    Can anyone tell me what am I doing wrong?
    Thank you
    Edited by: SolutionsQuest on Mar 6, 2008 11:14 AM
    Edited by: SolutionsQuest on Mar 6, 2008 11:15 AM

    Hi,
    Refer below threads:
    You are trying to access a page that is no longer active
    You are trying to access a page that is no longer active.
    You are trying to access a page that is no longer active.
    --Sushant                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Urgent - calling EJB methods from thread

    Dear all
    I am aware of EJB spec that does not permit developer managed threads within EJB components. However, I need to call EJB methods from my own thread. Hence, it there any way to to call EJB methods from developer managed thread ?? If yes, please advice me, thanks in advance and your help will be appriciated.
    Hava a nice day

    You can call EJB's from your threads. Your thread will act as the client and the call will to EJB will be same as any other client invoking EJB's. Hope I understand your question !.

  • Calling java method from c function

    Hi,
    I have been through some forums and tutorials, but nothing helps me yet.
    Here's my problem : I want to access java funtion from c function.
    <code java>
    public class MyClass {
    public int oneMethod() {
    return 5;
    </code java>
    <code c++>
    void main(int argc, char *argv[]) {
    // creation of JVM -> no problem
    cls = (env)->FindClass("MyClass");
    if (cls != 0) {
    // it finds the class
    mid = (env)->GetMethodID(cls, "oneMethod", "()I");
    if (mid != 0) {
    // it finds the method
    intReturn = (env)->CallIntMethod(cls, mid);
    printf("Result of oneMethod: %d \n", initReturn);
    </code c++>
    the initReturn gives me 0, and not 5. So what do you think the mistake is ?
    Should I pass by the GetClassObject() funtion, but in this case, what object would I pass in reference since I'm using a call from c to java.
    Thanks a lot for your response, and Happy new Year to all the comunity.

    1. You are - apparently - trying to call a method of a java object.
    2. But you are instead making the call on a class.
    3. You can do one of the following:
    o Pass a reference to the object as you call C.
    o Call some other java method (maybe static) that gets you a reference to a java object.
    o Use JNI to call a java constructor to create a java object.
    o Change your code to get the class object and call a static method.

  • Telling which class called your method

    Does anybody know a way you can tell which class is calling your method? I mean:
    class A {
    public static void main(String args[]) {
    new A.doIt();
    void doIt() {
    B b = new B();
    b.callMe();
    class B {
    public void callMe() {
    String whoDidIt;
    whoDidIt=[stuff i'm asking for];
    System.out.println("I was called from an instance of class " + whoDidIt);
    How can I get that code to print "I was called from an instance of class A"???
    Lots of thanks in advance

    Pass the calling object to callMe as a parameter, egB b = new B();
    b.callMe(this);callMe becomes:
    public void callMe(Object caller)
       System.out.println("I was called from an instance of class " + caller.getClass());
    }Of course, there is nothing to stop anyone who calls the method passing a different object and confusing callMe.

Maybe you are looking for