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

http://10.85.106.160:8080/wiki/jsp/Wiki?BootCamp

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

http://allen-sauer.com/com.allen_sauer.gwt.dnd.demo.DragDropDemo/DragDropDemo.html

Google like GWT?

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

Axis: installation

Axis installation

http://ws.apache.org/axis/


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


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

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

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

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:


   <dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>apache-activemq</artifactId>
    <version>4.1.1</version>
   </dependency>

   <dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.3.3_01</version>
   </dependency>
   <dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1</version>
   </dependency>
   <dependency>
    <groupId>xerces</groupId>
    <artifactId>xerces</artifactId>
    <version>2.4.0</version>
   </dependency>


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="com.hmco.edison.ws.axis.HierarchyServiceImpl"/>
  <parameter name="wsdlTargetNamespace" value="urn:soap.springaxis.HierarchyService.HMCO.com"/>
 </service>
...



Web Service Deployment Descriptor


<deployment xmlns="http://xml.apache.org/axis/wsdd/xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
  <service name="HierarchyService" provider="java:RPC" ><!-- style="rpc" use="encoded" -->
    <!--<parameter name="wsdlTargetNamespace" value="urn:soap.spring_axis.HierarchyService.HMCO.com/>-->
    <parameter name="className" value="com.hmco.edison.ws.axis.HierarchyServiceImpl" />
    <parameter name="allowedMethods" value="*" />
  </service>
</deployment>


Axis WSDD is mentioned on: AXIS

Axis: Spring configuration




<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/spring_axis-servlet.xml</param-value>
</context-param>

<listener>
  <listener-class>
    org.springframework.web.context.ContextLoaderListener
  </listener-class>
</listener>

<servlet>
  <servlet-name>springaxis</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>spring_axis</servlet-name>
  <url-pattern>*.axis</url-pattern>
</servlet-mapping>

<servlet>
  <servlet-name>AxisServlet </servlet-name>
  <display-name>Apache-Axis Servlet</display-name>
  <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
  <load-on-startup>5</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>AxisServlet</servlet-name>
  <url-pattern>/soap/*</url-pattern>
</servlet-mapping>


Axis: building using ant



<!-- Generate WSDL -->
    <target name="generateAuthenticationWSDL" depends="compile">
      <axis-java2wsdl 
        classname="com.hmco.morse.authentication.service.RemoteAuthenticationService" 
        namespace="urn:AuthenticationWS
        location="${soap.service}/AuthenticationWS" 
        output="${project.config.dir}/AuthenticationWS.wsdl">
        <mapping namespace="urn:AuthenticationWSpackage="com.hmco.morse.authentication.service"/>
      </axis-java2wsdl>
    </target>

    <!-- Generate WSDL -->
    <target name="generateAuthenticationWrappedWSDL" depends="compile">
      <axis-java2wsdl 
        classname="com.hmco.morse.authentication.service.RemoteAuthenticationService" 
        namespace="urn:AuthenticationWS
        location="${soap.service}/AuthenticationWS" 
        output="${project.config.dir}/AuthenticationWS.wsdl"
        style="wrapped">
        <mapping namespace="urn:AuthenticationWSpackage="com.hmco.morse.authentication.service"/>
      </axis-java2wsdl>
    </target>

    <!-- Generate Client And Move Descriptors -->
    <target name="generateAuthenticationClient">
      <axis-wsdl2java 
        url="${project.config.dir}/AuthenticationWS.wsdl" 
        output="${java2wsdl.output.dir}" 
        deployscope="request" 
        serverSide="yes"
      verbose="true" 
      helpergen="false">
      <mapping namespace="urn:AuthenticationWSpackage="com.hmco.morse.authentication.service"/>
    </axis-wsdl2java>
    <antcall target="moveAxisDescriptors"/>
    </target>

  <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"/>
  </target>

JavaScript: ArrayList


Example of use


var list = new ArrayList();
list.add("c");
list.add("f");
list.add("a");
list.add("d");
list.add("e");
list.add("b");
list.remove("d");
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){
    _array.push(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];
        j++;
      }
    }
    return tmp;
    }

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

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