tag:blogger.com,1999:blog-10170838519107358102024-03-05T09:27:54.719-08:00JavaUnknownnoreply@blogger.comBlogger11125tag:blogger.com,1999:blog-1017083851910735810.post-52930437130784198932009-01-10T10:35:00.000-08:002009-01-14T06:19:29.784-08:00Why Certify ?<span style="color: rgb(0, 0, 0);font-family:arial;" >Certifications at times play a good role when hiring an employee. A developer can be weighed by the certifications that he/she holds. But of what good are certifications ? Do they really help your career grow ? Let us dissect the good and bad of certifications and we can then address the crux of the problem</span><br /><br /><span style="color: rgb(0, 0, 0); font-weight: bold;font-family:arial;" >Good</span><br /><ul style="color: rgb(0, 0, 0); font-family: arial;"><li>You know the boundaries of the technology / area which you want to learn.</li><li>Your have theoretical mastery, and some certifications give you practical mastery as well.</li><li>Your prospective employer is probably going to be impressed.</li><li>That "Certified" logo is sure going to look great on your resume.</li></ul><span style="color: rgb(0, 0, 0); font-weight: bold;font-family:arial;" >Bad</span><br /><ul style="color: rgb(0, 0, 0); font-family: arial;"><li>Brain dumps, real exam questions kill the value of a certificate.</li><li>The certification process might expect you to learn things that are not practical to your work environment</li></ul><span style="color: rgb(0, 0, 0);font-family:arial;" >I have been interviewing candidates for quite a while now, and I must say that the brain dump problem is a very serious one. Of all the candidates that said they were SCJP (Beginner Java programmer certification) certified, only 2 actually deserved the certificate. Two ! This is from a sample space of around 100 - 200 candidates. What is more shocking is that some of these candidates actually think that they can pass off their fake certificates in an interview. Here is a conversation transcript from a recent interview. The candidate had passed SCJP with a score of 93%.</span><br /><br /><span style="font-weight: bold; color: rgb(51, 51, 255);font-family:arial;" >Interviewer</span><span style="color: rgb(0, 0, 0);font-family:arial;" >: What is println() in System.out.println() ? Is it a method, an abstract class, an interface ?</span><br /><span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" >Candidate:</span><span style="color: rgb(0, 0, 0);font-family:arial;" > I dont know.</span><br /><span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" ><span style="color: rgb(51, 51, 255);">Interviewer</span>:</span><span style="color: rgb(0, 0, 0);font-family:arial;" > Explain an object oriented concept / principle and its implementation in java.</span><br /><span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" >Candidate:</span><span style="color: rgb(0, 0, 0);font-family:arial;" > Security is one of them. Java's internal application firewall will secure the application. The byte code is also compiled quite strongly. Which helps with the security.</span><br /><br /><span style="color: rgb(0, 0, 0);font-family:arial;" >My brain died and my java IQ dropped by 100 points after that 6 minute interview. This was an exceptionally bad case however. It did put a smile on my face though :). </span><br /><br /><span style="color: rgb(0, 0, 0);font-family:arial;" >I give certifications zero importance during interviews. The irony is that I have 8 technical certifications under my belt and I earned each and every one of them. The frustration I feel when I encounter people who cheat is just unexplainable. Cheating to earn a certificate is comparable to buying a fake engineering degree. If you didn't earn it, don't bother putting it on your resume. Some pointers that cheaters simply do not understand</span><br /><ul style="color: rgb(0, 0, 0); font-family: arial;"><li>Those who cheat to get their certificates look really stupid in an interview. Asking as little as 2 questions would suffice to separate the fakers.</li><li>Why would I want to hire someone that lies in their resume ? How do I know that other data in the resume like projects / experience / roles are not fake. Most cheaters dont survive the interview and the job.</li><li>Not only do you hurt yourself, you also hurt people who have read books night and day in order to pass these exams. </li><li>The only people that win in this scenario are the ones that sell the dumps.<span style="color: rgb(0, 0, 0);font-family:arial;" ></span><span style="color: rgb(0, 0, 0);font-family:arial;" ><br /></span></li></ul><span style="color: rgb(0, 0, 0);font-family:arial;" ><span style="font-weight: bold;">So who is to blame ? </span><br /><br /></span><span style="color: rgb(102, 102, 204); font-weight: bold;font-family:arial;" >Candidates themselves:</span><span style="color: rgb(0, 0, 0);font-family:arial;" ><br />Some people are just lazy. They want to take the easy way out and earn the certificate without breaking sweat. Why "earn" a certificate when you can cheat ?</span><br /><br /><span style="color: rgb(102, 102, 204); font-weight: bold;font-family:arial;" >Employers:</span><br /><span style="color: rgb(0, 0, 0);font-family:arial;" >There are employers that want you to take 2 certifications per year whether you like it or not. Most employers do not have any way of verifying if the certificate was earned or bought. They need to understand that providing such targets to employees can hurt them. Some employers reimburse certifications, and</span><span style="color: rgb(0, 0, 0);font-family:arial;" > this will burn a hole in the their pocket.</span><span style="color: rgb(0, 0, 0);"> <span style="font-family:arial;">Pushing employees to certify themselves can promote an environment where everyone cheats.</span></span><br /><br /><span style="color: rgb(102, 102, 204); font-weight: bold;font-family:arial;" >Dump providers:</span><br /><span style="color: rgb(0, 0, 0);font-family:arial;" >When there is someone to provide the temptation to cheat, cheaters will always be there. </span><span style="color: rgb(0, 0, 0);font-family:arial;" ><br /><br /><span style="font-weight: bold;">What can we do to stop it ?</span></span><br /><ul><li><span style="color: rgb(0, 0, 0);font-family:arial;" >It is not financially viable for some certification vendors to pursue dump providers / cheaters. I do not expect a solution from vendors anytime soon.</span></li><li><span style="color: rgb(0, 0, 0);font-family:arial;" >It is not possible to convince cheaters not to cheat. Once a cheater, always a cheater.</span></li><li><span style="color: rgb(0, 0, 0);font-family:arial;" >The onus is on the interviewer. Weigh your candidates carefully. If the candidate provides top notch answers during an interview, it is likely they deserve their certificate and a hire. </span></li></ul><span style="color: rgb(0, 0, 0);font-family:arial;" >As for certificate takers themselves, should fakers prevent them from taking certifications all together ? No. You get certified because </span><span style="font-weight: bold; color: rgb(0, 0, 0);font-family:arial;" >you</span><span style="color: rgb(0, 0, 0);font-family:arial;" > want to. Anyone that has truly earned a certificate will realize that a certificate is more than just a piece of paper. It is the journey of the certification that matters more than the certificate itself. If a candidate did cheat on a certification, he/she better be prepared for a rough road ahead.</span><br /><br /><script type="text/javascript">var dzone_url = 'http://jtoee.blogspot.com/2009/01/why-certify.html';</script><br /><script type="text/javascript">var dzone_title = 'Why Certify ?';</script><br /><script type="text/javascript">var dzone_blurb = 'Certifications at times play a good role when hiring an employee. A developer can be weighed by the certifications that he/she holds. But of what good are certifications ? Do they really help your career grow ? Let us dissect the good and bad of certifications and we can then address the crux of the problem';</script><br /><script type="text/javascript">var dzone_style = '2';</script><br /><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1017083851910735810.post-2441167839600483162008-12-25T04:08:00.000-08:002008-12-25T08:36:50.051-08:00SSL security at different levels<span style="color: rgb(0, 0, 0);font-family:arial;" >Sometimes a server might have a requirement to receive requests over a secure line. Installing SSL certificates on your server will help you achieve the same. Where you install this certificate on the other hand might affect how your application behaves. Java for example allows you to detect if a line is secure by exposing the isSecure() method in the HTTPServletRequest interface.</span><br /><br /><span style="color: rgb(0, 0, 0);font-family:arial;" >So, we had a requirement where users had to submit documents over a secure line. In order to ensure requests were secure, a piece of code checked the same using the isSecure() method. A web server might well have the capability to block insecure requests to a given URL. But the code was written anyway as a backup to check for the line's security.</span><br /><br /><span style="color: rgb(0, 0, 0);font-family:arial;" >The code worked well in the DEV and Local environements where the SSL certificate was installed on the application server. When the code went into the QA environment - KABOOM. Every request was declared insecure and thrown out. A little investigation revealed that the certificate in QA was installed on an IIS web server, behind which was our application server. The same configuration was available in the live environment. Testing in the Local and DEV environments was performed with the certificate installed on the application server. A web server was available only in QA, which was one of the reasons this problem slipped past us. Since the line between the web server and the app server is not secure (but the line between the user and the web server is secure ), the isSecure() method returned false all the time.</span><br /><br /><span style="font-weight: bold; color: rgb(0, 0, 0);">Secure lines in QA:</span><br /><a style="color: rgb(0, 0, 0);" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVTFJCEoRaPEbLIPFduquFpLv6EZd0SLhK24wtozBre3nXdeGtjOSev3T2I0k8RdprSp6Ro50bWxpyE5BeaS2wKoBCntiIxrKRqV_75bN8Wt368HetGQCJtLQ5h0tYLSdc9Q4f0EoIvZIH/s1600-h/ssl.JPG"><img style="cursor: pointer; width: 400px; height: 142px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVTFJCEoRaPEbLIPFduquFpLv6EZd0SLhK24wtozBre3nXdeGtjOSev3T2I0k8RdprSp6Ro50bWxpyE5BeaS2wKoBCntiIxrKRqV_75bN8Wt368HetGQCJtLQ5h0tYLSdc9Q4f0EoIvZIH/s400/ssl.JPG" alt="" id="BLOGGER_PHOTO_ID_5283758935865069250" border="0" /></a><br /><br /><span style="color: rgb(0, 0, 0); font-weight: bold;font-family:arial;" >Configuration in DEV and Local:</span><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH8u783tug4O6z6rnEdK_4ddM_AQw_TyzobtuY1mu0mkX33PTrN5krXCSb6-mvVjNRid-28tDHYeE3ElTzF_2apZ_FQ0ueNoDmoO95WfeYozjVu21-7vmJwbxMx9-2Al8kyZqOgxCoM2gG/s1600-h/ssl2.JPG"><img style="cursor: pointer; width: 400px; height: 140px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH8u783tug4O6z6rnEdK_4ddM_AQw_TyzobtuY1mu0mkX33PTrN5krXCSb6-mvVjNRid-28tDHYeE3ElTzF_2apZ_FQ0ueNoDmoO95WfeYozjVu21-7vmJwbxMx9-2Al8kyZqOgxCoM2gG/s400/ssl2.JPG" alt="" id="BLOGGER_PHOTO_ID_5283764907115119442" border="0" /></a><br /><br /><span style="color: rgb(0, 0, 0);font-family:arial;" >It pays to know your environment well before you design / write code. Code usually fails when we fail to take into account details that would not normally be considered while testing. Configuration settings, Application server patches, batch jobs, scheduled tasks etc are to name a few.</span><br /><script type="text/javascript">var dzone_url = 'http://jtoee.blogspot.com/2008/12/ssl-security-at-different-levels.html';</script><br /><script type="text/javascript">var dzone_title = 'SSL at different levels';</script><br /><script type="text/javascript">var dzone_blurb = 'Sometimes a server might have a requirement to receive requests over a secure line. Installing SSL certificates on your server will help you achieve the same. Where you install this certificate on the other hand might affect how your application behaves.';</script><br /><script type="text/javascript">var dzone_style = '1';</script><br /><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1017083851910735810.post-72880462088776203892008-05-18T09:37:00.000-07:002008-12-12T13:05:13.406-08:00A better way to iterate java maps<script type="text/javascript">var dzone_url = 'http://jtoee.blogspot.com/2008/05/better-way-to-iterate-java-maps.html';</script><br /><script type="text/javascript">var dzone_title = 'A better way to iterate java maps';</script><br /><script type="text/javascript">var dzone_blurb = 'A better way to iterate java maps';</script><br /><script type="text/javascript">var dzone_style = '2';</script><br /><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><br />Imagine you have a map like so<br /><br /><span style="font-weight: bold; color: rgb(51, 51, 255);font-family:arial;" >Map:</span><br /> Map <Integer,String> map = new HashMap<Integer, String>();<br /> map.put(0, "Value1");map.put(1, "Value2");<br /><br /><br /><span style="font-family:arial;">I often see code written in this fashion to Iterate over the map</span><br /><br /><span style="font-weight: bold; color: rgb(51, 51, 255);font-family:arial;" >Not so good code:</span><br /><a style="font-family: arial;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidXhjgnTf6X5SChQMI997y0M1lDPsXEo-4UpIv7REqVm2F_SJhegChXApI9brWfXXruQs66daWwuEMfh_u8cpT6Cd1xruXvFPeSZzWrNkKweucAgBX5ZkFZLS16_hQe2d2YQBtwKA2nKOd/s1600-h/map2.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidXhjgnTf6X5SChQMI997y0M1lDPsXEo-4UpIv7REqVm2F_SJhegChXApI9brWfXXruQs66daWwuEMfh_u8cpT6Cd1xruXvFPeSZzWrNkKweucAgBX5ZkFZLS16_hQe2d2YQBtwKA2nKOd/s400/map2.JPG" alt="" id="BLOGGER_PHOTO_ID_5201764427539035554" border="0" /></a><br /><integer style="font-family:arial;"><br /><br />You can instead use the following code to iterate through each entry. A map is nothing but a series of Map.Entry objects. It is better to get a reference to Map.Entry and then iterate instead of getting all the keys and making the Map object do the work of fetching the value each time<br /><br /><span style="font-weight: bold; color: rgb(51, 51, 255);">Good code:</span><br /></integer><img style="font-family: arial;" src="file:///C:/DOCUME%7E1/u/LOCALS%7E1/Temp/moz-screenshot-2.jpg" alt="" /><a style="font-family: arial;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpFSPkmW_wQc3Y55gB3A56LBFocKApwZOrq9_YDrHdNIk8lXWZi-unoJNZ4hJY55XYTodYuCa5PO9x2fbDl8zYmIX3_RtikCmIaCg7w7igrjCSImuq439Tm0H-7VatkGcGqEZ1KRJasOAa/s1600-h/map3.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpFSPkmW_wQc3Y55gB3A56LBFocKApwZOrq9_YDrHdNIk8lXWZi-unoJNZ4hJY55XYTodYuCa5PO9x2fbDl8zYmIX3_RtikCmIaCg7w7igrjCSImuq439Tm0H-7VatkGcGqEZ1KRJasOAa/s400/map3.JPG" alt="" id="BLOGGER_PHOTO_ID_5201765484100990386" border="0" /></a><br /><script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shBrushCSharp.js"></script><br /><script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shBrushXml.js"></script><br /><script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shBrushCss.js"></script><br /><script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shBrushJScript.js"></script><br /><script language="javascript" src="http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/shBrushSql.js"></script><p></p><br /><br /><br /><script language="javascript"><br /> dp.SyntaxHighlighter.ClipboardSwf = 'http://mortenlyhr.googlecode.com/svn/trunk/SyntaxHighlighter/Scripts/clipboard.swf'; <br /> dp.SyntaxHighlighter.HighlightAll('code'); <br /></script>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1017083851910735810.post-84161448502379840742008-04-13T06:50:00.000-07:002008-12-12T13:05:16.527-08:00Writing PDF charts with iText in less than 2 minutes<script type="text/javascript"><br />var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");<br />document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));<br /></script><script type="text/javascript">r />var pageTracker = _gat._getTracker("UA-4113996-1");<br />pageTracker._initData();<br />pageTracker._trackPageview();<</script><span style="font-family:arial;">If you didnt already know, iText is an API through which you can write dynamic PDF content from a java application. iText is strong contender for being a solution that can be applied across different environments. Given the increase in the number of applications using PDF these days, an API like iText makes life a lot simpler for developers.</span><br /><br /><span style="font-family:arial;">iText is also integrated with other libraries out there like the JFreeChart API. This means that you can create a JFreeChart object and pass it to an iText method and expect PDF content to be returned as a result. That is pretty neat and the solution can be applied over a number of places. Given below is a brief overview of charts that can be created and converted to PDF format.</span><br /><br /><span style="font-family:arial;">To begin with lets create some JFreeChart objects that resemble a piechart and a barchart given some random data. The code snippet below would do the trick to accomplish this. Its not rocket science really. The code is self explanatory. You add a couple of name value pairs and mention how much of the chart area each value is allowed to occupy. Once the JFreeChart objects are constructed we can go ahead and convert the objects to PDF format.</span><br /><br /><span style="font-weight: bold;font-family:arial;" >Get a bar chart:</span><br /><a style="font-family: arial;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRmsDm_RF7KMxVGTHWArngf6vgSS6Qyc5YDiFugxyNBZ662GhxQPnx6td4jX4cSwfdxR67bgzwOXlJrFIA2sDELbIBSZC11l2CB1B0k7JK-nrUTIbwnl0PCnTH1u932lXl0gxUVy-zPuVB/s1600-h/jfree1.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRmsDm_RF7KMxVGTHWArngf6vgSS6Qyc5YDiFugxyNBZ662GhxQPnx6td4jX4cSwfdxR67bgzwOXlJrFIA2sDELbIBSZC11l2CB1B0k7JK-nrUTIbwnl0PCnTH1u932lXl0gxUVy-zPuVB/s400/jfree1.JPG" alt="" id="BLOGGER_PHOTO_ID_5188730571741771298" border="0" /></a><br /><br /><span style="font-weight: bold;font-family:arial;" >Get a pie chart:</span><br /><a style="font-family: arial;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC09uXanJbRIvYLLaX_i_l_BmET1KqSwpWNg-YKKe3LrkN0kuG0K9HIYPEWQ5DTuA_kfGQm9upWW3YhhmGPfoInsLEEnZwhoIejJeeiX60qw0uzDSsn16Jz9aZsjrmtjPE6YiB0NwY5b1V/s1600-h/jfree2.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC09uXanJbRIvYLLaX_i_l_BmET1KqSwpWNg-YKKe3LrkN0kuG0K9HIYPEWQ5DTuA_kfGQm9upWW3YhhmGPfoInsLEEnZwhoIejJeeiX60qw0uzDSsn16Jz9aZsjrmtjPE6YiB0NwY5b1V/s400/jfree2.JPG" alt="" id="BLOGGER_PHOTO_ID_5188730898159285810" border="0" /></a><br /><br /><span style="font-family:arial;">To convert these objects to PDF, first declare a Document from the iText API within a defined Rectangle. Use a PdfWriter object to write the contents of the PDF. The iText API is capable of creating a java AWT Graphics2D object based on a given PdfTemplate. Use the JFreeChart API to draw on the Graphics2D object and that is pretty much it ! Here is some code</span><br /><br /><span style="font-weight: bold;font-family:arial;" >Converting JFreeChart objects to PDF:</span><br /><a style="font-family: arial;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5x5M-Sf-4tMWWF_HxxvX4R1nXB7cEI0gvftmOsR6Zrh3iKuTgvzEXV05VFdDsyPNLxNIXFuWes4h3bqLCfOAqoV-5CfEJtVVVBlI8IsuXipzD_GNasen96-ZIEE008uOVznSgKwbjhzrE/s1600-h/jfree3.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5x5M-Sf-4tMWWF_HxxvX4R1nXB7cEI0gvftmOsR6Zrh3iKuTgvzEXV05VFdDsyPNLxNIXFuWes4h3bqLCfOAqoV-5CfEJtVVVBlI8IsuXipzD_GNasen96-ZIEE008uOVznSgKwbjhzrE/s400/jfree3.JPG" alt="" id="BLOGGER_PHOTO_ID_5188732714930452034" border="0" /></a><br /><br /><span style="font-weight: bold;font-family:arial;" >Run the program by calling the appropriate methods:</span><br /><a style="font-family: arial;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj43glngCFc9tg5Pjj83CTbwMeg1x6UmlrAd0syAkk_7a3uj97zes1B8lqyf7Ls-oRXT3GLWsJuUOyCe7Y-pJFy7s2Gr85d_s1VS_UNDUUXdK4Fc2Uo17ieHlXYeMMmPVvNSn22PNQ0WJTa/s1600-h/jfree4.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj43glngCFc9tg5Pjj83CTbwMeg1x6UmlrAd0syAkk_7a3uj97zes1B8lqyf7Ls-oRXT3GLWsJuUOyCe7Y-pJFy7s2Gr85d_s1VS_UNDUUXdK4Fc2Uo17ieHlXYeMMmPVvNSn22PNQ0WJTa/s400/jfree4.JPG" alt="" id="BLOGGER_PHOTO_ID_5188733118657377874" border="0" /></a><br /><br /><br /><span style="font-weight: bold;font-family:arial;font-size:130%;" >Output:</span><span style=";font-family:arial;font-size:130%;" > </span><br /><br /><span style="font-weight: bold;font-family:arial;" >Bar PDF:</span><br /><a style="font-family: arial;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMJFgOJ0lj65xVM5WK1ndwjLcBAVpUCCoj0nTRPG_zW10svWLZlc2EcVnCFbDhKIALmaD2UV7eW_x2iLcVj_vCje7x9rkiJL0So8F5duL92y-yNnwpg5WldTsE_I79FurbGc6dUId-EGKP/s1600-h/outPDF2.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMJFgOJ0lj65xVM5WK1ndwjLcBAVpUCCoj0nTRPG_zW10svWLZlc2EcVnCFbDhKIALmaD2UV7eW_x2iLcVj_vCje7x9rkiJL0So8F5duL92y-yNnwpg5WldTsE_I79FurbGc6dUId-EGKP/s400/outPDF2.JPG" alt="" id="BLOGGER_PHOTO_ID_5188734085025019506" border="0" /></a><br /><br /><span style="font-weight: bold;font-family:arial;" >Pie PDF:<br /></span><a style="font-family: arial;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQPPwXeRhqmDDpwn0xtYoB1RgruXQknUAl8aZLsVfjDS-OAu-vvx3HoCtG26njb65_dbM8etGiZdlYJ9JvUX1l-lTZiUk7vcxVu7MYM7cfZmKzsEZeuOwChAW29Q4DCRStcBMSRINSTdvB/s1600-h/outPDF1.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQPPwXeRhqmDDpwn0xtYoB1RgruXQknUAl8aZLsVfjDS-OAu-vvx3HoCtG26njb65_dbM8etGiZdlYJ9JvUX1l-lTZiUk7vcxVu7MYM7cfZmKzsEZeuOwChAW29Q4DCRStcBMSRINSTdvB/s400/outPDF1.JPG" alt="" id="BLOGGER_PHOTO_ID_5188733861686720098" border="0" /></a><br /><br /><br /><br /><span style="font-family:arial;">Besides you can integrate this solution with java SWING if you wanted to since it supports AWT objects. You could also write to a browser by getting hold of a response output stream instead of a file and thereby allowing your users to experience rich dynamic PDF content on the fly. iText is capable of much more, like</span><br /><br /><ul style="font-family: arial;"><li>Working with tables</li><li>Image support</li><li>Fonts</li><li>Indenting and nesting</li><li>Interactive forms with PDF</li><li>RTF Documents</li><li>Digitally signing a PDF</li></ul><br /><span style="font-family:arial;">There is much more to the API than the list mentioned above. If you are to work with this API I would recommend that you buy the iText in Action book from Manning. The example in this post is based on examples from the book and it really does deliver details of the API in a short and sweet format.</span><br /><br /><span style="font-weight: bold;font-family:arial;" >iText in Action:</span><br /><a style="font-family: arial;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.amazon.com/iText-Action-Creating-Manipulating-PDF/dp/1932394796"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoAxi8IdqeGWOj5XOPh3XkuqCHiAaoXzhZNSypFcmKEYjQh7f9gd5yICw8TBnycoLaq1paLWgsS1rBlZC9R2bQ3Ea4Od7BqylOqY0fc2mP2YiBsw0qrjbhUv_PjPJQuw2lLL8oWI0q2ky3/s400/iText.JPG" alt="" id="BLOGGER_PHOTO_ID_5188750779562899074" border="0" /></a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1017083851910735810.post-87643018168693540722008-03-24T05:12:00.001-07:002008-03-24T05:57:22.814-07:00Converting integers to String in Sybase<span style="font-family:arial;">I had to manually insert some data into a sybase DB recently to correct a recurring faulty programming logic. An application was attempting to insert 4 rows into the database. Of these rows, 1 row of data was already available in the database, so a primary key violation was raised by the application and the rest of the data never made it into the sybase DB. Since this was a recurring problem I simply took the previous SQLs written by some one else to fix this and inserted 3 records into the DB.</span><br /><br /><span style="font-family:arial;">Here is what one of the SQLs did</span><br /><br /><span style="font-weight: bold;font-family:arial;" >Begin</span><br /><br /><span style="font-family:arial;">...</span><br /><br /><span style="color: rgb(51, 51, 255);font-family:arial;" >insert into table values (str(@variable),'value',1,12.6)</span><br /><br /><span style="font-family:arial;">...</span><br /><br /><span style="font-weight: bold;font-family:arial;" >End</span><br /><br /><br /><span style="font-family:arial;">The <span style="font-weight: bold;">@variable</span> here was a primary key. This value is obtained dynamically each time as an integer and then converted to a string. For the sake of discussion lets assume it was 11576. The SQL worked pretty well and everything seemed to be going fine until I executed the following query on the sybase DB</span><br /><br /><span style="color: rgb(51, 51, 255);font-family:arial;" >select * from table where primary_key = '11576'</span><br /><br /><span style="font-family:arial;">To my shock the row from the table was never returned. I did not understand why, because this same SQL was executed previously to fix the problem. I modified the SQL to the following</span><br /><br /><span style="color: rgb(51, 51, 255);font-family:arial;" >select * from table where some_other_value = 'value' and something = 1</span><br /><br /><span style="font-family:arial;">Now the row was returned and I could see quite clearly that the primary_key was still 11576. Since it was a string i began to suspect that spaces might be a problem. Another modification</span><br /><br /><span style="color: rgb(51, 51, 255);font-family:arial;" >select * from table where primary_key like '%11576'</span><br /><br /><span style="font-family:arial;">This time the row was returned again. After going through the documentation for the str function, i figured it out. SELECT STR( 12345 ) would return '<span style="font-weight: bold; color: rgb(51, 51, 255);">(5 spaces)</span>12345'. When some one wrote this SQL they had assumed that str(number) would return the </span><span style="font-weight: bold;font-family:arial;" >exact</span> <span style="font-family:arial;">string representation of that number. Instead I used convert ( varchar(5), @variable ) and things worked as expected. You could also use SELECT STR( 1234.56, 6, 1 ) to return 1234.6. Here the length and the decimal places are mentioned.</span><br /><br /><span style="font-family:arial;">Lessons learnt here</span><br /><ul style="font-family: arial;"><li>Never assume that a previous fix is flawless</li><li>Consult the documentation when in doubt</li></ul>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1017083851910735810.post-69966785299190521692007-11-10T08:35:00.000-08:002008-12-12T13:05:17.744-08:00Parsing HTML with java<div id="dzone_vote_widget" style="float: left; margin-right: 8px;"><br /> <script language="javascript" src="http://www.dzone.com/widgets/zoneit.js"></script></div><br /><span style="color: rgb(0, 0, 0);">Sometimes it might be necessary to parse HTML to extract some data out of it. Practical requirements include extracting certain ID out of the HTML among other things. This can be a problem since HTML is not well formed. HTML is full of tags that need not be closed such as the </span><span style="font-weight: bold; color: rgb(0, 0, 0);">br</span><span style="color: rgb(0, 0, 0);"> tag. To get around this, use the HTMLEditorKit. The kit can also help you integrate a HTML solution with Swing. Here is some code<br /><br /></span><span style="font-weight: bold; color: rgb(51, 51, 255);">HTMLEditor kit parser:<br /><br /></span><blockquote style="color: rgb(0, 0, 0);">public class HTMLParser<br />{<br />public static void main(String [] args) throws Exception<br />{<br />HTMLEditorKit.ParserCallback callback = new CallBack();<br />Reader reader = new FileReader("d:/test.html");<br />ParserDelegator delegator = new ParserDelegator();<br />delegator.parse(reader, callback, false);<br />}<br /><br />}<br /><span style="color: rgb(0, 153, 0);">// Implement the call back class. Just like a SAX content handler</span><br />class CallBack extends HTMLEditorKit.ParserCallback<br />{<br />Stack stack = new Stack();<br />public void flush() throws BadLocationException{}<br />public void handleComment(char[] data, int pos){}<br /><br />public void handleStartTag(HTML.Tag tag, MutableAttributeSet a, int pos)<br />{<br /> <span style="color: rgb(0, 153, 0);">// get a tag and push it into a stack</span><br />System.out.println("Tag: " + tag );<br />stack.push(tag);<br />}<br /><br />public void handleEndTag(HTML.Tag t, int pos){}<br />public void handleSimpleTag(HTML.Tag t,MutableAttributeSet a, int pos){}<br />public void handleError(String errorMsg, int pos){}<br />public void handleEndOfLineString(String eol){}<br /><br />public void handleText(char[] data, int pos)<br />{<br /> <span style="color: rgb(0, 153, 0);"> // pop the stack to get the latest tag processed. If you are interested</span><br /><span style="color: rgb(0, 153, 0);"> // in parsing it and extracting the data continue. else return</span><br />Object o = stack.pop();<br />if ( ! ((HTML.Tag)o).toString().equals("span"))<br />{<br /> return;<br />}<br />String strData="";<br />for (char ch : data)<br />{<br /> strData = strData + ch;<br />}<br />System.out.println("Text: " + strData );<br />}<br />}</blockquote><span style="color: rgb(0, 0, 0);">The parser will tolerate tags that are not closed. </span><br /><br /><span style="color: rgb(0, 0, 0);">If you would prefer a DOM solution to the parser problem have a look at<span style="color: rgb(51, 51, 255);"> jTidy<br /></span></span><span style="color: rgb(51, 51, 255);"><br />http://jtidy.sourceforge.net/<br /><br /></span><span style="color: rgb(0, 0, 0);">A DOM solution is appropriate for HTML documents that are not too huge and require random access + modifications in memory. I have not tried jTidy myself. Lack of documentation made me stay away. The documentation available at source forge was pretty bad. Sample programs that where the lines of code were all fused into a continuous set of characters.<br /><br /></span><span style="color: rgb(0, 0, 0);">Another DOM like solution is HTML-Parser. Here is the link<br /><br /></span><span style="color: rgb(51, 51, 255);">http://htmlparser.sourceforge.net/<br /><br /></span><span style="color: rgb(0, 0, 0);">This parser is more powerful. You can use a light weight or heavy duty solution depending on your requirement. Here is some code for a light weight Lexer parser. Documentation for this parser was pretty good.<br /><br /></span><span style="font-weight: bold; color: rgb(51, 51, 255);">Lexer code (click to enlarge):</span><br /><blockquote style="color: rgb(0, 0, 0);"><title> New Document </title><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3_NXjrX7ncrrYCyDPCD29c4Mmi2A0aERUlTOIohf49v0MRscdnfxoeMNorpYMGgCuA0-iDl7unWkDB3bAwEPuGJ_u-GK-WpOK-gZ6WVUQpFAdQU1AOPwnsn44nrRls0mu4Qi9ET4-Y3DA/s1600-h/Lexer.JPG"><img style="cursor: pointer; width: 388px; height: 52px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3_NXjrX7ncrrYCyDPCD29c4Mmi2A0aERUlTOIohf49v0MRscdnfxoeMNorpYMGgCuA0-iDl7unWkDB3bAwEPuGJ_u-GK-WpOK-gZ6WVUQpFAdQU1AOPwnsn44nrRls0mu4Qi9ET4-Y3DA/s400/Lexer.JPG" alt="" id="BLOGGER_PHOTO_ID_5131281098766740658" border="0" /></a></blockquote><span style="font-weight: bold; color: rgb(51, 51, 255);">Here is the output:</span><br /><br /><blockquote style="color: rgb(0, 0, 0);">HTML<br /><br />HEAD<br /><br />TITLE<br />New Document<br />/TITLE<br /><br />/HEAD<br /><br />BODY<br /><br />/BODY<br />/HTML<br /><br /><br /></blockquote><span style="color: rgb(0, 0, 0);">One more solution is to use the<span style="color: rgb(51, 51, 255);"> swing Parser</span> class. Here is some code<br /><br /></span><span style="font-weight: bold; color: rgb(51, 51, 255);">Swing parser:</span><br /><blockquote style="color: rgb(0, 0, 0);"> DTD dtd = DTD.getDTD("html.dtd");<br />Parser parser = new Parser(dtd )<br />{<br />@Override<br />protected void handleText(char[] data)<br />{<br /> String str = "";<br /> for (char ch : data)<br /> {<br /> str += ch;<br /> }<br /> System.out.println("Text: " + str);<br />}<br /><br />@Override<br />protected void startTag(TagElement element) throws ChangedCharSetException<br />{<br /> System.out.println("Start tag: " + element.getElement().getName());<br /> super.startTag(element);<br />}<br /><br /><br />};<br />parser.parse(new FileReader(new File("d:/test2.html")));<br /></blockquote><span style="font-weight: bold; color: rgb(51, 51, 255);">test2.html:<br /></span><blockquote style="color: rgb(0, 0, 0);"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfmvcBC1IPFmFs9riJIbYIz5wH38HZNI9JCKE8EnSnnYV3EVNLBt38ywXp9WDyqXAScvpUDZcAfTGHaav-xA9l0CLZ1sWavzmrxhpL8GWRIfGyhLWuax6hIHl_N3irr3QJHjiJghVL6OI1/s1600-h/test2.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfmvcBC1IPFmFs9riJIbYIz5wH38HZNI9JCKE8EnSnnYV3EVNLBt38ywXp9WDyqXAScvpUDZcAfTGHaav-xA9l0CLZ1sWavzmrxhpL8GWRIfGyhLWuax6hIHl_N3irr3QJHjiJghVL6OI1/s400/test2.JPG" alt="" id="BLOGGER_PHOTO_ID_5131282236933074130" border="0" /></a><br /><br /></blockquote><span style="font-weight: bold; color: rgb(51, 51, 255);">Output:<br /></span><span style="color: rgb(51, 51, 255);"><blockquote style="color: rgb(0, 0, 0);">Start tag: html<br />Start tag: head<br />Start tag: title<br />Text: New Document<br />Start tag: body<br />Start tag: test<br />Text: testamondo<br />Start tag: h1<br />Text: Big Header</blockquote></span><span style="font-weight: bold; color: rgb(51, 51, 255);"><br /></span><blockquote style="color: rgb(0, 0, 0);"></blockquote><span style="color: rgb(0, 0, 0);">This parser is DTD driven. It is more suited to a SAX type solution. </span><br /><br /><span style="color: rgb(51, 51, 255);">In conclusion<br /><br /></span><ul><li><span style="color: rgb(0, 0, 0);">Use the <span style="color: rgb(51, 51, 255);">HTML Parser</span> when you need complex operations to be performed. You can choose between light weight and heavy duty implementations</span></li></ul><span style="color: rgb(0, 0, 0);"></span><ul><li><span style="color: rgb(0, 0, 0);">Use the <span style="color: rgb(51, 51, 255);">HTMLEditor kit</span> or the swing Parser when you intend to simply parse and read the HTML for specific data.</span></li></ul><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">I am refraining from suggesting <span style="color: rgb(51, 51, 255);">jTidy</span>. I have not found any documentation as yet that will let me compare it with the other parsers. If I do I will update this article.</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1017083851910735810.post-28766559679120127902007-10-29T06:08:00.000-07:002007-11-21T09:31:41.784-08:00ZoneInfo error ?<span class="optional"><script type="text/javascript">var dzone_url = '[url]';</script><script type="text/javascript">var dzone_title = '[title]';</script><script type="text/javascript">var dzone_blurb = '[description]';</script><script type="text/javascript">var dzone_style = '1';</script></span><script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script><span style="color: rgb(0, 0, 0);font-family:arial;" ><br /><br />I ran into this error some time back when I was loading a Sybase driver into my application code using Class.forName()<br /><br /></span><span style="color: rgb(0, 0, 0);font-family:arial;" ><span style="color: rgb(255, 0, 0); font-weight: bold;">ZoneInfo: null\lib\zi\ZoneInfoMappings (The system cannot find the path specified)</span><br /><br /></span><span style="color: rgb(0, 0, 0);font-family:arial;" >Analysis of the stack trace revealed that the system seemed to be trying to find out what time zone my JVM belonged to. The trace also mentioned that it was unable to find java.home. This was quite weird since my computer was in the right time zone and the java.home property was not set anywhere in my code or the eclipse runtime property set.<br /><br />After searching for a while I found out where the problem was. I was loading some properties into my system properties and while loading my properties the JVM wiped out the existing properties, thus creating the error. I wanted to use the name value pairs inside a <span style="color: rgb(0, 0, 153);">.properties</span> file and then have my application look up a system property every time it needed a configuration detail. Here was the problem<br /><br /><span style="font-weight: bold; color: rgb(255, 102, 0);">Not so good code:</span><br /></span><br /><span style="color: rgb(0, 0, 153);font-family:arial;" >java.util.Properties props = new java.util.Properties();<br /></span><span style="color: rgb(0, 0, 153);font-family:arial;" >props.load(new FileInputStream(new File(fileName)));</span><br /><span style="color: rgb(255, 0, 0);font-family:arial;" >System.setProperties(props); // Dont do this.</span><span style="font-weight: bold; color: rgb(255, 0, 0);font-family:arial;" ><br /></span><span style="color: rgb(0, 0, 0);font-family:arial;" ><span style="color: rgb(0, 0, 153);"><br /></span>The System.setProperties(props) method wiped out existing properties (like java.home or time zone information ) and wrote my properties into the system properties. I got around the problem by setting the system properties one by one in a loop using the System.setProperty() method.<br /></span><span style="color: rgb(0, 0, 0);font-family:arial;" ><br /><span style="font-weight: bold; color: rgb(0, 153, 0);">Better code:</span><br /><br /><span style="color: rgb(0, 0, 153);"> Iterator iterator = props.keySet().iterator();<br /></span> <span style="color: rgb(0, 0, 153);"> while(iterator.hasNext())<br /></span> <span style="color: rgb(0, 0, 153);"> {<br /></span> <span style="color: rgb(0, 0, 153);"> String key = iterator.next().toString();<br /></span> <span style="color: rgb(0, 0, 153);"> String value = props.getProperty(key);<br /></span> <span style="color: rgb(0, 0, 153);"> System.out.println(key + " " + value);<br /></span> <span style="color: rgb(0, 0, 153);"> System.setProperty(key,value);<br /></span> <span style="color: rgb(0, 0, 153);"><span style="color: rgb(0, 0, 153);"> }</span><br /></span></span><br /><span style="color: rgb(0, 0, 0);font-family:arial;" >However the approach shown above can be inefficient and spans a couple of lines as well. The Properties class extends from the Hashtable class thus making it a Map. The following code can be used to add properties to existing system properties in the best way possible.</span><br /><br /><span style="color: rgb(0, 153, 0); font-weight: bold;font-family:arial;" >Best code:</span><br /><br /><span style="color: rgb(0, 0, 153);font-family:arial;" >java.util.Properties props = new java.util.Properties();<br /></span><span style="color: rgb(0, 0, 153);font-family:arial;" >props.load(new FileInputStream(new File(fileName)));</span><br /><span style="color: rgb(0, 0, 153);font-family:arial;" >System.getProperties().putAll(properties); <span style="color: rgb(0, 102, 0);">// Does not replace existing property keys in system properties but will rather replace their values alone, if they already exist.</span></span><br /><br /><span style="color: rgb(0, 0, 0);font-family:arial;" >I should also mention that this problem is not always consistent. Sometimes the JVM wipes out the existing properties and other times it does not. With JDK 1.3.1 hosted on windows 2000 server I received this error but with JDK 1.5 and windows XP this error does not occur. Perhaps it was fixed in JDK 1.5 or the environment plays a role here. However it is better to avoid such random behavior if we are to write production quality code<br /><br />You might also want to consider saving an instance of the Properties class or loading the name value pairs into a resource bundle in case you do not want to load runtime configuration into a system property..</span><span style="font-weight: bold; color: rgb(255, 0, 0);font-family:arial;" ><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1017083851910735810.post-76620473746721790712007-10-21T12:12:00.001-07:002007-10-21T12:15:52.814-07:00SOA Certifications<div style="font-family: arial; color: rgb(0, 0, 0);" xmlns="http://www.w3.org/1999/xhtml">When I think about taking certifications that are based on SOA I am put off quite badly. Here are a list of certifications that I could probably get my hands on<br /><br /><ul><li>Sun - Java web services (Not really SOA, but covers a part of it)</li><li>BEA's SOA certification - Currently I work with this server</li><li>IBM's SOA certification</li></ul><br /><span style="color: rgb(51, 51, 255);">Sun's</span> certification is quite neutral, in that it does not attempt to push through its own products in the name of certifying you. However this certification is quite outdated. The last time I wanted to host a web service I used apache Axis. More recently after moving to weblogic 9, the integrated web services look promising and they are available via the workshop IDE for weblogic as well. This certification does not give as much juice as you would like to have.<br /><br /><span style="color: rgb(51, 51, 255);">BEA's</span> SOA certification strategy was starting to look promising until I started hunting for their study material. The courses were pretty costly and there was no way to pass the certification unless I bought them. This really put me off. If a client were to approach me and ask me how they could service enable their apps, I might end up saying 'uuhhhhhh......'. This is not to say that their SOA resource center is bad. They do have a couple of articles on what their products are. However there is no string of articles that lists them down, teaches you what they can do and cant, and when and where you can apply them. I cannot pay the earth for the courses that they offer.<br /><br /><span style="color: rgb(51, 51, 255);">IBM's</span> SOA certifications are divided in layers. From associate, you climb your way up. The training material is available via the IBM website and it was much more easily accessible. A few require you to shell some cash, but if your company is partnering with IBM, you can get them for free. My point is that their products and view of SOA are quite accessible. I do not use IBM products at my current project however. So that leaves this certification out as well.<br /><br />Any certification should aim at giving the candidate an overview and boundaries of a technology / product. Or in case of architecture certifications, much more than that, a clear understanding of what the technologies are and how to put them together. Right now SOA is a mix of both. It does have some standards like the BPEL and common use of SOA solutions like webservices with SOAP etc. However each vendor has their own view of what SOA really is. A SOA certification at this point in time is certainly going to be targeted at a particular vendor. You learn about the vendor's product more than SOA itself.<br /><br />Currently IBM seems to be pushing for a so called <b><span style="color: rgb(51, 51, 255);">SOA foundation</span>. </b>I attended a seminar where Rob High, chief architect for the IBM SOA foundation spoke of how they were aiming to standardize SOA, programming models, definitions, and the like. That is quite interesting. I wonder how that will turn out. Perhaps we can have an open standard and allow vendors to implement it in their own way, much like the JVM, MQ, JNDI technologies of today. That might still not help SOA certifications be vendor neutral, but atleast they will be less divergent in their views of SOA. </div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1017083851910735810.post-27476438469683932942007-10-16T11:04:00.000-07:002008-12-12T13:05:19.308-08:00Recursively recursing xsl<span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;">If you have ever programmed in XSLT you will have come across the problem of not being able to reassign variable values. XSLT is declarative in nature when it comes to variables. In the sense, you can assign a variable once and then the variable is immutable. To get around that you can write recursive functions that do the math for you by returning the desired result in steps. Such functions are pretty darn solid and work well once written, since variables inside them are immutable. Here's an example</span><br /><br /><span style="font-weight: bold;font-family:arial;" ><span style="color: rgb(51, 51, 255);">Products.xml</span><br /><br /></span></span><a style="color: rgb(0, 0, 0);" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl_KQmeo1ikcoCscyd-vzHRR-YJ3R0p2pWCa6jgsLCxRjErAgPfjiARZuiegR8yfar1e8dgLaTdS-eG7rXKG52QXJMM6Q_07SMDNKoonRHVMAicwvUOG6VjVnwnrKK-c_R_6NylYW4bVuc/s1600-h/productXML.JPG"> <img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl_KQmeo1ikcoCscyd-vzHRR-YJ3R0p2pWCa6jgsLCxRjErAgPfjiARZuiegR8yfar1e8dgLaTdS-eG7rXKG52QXJMM6Q_07SMDNKoonRHVMAicwvUOG6VjVnwnrKK-c_R_6NylYW4bVuc/s400/productXML.JPG" alt="" id="BLOGGER_PHOTO_ID_5122007827937163906" border="0" /></a><br /><span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-weight: bold;"><br /></span><span style="font-family:arial;"><br />Evaluate the sum of the prices in this xml using any one of these XLSTs. Various recursive logic can be employed.<br /><br /></span> <span style="font-weight: bold;font-family:arial;" ><br /><span style="color: rgb(51, 51, 255);">Recursively add each price by selecting one price at a time:</span></span><br /><br /></span><a style="color: rgb(0, 0, 0);" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-YTw4ibPV3xa22yCH1RUYs413Y6v1bqCbD7jfS_r7lfuCIsKU3qTq_6KHgGViPceuQNYS4eJ95pgw3yFpOEaZU_BrzpAAYNpk8h7M7YGoyAeX1utdeX8OPV0IPdH9TLNlBOevt095Bvzo/s1600-h/sum.JPG"> <img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-YTw4ibPV3xa22yCH1RUYs413Y6v1bqCbD7jfS_r7lfuCIsKU3qTq_6KHgGViPceuQNYS4eJ95pgw3yFpOEaZU_BrzpAAYNpk8h7M7YGoyAeX1utdeX8OPV0IPdH9TLNlBOevt095Bvzo/s400/sum.JPG" alt="" id="BLOGGER_PHOTO_ID_5122008089930168978" border="0" /></a><br /><span style="color: rgb(0, 0, 0);font-size:100%;" ><br /><br /><span style="font-family:arial;">This logic is pretty simple. Here is how it works</span><br /></span><ul style="color: rgb(0, 0, 0);font-family:arial;"><li><span style="font-size:100%;">Get first price</span></li><li><span style="font-size:100%;">Get second price + first price</span></li><li><span style="font-size:100%;">Get third price + second price + first price</span></li></ul><span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;">and so on until the total count of prices are reached. In this case it is 5. The terminating condition is to return the last price instead of making a recursive call again</span> <span style="font-weight: bold;font-family:arial;" ><br /><br /><span style="color: rgb(51, 51, 255);">Recursively manipulate a node list.</span><br /><span style="color: rgb(51, 51, 255);">Add the first price to a recursive result each time:</span></span><br /><br /></span><a style="color: rgb(0, 0, 0);" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzoNEUdGt154FSAu-enXAtGs63D5BJ-1ehRuckCjV2G3yQjDnJ1AFLfuh1Xh7WoEjGZStBFKwsbareIySDSzSqF9K7t_NPj4AO-QZm5pgQ6N5XCpxp443EWKao_BYvTxPJfZE5xZoeecFt/s1600-h/sum2.JPG"> <img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzoNEUdGt154FSAu-enXAtGs63D5BJ-1ehRuckCjV2G3yQjDnJ1AFLfuh1Xh7WoEjGZStBFKwsbareIySDSzSqF9K7t_NPj4AO-QZm5pgQ6N5XCpxp443EWKao_BYvTxPJfZE5xZoeecFt/s400/sum2.JPG" alt="" id="BLOGGER_PHOTO_ID_5122008360513108642" border="0" /></a><br /><span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;"><br />With this logic you begin with a node list of 5 </span><span style="font-weight: bold; color: rgb(51, 51, 255);font-family:arial;" >Product</span><span style="font-family:arial;">s. This is what happens</span> </span><ul style="color: rgb(0, 0, 0);"><li><span style="font-size:100%;"><span style="font-family:arial;">Get price of first product</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">Reduce node list size by moving to the next product</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">The Node list size is now 4. First product has been removed</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">Result = Price of first product + Recursively call the same method</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">Get price of first product (which used to be the second product in first iteration)</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">Reduce node list size by moving to the next product</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">The Node list size is now 4. First product has been removed</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">Result = Price of first product(1st Iter) + Price of first product(2nd Iter) + Recursively call the same method</span></span></li></ul><span style="color: rgb(0, 0, 0);font-size:100%;" > <span style="font-family:arial;">and so on... The terminating condition is to check for the existence of any nodes in the product list. If there are none return 0. So the addition becomes product1+ product2 +... +product5 +0</span> <span style="font-family:arial;">You should prefer tail recursion where possible since optimizers can execute them in iterations. More on tail recursions here</span> <span style="font-family:arial;"><br /><br /><a href="http://en.wikipedia.org/wiki/Tail_recursion"><span style="color: rgb(51, 102, 255); font-weight: bold;">http://en.wikipedia.org/wiki/Tail_recursion</span></a><br /><br />You can also use the <xsl:for-each> element where applicable. The trick is to know where to use recursion and where not to. For example factorials are not such a bad example of recursion. With factorials you return values like this<br /><br />if last number<br />return number;<br />else<br />return number * fac(number-1);<br /><br />This is ok. The method call stack is proportional to the number of numbers to find the factorial for. That is 5! requires 5 method calls on the call stack.<br /><br /><span style="font-weight: bold; color: rgb(51, 51, 255);">Method stack:</span><br /></xsl:for-each></span></span><ul style="color: rgb(0, 0, 0);"><li><span style="font-size:100%;"><span style="font-family:arial;">5 * 4!</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">4 * 3!</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">3 * 2!</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">2 * 1!</span></span></li><li><span style="font-size:100%;"><span style="font-family:arial;">1</span></span></li></ul><span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;">This becomes a bad idea with fibonacci. Here is some logic to do fibonacci math in recursion<br /><br />if number <= 1 return 1; else return fibo(number-1) + fibo (number-2); If I want to find the 4th fibonacci number, this is how the logic divides it <span style="font-weight: bold; color: rgb(51, 51, 255);"><br /><br />Method stack:</span><br /></span></span><ul><li><span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;">4 -> fibo (3) + fibo(2)</span></span></li><li><span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;">3 -> fibo(2) + fibo(1)</span></span></li><li><span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;">2 -> fibo(1) + fibo(0)</span></span></li><li><span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;">1-> 1</span></span></li><li><span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;">0 -> 1</span></span></li></ul><span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;"><br />Thats a lotta calls. 8 in total. This logic tries to divide each number into an addition of <span style="font-weight: bold; color: rgb(51, 51, 255);">1</span>s of that same number. That is -> 3 = 1 + 1 + 1. A large number will take forever to calculate using this logic. It is better to not use recursion for cases like this. You also dont want recursion or XSLT to do too much processing if the browser is going to to the work of translating the stuff into HTML for you.<br /><br />For more advanced topics on recursion you might want to look at this link<br /><br /><a href="http://www.ibm.com/developerworks/xml/library/x-xslrecur/"><span style="font-weight: bold; color: rgb(51, 51, 255);">http://www.ibm.com/developerworks/xml/library/x-xslrecur/</span></a><br /></span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1017083851910735810.post-88338023737199964942007-10-12T10:20:00.000-07:002008-12-12T13:05:19.835-08:00Solving the erroneous handlers error for weblogic<span style="color: rgb(0, 0, 0);font-size:100%;" ><span style="font-family:arial;">I was running my weblogic 9 server at work and one of the JSP pages threw this at me.</span><br /><br /><br /></span><span style="color: rgb(0, 0, 0);font-family:arial;font-size:100%;" >java.lang.InternalError: <b class="highlight">erroneous</b> <b class="highlight">handlers</b> </span><span style="color: rgb(0, 0, 0);font-size:100%;" > </span><span style="color: rgb(0, 0, 0);font-family:arial;font-size:100%;" >at com.sun.facelets.compiler.TextUnit.addChild(TextUnit.java:207) </span><span style="color: rgb(0, 0, 0);font-size:100%;" > </span><span style="color: rgb(0, 0, 0);font-family:arial;font-size:100%;" >at com.sun.facelets.compiler.CompilationManager.startUnit(CompilationManager.java:297) </span><span style="color: rgb(0, 0, 0);font-size:100%;" > </span><span style="color: rgb(0, 0, 0);font-family:arial;font-size:100%;" >at com.sun.facelets.compiler.CompilationManager.pushNamespace(CompilationManager.java:255) </span><span style="color: rgb(0, 0, 0);font-family:arial;font-size:100%;" >at com.sun.facelets.compiler.SAXCompiler$CompilationHandler.startPrefixMapping(SAXCompiler.java:199)<br /><br /><br /></span><span style="font-size:100%;"> <span style="font-family:arial;"><span style="color: rgb(0, 0, 0);">After being puzzled for a few minutes I figured that I was using the JROCKIT BEA VM to run my weblogic server and it was not giving me a proper description of what was actually wrong. If you encounter the stack trace shown above in your application (or something with </span><span style="font-weight: bold; color: rgb(0, 0, 0);">erroneous handlers</span><span style="color: rgb(0, 0, 0);"> in it), do the following from weblogic workshop to learn what the error really is. Probably a class file is missing. You should get a </span><span style="color: rgb(255, 0, 0);">NoClassDefFoundError </span><span style="color: rgb(0, 0, 0);">after you do these steps, if that is what the problem really is</span></span><span style="color: rgb(0, 0, 0);"> </span><span style="font-family:arial;"><span style="color: rgb(0, 0, 0);">Configure a server in weblogic workshop and double click on it to get this screen</span><br /><br /><br /></span> </span><span style="font-weight: bold;font-family:arial;font-size:100%;" >Server in Workshop:<br /></span><span style="font-size:100%;"> </span><div style="text-align: left;"><span style="font-size:100%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5YvXoVY0CmhWZtzTjrdAN29La17Bt5wDd3Mmv62YKRYwyWMvNq_uaKK7QYXh6VdHRdXnJs4SiaBDK5WRlBf41viF8Hkr9uFEhrlfL4y7ZmIk-cefDQrNiv5u86reIl4n-LXs9IifESqyx/s1600-h/serverInWorkshop.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5YvXoVY0CmhWZtzTjrdAN29La17Bt5wDd3Mmv62YKRYwyWMvNq_uaKK7QYXh6VdHRdXnJs4SiaBDK5WRlBf41viF8Hkr9uFEhrlfL4y7ZmIk-cefDQrNiv5u86reIl4n-LXs9IifESqyx/s400/serverInWorkshop.JPG" alt="" id="BLOGGER_PHOTO_ID_5120506461989304930" border="0" /></a><br /></span></div><span style="font-weight: bold;font-family:arial;font-size:100%;" ><br /><br /><br />Click on launch configuration:<br /></span><span style="font-size:100%;"><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTOQNApbjnYo_cQNoKFcphvbx4_2b-eeolz3H3a5HeLtQyJNnVDc2Hmm5wsZ7SwEbz89CI93ng0BvvXPrxlveZ_huqq816eY53OvNEK5jeRRfP_-I2XigXqi32DhcysG72l6YmJJQuPITv/s1600-h/serverLaunchConfig.JPG"><img style="cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTOQNApbjnYo_cQNoKFcphvbx4_2b-eeolz3H3a5HeLtQyJNnVDc2Hmm5wsZ7SwEbz89CI93ng0BvvXPrxlveZ_huqq816eY53OvNEK5jeRRfP_-I2XigXqi32DhcysG72l6YmJJQuPITv/s400/serverLaunchConfig.JPG" alt="" id="BLOGGER_PHOTO_ID_5120506625198062194" border="0" /></a><br /></span><span style="font-size:100%;"><span style="font-family:arial;"><br /><span style="color: rgb(0, 0, 0);">Set the JAVA_VENDOR flag to </span><span style="font-weight: bold; color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0); font-weight: bold;">Sun</span><span style="font-weight: bold; color: rgb(0, 0, 0);">'</span> <span style="color: rgb(0, 0, 0);">to use the sun JVM or</span> <span style="font-weight: bold;">'</span><span style="color: rgb(51, 51, 255); font-weight: bold;">BEA</span><span style="font-weight: bold;">'</span> <span style="color: rgb(0, 0, 0);">to use the JROCKIT JVM. In our case we set it to '<span style="font-weight: bold;">Sun</span>'.The sun JDK should now give us more information about the mysterious error. If the property JAVA_VENDOR is not available add it. </span></span> <span style="font-family:arial;"><span style="color: rgb(0, 0, 0);">If you have not configured anything in workshop you can always set the JAVA_VENDOR system property in the setDomainEnv.cmd file located in your domain bin directory using the line</span> </span><span style="color: rgb(51, 102, 255); font-weight: bold;font-family:arial;" >SET JAVA_VENDOR=Sun<br /><br /></span><span style="color: rgb(51, 102, 255);font-family:arial;" ><span style="color: rgb(0, 0, 0);">This should force weblogic to use the sun JVM instead. You can verify this by looking for the startup path from which java.exe is called from your console (the server log console not the web console)</span></span><span style="color: rgb(51, 102, 255); font-weight: bold;font-family:arial;" > </span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1017083851910735810.post-10267841006062235612007-10-05T08:08:00.000-07:002008-12-12T13:05:20.315-08:00Common code and the open closed policy<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpd95sc0dPF0Lzn5ECE51Pb-KDjVk1T7fk6IrnEaZOGc9GrJMNPuSq-IU5GlA-6X_NeHSp3-pD0TxPWP9c2rKyNzzozWRclOV3L3w7y-G23emA2kJdSmr2Ns6mJPk8mwUx70KmdsVU1o-C/s1600-h/minicommon.JPG"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpd95sc0dPF0Lzn5ECE51Pb-KDjVk1T7fk6IrnEaZOGc9GrJMNPuSq-IU5GlA-6X_NeHSp3-pD0TxPWP9c2rKyNzzozWRclOV3L3w7y-G23emA2kJdSmr2Ns6mJPk8mwUx70KmdsVU1o-C/s400/minicommon.JPG" alt="" id="BLOGGER_PHOTO_ID_5117882434539944482" border="0" /></a><br /><br /><br /><span style="font-weight: bold;">Common Application</span><br /><br /><blockquote>Often a group of applications write the same code to perform a particular task such as looking up user information or looking up EJB services through a service locator, or executing a query after fetching a connection to the database. These common services can be made available using EJB or POJO objects. </blockquote><blockquote>It is often a good idea to write a separate application that handles all the common functionality for you. The application would have to be designed well enough to allow you to work with existing logic without having to change it every time the common application undergoes a change. The common application services can be accessed via EJB, Spring POJO, or simple POJO distributed through JAR files. The JAR file becomes part of the library for other applications to use.<br /><br />Imagine that you have changed this common application and that the JAR file has to be updated in 20 other applications that use this common application. It would be cumbersome to test each application that uses the common services every time a change is made. Running a series of JUNIT tests is acceptable but manually testing the application every time a change is made is not.<br /><br />Code that is written using the open-closed principle will not need such exhaustive testing. When you write code always make sure that your existing functionality is wrapped nicely and is robust so that you need not touch it at any point in time. Also reduce the number of methods that you need to invoke in a common library to satisfy a particular service. Whatever your services do internally should not be exposed to the outside world. When you write code to this formula, your code is open for enhancements to it yet closed to change any existing code that works for you. All existing code should be frozen for change and extra features should be add ons to the existing code without changing them in any way.<br /><br />More on the open closed principle and other patterns/principles in this book, which I would highly recommend - Head first design patterns<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioBkQ9NlYI72p56WBZ0il3K4sdtyrBAVTPTSCE-3ImyYt1sQWRaNhmm0d3FIcB8RYHbDPEOMZ72TqNmKprp6ItDSDxUMTchweDTPrjPbf9PHc5Tv7RSaU3G7C8VQhNpgPhQBCbHvg68igU/s1600-h/51erdv4yRaL._SS500_.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioBkQ9NlYI72p56WBZ0il3K4sdtyrBAVTPTSCE-3ImyYt1sQWRaNhmm0d3FIcB8RYHbDPEOMZ72TqNmKprp6ItDSDxUMTchweDTPrjPbf9PHc5Tv7RSaU3G7C8VQhNpgPhQBCbHvg68igU/s320/51erdv4yRaL._SS500_.jpg" alt="" id="BLOGGER_PHOTO_ID_5117875867534948866" border="0" /></a><br /></blockquote>Unknownnoreply@blogger.com0