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).

Similar Messages

  • Error while calling a super class public method in the subclass constructor

    Hi ,
    I have code like this:
    CLASS gacl_applog DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS:
                create_new_a
                   IMPORTING  pf_obj       TYPE balobj_d
                              pf_subobj    TYPE balsubobj
                              pf_extnumber TYPE string
                   EXPORTING  pfx_log_hndl TYPE balloghndl
                   EXCEPTIONS error
    ENDCLASS.
    CLASS gacl_applog IMPLEMENTATION.
      METHOD create_new_a.
        DATA: ls_log TYPE bal_s_log.
      Header aufsetzen
        MOVE pf_extnumber TO ls_log-extnumber.
        ls_log-object     = pf_obj.
        ls_log-subobject  = pf_subobj.
        ls_log-aluser     = sy-uname.
        ls_log-alprog     = sy-repid.
        ls_log-aldate     = sy-datum.
        ls_log-altime     = sy-uzeit.
        ls_log-aldate_del = ls_log-aldate + 1.
        CALL FUNCTION 'BAL_LOG_CREATE'
             EXPORTING
                  i_s_log      = ls_log
             IMPORTING
                  e_log_handle = pfx_log_hndl
             EXCEPTIONS
                  OTHERS       = 1.
        IF ( sy-subrc NE 0 ).
          MESSAGE ID      sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING error.
        ENDIF.
      ENDMETHOD.
    CLASS gcl_applog_temp DEFINITION INHERITING FROM gacl_applog.
      PUBLIC SECTION.
        DATA: log_hndl   TYPE balloghndl READ-ONLY
            , t_log_hndl TYPE bal_t_logh READ-ONLY
        METHODS: constructor
                   IMPORTING  pf_obj       TYPE balobj_d
                              pf_subobj    TYPE balsubobj
                              pf_extnumber TYPE string
                   EXCEPTIONS error
               , msg_add      REDEFINITION
               , display      REDEFINITION
    ENDCLASS.
    CLASS gcl_applog_temp IMPLEMENTATION.
      METHOD constructor.
        CALL METHOD create_new_a
               EXPORTING  pf_obj       = pf_obj
                          pf_subobj    = pf_subobj
                          pf_extnumber = pf_extnumber
               IMPORTING  pfx_log_hndl = log_hndl.
        IF ( sy-subrc NE 0 ).
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING error.
        ENDIF.
      ENDMETHOD.
    A public method of Super class has been called from the constructor of the sub class. we are getting the syntax error :
    ' In the constructor method, you can only access instance attributes, instance methods, or "ME" after calling the constructor of the superclass…'
    Can you please suggest how to change the code with out affecting the functioanlity.
    Thank you ,
    Lakshmi.

    Hi,
    Call that method by instance of Subclass.   OR
    SUPER-->method.
    Read very useful document
    Constructors
    Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class. There are two types of constructors - instance constructors and static constructors. Constructors are methods with a predefined name. To use them, you must declare them explicitly in the class.
    The instance constructor of a class is the predefined instance method CONSTRUCTOR. You declare it in the public section as follows:
    METHODS CONSTRUCTOR
            IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL]..
            EXCEPTIONS.. <ei>.
    and implement it in the implementation section like any other method. The system calls the instance constructor once for each instance of the class, directly after the object has been created in the CREATE OBJECT statement. You can pass the input parameters of the instance constructor and handle its exceptions using the EXPORTING and EXCEPTIONS additions in the CREATE OBJECT statement.
    The static constructor of a class is the predefined static method CLASS_CONSTRUCTOR. You declare it in the public section as follows:
    CLASS-METHODS CLASS_CONSTRUCTOR.
    and implement it in the implementation section like any other method. The static constructor has no parameters. The system calls the static constructor once for each class, before the class is accessed for the first time. The static constructor cannot therefore access the components of its own class.
    Pls. reward if useful....

  • Calling a particular Method of all subclass from a super class

    hi
    I have a class 'A' which is a super class for 'B' ,'C' , 'D'
    my main method is in the class Main and while on the run i am calling methods of B,C,D form this main class.
    but as the first step of execution i need to call a init method which has been defined in all the sub-classes. and there can be any no of sub-classes and all will have the init method and i have to call the init method for all classes. is this possible to do that in runtime. ie i wil not be knowing the names of sub-classes.
    thanks
    zeta

    Sorry if i had mislead you all.
    I am not instantiating from my super class.
    as mjparme i wanted one controller class to do the
    init method calls
    so i got it working from the link you gave.
    URL url = Launcher.class.getResource(name);
    File directory = new File(url.getFile());
    This way i can get all the classes in that
    in that package
    and from reflection i can get whether it is
    her it is a sub class of the particular super class
    and i can call the init methods by making the init
    methods static
    thanks for the help
    zetaThis is a rather fragile solution.
    If the problem is one of knowing which subclasses exist, I would suggest specifying them explicitly via configuration (system property or properties file or whatever).
    One thing that's not entirely clear to me: Is the init going to be called once for each subclass, or once for each instance of each subclass? It sounds to me like it's once per class, but I want to make sure.

  • Calling super.method() from anonymous class

    Look at this:
    class SynchronizedListModel
      extends DefaultListModel
      public void addElement(Object obj)  {
            final Object fObj = obj;
            Runnable rAdd = new Runnable()
                public void run() {
                    super.addElement(fObj);
            if (SwingUtilities.isEventDispatchThread())  {
                rAdd.run();
            } else {
                SwingUtilities.invokeLater(rAdd);
    }super in super.addElement(fObj); does not reference the addElement(obj) method of the DefaultListModel but of Object. So the compiler throws an error.
    How can I call the addElement method of DefaultListModel in the inner Runnable-class?
    Thanks for your help
    Ulrich

    I use a more compact semi-recursive form
        class SynchronizedListModel
        extends DefaultListModel
            public void addElement(final Object obj)
                if (SwingUtilities.isEventDispatchThread())
                    super.addElement(obj);
                else
                    SwingUtilities.invokeLater(new Runnable()
                        addElement(obj);
        }This is not true recursion because call the to addElement() is done in the Swing event thread not in the calling thread.

  • Error in calling Super() method cannot reference ...

    import javax.swing.JFrame;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class MyFrame extends JFrame {
    String St="Rayudu";
         JPanel jp1= new JPanel();
         JButton jb1=new JButton("Hello");     
    public MyFrame() {
    super("Document :" + St);
              jp1.add(jb1);
              getContentPane().add(jp1);
    //...Then set the window size or call pack...
    setSize(300,300);
    //Set the window's location.
         setLocation(300,300);
         setVisible(true);
    public static void main(String ar[])
    MyFrame mf=new MyFrame();
    mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    C:\java>javac My*.java
    MyFrame.java:11: cannot reference St before supertype constructor has been called
    super("Document :" + St);
    ^
    1 error
    Can anyone explain?
    thanks in advance.

    Change your constructor to take an argument of type String, pass this along to the super method when you call the new instance of your class in main. ie:
    public myFrame( String title ) {
    super( "Document: " + title );
    st = title; //if you need it in that String Object assign it here.
    //etc...
    public static void main( String args[] ) {
    new myFrame( "Testing" );
    Does this answer your question?

  • How to call a bean method from javascript event

    Hi,
    I could not find material on how to call a bean method from javascript, any help would be appreciated.
    Ralph

    Hi,
    Basically, I would like to call a method that I have written in the page java bean, or in the session bean, or application bean, or an external bean, from the javascript events (mouseover, on click, etc...) of a ui jsf component. I.e., I would like to take an action when a user clicks in a column in a datatable.
    Cheers,
    Ralph

  • Calling java instance methods in XSLT stylesheet

    HI
    I know this has been answered in this forum but I cnanot get it to work.
    Before calling the transform() method on my transformer instance I do the following
    transformer.setParameter( "Confirm", confirm)confim is an instance of one of my own classes. I want to get the
    XSLT stylesheet to call a method on this object. The method sig is
    public void setTitle(String title)Accordingly in my stylesheet I do the following
    <xsl:param name="Confirm"/>having already declared the java namespace in my stylesheet element as xmlns:java="java", and later on call the setTitle method
    <xsl:value-of select="java:setTitle($Confirm,$Title)/>where $Title is another var generated in the XSLT.
    This should work, right? Well I get an error
    'The first argument to the non-static Java function 'setTitle' is not a valid object reference.'But it is as I can do this
    <xsl:value-of select="$Confirm"/>Thanks
    Mark

    Hi !
    I've being trying to use a java class into xsl but without success.
    If anybody can help me to no how do I have to organize the files (.class, .xsl)????
    My organization is like this
    c:
    WEBAPP
    WEB-INF (here I have the .xml and .xsl)
    classes
    com
    example (here I have the .class)
    And I use it as follows:
    --------------------------------------xslextension_prueba.XSL------------------ ---------------------------
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:java="java"
    extension-element-prefixes="java"
    version="1.0">
    <xsl:output method="html"/>
    <xsl:template match="/">
    <html>
    <body bgcolor="#FFFFFF">
    <h2>The smoking calendar</h2>
    <h3>
    <xsl:value-of select="java:Date.new()"/>
    </h3>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    --------------------------------------------XML-------------------------------- ----
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="xslextension_prueba.xsl"?>
    <articles>
    <article>
    <title>Using Web Services</title>
    <author>T. Cowan</author>
    <date>11/30/01</date>
    <text>
    content of article.
    </text>
    </article>
    <article>
    <title>Java May Be Just a Fad</title>
    <author>J. Burke</author>
    <date>08/15/95</date>
    <text>
    content of article.
    </text>
    </article>
    </articles>
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!AND I GET THIS ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    E The URI java does not identify an external Java class
    THANKS FOR YOUR HELP......

  • Unable to call exported client methods of EJB session bean remote interface

    I am unable to call client methods of a BC4J application module deployed as a Session EJB to Oracle 8i at the client side of my multi-tier application. There is no documentation, and I am unable to understand how I should do it.
    A business components project has been created. For instance, its application module is called BestdataModule. A few custom methods have been added to BestdataModuleImpl.java file, for instance:
    public void doNothingNoArgs() {
    public void doNothingOneArg(String astr) {
    public void setCertificate(String userName, String userPassword) {
    theCertificate = new Certificate(userName, userPassword);
    public String getPermission() {
    if (theCertificate != null)
    {if (theCertificate.getPermission())
    {return("Yes");
    else return("No, expired");
    else return("No, absent");
    theCertificate being a protected class variable and Certificate being a class, etc.
    The application module has been tested in the local mode, made remotable to be deployed as EJB session bean, methods to appear at the client side have been selected. The application module has been successfully deployed to Oracle 8.1.7 and tested in the remote mode. A custom library containing BestdataModuleEJBClient.jar and BestDataCommonEJB.jar has been created.
    Then I try to create a client basing on Example Oracle8i/EJB Client snippet:
    package bestclients;
    import java.lang.*;
    import java.sql.*;
    import java.util.*;
    import javax.naming.*;
    import oracle.aurora.jndi.sess_iiop.*;
    import oracle.jbo.*;
    import oracle.jbo.client.remote.ejb.*;
    import oracle.jbo.common.remote.*;
    import oracle.jbo.common.remote.ejb.*;
    import oracle.jdeveloper.html.*;
    import bestdata.client.ejb.*;
    import bestdata.common.ejb.*;
    import bestdata.common.*;
    import bestdata.client.ejb.BestdataModuleEJBClient;
    public class BestClients extends Object {
    static Hashtable env = new Hashtable(10);
    public static void main(String[] args) {
    String ejbUrl = "sess_iiop://localhost:2481:ORCL/test/TESTER/ejb/bestdata.BestdataModule";
    String username = "TESTER";
    String password = "TESTER";
    Hashtable environment = new Hashtable();
    environment.put(javax.naming.Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    environment.put(Context.SECURITY_PRINCIPAL, username);
    environment.put(Context.SECURITY_CREDENTIALS, password);
    environment.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    BestdataModuleHome homeInterface = null;
    try {
    Context ic = new InitialContext(environment);
    homeInterface = (BestdataModuleHome)ic.lookup(ejbUrl);
    catch (ActivationException e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    System.exit(1);
    catch (CommunicationException e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    System.exit(1);
    catch (NamingException e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    System.exit(1);
    try {
    System.out.println("Creating a new EJB instance");
    RemoteBestdataModule remoteInterface = homeInterface.create();
    // Method calls go here!
    // e.g.
    // System.out.println(remoteInterface.foo());
    catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    It doesnt cause any errors. However, how must I call methods? The public interface RemoteBestdataModule has no such methods:
    void doNothingNoArgs();
    void doNothingOneArg(java.lang.String astr);
    void setCertificate(java.lang.String userName, java.lang.String userPassword);
    java.lang.String getPermission();
    Instead of that it has the following methods:
    oracle.jbo.common.remote.PiggybackReturn doNothingNoArgs(byte[] _pb) throws oracle.jbo.common.remote.ejb.RemoteJboException, java.rmi.RemoteException;
    oracle.jbo.common.remote.PiggybackReturn doNothingOneArg(byte[] _pb, java.lang.String astr) throws oracle.jbo.common.remote.ejb.RemoteJboException, java.rmi.RemoteException;
    oracle.jbo.common.remote.PiggybackReturn customQueryExec(byte[] _pb, java.lang.String aQuery) throws oracle.jbo.common.remote.ejb.RemoteJboException, java.rmi.RemoteException;
    oracle.jbo.common.remote.PiggybackReturn setCertificate(byte[] _pb, java.lang.String userName, java.lang.String userPassword) throws oracle.jbo.common.remote.ejb.RemoteJboException, java.rmi.RemoteException;
    oracle.jbo.common.remote.PiggybackReturn getPermission(byte[] _pb) throws oracle.jbo.common.remote.ejb.RemoteJboException, java.rmi.RemoteException;
    I cannot call those methods. I can see how they are called in BestdataModuleEJBClient.java file:
    public void doNothingNoArgs() throws oracle.jbo.JboException {
    try {
    oracle.jbo.common.remote.PiggybackReturn _pbRet = mRemoteAM.doNothingNoArgs(getPiggyback());
    processPiggyback(_pbRet.mPiggyback);
    if (_pbRet.isReturnStreamValid()) {
    return;
    catch (oracle.jbo.common.remote.ejb.RemoteJboException ex) {
    processRemoteJboException(ex);
    catch (java.rmi.RemoteException ex) {
    processRemoteJboException(ex);
    throw new oracle.jbo.JboException("Marshall error");
    However, I cannot call getPiggyback() function! It is a protected method, it is available to the class BestdataModuleEJBClient which extends EJBApplicationModuleImpl, but it is unavailable to my class BestClients which extends Object and is intended to extend oracle.jdeveloper.html.WebBeanImpl!
    It seems to me that I mustnt use RemoteBestdataModule interface directly. Instead of that I must use the public class BestdataModuleEJBClient that extends EJBApplicationModuleImpl and implements BestdataModule interface. It contains all methods required without additional arguments (see just above). However, how must I create an object of BestdataModuleEJBClient class? That is a puzzle. Besides my custom methods the class has only two methods:
    protected bestdata.common.ejb.RemoteBestdataModule mRemoteAM;
    /*This is the default constructor (do not remove)*/
    public BestdataModuleEJBClient(RemoteApplicationModule remoteAM) {
    super(remoteAM);
    mRemoteAM = (bestdata.common.ejb.RemoteBestdataModule)remoteAM;
    public bestdata.common.ejb.RemoteBestdataModule getRemoteBestdataModule() {
    return mRemoteAM;
    It looks like the remote application module must already exist! In despair I tried to put down something of the kind at the client side:
    RemoteBestdataModule remoteInterface = homeInterface.create();
    BestdataModuleEJBClient dm = new BestdataModuleEJBClient(remoteInterface);
    dm.doNothingNoArgs();
    Of course, it results in an error.
    System Output: null
    System Error: java.lang.NullPointerException
    System Error: oracle.jbo.common.PiggybackOutput oracle.jbo.client.remote.ApplicationModuleImpl.getPiggyForRemovedObjects(oracle.jbo.common.PiggybackOutput) (ApplicationModuleImpl.java:3017)
    System Error: byte[] oracle.jbo.client.remote.ApplicationModuleImpl.getPiggyfront(boolea
    System Error: n) (ApplicationModuleImpl.java:3059)
    System Error: byte[] oracle.jbo.client.remote.ApplicationModuleImpl.getPiggyback() (ApplicationModuleImpl.java:3195)
    System Error: void bestdata.client.ejb.BestdataModuleEJBClient.doNothingNoArgs() (BestdataModuleEJBClient.java:33)
    System Error: void bes
    System Error: tclients.BestClients.main(java.lang.String[]) (BestClients.java:76)
    I have studied a lot of documents in vain. I have found only various senseless discourses:
    "Use the Application Module Wizard to make the Application Module remotable and export the method. This will generate an interface for HrAppmodule (HrAppmodule.java in the Common package) which contains the signature for the exported method promoteAllEmps(). Then, deploy the Application Module. Once the Application Module has been deployed, you can use the promoteAllEmps() method in your client-side programs. Calls to the promoteAllEmps() method in client-side programs will result in calls to the promote() method in the application tier."
    However, I have failed to find a single line of code explaining how it should be called.
    Can anybody help me?
    Best regards,
    Svyatoslav Konovaltsev,
    [email protected]
    null

    Dear Steven,
    1. Thank you very much. It seems to me that the problem is solved.
    2. "I logged into Metalink but it wants me to put in both a tar number and a country name to see your issue." It was the United Kingdom, neither the US nor Russia if you mean my issue.
    I reproduce the text to be written by everyone who encounters the same problem:
    package bestclients;
    import java.util.Hashtable;
    import javax.naming.*;
    import oracle.jbo.*;
    public class BestdataHelper {
    public static ApplicationModule createEJB()
    throws ApplicationModuleCreateException {
    ApplicationModule applicationModule = null;
    try {
    Hashtable environment = new Hashtable(8);
    environment.put(Context.INITIAL_CONTEXT_FACTORY, JboContext.JBO_CONTEXT_FACTORY);
    environment.put(JboContext.DEPLOY_PLATFORM, JboContext.PLATFORM_EJB);
    environment.put(Context.SECURITY_PRINCIPAL, "TESTER");
    environment.put(Context.SECURITY_CREDENTIALS, "TESTER");
    environment.put(JboContext.HOST_NAME, "localhost");
    environment.put(JboContext.CONNECTION_PORT, new Integer("2481"));
    environment.put(JboContext.ORACLE_SID, "ORCL");
    environment.put(JboContext.APPLICATION_PATH, "/test/TESTER/ejb");
    Context ic = new InitialContext(environment);
    ApplicationModuleHome home = (ApplicationModuleHome)ic.lookup("bestdata.BestdataModule");
    applicationModule = home.create();
    applicationModule.getTransaction().connect("jdbc:oracle:kprb:@");
    applicationModule.setSyncMode(ApplicationModule.SYNC_IMMEDIATE);
    catch (NamingException namingException) {
    throw new ApplicationModuleCreateException(namingException);
    return applicationModule;
    package bestclients;
    import bestdata.common.*;
    import certificate.*;
    public class BestClients extends Object {
    public static void main(String[] args) {
    BestdataModule bestdataModule = (BestdataModule)BestdataHelper.createEJB();
    Certificate aCertificate = new Certificate("TESTER", "TESTER");
    //calling a custom method!!
    bestdataModule.passCertificate(aCertificate);
    Thank you very much,
    Best regards,
    Svyatoslav Konovaltsev.
    [email protected]
    null

  • Calling a service method from a DataAction

    Hello!
    I'm trying to call a service method from a DataAction, cobbling ideas from the Oracle JDeveloper 10g Handbook and the Oracle ADF Data Binding Primer.
    I have created a service method and exposed it using the client interface node of the application module editor. It is called "process()" and it now appears in the data control palette under MyAppDataControl->Operations (just above the built-in action bindings Commit and Rollback). As part of this procedure, I modified MyAppImpl.java and put the process() method there.
    I don't want to call process() by dragging and dropping it onto a Data Action because depending on the outcome, I want to branch to different pages. process() returns an int that will tell me where to branch. Thus, I am trying to call it from an overridden invokeCustomMethod() method of the lifecycle of a DataAction, where I can get the int, create a new ActionForward, and set it in the DataActionContext. (If I'm barking up the wrong tree, let me know!)
    So, I need to call MyAppImpl.process() from within the invokeCustomMethod() method of my DataAction. Looking at the class declaration, I noticed that it extends ApplicationModuleImpl. I figure that, if I can get the ApplicationModule, I can cast it to MyAppImpl and call the process() method. Unfortunately, that doesn't work. When I got the application module, I checked the class and it's oracle.jbo.common.ws.WSApplicationModuleImpl. I tried casting it and got a class cast exception.
    Here's the code I'm using:
    protected void invokeCustomMethod(DataActionContext actionContext) {
    BindingContext ctx = actionContext.getBindingContext();
    DCDataControl dc = ctx.findDataControl("MyAppDataControl");
    log.debug("invokeCustomMethod(): dc.getClass().getName()=" + dc.getClass().getName()); // result is: oracle.jbo.uicli.binding.JUApplication
    ApplicationModule am = null;
    MyAppImpl myAppImpl = null;
    int processResult = 0;
    if (dc instanceof DCJboDataControl) { // this is true
    am = dc.getApplicationModule();
    log.debug("invokeCustomMethod(): am.getClass().getName()=" + am.getClass().getName()); // result is: oracle.jbo.common.ws.WSApplicaitonModuleImpl
    if (am instanceof ApplicationModuleImpl) { // this is false
    log.debug("invokeCustomMethod(): am is an instanceof ApplicationModuleImpl.");
    if (am instanceof MyAppImpl) { // this is false
    log.debug("invokeCustomMethod(): am is an instanceof MyAppImpl.");
    processResult = ((MyAppImpl)am).process();
    log.debug("invokeCustomMethod(): processResult=" + processResult);
    super.invokeCustomMethod(actionContext);
    What am I doing wrong? Can anyone explain the different class hierarchies and why my application module isn't the class I'm expecting?
    Thanks,
    -Anthony Carlos

    Georg,
    it was in the javadoc of oracle.adf.model.binding.DCBindingContainer
    http://www.oracle.com/webapps/online-help/jdeveloper/10.1.2/state/content/vtTopicFile.bc4jjavadoc36%7Crt%7Coracle%7Cadf%7Cmodel%7Cbinding%7CDCBindingContainer%7Ehtml/navId.4/navSetId._/
    However, I see it's not the case in other sub-classes of JboAbstractMap like DCControlBinding and DCDataControl.
    Weird... I'm keeping you informed if I find more information.
    Regards,
    Didier.

  • Calling backing bean method from HttpSessionListener

    Hi,
    I am detecting session expiration through HttpSessionListener's sessionDestroyed() method. I have a logout() method in my backing bean which does all the session clean up. If the user clicks the logout link, then I call the logout method and do the clean up. But when the user closes the browser, then I believe that the HttpSessionListener's sessionDestroyed() method will be called. How do I call the logout() method of my backing bean from from sessionDestroyed() method of HttpSessionListener.

    I did as you said, but the finalize method is never called. I can see the session timing out and sessionDestroyed() method being called, but not the finalize() method. Here is the code for sessionDestroyed()
        public void sessionDestroyed(HttpSessionEvent sessionEvent){
            System.out.println("Session Destroyed Called");
            HttpSession session = sessionEvent.getSession();
            session.invalidate();
            System.gc();
        }and for finalize()
        public void finalize() throws Throwable{
            System.out.println("In Finalize Method");
            FacesContext ctx = FacesContext.getCurrentInstance();
            Object requestObject = ctx.getApplication().getVariableResolver().
                                   resolveVariable(ctx, "databaseCon");
            DatabaseCon databaseCon = (DatabaseCon) requestObject;
            Connection con = databaseCon.getConnection();
            String sql = "DELETE FROM TEMP WHERE EX_ID = ?";
            PreparedStatement pstmt = con.prepareStatement(sql);
            pstmt.setInt(1,this.getExId());
            pstmt.executeUpdate();
            super.finalize();
        }

  • Overriding Methods and super.method()

    I've got some custom classes that extend and extension of the
    MovieClip. At the end of the movieclip timeline I want the end
    users to be able to simply call myMethod to signal they are at the
    end of the timeline. Certain classes will need to do something
    things and others yet others, but they will all also need to do a
    few things in common.
    I was hoping to define the "in common" things in the super
    class and then overide the method for the extensions. So in my
    example I was hoping that an instance of Class B would do what it
    needed to do and then call the super function. However Class C has
    nothing specific itself to do and since the method wasn't overriden
    the same myMethod() on the timeline would invoke the super classes
    method.
    So the case of Class C works. But in the case of Class B. I
    get the trace that the Class B method has been called, but I don't
    get a message that Class A was called. Is there a way to make this
    idea work? Is it a good idea? What am I missing?

    Okay I've worked it out. The trick comes in with how you call
    myMethod(). On the timeline I have to be sure and use a qualified
    reference. So, this is on the of an instance of B, if I use
    myMethod();
    I only get the myMethod() from class B, but if I do:
    this.myMethod()
    I get B and A. But oddly enough if I say invoke myMethod from
    the constructor of B, I get both trace statements -- regardless of
    whether or not I use a qualified reference! Now that is strange.

  • Super.super.method()

    super.super.method()
    Why does this not work?
    When I searched this on google, the people in the thread said this was a result of bad OO design. But in the following case I don't think that it is:
    Here is a small version of the tree:
    -Unit
    ---->Ship
    --------->Fighter
    --------->Droid
    ---->Building
    --------->Power Station
    What I'm focused on here is the getImage() method. For the Unit class, it looks like this:
    public Image getImage(){
    return myImage;
    }For the Ship class, the image should be rotated to the ship's rotation:
    public Image getImage(){
    rotate(myImage);
    retuern myImage;
    }Now, a Droid is in all ways a ship except that I don't want its image to rotate, so I want to call: return super.super.getImage();I know several workarounds:
    1. Have "boolean rotateImage" in the Ship class
    2. Have "if (this instanceof Droid) return super.getImage(); //in ship class
    But to me, super.super.getImage() seems like the best way, because it allows the Droid class to take the action and it also reduces the clutter in the large Ship class.
    Thanks

    //this calls the Droid's getImage() instead of the Unit's
    Well, yeah, this cause a problem...
    Okay, getImage in getNonrotatedImage is dynamically dispatched -- It will call Droid.getImage, which of course, calls Unit.getNonrotatedImage, which again calls Droid.getImage, which...
    you get the point.
    Look, if you want to put getNonrotatedImage in the Unit class, it needs to call a statically dispatched (i.e. private or final) method of Unit, or at the very least, not one that is overriden in Droid.
    Refactor the code in getImage into a private method getImage, and have both getImage and getNonrotatedImage call getImage, because _getImage will be statically dispatched.
    OR
    Move getNonrotatedImage to the Ship class, and have it call super.getImage (which, by the way, is guaranteed to be statically dispatched).
    - Adam

  • How to call OIM API from external app?

    Hi,
    I have an java application and I would like to call OIM API to accept a request. The application resides in separate server than OIM.
    My questions:
    *1.* What to do to call OIM API from external application (import any OIM jars etc.)?
    *2.* Which method to use, setRequestResponse , closeRequest or any other?
    I appreciate any help, thanks.
    Edited by: m.m. on Feb 2, 2010 5:33 AM

    Hello,
    If it is an external client, you need to provide the "login" and "password" details explicitly in the code (something like this), before getting any other Interface control to invoke the OIM APIs -
    public class OIMAPIClientTest {
    public static void main(String[] args) {
    try{
    System.out.println("Starting...");
    ConfigurationClient.ComplexSetting config = ConfigurationClient.getComplexSettingByPath("Discovery.CoreServer");
    Hashtable env = config.getAllSettings();
    tcUtilityFactory ioUtilityFactory = new tcUtilityFactory(env,"xelsysadm","abcd1234");
    System.out.println("Getting utility interfaces...");
    Regards,
    Amit
    Edited by: amitKumar on Feb 2, 2010 5:29 AM

  • How to find a caller of a method

    hi all,
    i have a method in a class and that method is being called from many different classes.
    Inside that method , I want to know who is the caller of the method.
    how can i find that. any help would be appreciated.
    Thanks,
    Dhanasekaran Vivekanandhan

    look at the method Thread.currentThread.getStackTrace(), and the class StackTraceElement. you can work out the rest yourself, hopefully
    but if your code depends on this knowledge, I reckon you've got design problems

  • How to call a C function calling a Java Method from another C function ?

    Hi everyone,
    I'm just starting to learn JNI and my problem is that I don't know if it is possible to call a C function calling a Java Method (or doing anything else with JNI) from another C function.
    In fact, after receiving datas in a socket made by a C function, I would like to create a class instance (and I don't know how to do it too ; ) ) and init this instance with the strings I received in the socket.
    Is all that possible ?
    Thank you very much for your help !

    Hard to understand the question, but by most interpretations the answer is going to be yes.
    You do of course understand that JNI is the "API" that sits between Java and C and that every call between the two must go through that. You can't call it directly.

Maybe you are looking for

  • Lines Between Report Columns in Purchase Order Report

    Hello All, I am working with the Oracle Purchasing Report called POXPRPOP.rdf. I am trying to add a black frame between each column in the report. Imagine in a purchase order where several columns of data that have a black line in between them. I hav

  • What does a BI Developer need to know about SAP tables and why?

    Hi, i. As a BI Developer, to what extent do you need to know about SAP tables? e.g. if you work mainly in the functional areas LO and FI ii. For example, I know that in Finance, GL relates to the tables BSEG and BKPF. And if it is important to know a

  • Multi Y-scale zoom problem

    I created two Y-scales on my XY Graph and attached one plot to each scale. The problem is that when i am trying to zoom the graph it changes both scales. I tried to set Active Scale before zooming but that didn' help. Is it possible to zoom scales in

  • FileUpload: Current thread not ownet?

    Hi, I use the common Apache FileUpload lib. When i use it on my local server i work! But on my NetWare Tomcat server, i got this message: Error Message:current thread not owner java.lang.IllegalMonitorStateException: current thread not owner at org.a

  • The symbols that appear on my internet page have gone (back, forward, favourites). How do i get them back?

    The symbols that appear on my internet page have gone (back, forward, favourites). How do i get them back? As well as this whenever I go into iPhoto and edit my images the image distorts or goes blank. Why is this?