|
|
|||||||||||||||||||||||||||||||||||||||||||||
Ahmed Hashim's Blog
AspectJ: Please don't use System.out.printlnPosted by ahashim on July 24, 2008 at 01:39 PM | Permalink | Comments (0)Usually if you are working in a "big" project and doing a code review; if you have a vendor who develop some application for your company; if you have a fresh graduate developer ... you will find a lot of bad-practices in the code being written! I don't like to see System.out.println() in the code .. because simply, it doesn't appears in the log files!!! As a solution, you can use Aspects to figure out the pointcuts in the code which uses "SYSO" and the advice will be to log the message yourself. Let's have a look into the code and how this will work:- 1- the idiot code will be like that as you see, the method add() will print some info the default output stream which is the console. This method is called from the main method. If you are an eclipse user, you will notice that there is a small orange arrow on the left side of the code editor referring to the line of code uses "SYSO"; we will back to this arrow after while ;). 2- We will now create a new aspect to solve this problem, the BPAspect will looks like the following:- to define a pointcut to SYSO, the pointcut definition will be pointcut syso():call(* java.io.PrintStream.print*(..)); which means: define a pointcut named syso and get all places which call a method print,println as a members in the PrintStream class, take any argument and return any value. then, mark the called for this method as warning in your code and display this message "Don't use SYSO" declare warning:syso():"Don't use SYSO"; then, how to log the message? the advice will come to do this job after():syso(){logger.info(thisJoinPoint.getArgs()[0]);} 3- What about the orange arrow? it indicates that there is an pointcut which this line matches with. There is a panel also shows the aspects which reference the code in this class on the other side, if you open the aspect code, the panel will show the code referenced by the aspects. you will see also that there is a warning message in this line 4- Now, we can run the application to see how it will work Add 1 to 2 and prints to the log file Beside Java ... FlexPosted by ahashim on June 10, 2008 at 01:42 PM | Permalink | Comments (5)Few months ago I did my Hello World Flex, I used Adobe Flex Builder and founded it interesting to produce RIA. After than I tried a simple application for file download and discovered some features in Flex. Now, I came with a new project and decided to use Flex to do the job. What is my project? It is a small and smart product catalog with search facilities and customer reviews. Why I decided to make this site with Flex? Java is not suitable because of the hosting issue, finally I want to upload my application in my cheap host which supports PHP only. Why not PHP? because I plan add this small project to a current projects, some of them developed with PHP and other with ASP. I thought about Flex to make it easy to plug to any website The first problem I got is the DB connectivity, there is a way to connect to DB through PHP code or Java, but I didn't like the idea; it will be the same problem again. I asked one of my friends, he is a Flex fan and he told me about a new project which add the feature of DB connection from Flex. The Action Script SQL it is a very new project and tried it yesterday .. it works well as early beta version. |
July 2008
Search this blog:CategoriesBusinessCommunity: Java Patterns Community: Java User Groups J2EE J2SE Open Source Programming Web Applications Archives
July 2008 Recent EntriesAspectJ: Please don't use System.out.println Book Review: High performance web sites | ||||||||||||||||||||||||||||||||||||||||||||
|
|