Using XML with Legacy Business Applications: Chapter 1 | 7
Using XML with Legacy Business Applications: Chapter 1
Additional C++ Considerations
A few words are in order regarding my approach to using C++. In particular, I want to point out handling of strings, exceptions, and constants.
The final ISO and ANSI C++ standard has extremely useful string classes (at last!). These are much easier to use and less prone to runtime exceptions than old C-style char arrays, char pointers, and the C string library. However, these string classes are still not universally supported “out of the box” by many major C++ compilers. They weren’t supported natively by Visual C++ 6.0, which I’m using for this book. Even though some add-on open source and proprietary class libraries do support these classes, many developers use only what is standard from the compiler vendor. In addition, a lot of the legacy C++ code currently in production doesn’t use these string classes. Finally, neither MSXML nor the Apache Xerces C++ API that is its best alternative use the ISO/ANSI string classes. MSXML uses COM strings (as we’ll discuss in Chapter 2 and Appendix C), and the Xerces C++ API uses its own XML char class. They both support conversions to and from char arrays, not ISO/ANSI strings. So, for all these reasons I’m sticking with char arrays, char pointers, and the old C string library.
In the early days of C++ compilers, throwing exceptions for common runtime errors was discouraged because exception handling wasn’t very efficient. The general view is that compilers have gotten a lot more efficient in this regard. However, a lot of the standard C++ library functions still use status codes or return values rather than throw exceptions for every little thing the way that Java does. For this reason I generally use the approach of returning status values from functions rather than throwing exceptions.
Regarding constants, some programmers believe that using #define rather than const to define constants is “evil” [Cline 2002]. I certainly prefer the Java style of defining constant class members. However, I found it extremely awkward to define constants that could be shared across classes using this approach with Visual C++ 6.0. There may be better ways to do it with compilers that provide better support for the final ISO/ANSI C++ standard. I’m sure there are people who are more clever about C++ programming than I am. At any rate, I’ve taken the easy way out in this book and used old C style #defines.
The general picture you should draw from this discussion is that the C++ code presented here does not necessarily represent current best practices in C++ coding. It instead represents “good” practices (I hope) as of the mid-1990s. However, I’m not really too concerned about that. If your legacy C++ applications are very old, they probably don’t reflect current best practices either. Your code may look very similar to mine. On the other hand, if you are using more up-to-date compilers and following current best practices (for example, using the string class instead of char arrays), by all means keep doing what you’re doing and don’t regress. You should, however, still be able to follow my code and update the techniques to your current best practices as appropriate.
~ How You Can Use the Utilities and Code
Welcome to the wonderful world of copyrights and licenses. All the utilities and code developed in this book are open source. Their copyrights are owned by the good people at Addison-Wesley, but you can use the utilities and code under the terms of the GNU General Public License (GPL), Version 2, included as Appendix A. This is the same license under which Linus Torvalds makes the Linux operating system available. I hope you and your organization will feel comfortable using this stuff without having to get the lawyers involved.
In the final analysis the terms of the GPL take precedence, but here is what I intend.
-
You may use the executable, binary forms of the utilities in any way you wish
for any purpose, whether it is public, private, commercial, not-forprofit, and
so on.
If you use the binaries, you do so with the understanding that no warranty of any kind is offered by anyone. The only exception is the case where you have explicitly executed a contract for warranty support with someone. (Just so the lawyers and my editor at Addison-Wesley don’t have anything to worry about, let me make it very clear that your purchase of this book doesn’t imply such a warranty contract. If it did, the book would be a lot more expensive. However, we thank you for buying it anyway!)
You may freely distribute the source code and binaries in their original form, provided that they are accompanied by the GPL and that you give appropriate notice of the Addison-Wesley copyright as well as a disclaimer of warranty. As is the case with Linux, you may charge a reasonable fee for your copy or distribution costs. You may offer warranty support for a fee.
You may modify or use parts of the source code in your programs so long as you retain the existing copyright notices and make your modifications available under the GPL.
The synopsis above applies to everyone. Here are my intentions for more specific groups of readers and users.
-
If you are a consultant, you may make the binaries available to your clients
for a nominal fee to cover actual copy costs. You may modify the source code
and offer the resulting binaries to your customers, again for only a nominal
copy fee, so long as you observe the GPL and make those modifications freely
available to others (like me!) under the terms of the GPL. You may accept payment
from your clients for performing the modifications, but you need to make sure
they understand that they don’t own the modified code. You may contract
with your clients to offer warranty support.
If you are a vendor of proprietary business applications software that does not natively support XML, you may make the binaries available to your customers for a nominal fee to cover copy or distribution costs. If you want to build native XML import/export support into your business application, you may use the algorithms and DOM processing techniques in your proprietary product, but you may not use the source code in your product.
If you are a vendor of proprietary EAI, EDI translation and management, or other middleware software, you may use the contents of this book as an aid to your development efforts. You may use the more common and generic techniques and algorithms. You may not use either the unique design approaches or the source code.
In short, I hope that you benefit indirectly from the programs and the source code and that you feel free to share them with others. However, don’t look to me for free warranty support, and don’t try to make money directly from this work.
(Oh, and just to make sure I haven’t forgotten anything: Everything I just said applies to the binaries and the source code but not to the book itself. It, too, is copyrighted by Addison-Wesley, but we want everyone to pay for copies. We have to get something out of this!)
~ References
Cafiero, Bill. 2002. Remarks while leading a panel discussion at the semimonthly
meeting of the Dallas/Fort Worth Electronic Commerce Forum, July 18, in Irving,
Texas.
Caine, S., and E. K. Gordon. 1975. “PDL—a Tool for Software Design.”
In the American Federation of Information Processing Societies’ Proceedings
of the 1975 National Computer Conference, Anaheim, CA, 19–22 May 1975.
Montvale, NJ: AFIPS Press, pp. 271–276. Available online at http://www.cfg.com/
pdl81/pdlpaper.html, accessed July 11, 2002.
Cline, Marshall. 2002. “C++ FAQ Lite.” Available online at http://www.atd.ucar.edu/software/c++faq/newbie.html#faq-29.7,
accessed March 27, 2003.
Shaw, Mary, and David Garlan. 1996. Software Architecture—Perspectives
on an Emerging Discipline. Upper Saddle River, NJ: Prentice Hall.
W3C (World Wide Web Consortium). 2002. Document Object Model main page. Available
online at http://www.w3.org/DOM/, accessed
July 10, 2002.
Apache Software Foundation: http://www.apache.org
Essential XML Quick Reference, by Aaron Skonnard and Martin Gudgin (Boston,
MA: Addison-Wesley, 2002). I don’t directly recommend very many other
books in this book, but this is one I suggest without reservation. If you deal
with XML on any technical basis at all, this book needs to be in your collection.
Microsoft’s XML Resources: http://msdn.microsoft.com/xml
Sun Microsystem’s Java Technology and XML: http://java.sun.com/xml
World Wide Web Consortium: http://www.w3.org The XML Cover Pages: http://xml.coverpages.org
Created: March 11, 2003
Revised: January 1, 2004
URL: http://webreference.com/programming/awxml2/

Find a programming school near you