Monday, June 30, 2008

UNIX: directory size

This command calculates the size of the directory and gives it in Kb
(80200 = 80.2 Mb):

$ du -ks csd_images
80200 csd_images
$du -sh csd_images

Thursday, June 26, 2008

DAO: creating new model

1. Write a model class with annotations.
2. Run hibernate3:hbm2ddl to create database scripts.
3. Write DAO interface.
4. Write jUnit test for DAO and make sure that they fail initially.
5. Implement DAO.
6. Pass jUnit test with all possible inputes to verify that DAO methdod work.

Baby Steps

Good code is a succession of small programming steps that would eventually create a well written functionality. In order to create a clean, simple, and functional code, it is good to follow some of the best practices of programming:

Lets say we want to create UI with following functionalities:

- List
- Add
- Edit
- Delete of items

1) Create a skeleton UI with "comming soon.." text, you test and commit code.
2) Make a fake, hardcoded list and you display it , you test and commit code.
3) Fetch the list via a service call that returns a fake list, , you test and commit code.
4) Implement the DAO , you test and commit.
5) Connect all pieces, you test and commit.

Now you have the "list" and you can move to the "add" functionality.

2007 BootCamp Wiki

Java: getting the size of File Directory

     * @author UkiDLucas 
     * @return size of file or directory in bytes [ use: long bytesToMb(long bytes) ]  
    public static long calcFileDirectorySize(File directory)
if (directory.isFile())
    return directory.length();

long size = 0;

for (File file : directory.listFiles())
    size += calcFileDirectorySize(file);
return size;

    public static double bytesToMb(long bytes)
return (bytes / 1024 / 1024);

Wednesday, June 25, 2008

GWT: drag-and-drop examples

Google like GWT?

Holly smoke!
Google listed my blog posting the same day!

Axis: installation

Axis installation

ulucas@LTBPK05D1 /cygdrive/c/opt/axis
$ wget
13:08:35 (267.78 KB/s- `axis-bin-1_4.tar.gz' saved [8093928/8093928]

ulucas@LTBPK05D1 /cygdrive/c/opt/axis
$ ls

ulucas@LTBPK05D1 /cygdrive/c/opt/axis
$ gunzip axis-bin-1_4.tar.gz

ulucas@LTBPK05D1 /cygdrive/c/opt/axis
$ ls

ulucas@LTBPK05D1 /cygdrive/c/opt/axis
$ tar xfv axis-bin-1_4.tar

in your ~/bashrc set up the following variables (make sure you re-run the bashrc):

export AXIS_HOME=/opt/axis/axis-1_4
export CLASS_PATH=$CLASS_PATH:$AXIS_HOME/lib/axis-ant.jar
export CLASS_PATH=$CLASS_PATH:$AXIS_HOME/lib/axis.jar
export CLASS_PATH=$CLASS_PATH:$AXIS_HOME/lib/commons-discovery-0.2.jar
export CLASS_PATH=$CLASS_PATH:$AXIS_HOME/lib/commons-logging-1.0.4.jar
export CLASS_PATH=$CLASS_PATH:$AXIS_HOME/lib/jaxrpc.jar
export CLASS_PATH=$CLASS_PATH:$AXIS_HOME/lib/log4j-1.2.8.jar
export CLASS_PATH=$CLASS_PATH:$AXIS_HOME/lib/saaj.jar
export CLASS_PATH=$CLASS_PATH:$AXIS_HOME/lib/wsdl4j-1.5.1.jar

export CLASS_PATH=$CLASS_PATH:$MAVEN_REPO/javax/activation/activation/1.1/activation-1.1.jar
export CLASS_PATH=$CLASS_PATH:$MAVEN_REPO/javax/mail/mail/1.3.3_01/mail-1.3.3_01.jar 

export tcpmon="java org.apache.axis.utils.tcpmon"
export wsdl2java="java org.apache.axis.wsdl.WSDL2Java -t "

Be aware Axis 4.1.1 brings dependency for the AXIS 1.2-RC1.jar which is NOT compatible with the newest AXIS 1.4!!!
add dependencies to the project, this will copy the jars to your local box ~/.m2/repository:



Axis installation is mentioned on: AXIS

Axis: WSDD

To list already deployed services

 java org.apache.axis.client.AdminClient list

the content displayed is same as server-config.wsdd file
for example...

 <service name="webservice" provider="java:RPC">
  <parameter name="allowedMethods" value="*"/>
  <parameter name="className" value=""/>
  <parameter name="wsdlTargetNamespace" value=""/>

Web Service Deployment Descriptor

<deployment xmlns=""">
  <service name="HierarchyService" provider="java:RPC" ><!-- style="rpc" use="encoded" -->
    <!--<parameter name="wsdlTargetNamespace" value=">-->
    <parameter name="className" value="" />
    <parameter name="allowedMethods" value="*" />

Axis WSDD is mentioned on: AXIS

Axis: Spring configuration





  <servlet-name>AxisServlet </servlet-name>
  <display-name>Apache-Axis Servlet</display-name>


Axis: building using ant

<!-- Generate WSDL -->
    <target name="generateAuthenticationWSDL" depends="compile">
        <mapping namespace="urn:AuthenticationWSpackage="com.hmco.morse.authentication.service"/>

    <!-- Generate WSDL -->
    <target name="generateAuthenticationWrappedWSDL" depends="compile">
        <mapping namespace="urn:AuthenticationWSpackage="com.hmco.morse.authentication.service"/>

    <!-- Generate Client And Move Descriptors -->
    <target name="generateAuthenticationClient">
      <mapping namespace="urn:AuthenticationWSpackage="com.hmco.morse.authentication.service"/>
    <antcall target="moveAxisDescriptors"/>

  <target name="moveAxisDescriptors">
    <echo message="moving: ${java2wsdl.output.dir}/com/hmco/morse/authentication/service/deploy.wsdd"/>
    <move file="${java2wsdl.output.dir}/com/hmco/morse/authentication/service/deploy.wsdd" todir="${project.deploy.dir}" failonerror="false"/>
    <echo message="moving: ${java2wsdl.output.dir}/com/hmco/morse/authentication/service/undeploy.wsdd"/>
    <move file="${java2wsdl.output.dir}/com/hmco/morse/authentication/service/undeploy.wsdd" todir="${project.deploy.dir}" failonerror="false"/>

JavaScript: ArrayList

Example of use

var list = new ArrayList();
alert('get()' + list.get());
alert('getSortedAsc()' + list.getSortedAsc());
alert('getSortedDesc()' + list.getSortedDesc());

The JavaScript implementation of (pseudo) 
ArrayList for MSIE and Mozilla:

function ArrayList() {
    var _array = [];

    this.add = add;
    this.get = get;
    this.remove = remove;
    this.size = size;
    this.toString = toString;
    this.getElementIndex = getElementIndex;
    this.getSortedAsc = getSortedAsc;
    this.getSortedDesc = getSortedDesc;
    this.isElementExists = isElementExists;
    this.hasAnyNotNullElement = hasAnyNotNullElement;

    function add(value){

    function remove(value){
    var toDelete = getElementIndex(value);
    delete _array[toDelete];

    function size(){
    return _array.length;

    function toString(){
    var t = '';
    for(var i = 0; i < size(); i++){
      t += _array[i];
      if(i < size() 1t += ', ';
    return t;

    function getElementIndex(value){
    for(var i = 0; i < size(); i++)
      if(_array[i== valuereturn i;
    return 'false';

    function isElementExists(value){
    return (getElementIndex(value== 'false') false true;

    function hasAnyNotNullElement(){
    for(var i = 0; i < size(); i++){
      if(_array[i!= '' && typeof(_array[i]) != 'undefined')
        return true;
    return false;

    function get(){
    var tmp = [];
    var j = 0;
    for(var i = 0; i < size(); i++){
      if(typeof(_array[i]) != 'undefined'){
        tmp[j= _array[i];
    return tmp;

    function getSortedAsc(){
    var tmp = [];
    tmp = get();
    return tmp.sort();

    function getSortedDesc(){
    var tmp = [];
    tmp = get();
    return tmp.reverse();