Well, the following bit of code: Object obj = uctx.unmarshalElement(); System.out.println( obj.getClass( ).getName( ) );
Will print out: "SwissProt" In the example you gave below; in other words, java.lang.Object.getClass( ) always returns the actual type of the object. So, if you're going to be doing reflective programming, you probably just want to pass "obj.getClass( )" into your reflective methods and code them generically from there. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tamas Hegedus Sent: Thursday, August 25, 2005 9:34 AM To: [email protected] Subject: [jibx-users] dynamic casting & performance Hi, My current problem is loosly connected to jibx but all the routs go to Sosnoski Inc: I was googling the 'cast...' I would like to make dynamic casting, but it seems it not commonly used and people bringing up the topic does not know much about it even about the casting (?). E.g. I have red that the casting is just saying to the compiler that you know better than the compiler that this object is that particular type. But see my example: // This works fine Object obj = uctx.unmarshalElement(); SwissProt sp2 = (SwissProt) obj; for(int i = 0; i < sp2.accessions.length; i++ ) { System.out.println( sp2.accessions[i]); }; // This doesn't (I am not surprised) Object obj = uctx.unmarshalElement(); for(int i = 0; i < obj.accessions.length; i++ ) { System.out.println( obj.accessions[i]); }; =========================================== I would like to have the following situation: > I write a java-package (a very dynamic one); > The users creates the jibx binding fieles and the corresponding java class files; ====> I do not know what type of object will be unmarshelled at the time of the writing of my package; > The users have to make compile and binding steps (but I do not think that my problem can be solved at this step); !!! > unmarshaling into the object that was created by the user; that needs the dynamic casting; how??? > I plan handle the object with java reflection (and my own classes reflecting the object). The other important thing connected to Dannis' earlier work: I would like to unmarshall large documents with pretty large and complicated objects with pretty high number of objects; the performance of the casting could become important bottleneck. Thanks for the solutions :-), ideas, comments, Tamas -- Tamas Hegedus, PhD | phone: (1) 919-966 0329 UNC - Biochem & Biophys | fax: (1) 919-966 5178 5007A Thurston-Bowles Bldg | mailto:[EMAIL PROTECTED] Chapel Hill, NC, 27599-7248 | http://biohegedus.org ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ jibx-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jibx-users ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ jibx-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jibx-users
