xml to xml conversion using xslt

As I am new to XSLT wanted to perform some xsl transformation on my xml file and generate the xml. But when I were looking for some example how to do it I was getting all example who teach you how to transform an xml to html. So here is the way I found after some web search. Look at the tag <xsl:output> and its method just set it to xml as below. The code snippet to just copy all the elements and attributes from one xml file to another. If you want to perform some operations or checks you are free to add new templates.

<xsl:stylesheet version='1.0' 
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> 

<xsl:output method='xml' indent='yes' /> 

<!-- copy all elements which don't match any template --> 
  <xsl:template match="* | @*"> 
    <xsl:copy> 
       <xsl:copy-of select="@*" /> 
       <xsl:apply-templates /> 
    </xsl:copy> 
  </xsl:template> 
</xsl:stylesheet>

Posted at at 6:19 AM on Thursday, September 30, 2010 by Posted by Ravindra Nikam | 0 comments   | Filed under: , , ,

Tools for java object to object mapping

There are few libraries out there:

Transmorph: Transmorph is a free java library used to convert a Java object of one type into an object of another type (with another signature, possibly parameterized).

EZMorph: EZMorph is simple java library for transforming an Object to another Object. It supports transformations for primitives and Objects, for multidimensional arrays and transformations with DynaBeans

Commons-BeanUtils: ConvertUtils -> Utility methods for converting String scalar values to objects of the specified Class, String arrays to arrays of the specified Class.

Commons-Lang: ArrayUtils -> Operations on arrays, primitive arrays (like int[]) and primitive wrapper arrays (like Integer[]).

Commons-Convert: Commons-Convert aims to provide a single library dedicated to the task of converting an object of one type to another. The first stage will focus on Object to String and String to Object conversions.

Morph: Morph is a Java framework that eases the internal interoperability of an application. As information flows through an application, it undergoes multiple transformations. Morph provides a standard way to implement these transformations.

•Lorentz: Lorentz is a generic object-to-object conversion framework. It provides a simple API to convert a Java objects of one type into an object of another type. (seems dead)

Spring framework: Spring has an excellent support for PropertyEditors, that can also be used to transform Objects to/from Strings.

Dozer: Dozer is a powerful, yet simple Java Bean to Java Bean mapper that recursively copies data from one object to another. Typically, these Java Beans will be of different complex types.

OTOM: With OTOM, you can copy any data from any object to any other object. The possibilities are endless. Welcome to "Autumn".

Smooks: The Smooks JavaBean Cartridge allows you to create and populate Java objects from your message data (i.e. bind data to) (suggested by superfilin in comments).

Transmorph (pretty recent), EZMorph, Dozer, OTOM are all serious candidates. Dozer seems to be the most active project though (and maybe the most advanced). I personally used Dozer and happy with it. (list from Pascal Thivent)

Posted at at 4:12 AM on Tuesday, August 3, 2010 by Posted by Ravindra Nikam | 0 comments   | Filed under: , , ,

Hibernate criteria join

Pasted from stackoverflow.com

Hello, We have two tables Family and Member, the relation between these two is Family has set of members in it but member don't have any family relationship within it.

I wanted get member using dob and family for that I am using Hibernate criteria API's but I am not getting how to write join query since members don't have Family instance with it. So not able to use FetchMode. Any other way to achieve this ?

Ans:

DetachedCriteria subquery = DetachedCriteria.forClass(Family.class, "family")
.add(Expression.eq("family.id", family.getId()));

subquery.createAlias("members", "members")
.add(Restrictions.eqProperty("members.id", "m.id"))
.add(Expression.eq("members.DOB",Date));

subquery.setProjection(Property.forName("members.id"));

Criteria crit = session.createCriteria(Member.class, "m")
.add(Subqueries.propertyIn("m.id", subquery));

results = crit.list();

Posted at at 1:35 AM on Friday, November 6, 2009 by Posted by Ravindra Nikam | 0 comments   | Filed under: , ,

Current opennings at SpiderLogic Pune

Hi all,
We currently have openings for :
• Senior Developers in Java and .net (4 -6 Yrs)
• Java and .Net Architects(7+ yrs)
• QA Architect.(7+yrs)
We are looking at people who are hands on development and really passionate about coding and technology. If you have any friends or ex colleagues who would be interested in working with us kindly send me their resumes at rnikamATspiderlogicDOTcom

website : www.spiderlogic.com

Posted at at 6:34 AM on Tuesday, September 22, 2009 by Posted by Ravindra Nikam | 0 comments   | Filed under: , ,

Unit testing ejb3 reference

To test ejb either we have to put test in ejb container or we can put container in test itself. following are few links to refer writing containers in test using openEJB.

How to unit test EJB
Build, deploy, and test EJB components in just a few seconds

Posted at at 6:35 AM on Thursday, August 20, 2009 by Posted by Ravindra Nikam | 0 comments   | Filed under: ,

Using regular expresions(regex, regexp)

Regular Expression Basic Syntax Reference

Posted at at 4:24 AM on Sunday, August 9, 2009 by Posted by Ravindra Nikam | 0 comments   | Filed under:

TestNG and JUnit in one project with maven surefire

This can be achieved using options such as using different profiles for both and another is by setting JUnit property true for surefire plug in.

Run "mvn test". Only the TestNG test will run since as soon as the maven founds the TestNG dependency in main profile it executes TestNG tests only. If you modify the pom to set the property "junit=true", only the JUnit test will run.


org.apache.maven.plugins
maven-surefire-plugin
2.4.2



junit
true



  

But personally my experience is it wont works with JUnit4.

Since it is the TestNG dependency that triggers surefire to use the TestNG runner to execute tests, We've to move this dependency out of the main project scope. In order to compile and run all JUnit tests, and needs to exclude the TestNG tests from the compiler and surefire plugins.

Then in a profile, add TestNG dependency and adjust the compiler and surefire plugins to include the TestNG tests but don't forget and override exclude if you are inheriting from main profile.


test



org.apache.maven.plugins
maven-compiler-plugin
2.0.2

1.5
1.5

**/testNGTests/**.java








testNG



org.apache.maven.plugins
maven-compiler-plugin
2.0.2

1.5
1.5

**/junitTests/**.java







org.testng
testng
5.8
test
jdk15





To run JUnit tests I use: mvn test
To run testNG tests I use: mvn test -P testNG

Posted at at 3:36 AM on Saturday, August 8, 2009 by Posted by Ravindra Nikam | 0 comments   | Filed under: , ,