Tuesday, March 20, 2012

Creating PDF document in JAVA using itext library

The java code to create a sample pdf document using itext.

Jar file required: itextpdf.jar

package itext;

import java.io.FileOutputStream;
import java.util.Date;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;

public class SamplePDF {
private static String FILE = "c:/temp/SamplePdf.pdf";
private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18,
private static Font redFont = new Font(Font.FontFamily.TIMES_ROMAN, 12,
Font.NORMAL, BaseColor.RED);
private static Font subFont = new Font(Font.FontFamily.TIMES_ROMAN, 16,
private static Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12,

public static void main(String[] args) {
try {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(FILE));
} catch (Exception e) {

private static void addTitlePage(Document document)
throws DocumentException {
Paragraph preface = new Paragraph();
addEmptyLine(preface, 1);
preface.add(new Paragraph("Sample Document", catFont));
addEmptyLine(preface, 1);
// File properties
preface.add(new Paragraph(
"Report generated by: " + System.getProperty("user.name") + ", " + new Date(), smallBold));
addEmptyLine(preface, 3);
preface.add(new Paragraph(
"This is a sample document ceated by itext ",

addEmptyLine(preface, 8);

// Start a new page

private static void addContent(Document document) throws DocumentException {
Anchor anchor = new Anchor("First Chapter", catFont);
anchor.setName("First Chapter");

// Second parameter is the number of the chapter
Chapter catPart = new Chapter(new Paragraph(anchor), 1);

Paragraph subPara = new Paragraph("Subcategory 1", subFont);
Section subCatPart = catPart.addSection(subPara);
subCatPart.add(new Paragraph("Hello"));

subPara = new Paragraph("Subcategory 2", subFont);
subCatPart = catPart.addSection(subPara);
subCatPart.add(new Paragraph("Paragraph 1"));
subCatPart.add(new Paragraph("Paragraph 2"));
subCatPart.add(new Paragraph("Paragraph 3"));

// Add a list
Paragraph paragraph = new Paragraph();
addEmptyLine(paragraph, 5);

// Add a table

// Now add all this to the document

// Next section
anchor = new Anchor("Second Chapter", catFont);
anchor.setName("Second Chapter");

// Second parameter is the number of the chapter
catPart = new Chapter(new Paragraph(anchor), 1);

subPara = new Paragraph("Subcategory", subFont);
subCatPart = catPart.addSection(subPara);
subCatPart.add(new Paragraph("This is a very important message"));

// Now add all this to the document


private static void createTable(Section subCatPart)
throws BadElementException {
PdfPTable table = new PdfPTable(3);

PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1"));

c1 = new PdfPCell(new Phrase("Table Header 2"));

c1 = new PdfPCell(new Phrase("Table Header 3"));




private static void createList(Section subCatPart) {
List list = new List(true, false, 10);
list.add(new ListItem("First point"));
list.add(new ListItem("Second point"));
list.add(new ListItem("Third point"));

private static void addEmptyLine(Paragraph paragraph, int number) {
for (int i = 0; i < number; i++) {
paragraph.add(new Paragraph(" "));

Oracle SOA Suite 11g - Domain Value Map Qualifier Support

Oracle SOA Suite 11g - Domain Value Map Qualifier Support:

Qualifier support is the new feature in Oracle SOA Suite 11g.Qualifiers qualifies mappings. A mapping may not be valid unless qualified with additional information. For example, a domain value map containing a city code-to-city name mapping may have multiple mappings from KN to Kensington because Kensington is a city in both Canada and the USA. Therefore, this mapping requires a qualifier (USA or Canada) to qualify when the mapping becomes valid

Country (Qualifier)CityCodeCityName


You can also specify multiple qualifiers for a domain value map

Country (Qualifier)State (Qualifier)CityCodeCityName
USANorth CarolinaBELGBelgrade
CanadaPrince Edward IslandKNKensington

A qualifier order is used to find the best match during lookup at runtime. The order of a qualifier varies from highest to lowest depending on the role of the qualifier in defining a more exact match. In above Table, the state qualifier can have a higher order than the country qualifier, as a matching state indicates a more exact match.

Domain value maps support hierarchical lookup. If you specify a qualifier value during a lookup and no exact match is found, then the lookup mechanism tries to find a more generalized match by setting the higher order qualifiers to a "". It proceeds until a match is found, or until a match is not found with all qualifiers set to a ""

State=Arkansas, Country=Canada, CityCode=KN_USA
In this example, the State qualifier has a qualifier value of 1 and the Country qualifier has a qualifier value of 2.
the lookup mechanism sets the higher order qualifier State to the exact lookup value Arkansas and uses Canada"" for the lower order qualifier Country.

When no match is found, the lookup mechanism sets the higher order qualifier State to a value of "" and sets the next higher qualifier Country to an exact value of Canada.
When no match is found, the lookup mechanism sets the value of the previous higher order qualifier Country to a value of "". One matching row is found where CityCode is KN_USA and Kensington is returned as a value.
Domain Value Map Lookup Result

StateCountryShort ValueLookup Result
ArkansasCANADA" "KN_USANo Match

DVM Lookup function to use the Qualifier

dvm:lookupValue(dvmMetadataURI as string, SourceColumnName as string,SourceValue as string, TargetColumnName as string, DefaultValue as string,(QualifierSourceColumn as string, QualifierSourceValue as string)*) as string
dvm:lookupValue ('cityMap.dvm','CityCodes','BO','CityNames', 'CouldNotBeFound', 'State', 'Massachusetts')

Wednesday, March 14, 2012

how to add namespace Prefix to all the elements of JAX-WS webservice output

how to add namespace Prefix to all the elements of JAX-WS webservice output

This post will explain, how to add namespace Prefix to all the elements of JAX-WS webservice output

Sometimes we may required to have the namespace prefix (ex.ns1) defined for all the elments of the JAX-WS webservice output.

The default annotation of the package-info.java class looks like below

@javax.xml.bind.annotation.XmlSchema(namespace = "PPDS:OPIRequest", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.reuters.eai.types;

This case only the parent element will be have the namespace prefix but not the child elements.


<ns1:Employee ns1="PPDS:OPIRequest">

To have the namespace prefix in all the output elements,modify the above annotaion in the package-info.java class as mentioned below.

@XmlSchema( namespace = "PPDS:OPIRequest", elementFormDefault = XmlNsForm.QUALIFIED, xmlns={@XmlNs(prefix="ns3", namespaceURI="PPDS:OPIRequest")})
package com.reuters.eai.types;
import javax.xml.bind.annotation.*;


<ns1:Employee ns1="PPDS:OPIRequest">

Friday, March 9, 2012

Oracle SOA Suite – Utility to manage the composite revisions.

Oracle SOA Suite – Utility to manage the composite revisions:

In our project we had a requirement to retire/undeploy the older versions of composites and keep the specified number of newer versions. We have developed a java utility to do this functionality.
Thought of sharing the same, it may help someone looking for the similar utility.
If we have more number of deployed composite, it will increase the server startup time and also the loading time of the em console, its better we can keep only the latest versions and retire or undeploy the older versions.
This java utility will keep the specified number of latest versions (based on the user input) and undeploy/retire all the other older versions based on the operation specified by the user. The default version will be skipped from undeploy/retire operation.
This utility is developed for UNIX server; the same can be modified to work on windows.
Steps to execute:-
Copy ManageComposites.java and ManageComposites.xml (Refer the attachment) files to the server to a particular location.
Open the putty session; change the window scroll size of the putty session to a higher value (to increase the display size)
Set the following environment variables before executing the utility
Execute the script - ant –f ManageComposites.xml
Enter the input for the server details, operation(R – retire, U - Undeploy) and the number of versions to be kept for a composite.
Undeploy the older versions of all the composites expect the last two versions.

Thursday, March 8, 2012

Dispalying the XML node as formatted string

Displaying the XML node as formatted string:

import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Node;

public class TransformUtil {

public static String nodeToString(Node node) throws Exception{
StringWriter sw = new StringWriter();
try {
Transformer t = new org.apache.xalan.processor.TransformerFactoryImpl().newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.transform(new DOMSource(node), new StreamResult(sw));
} catch (TransformerException te) {
System.out.println("nodeToString Transformer Exception");
throw te;
return sw.toString();