Grab the source code from here
Wicket XML-RPC
13 11 2012Comments : Leave a Comment »
Tags: Wicket and XML-RPC, Wicket and XML-RPC integration, Wicket XML-RPC
Categories : Wicket
Drop Out Stack
22 10 2012Efficient Array Based Drop out Stack
public class DropOutStack implements Stack {
private static final int DEFAULT_CAPACITY = 10;
private final T[] elements;
private int top;
private int count;
public DropOutStack() {
this(DEFAULT_CAPACITY);
}
@SuppressWarnings("unchecked")
public DropOutStack(final int size) {
assert size > 0;
this.elements = ((T[]) new Object[size]);
this.top = 0;
this.count = 0;
}
public final void push(final T element) {
this.elements[top] = element;
this.top = (this.top + 1) % this.elements.length;
if (this.count != this.elements.length) {
this.count++;
}
}
public final T pop() {
if (isEmpty()) {
throw new CollectionEmptyException();
}
this.top = (this.top + this.elements.length - 1) % this.elements.length;
T result = this.elements[this.top];
this.elements[this.top] = null;
this.count--;
return result;
}
public final int size() {
return this.count;
}
public final T peek() {
return this.elements[this.top - 1];
}
public final boolean isEmpty() {
return this.count == 0;
}
}
Comments : Leave a Comment »
Tags: Array based Drop out stack, Array stack, drop out Stack, drop out Stack java, Stack
Categories : Data Structures, Java
Wicket Facebook
9 04 2012Wicket facebook integration using scribe-java and google-gson
Step 1
Goto Fecebook Developers click on Create new App
Step 2 : Update the web.xml with the facebook App ID and Secret
Step 3
Do mvn jetty:run and go to the app as follows
Step 4 : Access the canvas page
Grab the source code from Github repo
Comments : Leave a Comment »
Tags: google gjson, scribe java, Wicket facebook, wicket facebook scribe-java gjson
Categories : Java, Wicket
Struts Post process hooks
18 03 2012- processPreprocess() method of standard org.apache.struts.action.RequestProcessor
- “servlet-standard-preprocess” Chain in Catalog “Struts” for the modern org.apache.struts.chain.ComposableRequestProcessor
Example post process implementations
Subclassing standard org.apache.struts.action.RequestProcessor
Using commons chain (Chain or responsibility and command pattern)
1) Step1
<servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>chainConfig</param-name> <param-value> /WEB-INF/tiles-main-chain-config.xml, /WEB-INF/custom-chain-config.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
2) Step2
tiles-main-chain-config.xml is the exact replica of either org/apache/struts/chain/chain-config.xml (if you don’t use tiles)
or
org/apache/struts/tiles/chain-config.xml (if you use tiles)
3) Step3
<catalog name="struts"> <chain name="servlet-standard-postprocess"> <command className="com.test.struts.chain.commands.PostProcess"/> </chain> </catalog>
Comments : Leave a Comment »
Tags: post processor, Strtus post process, Strtus post processing, Strtus post processor, struts
Categories : Struts
quality-metrics-with-ant
22 01 2012Get the sample project here
Comments : Leave a Comment »
Tags: checkstyle-ant, cpd-ant, pmd-ant, quality metrics with Ant, sonar-ant
Categories : Java
Wicket Loose Coupling
29 10 2011We can do it in two ways,
-
Using Model : Partially loosely coupled , it is really worth considering
-
Using Custom Events : Fully loosely coupled
Loose Coupling Using Model
public class ChangeSensitiveModel extends Model {
private static final long serialVersionUID = 1L;
public ChangeSensitiveModel() {
}
public ChangeSensitiveModel(final T object) {
super(object);
}
final public void setObject(final T newObject) {
if (onBeforeSet(newObject)) {
super.setObject(newObject);
onAfterSet();
}
}
protected boolean onBeforeSet(T newObject) {
return true;
}
protected void onAfterSet() {
}
}
ChangeSensitiveModel In Action
Set object to the ChangeSensitiveModel Model
private Button newButton(final ChangeSensitiveModel<ValueMap> model, final Form<ValueMap> searchForm) {
return new AjaxButton(("sayHello")) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
model.setObject(searchForm.getModelObject());
}
};
}
Override the call back
public LooseCouplingUsingModelPage() {
changeSensitiveModel = new ChangeSensitiveModel(){
private static final long serialVersionUID = 1L;
@Override
protected void onAfterSet() {
LooseCouplingUsingModelPage.this.addOrReplace(new ResultPanel(RESULT_PANEL_ID, changeSensitiveModel));
AjaxRequestTarget ajaxRequestTarget = AjaxRequestTarget.get();
if (ajaxRequestTarget != null) {
ajaxRequestTarget.addComponent(LooseCouplingUsingModelPage.this.get(RESULT_PANEL_ID));
}
}
};
add(new SearchPanel(SEARCH_PANEL_ID, changeSensitiveModel));
add(newEmptyPanel());
}
Loose Coupling Using Custom Event
Firing an Event
new RefreashFeedBackPanelEvent(SearchPanel.this, target, searchForm.getModelObject()).fire();
Responding to Event : Any component wanting to respond to Customer event should implement AjaxUpdateListener
public void handleAjaxUpdate(final AjaxUpdateEvent event) {
if (event instanceof RefreashFeedBackPanelEvent) {
info("You said : " + ((RefreashFeedBackPanelEvent)event).getSourcData().getString("name"));
event.getTarget().addComponent(feedbackPanel);
}
}
Go Grab the source code from GitHub
do mvn jetty:run and see the example in Action.
Comments : Leave a Comment »
Tags: loose coupling, Loose coupling in wicket, wicket, wicket loose coupling
Categories : Java, Wicket
Good Vs. Bad Programmer
16 10 2011Good vs. Bad Programmer
Good Programmer is one who
- Always strives for excellence;
- follows good design principles;
- Always keep in mind CHANGE and MAINTAINIBILITY;
- At least refactors his/her code thrice
- Always try to improve the code base.
- While working with Object oriented language always thinks of Object Oriented Design and Principles, so on…
In short a good programmer tries to stick to:
“Don’t Comment the Bad code rewrite it”
On the contrary a bad programmer (not so good programmer to be politically correct
) is one who
- Don’t care about any rule
- Don’t follow any principle
- Never think about MAINTAINABILITY and the cost involved.
- Always try to find an excuse to support their bad code, for example they will say “Man!! I am not doing anything new or wrong that sort of code is already there in the code base.” Duh!!! We can’t expect them to improve the existing code base (in small steps of course) because they are not even willing to write the new code well.
The fundamental question nowadays is “Why do people write Bad Code?”
Let me share with you my experience before I answer that question!!
I have been mentoring wide varieties of people, from college graduate level to 8years programming experience doods. Here is my experience with them.
- College graduates learn things (good programming techniques) faster (given correct guidance, of course candidate should be willing to learn)
- There are three categories of experienced people.
- People who do good programming. [Very rare]
- People who do not know what is clean code but they are willing to learn (I consider my self here). [masses]
- People who neither know about clean code nor they are willing to learn. This kind of people are very dangerous for the project, get rid of this kind of people at the very first place (obviously after giving them some warnings) [rare]
So we have masses who don’t know anything about good programming, so obviously they will write Bad Code, because they are not exposed to Clean Coding (I see people write sequential Code With Object Oriented Languages [really frustrating])
Bad Code don’t Do this
public List<XyzCondition> getConditions() {
List<XyzCondition> conditions = // Build or Get Conditions
return conditions;
}
List List<XyzCondition> list = getConditions();
list.remove(conditionName);
Simplified Version
public Conditions getConditions() {
List<XyzCondition> conditions = // Build or Get Conditions
return new Conditions(conditions);
}
Conditions conditions = getConditions();
conditions.removeCondition(conditionName);
There are lots of problems with the first version of the code, but most people would argue that there is not much difference. In fact some people would go to extend that they would say first code is simple than the later one. Duhhhh !!!!
People wont even think twice before initiating such kind of discussion, They enjoy writing sequential code and they can’t tolerate a change, there is a bit of emotional baggage that they don’t want to overcome
People (99% of them, as I said there will always be some exceptions) who work with me always think in terms of Object Oriented Design and principles, even in tight schedules they produce high quality code. I am aware that some people would ask for more time the moment we demand clean code. Because for them writing clean code is like rocket science engineering.
Comments : 2 Comments »
Tags: Bad programmer, Good programmer, Good Vs Bad programmer
Categories : General



