Have finished reading book AspectJ in Action.
This is a rather lengthy book, but it covers AOP in depth. First, AOP theory and AspectJ as a reference implementation. Second, Spring AOP and the use of AspectJ and Spring altogether.
The author writes that AOP is not the silver bullet. As always choose the right tool for the right job.
I would also recommend read Spring documentation on AOP together with this book. Also, the book contains the path to gradually adoption of AOP in your projects.
This blog is a collection of minds around linux, java, javascript, etc. Looking for great opportunities.
среда, 8 января 2014 г.
суббота, 4 января 2014 г.
Spring 3.2.6 + AspectJ 1.7.4 + LTW + WebSphere Application Server v8.5.5.1
Hello!
Happy New Year 2014!
Today I want to prove the work of AspectJ LTW in WebSphere Application Server v8.5.5.1.
Happy New Year 2014!
Today I want to prove the work of AspectJ LTW in WebSphere Application Server v8.5.5.1.
среда, 4 декабря 2013 г.
Apache POI 3.9 DOCX Cookbook
Here is my cookbook recipes for working with Apache POI 3.9 and DOCX.
Api for DOCX in Apache POI is scarce.
1) It is difficult to grab the terminology at first. To understand the terminology you can look at the http://officeopenxml.com. This site contains the information about the structure of DOCX format.
2) Create paragraph and center it:
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
3) Fill the paragraph with bold text, size 16 and break after it:
XWPFRun paragraphRun = paragraph.createRun();
paragraphRun.setBold(true);
paragraphRun.setText("my text");
paragraphRun.setFontSize(16);
paragraphRun.addBreak();
4) Merge 2 cells in table (like colspan attribute in html):
XWPFTable table = document.createTable();
XWPFTableRow row = table.getRow(0);
row.getCell(0).setText("my cell);
// get a table cell properties element (tcPr)
CTTcPr tcpr = row.getCell(0).getCTTc().addNewTcPr();
// set gridspan
CTDecimalNumber gridSpan = tcpr.addNewGridSpan();
gridSpan.setVal(new BigInteger("2")); <-- the colspan of cell
5) Set background of cell:
// set fill color
CTShd ctshd = tcpr.addNewShd();
ctshd.setColor("auto");
ctshd.setVal(STShd.CLEAR);
ctshd.setFill("E3E7E9"); <-- RGB color
6) Set width of cell to 100%:
// setwidth
CTTblWidth cttblwidth = tcpr.addNewTcW();
cttblwidth.setW(BigInteger.valueOf(100));
cttblwidth.setType(STTblWidth.PCT);
Api for DOCX in Apache POI is scarce.
1) It is difficult to grab the terminology at first. To understand the terminology you can look at the http://officeopenxml.com. This site contains the information about the structure of DOCX format.
2) Create paragraph and center it:
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
3) Fill the paragraph with bold text, size 16 and break after it:
XWPFRun paragraphRun = paragraph.createRun();
paragraphRun.setBold(true);
paragraphRun.setText("my text");
paragraphRun.setFontSize(16);
paragraphRun.addBreak();
4) Merge 2 cells in table (like colspan attribute in html):
XWPFTable table = document.createTable();
XWPFTableRow row = table.getRow(0);
row.getCell(0).setText("my cell);
// get a table cell properties element (tcPr)
CTTcPr tcpr = row.getCell(0).getCTTc().addNewTcPr();
// set gridspan
CTDecimalNumber gridSpan = tcpr.addNewGridSpan();
gridSpan.setVal(new BigInteger("2")); <-- the colspan of cell
5) Set background of cell:
// set fill color
CTShd ctshd = tcpr.addNewShd();
ctshd.setColor("auto");
ctshd.setVal(STShd.CLEAR);
ctshd.setFill("E3E7E9"); <-- RGB color
6) Set width of cell to 100%:
// setwidth
CTTblWidth cttblwidth = tcpr.addNewTcW();
cttblwidth.setW(BigInteger.valueOf(100));
cttblwidth.setType(STTblWidth.PCT);
пятница, 29 ноября 2013 г.
WebSphere Portal 7. Longrunning tasks in portlets.
Sometimes operations in portlets can take a long time to complete, like a report generating task. It is better not to execute such tasks in a synchronous way, because :
- they block the web container thread, which slows down user satisfaction;
- make the appearance of application to freeze;
- the task can take up time of no more then request timeout;
- you cannot cancel the task;
- you don't see the progress of your task.
среда, 30 октября 2013 г.
Code complete. Complete.
Just have finished reading Code Complete by Steve McConnell. This book blew up my mind. It contains a lot information about programming as a collection of activities. The most useful idea for me was that we program for people first, computers second. Some useful thoughts i wrote out in my recent post "Programming quotes".
The last chapter contains the book list that a developer should read. Here it is:
The last chapter contains the book list that a developer should read. Here it is:
суббота, 26 октября 2013 г.
Java 7. Find yourself what's new?
During the reading of Code Complete 2e I've come across the grep example. This utility helps you to find files matching your search criteria.
If you have a javadoc and you want to find out what's new then you can use the following example:
duglas@duglas-ThinkStation /usr/share/doc/openjdk-7-doc/api $ grep -R -l --include="*.html" "<dd>1.7</dd>" . > /home/duglas/j.txt
This command will find all files that have been changed or added to the JDK 1.7. Moreover it allows you not only to rely on the what's new file but to explore the changes to the JDK documentation by yourself.
If you have a javadoc and you want to find out what's new then you can use the following example:
duglas@duglas-ThinkStation /usr/share/doc/openjdk-7-doc/api $ grep -R -l --include="*.html" "<dd>1.7</dd>" . > /home/duglas/j.txt
This command will find all files that have been changed or added to the JDK 1.7. Moreover it allows you not only to rely on the what's new file but to explore the changes to the JDK documentation by yourself.
пятница, 25 октября 2013 г.
Spring Portlet MVC 3 on WebSphere Portal 7 cookbook
Here are my personal experience of Spring Portlet MVC 3 on WebSphere Portal 7.
When using @ResourceMapping method you can return string, that will map to the jsp, so you can conveniently serve jsp content.
- Spring profiles feature is not working in portlet environment.
- If your portlet use session for anonymous user, then you can enable it with container-runtime-option feature in portlet.xml like this:
<container-runtime-option>
<name>com.ibm.portal.public.session</name>
<value>true</value>
</container-runtime-option> - Using client side aggregation and file upload doesn't work together. Switch you page to server side aggregation mode.
- When you first time add the event processing feature to portlets and deploy them to portal then you better switch the client side aggregation to server side aggregation. If you don't do this, then you cannot setup wires between your portlets.
- If you want your spring portlet to work in client side aggregation, then in your "form:form" tag set attribute htmlEscape="false".
- If you use Spring JDBC on WebSphere Portal then set connection extractor on your jdbc template like this:
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor" />. This is especially useful if you need to work with special database types and\or stored procedures. - Spring JDBC. Use jndi to create the datasource like this in application context:
<jee:jndi-lookup id="myDataSource" jndi-name="jdbc/myds" cache="true" resource-ref="true" lookup-on-startup="false" proxy-interface="javax.sql.DataSource" /> - If you use JNDI resources in portlet then declare them in ibm-web-bnd.xml file like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-bnd
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
version="1.0">
<virtual-host name="default_host" />
<resource-ref name="jdbc/mydb" binding-name="jdbc/mydb" />
</web-bnd>
Also don't forget to declare it in web.xml:
<resource-ref>
<res-ref-name>jdbc/mydb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
<mapped-name>jdbc/mydb</mapped-name>
</resource-ref> - When declare portlet.xml use the following declaration:
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
id="myportlet.war">.
Take a look at id attribute. This is how WebSphere Portal distinguishes your war files on portal. - When work with AJAX use @ResourceMapping annotation extensively.
- Use spring portlet mvc mock objects for unit testing your controllers.
- Use @ExceptionHandler annotation to process exceptions in controller.
- Some other interesting information can be found http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.html .
When using @ResourceMapping method you can return string, that will map to the jsp, so you can conveniently serve jsp content.
суббота, 12 октября 2013 г.
Programming quotes
Minimizing complexity is a key to writing high-quality code.
If you treat modifications as opportunities to tighten up the original design of the program, the quality improves.
A long parameter list is a warning that the abstraction of the routine interface has not been well thought out.
Program changes are a fact of life both during initial development and after initial release.
Ideas to manage your manager:
Plant ideas for what you want to do, and then wait for your manager to have a brainstorm (your idea) about doing what you want to do.
Educate your manager about the right way to do things. This is an ongoing job because managers are often promoted, transfered, or fired.
Focus on your manager's interests, doing what he or she really wants you to do, and don't distract you manager with unnecessary implementation details. (Think of it as "encapsulation" of your job.)
Refuse to do what your manager tells you, and insist on doing your job the right way.
Find another job.
Code as if whoever maintains your program is a violent psychopath who knows where you live. -- Anonymous.
One key to effective programming is learning to make mistakes quickly, learning from them each time. Making a mistake is no sin. Failing to learn from a mistake is.
Code complete.2e.
If you treat modifications as opportunities to tighten up the original design of the program, the quality improves.
A long parameter list is a warning that the abstraction of the routine interface has not been well thought out.
Program changes are a fact of life both during initial development and after initial release.
Ideas to manage your manager:
Plant ideas for what you want to do, and then wait for your manager to have a brainstorm (your idea) about doing what you want to do.
Educate your manager about the right way to do things. This is an ongoing job because managers are often promoted, transfered, or fired.
Focus on your manager's interests, doing what he or she really wants you to do, and don't distract you manager with unnecessary implementation details. (Think of it as "encapsulation" of your job.)
Refuse to do what your manager tells you, and insist on doing your job the right way.
Find another job.
Code as if whoever maintains your program is a violent psychopath who knows where you live. -- Anonymous.
One key to effective programming is learning to make mistakes quickly, learning from them each time. Making a mistake is no sin. Failing to learn from a mistake is.
Code complete.2e.
суббота, 31 августа 2013 г.
jQuery Tree plugin
Very often in web development UI you need a tree component. Some time ago I've written about jsTree and lazy loading. Now I've found the promising alternative called zTree. It is a jQuery plugin that supports JSON, AJAX, checkbox and other things you can imagine. Also it has good documentation and examples. Moreover it is easy to use.
среда, 21 августа 2013 г.
jQueryUI position utility
In web-development you often need to work with html, css, javascript.
The most tedious part of this work is to position elements among each other.
What can help you to speed up this work?
I have discovered the position method in jQueryUI library.
This method easily allows you to position given element against selector, element, jquery or event. The last option means that you can also position elements against your cursor.
Hope this help someone.
The most tedious part of this work is to position elements among each other.
What can help you to speed up this work?
I have discovered the position method in jQueryUI library.
This method easily allows you to position given element against selector, element, jquery or event. The last option means that you can also position elements against your cursor.
Hope this help someone.
Подписаться на:
Сообщения (Atom)