Friday, October 21, 2005

Attribute Oriented Programming

I have been reading stuff about Attribute Oriented Programming. I realise this makes me Captain Spug, King of Dullness but I thought I would share my insights.

Appfuse is a j2ee acceleration thing that enables you to get up an running quickly using Hibernate, Spring, Xdoclet and test driven stuff. One groovy thing is that a lot of the code is generated for you via Xdoclet. For instance by adding the following order object (POJO!):



/*
* Created on 30-Sep-2005
*
* TODO get a life, play more uke, look out of the window
*/
package uk.co.bluetrail.demo.model;

import java.io.Serializable;

/**
* @author Spug-mola
* @hibernate.class table="morder"
* @struts.form include-all="true" extends="BaseForm"
**/
public class Order extends BaseObject implements Serializable {

private Long id ;
private String username;
private int orderNo ;
private int custNo ;
private int prodNo ;
private int quantity ;
private String Notes ;



/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
// TODO Auto-generated method stub
return "" + this.getOrderNo();
}

/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) {

Order order = (Order) o ;

return order.getOrderNo() == this.getOrderNo();
}

/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
// TODO Auto-generated method stub
return this.getOrderNo();
}

/**
* @return Returns the custNo.
* @hibernate.property
* @struts.validator type="required"
*/
public int getCustNo() {
return custNo;
}
/**
* @param custNo The custNo to set.
*/
public void setCustNo(int custNo) {
this.custNo = custNo;
}
/**
* @return Returns the id.
* @hibernate.id column="id"
* generator-class="increment" unsaved-value="null"
*/
public Long getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return Returns the notes.
* @hibernate.property length="255"
*/
public String getNotes() {
return Notes;
}
/**
* @param notes The notes to set.
*/
public void setNotes(String notes) {
Notes = notes;
}
/**
* @return Returns the orderNo.
* @hibernate.property
* @struts.validator type="required"
*/
public int getOrderNo() {
return orderNo;
}



/**
* @param orderNo The orderNo to set.
*/
public void setOrderNo(int orderNo) {
this.orderNo = orderNo;
}
/**
* @return Returns the prodNo.
* @hibernate.property
* @struts.validator type="required"
*/
public int getProdNo() {
return prodNo;
}
/**
* @param prodNo The prodNo to set.
*/
public void setProdNo(int prodNo) {
this.prodNo = prodNo;
}
/**
* @return Returns the quantity.
* @hibernate.property
* @struts.validator type="required"
*/
public int getQuantity() {
return quantity;
}
/**
* @param quantity The quantity to set.
*/
public void setQuantity(int quantity) {
this.quantity = quantity;
}
/**
* @return Returns the username.
* @hibernate.property length="20"
* @struts.validator type="required"
*/
public String getUsername() {
return username;
}
/**
* @param username The username to set.
*/
public void setUsername(String username) {
this.username = username;
}
}



I can run an ANT build target that generates

my database creation sql
my hibernate DAOs
the validation for struts
simple JSPs to add an order
simple JSPs to view orders
..... and many many more (said in Ronco voice)

This is all achieved by adding the xDoclet tags at the top of some of the functions and class declarations.

Clever ..

or maybe an indication of how looney-emporers-new-clothes-a-like j2EE has become, not sure which at the mo.

0 Comments:

Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?