Can we invoke a method using BCEL(byte code engineering library)

Hi i am new in Java bcel,So can anyone guide me in this problem.
I am searching for some techniques in BCEL to invoke a method of some class just like we use to invoke methods using Java Reflection.I have also tried a Java Assembler named "Jasmin" that used to interact with Operand Stack,Local variable array & Constant Pool etc so i guess this is the same containers with which our BCEL also interact with so then i am wondering why not then there exists a way through which we can invoke a method using BCEL IF this will happen in any case then kindly point it out some direction of help.
thanks in advance

856989 wrote:
I think i have clearly mentioned that "Tell me any way in doing this invocation in BCEL not in Reflection."
Why i not want to use reflection because it have "invocation overhead"Wrong.
If I dynamically load a class and reference it via a interface there is absolutely no difference in that and if I referenced the class statically and used it via an interface. The load and use process is exactly the same.
And the first uses "reflection".
If you use a proxy interface via something like java.lang.reflect.Method
then of course there is some overhead because there is in fact more classes involved. Just as if you had any other layer in any other code.
And even so unless you have actually profiled the application and found an actual bottleneck (and not just a measured impact) then even looking at it is a waste of time.
If it was me I would be far more concerned that inserting byte codes was correct for all cases.

Similar Messages

  • Can I invoke instance method using JNI pointer

    Hi,
    In my work, I need to pump data from dll to my java application.. for this I came to the following workaround.
    1. Created a static method with (printMe()) in my java class (GrabTest.java)
        public static int count = 5;
        public static int printMe(int a)
            System.out.println("result printMe : " + a);
            return count--;
        }2. Invoked this class object in dll side as follows
         jclass cls = env->FindClass("GrabTest");
         jmethodID mid = env->GetStaticMethodID(cls, "printMe", "(I)I");
         jint count = env->CallIntMethod(cls, mid, 10);
         cout<<"Count =" <<count<<endl;This works fine, i able to invoke the static method of GrabTest class from dll and I can pass an int value from there.
    I tried to call a not static method which in GrabTest.java, from dll as follows
            jmethodID mid2 = env->GetMethodID(cls, "printMe", "(I)I");
         jint counter = env->CallIntMethod(cls, mid2, 10);
         cout<<"Counter =" <<counter<<endl;when I try to invoke the instance method from dll, my application get crashes.
    So, I would like know,
    1. Is there any other way to pump data from dll side to the client application,
    2. If i go with the static method to pump the data from dll, weather the other values of class variables of my GrabTest will give problem?
    Looking for your guidance on this issue.
    Thanks in advance,
    Ramesh

    856989 wrote:
    I think i have clearly mentioned that "Tell me any way in doing this invocation in BCEL not in Reflection."
    Why i not want to use reflection because it have "invocation overhead"Wrong.
    If I dynamically load a class and reference it via a interface there is absolutely no difference in that and if I referenced the class statically and used it via an interface. The load and use process is exactly the same.
    And the first uses "reflection".
    If you use a proxy interface via something like java.lang.reflect.Method
    then of course there is some overhead because there is in fact more classes involved. Just as if you had any other layer in any other code.
    And even so unless you have actually profiled the application and found an actual bottleneck (and not just a measured impact) then even looking at it is a waste of time.
    If it was me I would be far more concerned that inserting byte codes was correct for all cases.

  • Invoking a method using reflection with json data as argument

    Hi,
    I want to invoke a method using reflection and this method have one argument . Now I want to pass a json data as an argument to this method .Please see the following code.
    int HelloWorld(int Id){
    return Id;
    json data{"Id":43}
    how can I use the reflection to use the json.
    Please provide your guidelines

    Thanks for your reply, I am building a windows console application .And I want to convert the json data to object array to use in Method Base.Invoke method.
    Regards,
    Ethan
    Maybe you could select the correct language development forum here:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages&filter=alltypes&sort=lastpostdesc
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Difference between invoking a method using reflect.proxy and reflect.Method

    Could any one tell me the difference between invoking a method using reflection java.lang.reflect.Method and java.lang.reflect.Proxy
    using both the class, we can invoke a method at runtime
    1)
    Method mthd=cl.getMethod("methodName",parameterName);
    Integer output=(Integer)mthd.invoke(new RunMthdRef(),input);
    2)
    Proxy.newProxyInstance(super.getClass().getClassLoader(), new Class[] { adapter }, new SomeClass(this));
    Does anybody have any idea?

    The two idioms are fundamentally different. Using java.lang.reflect.Method is how we call a method on a class, using Proxy is how we intercept that method call. An exercise for you, to illustrate that they do not do the same thing: write a simple class with one method, then use java.lang.reflect.Method to invoke that method, and then use a Proxy to invoke that method

  • [u][b]perl- can't locate objet method "USE" via strict  package[/b][/u]

    [b[u]
    i am working on Redahat Linux 7.3 with perl 5.6.0
    when ever run the perl script to connect oracle
    i get following message
    " can't locate object method "USE" via package "strict"
    i installed the oracle for perl
    can anyone help to get rid of the problem

    implement synchronizable and createa constructor, then check it once again.

  • I pick up a virus sent laptop in to remove the virus now unable to open Photoshop can I download it again using the ID code

    Pick up a virus on laptop, Sent it in to be removed, now unable to access Photoshop. Can I download it again using the ID code.

    Try this link and validate with your 24 digit serial number - click here for PSE downloads

  • How can I invoke a method on a subclass based on the runtime type?

    Hi all,
    I have defined a base class OrderDetail, and 2 subclasses which extend it: OrderDetailSingleReservation and OrderDetailMonthReservation. Furthermore, I have a method:
        public Order order_generate(OrderDetail orderDetail) {
            if (orderDetail instanceof OrderDetailSingleReservation) {
                return order_generate((OrderDetailSingleReservation) orderDetail);
            }  else if (orderDetail instanceof OrderDetailMonthReservation) {
                return order_generate((OrderDetailMonthReservation) orderDetail);
            } else {
                Misc.alert("orderAndInvoice_Generate(GENERIC): unsupported type.");
                return null;
        }The type of this method's parameter is OrderDetail, as you can see. (This particular method only serves as a kind of dispatcher and is therefore not very interesting in itself, but the same pattern using 'instanceof' occurs in a codebase I am working on several times, and I would like to factor it out if possible.)
    My question: it seems that the invocation of order_generate() from within this method requires an explicit downcast to one of the two subclasses. If not, java invokes the method on the superclass. But at runtime, the JVM knows what type of object it is dealing with, right? So is there no way to do this without the explicit downcast?
    A similar problem occurs when trying to invoke a method on an object whose type is one of the subclasses; the method on superclass is called, instead of the one in the appropriate subclass that overrides it.
    Any help would be greatly appreciated!
    Thanks,
    Erik

    Thanks for your replies! I was editing my post last night to clarify it, but my connection went down and the edit was lost :(
    Anyway, yes, it should be done with polymorphism. I was constructing an example using the famous Animal, Cat and Dog classes to demonstrate my question more clearly, and to my surprise the problem does not occur in my example code.
    LRMK: Invoking a method such as in your example, where the method is inside the class itself, works fine. However for MVC's sake, I have a separate class called Invoicing with methods as below:
    class invoicing
      // the method for the superclass
      public Invoice invoice_create(OrderDetail orderDetail) {
         System.out.println("type: " + orderDetail.getClass());
         return null;
      // the method for one of the subclasses (this method is being not invoked)
      public Invoice invoice_create(OrderDetailSingleReservation orderDetail) {
         return null;
      // ...nor is this one.
      public Invoice invoice_create(OrderDetailMonthReservation od) {
         return null;
    }Now I attempt to invoke these methods:
    // create example objects
    OrderDetailSingleReservation odSingle = new OrderDetailSingleReservation();
    OrderDetailMonthReservation odMonth = new OrderDetailMonthReservation();
    // this call displays "odSingle type: OrderDetailSingleReservation"
    System.out.println("odSingle type: " + odSingle.getClass());
    // this call displays "odMonth type: OrderDetailMonthReservation"
    System.out.println("odMonth type: " + odMonth.getClass());
    // this call invokes Invoicing.invoice_create(OrderDetail)
    // instead of Invoicing.invoice_create(OrderDetailSingleReservation)
    Invoicing.invoice_create(odSingle);
    // this call invokes Invoicing.invoice_create(OrderDetail)
    // instead of Invoicing.invoice_create(OrderDetailMonthReservation)
    Invoicing.invoice_create(odMonth);So these calls will invoke the method for the superclass, i.e. Invoicing.invoice_create(OrderDetail od). That method then then executes the System.out.println() call which displays the class type of its parameter as one of { OrderDetailSingleReservation | OrderDetailMonthReservation }, that is, the expected subclass types!
    So the dynamic dispatch isn't working the way I would expect it to. If I do the explicit if-else checking using instanceof, as described in my first post, the correct methods are called.
    I hope the problem is somewhat clearer now. I am a bit lost as to what might be causing this, or how to monitor what's going on inside the jvm. Any ideas? BTW, the OrderDetail class and its subclasses are JPA entities (though I don't think it should matter).
    Thanks!
    Erik

  • Can i invoke a method of a different class?

    I want to tell my method that if a certain event occurs, to invoke a method thats located in a different class but in the same package. But neither inherit each other.
    I also want the original method to pass parameters to the remote method so it can perform actions on them.
    Is this possible somehow, or am I barking up the wrong tree?
    I've included an example to illustate.
    edu.example;
    public class one extends bank{
    protected void count (){
    If i>100{
    spend(5); // method thats in the two class
    else break;
    edu.example;
    public class two extends bank{
    protected void spend (int x){
    i = i - x;

    either the method you want to invoke will have to be static, or you will need an instance of the class that contains the method you want to invoke.
    If your not in school, its probably best you buy a Java book. It will speed things along considerably.
    I have always bought books by Ivor Horton. "Beginning Java" is a good one. Wrox publisher I think. Once you pass that book you will not need any other books unless you go deep into a particular subject such as encryption.

  • How can I invoke a JSP using a URL instance from another JSP?

              Hi all.
              I've been developed a J2EE application using Oracle 9iAS.
              Now I'm migrating to WL Server and I have the following problem.
              I was using the following code to read a URL contents from another JSP:
              URL url = config.getServletContext().getResource("/path/to/url/of/textfile.xsl");
              This was working fine in a expanded directory project structure (typical during
              development time) and Oracle 9iAS.
              When I execute this code from my WL packed .ear file I get a URL not found exception.
              Which is the right way to get a resource available from the same context root?
              Thanks in advance for your answers (and sorry for my bad english ;-))
              

    The previous owner of that machine should have wiped it and install the original OS that shipped with the system leaving the system at the point where the new owner takes over and enters all there own information.
    Before you go much further with this machine you should seriously consider backing up any new stuff you have done and wiping it and starting from scratch. If you keep the system like it is you  will be plagued with problems. Even doing OS updates will prove frustrating.
    Right now the best you can do is to move the Aperture that is on the system into the trash, log into the App Store using your ID and buying Aperture. That should work but to be honest I have never had to do it so can;t say for sure.
    You might want to look at this What to do before selling or giving away your Mac from Apple to read what they recommend.
    good luck
    regards

  • Can I create a file using pl/sql code in application server ?

    Hi
    I wanted to create a file(any kind of file .txt .csv .exe etc..) using pl/sql code in application server?
    Please help me with an example...in this regard
    Regards
    Sa

    864334 wrote:
    I wanted to create a file(any kind of file .txt .csv .exe etc..) using pl/sql code in application server?And how is this "file" to be delivered?
    Files can be created by PL/SQL code and stored in the Oracle database as CLOBs. This a fairly easy and robust process. It runs entirely in the database. It conforms to transaction processing. The "file" (as a CLOB) resides in the database and can thus be secured via database security, is part of database backups and so on.
    The basic issue is how to deliver the contents of the CLOB to the user. If via FTP, then the database can directly FTP the contents of the CLOB to the FTP server as a file. If via HTTP, the database can deliver the CLOB as a HTTP download directly to the web browser.
    If the client is Java or .Net, then the CLOB contents can be delivered via SQL or DBMS_LOB or a custom PL/SQL interface.
    In such cases, there is no need to step outside the secure and flexible database environment and create a physical o/s file in the wild (outside the controls of database security, data integrity and transaction processing). This is thus recommended and is the preference.

  • Advantage/disadvantage:invoke method using refllection vs normal instance

    What is the difference in invoking the method using refflection and normal method invocation using the instance.

    Techchies wrote:
    Thanks for the response.
    can you please eloberate "extra cpu time and obscurity". In case of refflection would it take more CPU time.Yes. Whether that matters or not is irrelevant. Actually, in practice, as alluded to above by EJP, it doesn't matter at all because you shouldn't be in a situation where you are choosing between the two. Either you actually need reflection, or you don't bother using it. Anything else is just "shiny thing" syndrome.
    Can you tell me the scenario where we need to use Refflection to invoke the method instead of normal invocation, when instance is available either by Refflection or using new operator.When you don't know the types involved at compile-time, basically. Like, if you know - or suspect - that an object will have a method called foo, but at compile-time, don't have the actual type upon which that method is declared, you might need reflection. Or another common case is when you have arbitrary objects that follow a vague spec, such as the JavaBeans spec, and you want to find, then invoke, all the methods that obey that spec. That's a case for possible reflection. This is how things like OR/M tools and certain containers work.
    If you've managed to instantiate a class using the new keyword, you almost certainly don't need reflection. If you don't know what type you're instantiating until runtime, you may have a case where reflection is necessary, but in many of these cases, it can be avoided by the use of interfaces.
    But the bottom line is, if you're asking "shall I use direct invocation here, or reflection?" the answer is "direct invocation".

  • Error while invoking ContactQueryPage method from contact.wsdl

    Hi All,
    Could any one provide me the java client for OnDemand webservice (contact.wsdl). I want to query ContactQueryPage operation.
    I am facing some problem while making a call. I am trying with both Axis call as well as ContactStub. but its not working in either way.
    Here is the snnipet I am using to invoke a method using ContactStub
    String endpoint = "https://secure-ausomxdsa.crmondemand.com/Services/Integration;"+jessionId;
                   ContactStub stub = new ContactStub(endpoint);
                   ContactWS_ContactQueryPage_Output queryOutput = null;     
                   ContactWS_ContactQueryPage_Input queryInput = new ContactWS_ContactQueryPage_Input();
                   ListOfContact listOfContact = new ListOfContact();
                   Contact contact = new Contact();
                   queryInput.setListOfContact(listOfContact);
                   queryInput.setUseChildAnd("Contact");
                   queryInput.setPageSize("10");
                   queryInput.setStartRowNum("1");
                   queryOutput = stub.ContactQueryPage(queryInput);
    When I run the program..I get following exception :
    org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '"' (code 34) in DOCTYPE declaration; expected a space between public and system identifiers
    Can any one help me out. Its needed urgently.
    Thanks & Regards,
    Sanjay

    Hi !
    From what I see, the only problem is the setUseChildAnd function which is waiting for a true or false argument and not a char...
    Hope this will help, feel free to ask more !
    Max

  • How to invoke a method in application module or view objects interface?

    Hi,
    perhaps a stupid RTFM question, but
    How can i invoke a method that i have published in the application modules or view objects interfaces using uiXml with BC4J?
    Only found something how to invoke a static method (<ctrl:method class="..." method="..." />) but not how to call a method with or without parameters in AM or VO directly with a uix-element.
    Thanks in advance, Markus

    Thanks for your help Andy, but i do not understand why this has to be that complicated.
    Why shall i write a eventhandler for a simple call of a AM or VO method? That splatters the functionality over 3 files (BC4J, UIX, handler). Feature Request ;-)?
    I found a simple solution using reflection that can be used at least for parameterless methods:
    <event name="anEvent">
      <bc4j:findRootAppModule name="MyAppModule">
         <!-- Call MyAppModule.myMethod() procedure. -->
          <bc4j:setPageProperty name="MethodName" value="myMethod"/>
          <ctrl:method class="UixHelper"
                  method="invokeApplicationModuleMethod"/>
       </bc4j:findRootAppModule>
    </event>The UixHelper method:
      public static EventResult invokeApplicationModuleMethod( BajaContext context,
                                                               Page page,
                                                               PageEvent event ) {
        String methodName = page.getProperty( "MethodName" );
        ApplicationModule am = ServletBindingUtils.getApplicationModule( context );
        Method method = null;
        try {
          method = am.getClass(  ).getDeclaredMethod( methodName, null );
        } catch( NoSuchMethodException e ) {
          RuntimeException re = new RuntimeException( e );
          throw re;
        try {
          method.invoke( am, null );
        } catch( InvocationTargetException e ) {
          RuntimeException re = new RuntimeException( e );
          throw re;
        } catch( IllegalAccessException e ) {
          RuntimeException re = new RuntimeException( e );
          throw re;
        return null;
      }Need to think about how to handle parameters and return values.
    Btw. Do i need to implement the EventHandler methods synchronized?
    Regards, Markus

  • Invoke beanshell methods from java

    Hello
    I'm learning beanshell and using it to write scripts that are ran in JDK 6.
    My question is how to invok beanshell methods from java source codes.
    My codes is:
    import javax.script.*;
    public class InvokeFunctions {
    public static void main (String[] args)throws ScriptException, NoSuchMethodException
    ScriptEngineManager sem = new ScriptEngineManager();
    ScriptEngine bshEngine = sem.getEngineByName("beanshell");
    String script = "public void sayHello()"+"{print (\"sayHello() is a method in bsh script\");}";
    bshEngine.eval(script);
    Invocable inbshEngine = (Invocable)bshEngine;
    inbshEngine.invokeFunction("sayHello");
    I defined a method "sayHello()" using beanshell, but i just can't invoke it in Java.
    I got an error msg said:
    Exception in thread "main" java.lang.IllegalAccessError: tried to access method bsh.NameSpace.getThis(Lbsh/Interpreter;)Lbsh/This; from class bsh.engine.BshScriptEngine
    Any one has any idea about it?
    Thanks

    Look at the Javadoc documentation of IllegalAccessError. It says:
    Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.
    Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
    Maybe recompiling all your sources (make sure you delete all existing *.class files) will help?

  • Invoking java methods

    hi
    i have used flash builder 4.
    i can't plugin eclipse ide.
    can i invoke java methods in flash builder 4 .
    is it possible.
    if it's possible pls give some ideas.
    thanks in advance
    regards
    athi

    If you want to invoke java methods that are remote though, you might want to use a Java Remoting technology like BlazeDS.
    Using a <s:RemoteObject> tag, you could connect to the server and invoke java methods.
    Here is a small sample app code that helps me execute a remote java method.
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
       creationComplete="ro.getProducts()">
    <fx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.messaging.channels.AMFChannel;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    protected function ro_resultHandler(event:ResultEvent):void
    Alert.show(event.result.toString())
    protected function ro_faultHandler(event:FaultEvent):void
    Alert.show(event.fault.faultString);
    ]]>
    </fx:Script>
    <fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <s:RemoteObject id="ro"
    destination="productService"
    endpoint="http://localhost:8400/samples"
    fault="ro_faultHandler(event)"
    result="ro_resultHandler(event)"/>
    </fx:Declarations>
    </s:Application>
    Hope this helps,
    Balakrishnan V

Maybe you are looking for

  • A bit off topic, but not too far

    due to the lack of an autodownload for JRE 1.4 I am forced to use another method for installing it. Does anyone know a way to check what JRE version the user has using some sort of web scripting? I've seen examples of how to check within an applet or

  • IOS 5 Problem with Music

    Something wrong with "music" stuff after upgrading to iOS5. Itunes says about successful synchronization of playlists, but when it comes to listening the music it makes me mad. On the screen there is a "play" sign but no music, even when I'm trying t

  • W530 Nvidia Discrete Mode - problems in PowerPoint and Excel

    Hi, I've experienced problems with window refreshing in PowerPoint and Excel while running W530 in Nvidia Discrete Mode. While creating and wiewing PowerPoint 2007 presentation in normal view the slides' miniatures are not refreshing when selected. W

  • Maximum HD size

    Hi, I am new to MAC having just inherited a Powerbook G4 15" Titanium 400 Mhz processor with 512Mb of RAM and a 10GB Hard drive. I am planning to boost the memory to 1GB and upgrade the hard drive. I am running OS 10.4.11. What is the maximum HD it w

  • Part of itunes is blind?

    Okay, as it stands, I know my shuffle is installed and I would thuink properly since I have been through every trouble shooting task I can find. Also, before ipod was installed, there was no topic in the itunes help section for ipod and as soon as it