Reflection - Two packages/classes with same name

Hi There !
I am in a situation and I need some help, if anyone can help me.
I have two tools to work with different version of a server application. Now, the admin wants to have only one tool to work with both server app.
The problem is that the server app has a jar file with the API to be used to access it. One jar for each version.
Inside those jars files I have the same package and the same class ! But the implementation is diferent. So I will need to access one jar when accessing the old server app and another jar to access the new server app.
I have no idea how to do it.
I search arround google and I found that I can load a class at runtime and then with Reflection call its methods.
I made a test app (simple, just 2 different jars with same package and class name just printing a Hello World and Bye World) and it worked very well.
But when I tried to apply this to my code, I realize that one class need the reference of the other class...
For example, I have a class named Server and other called ServerStatus.
The Server class do the connection to the server and the ServerStatus get some server information. But the method that give me this information has a argument asking for an object of Server... like this:
Server serv = new Server();
serv.connect();
ServerStatus servStat = new ServerStatus();
servStat.getServerStatus(serv);I tried to do this with reflection but in the part that I need to invoke the method getServerStatus, I do not have the name of the class that is the argument (in this case Server).
Something like this:
   Method  m = serverClass.getMethod("getServerStatus", new Class[] {?????.class});
         result = (Boolean)m.invoke(server, new Object[] {serverStatus});Do you have any ideiias to resolve this ?
Or something different from reflection to access two different implementations with same package and class name ?
If you need any other information, please ask me..
Thank you so much !
Regards,
Thiago

Thiago wrote:
Hi.
But now, how can I handle the object (because the newInstance() return a Object object.... not the class that I want (Server, for example)).
When you declare a reference to be something more narrow than "Object" you're telling the compiler what methods and fields the referenced object supports. With a dynamically loaded class you can't do that at compile time, because the nature of the class isn't known until you load it at runtime.
That's why it's very handy if you know that the class you are to load implements some interface which is known at compile time. Then you can access the object through a reference to that interface.
Otherwise there's really no option but to handle the object through reflection. Find methods with getMethod() on the Class object and invoke them with Method.invoke().
There are tricks to impose an interface onto a dynamically loaded class at runtime, but they are just neat ways of working through reflection.

Similar Messages

  • Problem in importing two different classes with same name...

    I have to import two different classes in my program with the same name....
    import org.apache.lucene.document.Document;
    import org.w3c.dom.Document;
    //    I AM USING THE DOCUMENT FROM W3C PACKAGE HERE....
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                     DocumentBuilder builder = factory.newDocumentBuilder();
                     InputSource is = new InputSource( new StringReader( tempString ) );
                     d = builder.parse( is );
                     NodeList images = d.getElementsByTagName("img");
                     int length = images.getLength();
                     for(int i = 0;i<length;i++)
                         Node image = images.item(i);
                         String tempAltText = image.getAttributes().getNamedItem("alt").getNodeValue();
                         altText = altText.concat(" ").concat(tempAltText);
                     }and the error i am getting is
    [javac] C:\Documents and Settings\sumit-i\WolframWorkspaces\Base\WolframNutch\src\java\com\wolfram\nutch\indexer\InfoCenterFilter.java:20: org.apache.lucene.document.Document is already defined in a single-type import
        [javac] import org.w3c.dom.Document;
        [javac] ^
        [javac] C:\Documents and Settings\sumit-i\WolframWorkspaces\Base\WolframNutch\src\java\com\wolfram\nutch\indexer\InfoCenterFilter.java:132: incompatible types
        [javac] found   : org.w3c.dom.Document
        [javac] required: org.apache.lucene.document.Document
        [javac] d = builder.parse( is );
        [javac] ^
        [javac] C:\Documents and Settings\sumit-i\WolframWorkspaces\Base\WolframNutch\src\java\com\wolfram\nutch\indexer\InfoCenterFilter.java:133: cannot find symbol
        [javac] symbol  : method getElementsByTagName(java.lang.String)
        [javac] location: class org.apache.lucene.document.Document
        [javac] NodeList images = d.getElementsByTagName("img");
        [javac] ^
        [javac] Note: Some input files use unchecked or unsafe operations.
        [javac] Note: Recompile with -Xlint:unchecked for details.
        [javac] 3 errorsany idea ..how to resolve it
    Edited by: ping.sumit on Jul 16, 2008 3:39 PM
    Edited by: ping.sumit on Jul 16, 2008 3:40 PM

    now i changed the code to
    import org.apache.lucene.document.Document;
    import org.w3c.dom.Document;
    org.w3c.dom.Document d = null;
    try{
         System.out.println("in author");
                   URL url = new java.net.URL(urlString);
                   java.net.URLConnection conn = url.openConnection();
                   BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                   while ((in.readLine()) != null)
                        //tempString = tempString.concat(in.readLine());
                        String temp = in.readLine();
                        tempString = tempString + " " + temp;
                   System.out.println("the string in author" + tempString);
                    in.close();
                    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                     DocumentBuilder builder = factory.newDocumentBuilder();
                     InputSource is = new InputSource( new StringReader( tempString ) );
                     d = builder.parse( is );
                     NodeList images = d.getElementsByTagName("img");and their is only one error i am getting ...and that is
    [javac] C:\Documents and Settings\sumit-i\WolframWorkspaces\Base\WolframNutch\src\java\com\wolfram\nutch\indexer\InfoCenterFilter.java:20: org.apache.lucene.document.Document is already defined in a single-type import
        [javac] import org.w3c.dom.Document;
        [javac] ^
        [javac] Note: Some input files use unchecked or unsafe operations.
        [javac] Note: Recompile with -Xlint:unchecked for details.
        [javac] 1 error

  • Two soa domain with same name "TestSOADomain" sharing same SOA schema ?

    I tried creating two soa domain with same name "TestSOADomain" (different path) sharing same SOA schema .However one domain came UP to Running mode and other domain going to AdminMode and "soa-infra" application of that domain is not active.
    I do want to understand can this be possible with SOA ,ie. two soa domain sharing same SOA schema ?
    If possible what are all the problems might come
    1. While executing soa composites with asyncronous behaviour ?
    2. How the polling services will work ?
    3. will the XREF_DATA table ROW_NUMBER column inserted uniquely while inserting data from two different domain into same SOA schema ?
    4. Other issues ?
    Thanks

    Each domain is expected to refer to its own unique database schema. Same SOA schema should not be shared by multiple SOA clusters/domains. It is technically possible though, I suppose, and still can run fine any one SOA environment at any given time with the other SOA environments/domains (sharing the same SOA schema) shutdown. It is not the general/recommended practice to share SOA schema across domains and there could be potential implications and unexpected behavior, particularly when the SOA environments pointing to the same schema are all running at a time.

  • Distringuishing between 2 classes with same name

    Hi,
    I have just recently begun programming in Java on a software project with more than one programmer. On of my coworkers had us use the directory structure such that our packages are name with our domain backwards (ie, an example package is gov.lanl.gui). He was under the impression that by structuring things in this manner one would not have to worry about duplicate class names. So to test it he made a class called Point (knowing such a class existed in the Java API). When he tried to compile the code the compiler was confused as to which Point.java he wanted to use.
    Is there a way to reconcile this without having to make sure a class doesn't already exist with the same name?
    thanks,
    Keri

    I am confused by the statement:
    When he tried to compile the code the compiler
    was confused as to which Point.java he wanted to use.Why would there be more than one Point.java on his workstation? Did he extract the src.jar to his local file system? Please post the actual compiler error.
    He is correct that the package structure allows for two different classes to have the same name. If you import java.util.* and java.sql.* into a class and then try to reference the Date class you will get a complier error. This is because there is a java.util.Date class and also a java.sql.Date class. This is one of the reasons that you shouldn't usually import an entire package. Another is that it can make complilation really slow. If you have to import both classes you can do so using the entire package structure in front of the class name e.g.
    java.util.Date utilDate;
    java.sql.Date sqlDate;

  • Are Multiple Classes with Same name in a single Class valid ?

    package inheritance;
    interface Foo
         int bar();
    public class Inh6 {
         class A implements Foo  // THis is the first class
              public int bar()
                   return 1;
         public int fubar(Foo foo)
              return foo.bar();     
         public void testFoo()
              class A implements Foo // THis is the second class
                   public int bar()
                        return 2;
              System.out.println(fubar(new A()));
         public void testFooModified()
              class A implements Foo // THis is the first class
                   public int bar()
                        return 4;
              System.out.println(fubar(new A()));
         public static void main(String[] args) {
              new Inh6().testFoo();
              new Inh6().testFooModified();
    O/P :
    2
    4My question is this class "A" which is present in the different methods like testFoo() and testFooModified() different declarations of the same class or altogether different classes local to each method,something like err...Local Class ?
    Thanks in Advance.

    kajbj wrote:
    My question is this class "A" which is present in the different methods like testFoo() and testFooModified() different declarations of the same class Why would it be the same class? They have different scopes.
    KajSo you mean to say they are actually different classes with the same name,which will be invisible out of the respective methods in which they are defined ?
    Thanks.

  • Responding to two user events with same name

    LV 2013, Win 7, & LVRT 2013, PharLap OS
    I have a situation where I create an ARRAY of User Events, one for each "domain" .  
    A "domain" is an area of DAQ: there is a SCXI domain, a CDAQ domain, an EtherCAT domain, several domains dealing with TCP instruments etc., about 25 domains all told. The name of the event is "New Channels This Domain".
    When a new configuration comes to the PXI from the host, I sort out the channels by their domain and generate a user event for whichever domains have channels that have changed: more channels, fewer channels, differences. If a domain has no channels that have changed, I do not generate an event for it.
    There is a handler for each domain: in that handler, I pick out the event for this domain from the array, and register to receive it.  I have an event structure that responds to the NEW CHANNELS THIS DOMAIN event.  Since it is an array, then no matter which domain I select, the name of the array is "New Channels This Domain".
    All this works fine.
    Now I have a situation where it makes sense to have one handler for TWO domains.
    I can pick out TWO elements of the array just fine, and register them both.   (See attached pic)  But now, in the EDIT EVENTS FOR THIS CASE list, I have TWO events called "New Channels This Domain".  I can select one for one case, and the other for the other case and it seems to work.
    --- Is there any heartache ahead with this scheme?  
    --- If I change the events in the clusters before, is it going to confuse LabVIEW?  
    --- Is there something I can do to change the name of the event after I pick it out of the array?  
    --- Is there something I SHOULD do at that point?
    Like I said, it seems to work, but I'm leery of it staying that way - I've had event structures disturbed before (LV2010) when changing cluster order.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

    CoastalMaineBird wrote:
    Thanks, Greg for that link.  I gave kudos to the idea of the COERCE TO TYPE function, and it seems like it would do the trick, but as of LV2014 it's still not on the palette.
    My question still remains: is it necessary?  Will the event structure remember that it's supposed to use the SECOND event named "X", through all edits and recompiles?  My guess is no, but I'll listen to alternative stories.
    I've been using the Coerce to type for this and enums in versions 2011 through 2014 since learning about it.  I've seen no issue using it in these cases.  I'm guessing it doesn't behave in an expected way for extreame uses which is why NI doesn't release it yet.
    As for would it always know to go to the second event if they are named the same?  My guess is yes.  They maybe named the same but they have different references.  I would think it would be just like having two controls with the same label.  You should never do this, but if you did, and made a local variables on one and wrote to it, it would always write to the correct control.  It would never write to the different control with the same name.  Now even if this is the case it could be confusing to a developer looking at the code, which is why I strongly suggest having unique names.  But if you don't I suspect every thing would work fine, just have a bold comment or something explaining what each case actually is handling.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Does alias exist to differentiate between 2 classes with same name?

    I have 2 classes (a domainmodel-class and a webpage-class) with the same name. Of course I get a naming-conflict when I want to reference the domainmodel-class from the webpage-class (because they have the same name).
    I was wondering if there's a language construct in java to import my domainmodel-class under a different name / alias in the webpage-class.
    Of course I could simply rename my webpage-class, but that has some impact which I'd rather avoid.
    Thanks,
    Geert-Jan

    gbrits wrote:
    I have 2 classes (a domainmodel-class and a webpage-class) with the same name. Of course I get a naming-conflict when I want to reference the domainmodel-class from the webpage-class (because they have the same name).
    I was wondering if there's a language construct in java to import my domainmodel-class under a different name / alias in the webpage-class.
    Of course I could simply rename my webpage-class, but that has some impact which I'd rather avoid.
    Thanks,
    Geert-JanNo, you can't do that. But one class can be imported, and the other one be used with fully qualified name all of the time.

  • Two mail accounts with same name and SSL not allowed?!

    Dear Common Wisdom:
    I have two accounts in my Mail program with the same web host. That means the outgoing mail server has the same name.
    If I put on SSL, though, it is not allowed to save two servers with the same name in two different accounts.
    Can I get around this and still use SSL for both accounts?
    Thanks!
    Kostas

    Each domain is expected to refer to its own unique database schema. Same SOA schema should not be shared by multiple SOA clusters/domains. It is technically possible though, I suppose, and still can run fine any one SOA environment at any given time with the other SOA environments/domains (sharing the same SOA schema) shutdown. It is not the general/recommended practice to share SOA schema across domains and there could be potential implications and unexpected behavior, particularly when the SOA environments pointing to the same schema are all running at a time.

  • Batch Rename - Two File Formats with Same Name

    Hi everyone!
    I'm having troubles using the batch rename function i Bridge CS5.
    I've got several pictures that I've captured in both jpeg and raw. When importing the pics with windows photo import they get the same name. This means that I've got one JPG and one RAW file which contains the "same" picture, and have same name as shown below:
    What I would like to do is to rename the pictures, but still have Bridge name the same pictures with the same name as shown below:
         IMG_1268.CR2          ->          Picture 2011 - 0001
         IMG_1268.JPG          ->          Picture 2011 - 0001
         IMG_1269.CR2          ->          Picture 2011 - 0002
         IMG_1269.JPG          ->          Picture 2011 - 0002
    Is this even possible? And if possible, how?
    Thanks in advance
    Martin

    Most things are possible and so is this..
    Make sure you do a test first by copying the files to a temp folder!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    First copy the script below and paste it into ExtendScript Toolkit (this gets installed with Photoshop)
    #target bridge
    var sels = app.document.selections;
    for(var a in sels){
    var f = decodeURI(sels[a].spec.name);
    var newName = "Picture 2011 - "+ zeroPad((f.match(/\d{4}/)[0]-1267).toString(),4)+ f.match(/\....$/);
    sels[a].spec.rename(newName);
    function zeroPad(n, s) {
       n = n.toString();
       while (n.length < s)  n = '0' + n;
       return n;
    Now open Bridge and select the files you want to rename, then run the above script from ExtendScript Toolkit.

  • Can I have two Aperture projects with same name?

    Hi. I'm new to Aperture and an advanced iPhoto user. I started using Aperture sharing the same library with iPhoto (that new functionallity).
    I've read lots of manuals and tutorials (Apple's and others) as well as this support topics. I understand iPhoto Events are now Aperture Projects and I've read a lot about how should it be organized and so on.
    My problem is: I got, for example, 4 iPhoto Events with the name "Friends". The appear in Apperture as 4 Projects named "Friends". I decided to rename one of them and the I came back to "Friends" name. Aperture won't let me: it appends "(1)". It seems I cannot name to Projects the same way, although I have that.
    Before: Friends, Friends, Friends, Friends
    After renaming one of them and trying to get back to original name: Friends, Friends, Friends, Friends (1)
    I have that duplicated name because it is like a title, photos of my friends in different time (one Friends is from 2005, other from 2010, and so on, for example).
    It seems pretty bad I have to come up with a new name for each new Project, considering I have hundreds of them today. Any tips? Thanks.

    If there is nothing separating the images then put them all in the same project. If you have a project Friends you know all your friends images are in there and you can find the ones you want by date or keyword or even Face.
    There is no requirement to have the images from different times at the bar to be in different projects. I personally wouldn't work that way but if having a project called Friends at Bar works for you then place all the images of your friends at the bar in that project.
    Of course another way to look at this is to use albums to pull all the images of your Friends at Bars together. Don't have the name of the project organize your library, create albums and/or smart albums to collect the images into meaningful groupings.
    regards

  • Use Class with Same Name as Default Package Class

    I am upgrading a project to Flash CC and need to use the old JSON class in com.adobe.serialization.json. When I compile, I get an error, "1061: Call to a possibly undefined method decode through a reference with static type Class" because it probably is trying to use the newer default package JSON class rather than the one in com.adobe. I have the import statement in my class, "import com.adobe.serialization.json.JSON", but I guess its checking against the default package and giving me a compile error when I call "var parts:Object = JSON.decode(jsonData);"

    Thanks. I changed my publish settings to fp 10 which fixed it for now. I was hoping there might be a more elegant solution as the custom class is actually an Adobe class that would be better to not to have to rename.

  • Is it OK to have two SBS Servers with same name, on different subnets but connected over a VPN?

    Hi Everyone,
                       I'm just about to connect up two SBS 2011 Servers with the same server name but on different subnets & domains over a VPN.
    So for example both servers will have the name Server01, one would have an ip address of 192.168.85.5, the other 192.168.86.5, they both then would be connected over a VPN.
    Can anyone foresee any issues with this configuration, like DNS & DHCP requests, adding new machines to the domain, mapping drives etc.
    Many thanks,
    Nick

    Hi Larry & Strike First,
                      Thank you for your responses. I understand that this is an unusual situation. Basically I've recently taken over the IT support for this client. The client has just had a new phone system installed
    & are asking if they can speak to each office internally, which can easily be done once I setup the VPN.
    However I noticed whilst looking at this further that the Server names are the same, hence my question?
    Am I right in saying that providing the workstations  have a trust relationship with their own domain controllers through their individual domains on separate subnets, that hopefully there shouldn't be any DNS issues between the two domains and Servers?
    I could build a new VM if you feel it would be better practice to do so?
    Many thanks for your assistance,
    Nick

  • Two virtual disks with same name - how to safely delete one of them

    I mistakenly created a disk in a repository that uses the same friendly name as an existing disk that is in use by a virtual machine.
    Can I safely remove the second disk with out OVM trying to delete the original disk as well?
    Thanks

    Yes, you will be safe, bacause OVM uses the disk ID to identify the disk.
    You can also use the little triangle just to the left of the virtual disk name. It will open a message saying if disk is in use by a Virtual machine.
    Also, the GUI will not let you delete a disk which is in use.
    If you want another way, you can "edit" the disk in the OVMM GUI, read its ID, cancel the edit, and go delete it from a root command shell on the VM server.
    br.

  • Two folder locations with same name

    I have Two "Local Disk (D:)" in the folders section of lightroom.  I have no idea how it got this way. When I expand each "Local Disk (D:)", there are unique subdirectories.  I would like to have everything under "Local Disk (D:)", how do I merge the two?  When I try to grab a subfolder and move it to the first "Local Disk (D:)", it tells me that the subfolder already exists.  See screenshot..

    This happens to me some times too. I'm on a Mac and my photos are on a Drobo S connected via FireWire.
    It seems that Lightroom doesn't like the Drobo as I frequently have problems locating it, having to re-link the catalogue, sometimes resulting with the problem above.
    Now I re-installed the OS the see whether that solves anything. But overall I'm finding Lightroom 3 to be a bit problematic compared to LR1 and 2, at least on a Mac.

  • How to separate two contact with same name

    Hi, anyone knows how to separate two contacts with same name in Contacts?  Actually they are two persons from two gmail contacts with same name but different contact numbers, different emails....etc, but Contacts assume they are same person and merge them as one!

    FG,
    In Lion, you have the File > Duplicate option. You will then have two copies of your document open, and the one on top will have the temporary filename "OriginalFileName copy", and your next responsibility is to File > Save (or Command-S) and rename the duplicate. At this point, you edit the copy's name, to perhaps ...copy 1, or whatever you wish. The document you had open when you initiated the File > Duplicate will still be there on your screen, waiting for you to Close it or continue editing.
    Jerry

Maybe you are looking for

  • How to get the last record from the database

    I am using MS Access database and Swings as GUI. I want to get the last record of a particular column from the table and store it as a varaible.

  • Error 0x8002006E When trying to burn data to a DVD

    I've been having a recurring problem when I try burning files to a Memorex DVD+R on my G5 iSight. My configuration is the standard SuperDrive, etc. I open the DVD, drag files, click "burn" and I get this error shortly after the process begins. I'm no

  • UNION ALL -

    Hi Guys, I require order by to be applied on both queries separatly. select a1,a2 from a union all select b1,b2 from b; in above scenerio, i want to sort query 1 by first column ie.a1 and query 2 by sencond column i.e. b2. Please suggest pointers on

  • Help oN PM report

    Hi, I need to develop a PM Report, where each PM order is assigned to Work centre and Cost centres, depicting the Actual Costs, Planned Cost and Estimated Cost againt the PM order.        Though I am getting all the reqd Characteristics in the cube 0

  • Repeatable non-application specific crash on iMac C2D

    I am very used to enter Chinese punctuation by pressing the key combination option+` on my iBook, but now, whenever I press these keys together on my iMac, it causes an exception EXCBADACCESS (0x0001) with codes KERNPROTECTIONFAILURE (0x0002), and th