Sunday, November 22, 2009

Groovy for quick text clean-up

Having some XML files to clean-up and transform, I was looking for a script-based solution, so that I don't have to go through the Java edit-build-run cycle. Usually I would think to Python, but it's a long time since I have touched it and then I wanted to try some Groovy.

The file I have to transform is an automatically generated XML, like this:

<_pdl></_pdl>
<_tkn></_tkn>
<_out></_out>
<_tds></_tds>
<_evt></_evt>
<_lfn></_lfn>
<tc></tc>
<fc></fc>

I want to strip things out to get only the start elements, like this:
<_pdl>
<_tkn>
<_out>
<_tds>
<_evt>
<_lfn>
<tc>
<fc>

A quick and dirty Groovy solution can be something like:

def file = "C:\\Users\\mauri\\Desktop\\mapping.txt"

StringBuffer dest = new StringBuffer();
new File(file).eachLine{ line -> line = line.trim()
   if (line.equals("")) {}
      else if (line.indexOf("/") > -1) {
      dest.append(line.substring(0, line.indexOf("/")-1))
      dest.append("\n")
   } else {
      dest.append(line)
      dest.append("\n")
   }
}

print dest.toString()

Probably there are much better ways to do that in Groovy (I'm a rookie here), but I can recycle most of my Java skills and well known Java syntax, which saves me a lot of time. Especially, even if I have to learn new interesting things like closures, I can re-use years of knowledge about the Java API, which from my point of view makes Groovy a winning tool in the JVM world.

Tuesday, November 3, 2009

Fuji Simple Service API, SpringDM and OSGi Integration with JBI

Sujit Biswas wrote an interesting article which:

"[...] shows how to integrate Fuji simple service api with spring/springDM application, We will create a springDM application which instantiates the above provider Implementation , based on spring-config and spring-osgi-config files."

Fuji allows for Spring and OSGi services integration

"The simple service provides the capability to invoke/interact with JAVA code outside of JBI, i.e Service API provides a bridge between code that is hosted outside of a JBI component and service endpoints available on the NMR."

This enables integration of OSGI/POJO services with JBI. Read Sujit's article for more.

About Fuji:

"Project Fuji forms the core component of Open ESB v3 effort and represents Sun's next generation open source integration runtime, focused on providing a lightweight, developer-friendly, and extensible platform for composite application development.

At the core of Project Fuji is a lightweight micro-kernel based on JBI (JSR 208) and OSGi. Packaged as an OSGi bundle, the micro-kernel can be installed in any OSGi R4 compliant runtime (such as Felix, Knopflerfish or Equinox), including GlassFish v3. JSR 208 support introduces a robust, message-based service bus to the OSGi environment and allows the wide range of existing JBI "components" (adapters and containers) to run in Fuji.

Developer experience is a primary focal point in Fuji as evidenced by the level of flexibility and accessibility offered in the platform. Starting with a rapid, top-down development language, IFL (Integration Flow Language), developers can quickly and easily generate an integration application using a domain-specific grammar. The service development model favors convention and configuration over boilerplate code and framework APIs, allowing integration developers to focus on the code that matters. "