Doubt on REFLECTION

Hi forum,
Please help me out with this problem.
I am getting the parameter types of a method in a class as
Class[] parameterTypes=method.getPrameterTypes();
I need to test if the parameter types are of primitive types i.e int or String or long etc...For that i used the following code.The trouble is that it doesnt seems to test the whole conditions.It seems to check only the first condition and for all other conditions it gives a negative result.i.e for String,long,float etc it shows the message box whereas it should be executing else condition instead.Please tell me whats wrong with it.
                        for (int i = 0; i < numOfParameters; i++)
                             if ( ! (parameterTypes.toString().equals("int") || parameterTypes[i].toString().equals("Integer"))||
(parameterTypes[i].toString().equals("long") || parameterTypes.toString().equals("Long"))||
(parameterTypes[i].toString().equals("java.lang.String")||
(parameterTypes[i].toString().equals("float") || parameterTypes[i].toString().equals("Float"))||
(parameterTypes[i].toString().equals("boolean") || parameterTypes[i].equals("Boolean")))
JOptionPane.showMessageDialog(null, "Do Not Support The Data Type","Error",JOptionPane.ERROR_MESSAGE);
break;
else{---------------------------}
Thank you all.

@OP. Why making it so hard, and do negation, and execute else when you can do it the other way around?
for (int i = 0; i < numOfParameters; i++) {
     String type = parameterTypes.toString();
     if (type.equals("int") || type.equals("Integer") || type.equals("long") || type.equals("Long") ||
               type.equals("java.lang.String") || type.equals("float") || type.equals("Float") || type.equals("boolean") ||
               type.equals("Boolean")) {
          continue;
     } else {
          System.out.println("error");
Kaj

Similar Messages

  • A doubt regarding the usage of Reflection

    There are several classes A, B, C, D,.... in a package.
    A, B, C & D are generic names given to the java files inside the package.
    They actually indicate files selected by the user during run-time.
    A a = new A();
    B b = a.getB();
    C c = b.getC();
    D d = c.getD();
    int count = d.getCount();
    a.getB() returns an instance of B.
    similarly with getC() & getD() too.
    The classes indicated by A, B, C & D are selected by the user.
    So, I need to use reflection to implement the above 5 statements.
    How do I go about doing this?
    Thanks

    Basically to create an instance of a dynamic class:
    Class cl = Class.forName(myClassName);  // get class
    for name
    Object o = cl.newInstance();  // create an instance
    the above code works fine, if Iam dealing with a single class.
    But my problem is Class A returns an object of Class B
    which I need to use to get an Object of class C and so on until I get the required data to be parsed form the XML document.
    When I invoke a method in Class A, it returns an object(of class B, which I need to use to invoke a method in class B) and so on to get the final value.
    I have a large XML document as shown below, which I need to parse.
    !-- an xml document -->
    <Element A>
       <Element B>
          <Element P>
             Some data for Element P
          <Element Q>
             Some data for Element Q
          <Element R>
       </Element B>
       <Element C>
       <Element D>
       <Element E>
    </Element A>I have a class that represents the whole document with the main elements in it. (Class A representing the whole document along with objects representing the main Elements B, C, D & E)
    Each element in turn has its own class which are necessary to access the sub-elements of it. (Class B representing Element B and also including Element P & Q)
    If I want to parse a specific part of the document(if i need to get the data in Element P), I need to get the Element B from a Class A and use that Object representing Element B to get Element P and then use it to get the required data.
    Each class returns a part of the document and as you use the classes(and the returned part of the document), we narrow down to the required region to get the data.

  • One doubt in VL03N transaction/

    Hi All,
              I have one doubt in VL03N transaction.I am an ABAPer.I don't iknow much about the SD process.My SD consultant has changed the Ship-To-Party addressin customer master but it is not reflecting in the document in VL03N.But when I see in the Environment -> Ship-To-Party i can see the address which we changed.Can anyone suggest the reason behind this difference?

    Hi Saket,
    if u have different ship to party, while creating the sales order u have to sellect the  ship to party. while creating delivery document WRT sales order sys automatically specifies that ship to party. ( i think they have not selected new ship to party at sales order level)
    Regards,
    Gopi

  • Excise invoice number getting reflected in the reference field in VF01

    Hello,
    I require excise invoice number to get get reflected in the reference field of billing document number . (i.e accounting document generated from VF01)
    Thanks,

    Dear Muscan,,
    As per STANDARD SAP PROCESS this functionality is not Possible. The reason is very clear, Excise Invoice is always created after creating billing/invoice document. Without creating excise invoice you cannot have excise invoice number reflected in the reference field of billing document.
    Hope this clarifies your doubt?
    Regards
    MBS

  • Very urgent: Doubts regarding CRM WORKFLOW OF BUSINESS PARTNER CREATION

    HI ,
    I HAVE DOUBTS REGARDING CRM WORKFLOW OF BUSINESS PARTNER CREATION, WHILE I AM CREATING BUSINESS PARTNER THROUGH R/3 , IT REFLECT IT INTO MYSAP CRM ALSO, AT THAT TIME IT SENDING THE MAIL TWICE TO THE RECEIPIENT. IS THERE ANY WAY THROUGH  WHICH I CAN RESTRICT IT TO SEND THE MAIL ONLY ONCE,
    PLZ SEND ME THE REPLY AS SOON AS POSSIBLE,
    THANKS  ADVANCED,

    HI
    WORKFLOW SEETING. SAP MAIL
    MULTIPLE MAILS AND
    ONLY ONCE CHOOSE
    ONLY ONCE OPTION ON WHICH VERSION U R WORKING?
    REWARD IF HELPFUL
    VENKAT

  • 1099 Reporting doubts

    Hi all,
    I am doing 1099 coniguration for an US Company. I have the following doubts. Pl help me with your inputs.
    1. What is to be taken as reporting base for 1099 - Invoice or payment (withholding tax type for invoice posting or payment posting)
    2. How will the Vendor who gives tax exemption certificate be reflected in the Report.
    Thanks
    Sri.

    Hi,
    To flag a vendor in SAP as a 1099 vendor, two fields need to be populated.
    1. On the Control screen of the vendor master, populate either "Tax Code 1" field with his social security number if his social security number is his tax id. or "Tax Code 2" field with his corporate tax id. if he has been issued a corporate tax id. Input either of the two in their correct format i.e. social security as xxx-xx-xxxx or corporate id as xx-xxxxxxx.
    2. On the Accounting Info. screen, populate the "W.tax code" field under the "Withholding Tax" box with the value "07" if it is a US vendor or "42" if it is a foreign vendor.
    These are the two fields that specify a vendor as being a 1099 vendor.
    Any posts done before this changes were implemented will not show on 1099.
    You will need to run program RFWT0020 to flag 1099 items retroactively.
    ...and/or you can change the "Document Change rules" for BSEG-QSSHB and BESG-QSSKZ for account type "K" so that you can change the Withholding tax code after the line item has been cleared (i.e. after entering the required information in the vendor master record as the user above has recommended) (Refer to OSS Note: 363650).
    But if you use MIRO to post invoices, you might want to look at Note 482245 too...
    In SAP v40b, the new 1099 report is RFW1099M. It is a neat report since it merges all the three reports that are listed in the AP info system under the withholding tax.
    Regards,
    Satish Muvva.

  • Exporting video from Premiere 2 Encore... change video in Premiere... Encore does not reflect change

    Hi everyone,
    I have a good question, hopefully it's a Premiere question, but it's also an Encore question.
    First off, I have my video project, simple segments of video, that I've added to my timeline, and I've added a simple
    title to the whole thing ( entire length of videos )
    So far so good.
    So what I did was export the project to Encore, where it loaded fine, and in Encore I worked on making a simple DVD menu for the movie.
    I did about 2 hours on the DVD menu, and then saved the Encore project.
    .... then I realized that the video project in Premiere needed some tweeking, so I went back and did that.  I saved the Premiere project
    and now I'm stumped as what to do next.
    After I saved the newly tweeked Premiere project, I exported it to Encore, and of course, as I knew it would happen, Encore opened up
    a new project with none of my menu system I had made for the DVD.  Argh, now I'm very disappointed..... HOW would I go about getting
    the DVD menu to work with the newly tweeked Premiere project ?
    I'm guessing I'm doing something wrong, and that there is indeed a way to fix this.  I'm really really hoping so.
    Thanks for any help you can offer.
    Dave.

    Hi Dave, To be honest Colin's way is the correct way to do it and it has worked so you should probably do it that way. I just like to
    take the full control back so if I do make changes I like to give it another version number and then match that version number in my
    new saved Encore project taken from the original. It is also the very last thing I do as well so I just find that workflow means I
    control every asset and version but no doubt about it Colin's way is the correct method and the one that allows all
    changes within Adobe to reflect through. Cheers, Steve.

  • Java Reflection API problem... Please HELP!

    Hi,
    I'm writing a Client-Server program set where the Server class receives a Java file, along with some parameters, from the Client class/computer.
    The Server class then invokes a certain method from the Java file it received (depending on the parameters received).
    My Server program keeps giving me a ClassNotFoundException, and I'm going crazy.. I've been trying to fix it for a long time now... but with no avail.
    Here's the Server program.. but I doubt you need to read it all. Please just scroll down to "// The line below is what give me problems:".
    package remoterun;
    import java.net.*;
    import java.io.*;
    import java.lang.reflect.*;
    * <p>Copyright: Copyright ms2000 (c) 2005</p>
    public class Server2 {
        public static void main(String args[]) throws Exception {
            int numParameters;
            int port = 6789;
            boolean isThere = false;
            String className, methodName;
            Object[] parameters;
            ServerSocket welcomeSocket = new ServerSocket(port);
            for (; ; ) {
                 * Create a new socket, called connectionSocket, when some client knocks
                 * on welcomeSocket. This socket has the same port number. TCP then
                 * establishes a direct virtual pipe between the client socket and
                 * connectionSocket at the server so the client and server can send bytes
                 * to each other over it.
                Socket connectionSocket = welcomeSocket.accept();
                // Get number of parameters
                DataInputStream in = new DataInputStream(new BufferedInputStream(
                        connectionSocket.getInputStream()));
                numParameters = in.readInt();
    // Get the parameters for the method to be invoked.
                parameters = new Object[numParameters];
                ObjectInputStream objStream = new ObjectInputStream(
                        connectionSocket.getInputStream());
                for (int i = 0; i < numParameters; i++) {
                    parameters[i] = objStream.readObject();
                // read the class
                File program = (File) objStream.readObject();
                System.err.println(program); // It prints the program name correctly, e.g. Class2.java
    // Receiving some String parameters...
                            BufferedReader inFromClient = new BufferedReader(new
                        InputStreamReader(connectionSocket.getInputStream()));
                className = inFromClient.readLine();
                methodName = inFromClient.readLine();
                // The line below is what give me problems:
                Class classDefinition = Class.forName("remoterun." + className + ".java");
                Object object = classDefinition.newInstance();
                Method[] theMethods = classDefinition.getMethods();
                for (int i = 0; (i < theMethods.length) && (!isThere); i++) {
                    if (theMethods.getName().equals(methodName)) {
    isThere = true;
    theMethods[i].invoke(object, parameters);
    The Client code just sends the stuff to the Server, and it works fine. The code is below if it may help:
    package remoterun;
    import java.net.*;
    import java.io.*;
    public class Client2 {
        public static void main(String[] args) throws Exception {
            int result;
            int port = 6789;
            int num1 = 5;
            int num2 = 6;
            int numParameters = 3;
            String hostIP = "127.0.0.1";
            String className = "Class2";
            String methodName = "add";
            Object[] parameters;
            Socket clientSocket = new Socket(InetAddress.getByName(hostIP),
                                             port);
            // Send numParameters, className, methodName
            DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
                    clientSocket.getOutputStream()));
            out.writeInt(numParameters);
            out.flush();
            Integer num3 = new Integer(num1);
            Integer num4 = new Integer(num2);
            parameters = new Object[] {num3, num4, InetAddress.getLocalHost()};
            File program = new File((className + ".java"));
            ObjectOutputStream output = new ObjectOutputStream(clientSocket.
                    getOutputStream());
            for (int i = 0; i < numParameters; i++) {
                output.writeObject(parameters);
    output.writeObject(program);
    output.flush();
    DataOutputStream outToServer = new DataOutputStream(clientSocket.
    getOutputStream());
    outToServer.writeBytes(className + '\n');
    outToServer.writeBytes(methodName + '\n');
    outToServer.flush();
    clientSocket.close();
    The error I get from the Server class is:
    java.lang.ClassNotFoundException: remoterun.Class2.java
    at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:141)
    at remoterun.Server2.main(Server2.java:94)
    Exception in thread "main"
    (I also get a dialog box saying sthg like, "A fatal exception occured.. will exit now".)
    It's really odd, becuase there were rare times when it works although I don't change the program...
    I tried changing the problem line to stuff like:
                Class classDefinition = Class.forName(className + ".java");or
       Class classDefinition = Class.forName(className);but with no use. Same error. Can someone please pinpoint the problem?
    I'm sure the program does get to the Server, because it can print out the file name.
    PS: Sometimes it works when I use the same PC as the client/server, sometimes it doesn't.... Help :-(
    I'd appreciate some assistance in this.
    Thank you.

    What's this dot-java stuff? Are you sending a source file? If so, that isn't going to work. You need to compile the file and send the dot-class file.
    I'll try that. However, can I make the Client program complie the .java file? For example. something like Class2.compile()? Is this feature available, or do I have to open Class2.java and compile it from there?
    And in the server you need to either store that somewhere in the server's classpath....
    Isn't it automatically stored there? If not, how do I make it stored in the same file as the Server source file (I assume that's what you mean by classpath)?
    Thanks for your help... !!!

  • In Journalization updates are not reflecting in target

    Hi,
    I am using Simple Journalization for SQL Server tables. Only the newly added rows are reflecting in the target but not the updated ones. I have inserted two rows and updated one row in source. Only the inserted records are reflecting in target and updated record is not reflecting in target.
    When I check the intermediate(I$_CDC_TARGET) and JKM tables(J$CDC_SOURCE) both inserted and updated rows are there. Why this updated records are not reflecting in target?
    Both Source and Target tables have Primary keys.
    Thanks,
    Naveen Suram

    Hi,
    I am using IKM SQL Incremental Update (row by row). Updated are coming to I$ table and I am able to see these records in Journal data also.
    One doubt here: In my source no extra columns are coming...I refered JohnGoodwin blog...according to the blog...there should be some extra columns related to journal right? Why they are not coming?
    First I have added the JKM to my model..then added the data source to CDC...then created a sunscriber...then started a Journal....
    Any thing I am missing?
    Thanks,
    Naveen Suram

  • Is airplay or reflections better for projecting an iPad 2 with volume?

    Is airplay or reflections better for projecting an iPad 2 with volume? What cable do you need to connect an iPad 2 and apple tv so you can hear the iPad?

    Barring special circumstances, I doubt that either will be better in terms of volume than the other. But you would use Reflector (which is what I presume you mean) only if you want to show your iPad's screen on a computer. If you have an Apple TV, you don't need Reflector.
    As to cable, you don't connect an iPad to an Apple TV via a cable. It works via WiFi.
    http://support.apple.com/kb/HT4437
    Regards.

  • Doubt in Basic ABAP.

    Hi Gurus,
    I have a small doubt in basic ABAP.
    What is the exact difference between the below statements.
    Types: Begin of ty_data,
                 matnr type mara-matnr,
              end of ty_data.
    Types: Begin of ty_data,
                 matnr type matnr,
              end of ty_data.
    Types: Begin of ty_data,
                 matnr like mara-matnr,
              end of ty_data.
    Types: Begin of ty_data,
                 matnr like matnr,
              end of ty_data.
    data: matnr type mara-matnr.
    data: matnr type matnr
    data: matnr like mara-matnr
    data: matnr like matnr.
    In those above statement which are correct. And the difference between those statements.
    Thanks,
    Srihari.

    hi,
    LIKE means the datatype of the variable is similar to the referenced variable.
    TYPE means it is a predefined data type.
    Eg:
    DATA int TYPE i.
    Here int is of integer data type.
    DATA var LIKE int.
    var IS a variable having same data type of int. which in turn is integer.
    You can find these helpful when you reference database table variables... You need not know what is the datatype defined.
    Also it adds to FLEXIBILITY.
    Whenever you make changes to your database tables and fields,
    that change is REFLECTED back to your program that is,
    You need not change all your program code when you change your table fields...
    Hope you understand and appreciate the flexibility that SAP provides to the programmers...
    Thanks
    Arun

  • What is reflection used for in RMI

    hi,
    I have a doubt regarding the use of reflection in RMI. why it is used and for what purpose?

    Just generally, I would say, it is used for the same things its used for throughout java - to discover at runtime details of classes in the JVM, by examining their internals.
    If you want a more specific answer, ask a more specific question.

  • Master data updation not reflected in Bex report

    Hi,
    There is a field "Approver" in a report. It will only show the name of the Approver. And recently the same approver name has been changed in MDM system and now the problem is newly changed name is not reflecting the reporting. It shows the only old name in reporting.
    My doubt is, what about already loaded record in BW system. Whether changes will be made for the older data. I mean it is possible to overwrite the approver name stored earlier in BW.
    D Raj

    Hi
    Yes, master is always overwritten.
    load the new value to the  approver Info object.
    in RSA1 -> right click --> activate master data.
    Initially when data loaded, records will be Modified version. when you perform activate master data then M versions records will turn to A version.
    records with A version are only visible in Report.
    If your report is on Aggregates, then you have to perform ACR (attribute change run) to update the same new value in aggregate.
    you can use the program RSDDS_AGGREGATES_MAINTAIN.
    Regards,
    Venkatesh

  • Class loading and reflection

    Hi,
    I am trying to use a custom class loader to dynamically load Java classes so that I can get some info (e.g. methods) about the classes via reflection. My problem is that my class loader is written to load Java core classes (i.e. java.lang, java.util, etc.), which as far as I know cannot be done since ClassLoader.defineClass() disallows such attempts. The reason I need to load the core classes is because my program extensively uses Java 5 features (thus have to run using JRE version 5) but need access to Java 1.4 classes in order to get the class' info via reflection.
    I am almost out of ideas and thought that what I am trying to do might be achievable if there is a way where I can use the reflection APIs without loading a class first -- I doubt that this can be done using standard Java API, but I will appreciate it if anyone knows any tools/libraries that can do this or if anyone can give other suggestions to solve my problem.
    Thanks,
    Hendrik

    slackiz wrote:
    Hi,
    I am trying to use a custom class loader to dynamically load Java classes so that I can get some info (e.g. methods) about the classes via reflection. My problem is that my class loader is written to load Java core classes (i.e. java.lang, java.util, etc.), which as far as I know cannot be done since ClassLoader.defineClass() disallows such attempts. The reason I need to load the core classes is because my program extensively uses Java 5 features (thus have to run using JRE version 5) but need access to Java 1.4 classes in order to get the class' info via reflection.
    Just to be clear in case someone else in the future finds this....
    You cannot and must not attempt to "load" core classes from different VM versions into the same VM.
    It doesn't matter what the reason is it is will always be wrong.
    Conversely I am guessing the OP just wants to look/interpret the classes versus actually loading them. So BCEL should work or one could always roll their own class file reader.

  • Casting vs reflection as flowcontrol

    I remember having read somewhere, that casting shouldnt be used to control the flow of statements. I just did some testing, calling a method with code like this:
    try {
    SomeObject b = (SomeObject)object;
    doSomething(b);
    } catch (ClassCastException f) {}
    vs.
    if(SomeObjectClass.isInstance(object)) doSomething(b);
    and it turned out the casting was faster even in cases where an exception was thrown. Could someone explain this. Is my use of reflection wrong?
    Stig.

    Did you try running the test with perhaps 1,000,000
    iterations?Testing the successful cast with 100,000,000 iterations yielded the following results:
    Successful cast... 5407ms
    Successful test... 6540ms
    Successful cast... 6920ms
    Successful test... 7901ms
    Successful cast... 6920ms
    Successful test... 7901ms
    Successful cast... 6940ms
    Successful test... 7902ms
    Successful cast... 6920ms
    Successful test... 7851ms
    For some reason JIT performance degraded, even though the test calls the same method (which performs the test/cast) in each case.
    Testing before casting consistently runs 13% slower than only casting. Having said that, the following figures also imply that each instanceof test took approximately 9.6x10^(-6) milliseconds. That's 10 nanoseconds each test, or 100,000 tests each millisecond. I doubt this would form the bottleneck for any system that actually does anything.
    Just for completeness, the times for the unsuccessful cast with only 100,000 iterations yielded:
    Unsuccessful cast... 4657ms
    Unsuccessful test... 10ms
    Unsuccessful cast... 4597ms
    Unsuccessful test... 0ms
    Unsuccessful cast... 4516ms
    Unsuccessful test... 0ms
    Unsuccessful cast... 4527ms
    Unsuccessful test... 10ms
    Unsuccessful cast... 4466ms
    Unsuccessful test... 10ms
    I don't know what the proportion is here, since the time required for the unsuccessful test is obviously not accurate enough, but I didn't think an exact proportion was called for :-)
    If there is a reasonable chance that the cast will be unsuccessful, it is no longer an exceptional case... which suggests that using exceptions is no longer appropriate, in terms of design if not in terms of performance.

Maybe you are looking for

  • Hard drive not recognized by M35X-S329 laptop

    My laptop got the Windows Blue Screen and I shut it down. Upon restart, I get a message "PXE-E61" Media Test Failure, check cable. When I enter the BIOS, it does not show a hard drive. I've taken out the hard drive and put it in a USB enclosure case

  • My ipod touch won't turn on even when connected to my pc itunes says software for this iphone is not currently available

    My Ipod touch will not turn on even when hooked to my pc. When i open itunes it says it has detected an iphone in recovery mode And You must restore this iphone before using in itunes. When i click restore iphone a msg. comes up saying software for t

  • Adobe Reader for Ipad 1

    Hi Everyone, I would like to complete a file on my Ipad 1. This file is a pdf only supported by Adobe Reader. The file (about 969 k) is suported in my computer whithout any problem, but I can't open it on the Ipad, even if I get the latest version of

  • Accessing podcasts on another mac

    I have some podcasts on my macbook pro Itunes, when i log in to itunes on my macbook air it does not show the podcasts from the pro. I need to be able to have the podcasts on both pc for my work. Any ideas how I can do this please.

  • AC 5.3 - CUP - initiator attributes - conditional logic

    Is there a trick to making the conditional logic work correctly in CUP when trying to define/select the initiator attributes?   Even when I specify to use AND, it seems to still be adding the attribute with an OR condition. For our non-production pro