TBright's BLOG

One PM floating down the stream. What? Did you expect a rock parting the waters?

XML Conversion - A better look at the hierarchy issue

I will apologize again for this post taking me forever to write. 

 

When I converted the Apache project I ran into a fundamental or more precisely a philosophical problem; that, unfortunately, can not be fixed by the JLCA.  The problem is whether it is better to keep to the original structure or migrate that structure to the .NET structure.  While hierarchy differences are always some of the most difficult issues to resolve, this wasn’t an issue until I made it one.  The Apache project was almost completely self-contained.  The project had its own interfaces and super-classes.  The problem was that I started to convert the classes that implemented (for example) Apache’s XMLDocument interface into classes that extended .NET’s concrete XmlDocument class.  As you can imagine this caused a number of classes to now “have” multiple parent classes which I had to resolve, not to mention duplication of code (since Apache’s sub-classes had implemented the XMLDocument interface).  This I kind of expected although it turned into more of a headache than I ever would’ve imagined.  What I didn’t expect was the thousands of now incorrect virtual, overrides, and new keywords that the JLCA had inserted (assuming that I would continue to try and use Apache’s hierarchy) which I now had to fix.  These were unbelievably tedious, and I came very close to not finishing the conversion a number of times.  What makes these so bad is that they are easily covered by “real” compiler errors and so they seem to jump out at you continuously and make keep you from fixing all of them once and for all.  Plus they have a cascading effect that goes down the hierarchy, so as you “fix” one, you break each of that class’s sub-classes.  And so on, and so on…

 

I still believe (take this with a grain of salt since I am still a high-level “programmer”) that it is best to be as close to the bare-metal as possible.  What I mean is that I would rather convert the XML libraries to use .NET’s built-in support than re-implement this myself (or use Apache’s implementation of it).  But this did end up making a lot more work.  I have to admit that the JLCA does not handle this aspect of conversion very well.  The JLCA tries its best to keep the exact form/function of the Java code which, in this case, was at odds with what I wanted my C# code to be.  I think this is a rather extreme example of this problem since all of Apache’s XML functionality is present in .NET’s XML libraries so just about every class I ran into had to be changed to accommodate this.  What I ended up with is a programmatic interface that pretended to mirror Apache’s XML interface on top of .NET’s XML libraries.  This would’ve been a lot faster to just implement this interface from scratch instead of pruning all of the original Java implementations out of the migrated code one at a time.  I actually created almost an exponential growth of errors as I went about my restructuring! 

 

While I can justify this as a great experiment that I learned a lot doing (I love my job!), from an Enterprise view this should stand as a warning.  The JLCA, or any tool for that matter, is just that: a tool.  If, at any point during the migration, you find that you are in a similar situation (exponential error growth, cutting massive amounts of the old Java logic that is now covered in .NET, …) you should stop and re-evaluate if it wouldn’t be easier to start writing C# from a blank file.  This isn’t to say that you have to choose one path or the other, if I was writing a real Enterprise application that happened to use this set of Apache’s libraries I could easily convert the rest of the application with the JLCA and only implement a similar interface on top of .NET’s libraries as I suggested above (or you could migrate the rest of the app and then modify the calls that use to use Apache’s libraries to use .NET’s and cut the interface out completely.) 

 

I would like to point out that I am not saying the JLCA is not useful, just that it isn’t the only option and, although it pains me to admit, it is not always the best option.  Besides rewriting there is also J#, interoperability, and other 3rd party tools that could be used instead or in addition to the JLCA.  The idea is to choose the right approach for your situation.  This is an aspect that I don’t think a lot of people think about; especially the J# option.  J# has full access to the .NET platform and the J# DLLs work just as smoothly with a C# project as any other .NET DLL.  Areas of your application that limit themselves to the JDK 1.1.4 functionality or just fit within J#’s domain would be converted at almost 100% instead of the JLCA’s 85-90%.  This could save you a lot of time by converting component of you application individually with whichever tool was easiest.  I think that I will try to focus the next couple of posting on this aspect of conversion instead of the more technical issue-fixing side.  Hopefully I will be able to get back into my weekly posting schedule again!

Published Monday, May 03, 2004 1:45 AM by tbright
Filed under:

Comments

 

Andreas Häber said:

Do you know if the Microsoft-Sun agreement will change things for JLCA? I'd really like to see is support for a newer version of J2SDK instead of the JDK1.1.4.

Recently I tried to convert a library for MBUS written in Java using JLCA. Because the library used a lot of security features of the newer versions of J2SDK I just gave up trying to convert it. Instead I used P/Invoke to use a C-library which did the job, but the Java version of the library is a lot more complete.
May 3, 2004 4:57 AM
 

Adrian Moore said:

I've found moving to J# is the best option. Its like using managed C++. The only limitation is that it doesn't use managed types, but its own. Looking forward to VS 2005 when this limitation can be eliminated and J# becomes a first class language.
May 3, 2004 6:16 AM
 

Umesh Unnikrishnan said:

Adrian: J# is a first class language in .NET. And, J# does use the managed types, but with something like a wrapper so that they're compatible with Java semantics. Is this an issue for you? I'd like to know more about why you think this is an issue.
May 3, 2004 10:34 AM
 

TBright said:

I have high hopes for the Sun agreement helping the JLCA in the future. But I can only speculate on how… One aspect of the previous Sun-Microsoft "arrangement" was Microsoft being forced to use IBM's implementation of the JDK. This limited the latest JLCA release (version 3.0 which is currently in Beta) to JDK 1.3 since there wasn't an IBM implementation of 1.4. But I have to say that I am not a lawyer so I have to wait for people who are to interpret what this mean for my team. Simon Guest (the Interop-guru and author of .NET and J2EE Interoperability Toolkit) would be a better person to ask about this. If Sun really wants to try and work with Microsoft then our customers can only benefit. Allowing MS to continue supporting the MSJVM is a great start! I can’t tell you how many customers were in serious trouble and starting to panic about that issue.
May 3, 2004 10:50 AM
 

Umesh Unnikrishnan said:

Adrian: Take a look at
http://msdn.microsoft.com/library/en-us/dv_vjsharp/html/vjlrfobjecthierarchysemantics.asp. This should give you an idea of how Objects in J# work.
May 5, 2004 7:05 AM
 

Peter Gloor said:

I hope to see more postings covering this aspect of conversion soon. I've been running into similar problems with a larger Java application based on Xerces and Xalan.

I've given up and startet to redesign and rewrite the application from scratch. Even the architecture will be different, there are a large number of methods and classes I can take from the JLCA conversion and reuse in the new project.

Before I desided to redesign the application I made some evaluations. At the moment I expect the new application to be much smaller (about 40% (!) of the code can be eliminated) and faster.

June 27, 2004 8:37 AM
 

TBright said:

I need to get back on track! With TechEd, Whidbey Beta 1, and finishing version 3.0 my Blogging has fallen through the cracks. I am glad that you are finding the JLCA useful. What exactly would help you the most helpful with your conversion?
June 28, 2004 11:41 AM
 

TBright [MSFT] said:

Forgot to add:
As always, feel free to send me an email if/when you run into any issues or problems with your conversions. TBright is my alias at MS so just add the @microsoft.com to that for my email address.
June 28, 2004 11:43 AM
 

dianying xia zai said:

July 26, 2004 12:16 AM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker