Archive

Archive for November, 2009

svn: PROPFIND request failed

November 20, 2009 Leave a comment

Problem Statement:
svn: Processing PROPFIND request response failed: Content is not allowed in prolog. (/svn/project1/module1)
svn: PROPFIND request failed on ‘/svn/project1/module1′
svn: Processing PROPFIND request response failed: Content is not allowed in prolog. (/svn/project1/module1)
svn: PROPFIND request failed on ‘/svn/project1/module1′
RA layer request failed
svn: PROPFIND of ‘/svn/project1/module1′: 200 OK (http://localserver)

Solution:
Server SVN version is 1.4.8. Client version used is 1.6.6
After uninstalling 1.6.6 and installing 1.4.8 all issues resolved.

-o-

Spring Bean – Order of injecting properties

November 13, 2009 Leave a comment

Problem Statement: We need to start some task, after injecting all properties. How to resolve this?

Solution: Dont / Never depend on order of injecting values into bean. It is not controlled.


import org.springframework.beans.factory.InitializingBean;

public class BeanName implements InitializingBean
{

public void afterPropertiesSet() throws Exception
  {
    System.out.println( "It will be called after completion of properties setting.");
    //do whatever is required here.
  }

}

Injecting boolean values into Spring bean

November 13, 2009 Leave a comment

Problem Statement: How to inject boolean values into spring bean?

Wrong:

<property name="isFlagEnabled" value="true"/>

private boolean isFlagEnabled = false;

Correct:

<property name="isFlagEnabled">
	<value type="java.lang.Boolean">true</value>
</property>

private Boolean isFlagEnabled = false;

-o-

Web based development

November 6, 2009 Leave a comment

Recently looked at it. And it looks great.
http://www.makumba.org/

This is easy to build application based on CRUD operations for existing database.
http://examples.codecharge.com

This provides nice tabular view of the data with lots of features. Used in many projects.
http://displaytag.homeip.net/displaytag-examples-1.2/index.jsp

Categories: J2EE

HashMap deep copy Vs simple copy

November 2, 2009 Leave a comment

Question: Many times we ask same question again and again, year after year.
The best way to understand is run the following code.


import java.util.HashMap;
import java.util.Iterator;

public class HashMapTest
{
  public static void main( final String[] args )
  {
    testReference();
    testDeepCopy();
  }

  private static void testDeepCopy()
  {
    System.out.println( "Deep Copy Test" );
    final HashMap<Integer, String> data1 = new HashMap<Integer, String>();
    data1.put( new Integer( "1" ), "one" );
    data1.put( new Integer( "2" ), "two" );

    final HashMap<Integer, String> data2 = new HashMap<Integer, String>( data1 );
    printHashMap( data1, "data1" );
    printHashMap( data2, "data2" );

    System.out.println( "Remove data in data2" );

    data1.remove( new Integer( 2 ) );
    printHashMap( data1, "data1" );
    printHashMap( data2, "data2" );
  }

  private static void testReference()
  {
    System.out.println( "Simple Copy Test" );
    final HashMap<Integer, String> data1 = new HashMap<Integer, String>();
    data1.put( new Integer( "1" ), "one" );
    data1.put( new Integer( "2" ), "two" );

    final HashMap<Integer, String> data2 = data1;
    printHashMap( data1, "data1" );
    printHashMap( data2, "data2" );

    System.out.println( "Remove data in data2" );

    data1.remove( new Integer( 2 ) );
    printHashMap( data1, "data1" );
    printHashMap( data2, "data2" );
  }

  private static void printHashMap( final HashMap<Integer, String> map,
    final String message )
  {
    System.out.println( "---- " + message + " Begin ----" );
    final Iterator iterator = map.keySet().iterator();

    while ( iterator.hasNext() ) {
      final Integer key = (Integer)iterator.next();
      final String value = map.get( key );

      System.out.println( key + " " + value );
    }
    System.out.println( "---- " + message + " End ----" );
  }

}

Result:
Simple Copy Test
—- data1 Begin —-
1 one
2 two
—- data1 End —-
—- data2 Begin —-
1 one
2 two
—- data2 End —-
Remove data in data2
—- data1 Begin —-
1 one
—- data1 End —-
—- data2 Begin —-
1 one
—- data2 End —-
Deep Copy Test
—- data1 Begin —-
1 one
2 two
—- data1 End —-
—- data2 Begin —-
1 one
2 two
—- data2 End —-
Remove data in data2
—- data1 Begin —-
1 one
—- data1 End —-
—- data2 Begin —-
1 one
2 two
—- data2 End —-

Categories: Core Java

Spring – Inject Properties file into Bean

November 2, 2009 Leave a comment

Problem Statement: Spring – Inject Properties file into Bean

Spring Bean configuration file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">

<util:properties id="propertiesFileID1" location="classpath:complete_file_path\filename.properties"/>

<bean name="BeadID" class = "com.abc.ClassNameABCD" >
	<property name="propFile1" ref="propertiesFileID1"/>
</bean>

</beans>

Source code


package com.abc;

import java.util.Properties;

public class ClassNameABCD
{

 private Properties propFile1;

 //Prepare getter and setters for propFile1;

}

Read this for more information

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/apcs02.html#xsd-config-body-schemas-util-properties

Follow

Get every new post delivered to your Inbox.