Thursday, 13 October 2016

                                 Deleting Empty Lines 


Hello,

Suppose you want to delete the empty lines from the Text File  ...

You can use the JCN .......WOW it woks........





Following are the code .........in JCN
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.MbBLOB;
import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbMessage;
import com.ibm.broker.plugin.MbMessageAssembly;
import com.ibm.broker.plugin.MbOutputTerminal;
import com.ibm.broker.plugin.MbUserException;

public class IdiotFlow_JavaCompute extends MbJavaComputeNode {

                public void evaluate(MbMessageAssembly inAssembly) throws MbException {
                                MbOutputTerminal out = getOutputTerminal("out");
                //            MbOutputTerminal alt = getOutputTerminal("alternate");
                                MbMessage inMessage = inAssembly.getMessage();
                                                                MbElement inputRoot=inMessage.getRootElement();
                                 byte[] MessageBodyByteArray  = (byte[])(inputRoot.getFirstElementByPath("/BLOB/BLOB").getValue());
                                byte[] outdata = createFile(MessageBodyByteArray);
                                 MbMessageAssembly outAssembly = null;
                                try {
                                                MbMessage outMessage = new MbMessage();
                                                copyMessageHeaders(inMessage, outMessage);
                                                outAssembly = new MbMessageAssembly(inAssembly, outMessage);
                                                                                                MbElement outRoot = outMessage.getRootElement();
                                                MbElement outParser = outRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
                                                outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", outdata);
                                                                                                                                } catch (MbException e) {
                                                // Re-throw to allow Broker handling of MbException
                                                throw e;
                                } catch (RuntimeException e) {
                                                // Re-throw to allow Broker handling of RuntimeException
                                                throw e;
                                } catch (Exception e) {
                                                // Consider replacing Exception with type(s) thrown by user code
                                                // Example handling ensures all exceptions are re-thrown to be handled in the flow
                                                throw new MbUserException(this, "evaluate()", "", "", e.toString(),
                                                                                null);
                                }
                                // The following should only be changed
                                // if not propagating message to the 'out' terminal
                                out.propagate(outAssembly);

                }

                                public void copyMessageHeaders(MbMessage inMessage, MbMessage outMessage)
                                                throws MbException {
                                MbElement outRoot = outMessage.getRootElement();
                                                                MbElement header = inMessage.getRootElement().getFirstChild();
                                while (header != null && header.getNextSibling() != null) // stop before
                                                                                                                                                                                                                                                               
                                {
                                               
                                                outRoot.addAsLastChild(header.copy());
                               
                                                header = header.getNextSibling();
                                }
                }
                @SuppressWarnings("null")
                private byte[] createFile(byte[] MessageBodyByteArray)
                {
                                byte[] output = null;
                                InputStream source = new ByteArrayInputStream(MessageBodyByteArray);
                                OutputStream out1= new ByteArrayOutputStream();
                                PrintStream out = new PrintStream(out1);
                                Scanner scanner=new Scanner(source) ;
                                try{
                                                while(scanner.hasNextLine()){
                                                    String line = scanner.nextLine();
                                                    line = line.trim();
                                                    if(line.length() > 0)
                                                        out.println(line);
                                                }    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
                  
                        output= ((ByteArrayOutputStream) out1).toByteArray();

                                } catch ( Exception ex ) {
         System.out.println(ex);

     }
                                return output;
                }
}


Tuesday, 11 October 2016

                                        Email Via JCN

Good Morning,
Here is the way u can send mail via JCN ....
For This you need two jars to add on the classpath ....

1. javax.mail
2. javax.activation

How to add the jars in the Classpath ........

Click on the java perspective ....................
 ...........                Right Click on Application where you need to attach the jars
........................                Click on Build Path  Followed by Configure Build Path
.........................................Click on the Tab Libraries.

On the Right side click on Add External Jars and than Click ok ...ok.


The Massage You put in the Email Queue will be in xml Form
For Example:-

<Email_Configuration>
<To>ashi2uashi@gmail.com,xyz@gmail.com,abc@gmail.com</To>
<Subject>Hi Little Master</Subject>
<Body>Hi Now Its Working Fine</Body>
</Email_Configuration>

Following are the code .............................................................................................................................
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbMessage;
import com.ibm.broker.plugin.MbMessageAssembly;
import com.ibm.broker.plugin.MbOutputTerminal;
import com.ibm.broker.plugin.MbUserException;


public class Sending_Emails_JavaCompute extends MbJavaComputeNode {
                Integer port = (Integer)getUserDefinedAttribute("Port");
                String Server = (String)getUserDefinedAttribute("SmtpSever");
                String EnvTypte = (String)getUserDefinedAttribute("ENV");
                String password = (String)getUserDefinedAttribute("PASSWORD");
                String emailid = (String)getUserDefinedAttribute("EMAILID");
                public void evaluate(MbMessageAssembly inAssembly) throws MbException {
                                MbOutputTerminal out = getOutputTerminal("out");
                //            MbOutputTerminal alt = getOutputTerminal("alternate");

                                MbMessage inMessage = inAssembly.getMessage();
                                MbMessageAssembly outAssembly = null;
                                try {
                                               
                                                MbMessage outMessage = new MbMessage();
                                                outAssembly = new MbMessageAssembly(inAssembly, outMessage);
                                               
                                                //String to = inMessage.getRootElement().getLastChild().getFirstChild().getFirstChild().getValueAsString();
                                               
                                                Object obj = inMessage.getRootElement().evaluateXPath("/Email_Configuration/To");
                                                String to = obj.toString();
                                                int s = to.lastIndexOf("value:");
                                                int en= to.length();
                                                to = to.substring(s+7,en-3);
                                                //String to= inMessage.getRootElement().getLastChild().getFirstElementByPath("/Email_Configuration/To").getDOMNode().getFirstChild().getNodeValue();
                                               
                                                String[] recipientList = to.split(",");
                                               
                                                InternetAddress[] recipientAddress = new InternetAddress[recipientList.length];
                                               
                                                int counter = 0;
                                                for (String recipient : recipientList) {
                                                    recipientAddress[counter] = new InternetAddress(recipient.trim());
                                                    counter++;
                                                }
                                                //String Subject=inMessage.getRootElement().getLastChild().getFirstChild().getFirstChild().getNextSibling().getValueAsString();
                                                Object objSubject = inMessage.getRootElement().evaluateXPath("/Email_Configuration/Subject");
                                                String Subject = objSubject.toString();
                                                int sSubject = Subject.lastIndexOf("value:");
                                                int enSubject= Subject.length();
                                                Subject = Subject.substring(sSubject+7,enSubject-3);
                                                Subject = "String"+EnvTypte+": "+Subject;
                                                //String Subject= inMessage.getRootElement().getLastChild().getFirstElementByPath("/Email_Configuration/Subject").getDOMNode().getFirstChild().getNodeValue();
                                               
                                                //String Body = inMessage.getRootElement().getLastChild().getLastChild().getLastChild().getValueAsString();
                                                Object objBody= inMessage.getRootElement().evaluateXPath("/Email_Configuration/Body");
                                                String Body = objBody.toString();
                                                int sBody = Body.lastIndexOf("value:");
                                                int enBody= Body.length();
                                                Body = Body.substring(sBody+7,enBody-3);
                                                //String Body= inMessage.getRootElement().getLastChild().getFirstElementByPath("/Email_Configuration/Body").getDOMNode().getFirstChild().getNodeValue();
                                               
                                                //Get the session object 
                                                  Properties props = new Properties(); 
                                                  props.put("mail.smtp.host", Server);
                                                  props.put("mail.smtp.starttls.enable", "true");
                                                  props.put("mail.smtp.auth", "true"); 
                                                  props.put("mail.smtp.port", port); 
                                                  
                                                  Session session = Session.getDefaultInstance(props, 
                                                   new javax.mail.Authenticator() { 
                                                   protected PasswordAuthentication getPasswordAuthentication() { 
                                                   return new PasswordAuthentication(emailid,password);//change accordingly 
                                                   } 
                                                  }); 
                                                  
                                                  //compose message 
                                                  try { 
                                                   MimeMessage message = new MimeMessage(session); 
                                                   message.setFrom(new InternetAddress(emailid));//change accordingly 
                                                   message.addRecipients(Message.RecipientType.TO,recipientAddress); 
                                                   //message.setSubject("Hello"); 
                                                  // message.setText("Testing.......");
                                                   message.setSubject(Subject); 
                                                   message.setText(Body);
                                                    
                                                   //send message 
                                                   Transport.send(message); 
                                                 
                                                   //System.out.println("message sent successfully"); 
                                                  
                                                  } catch (MessagingException e) {throw new RuntimeException(e);} 
                                               
                                                  finally
                                                  {
                                                                  Object message = null;
                                  }
                                                  out.propagate(outAssembly);
                                                  
                                                 
                                } catch (MbException e) {
                                                // Re-throw to allow Broker handling of MbException
                                                throw e;
                                } catch (RuntimeException e) {
                                                // Re-throw to allow Broker handling of RuntimeException
                                                throw e;
                                } catch (Exception e) {
                                                // Consider replacing Exception with type(s) thrown by user code
                                                // Example handling ensures all exceptions are re-thrown to be handled in the flow
                                                throw new MbUserException(this, "evaluate()", "", "", e.toString(),
                                                                                null);
                                }
                                // The following should only be changed
                                // if not propagating message to the 'out' terminal
                                //out.propagate(outAssembly);
                                finally {
                                                MbMessage outMessage = null;
                                                //outMessage.clearMessage();
                                                Object props = null;
                                                Object recipientAddress = null;
                                                Object objBody = null;
                                }

                }

}

Tuesday, 4 October 2016


                                 Play with JCN (Java compute node ) 

As the name spell it is the mix behaiour of java and compute node
One of the most important question is why and when to use JCN in IIB ToolKit.
Ans.This question can be better understood in the way you have the requirement as the same work can be done with Compute node also than why JCN ....
----it provies the flexibility.
----you can use the java code free from applying mind in esql.
----Becouse java is inbuilt in toolkit you can use the java inbuilt method.
----Higher use when u use Collection (java.util) package i  will explain with example so that you can  know    the horizon of java is unlimited but with compute node you have the limited access.
------------------------------              let us having an interesting example using Collection (TreeSet)------------------------

Set<String> setSheetNames =  new TreeSet<String>();
String SheetName = null;
MbElement root = message.getRootElement();
java.util.List record = (java.util.List)root.evaluateXPath(new MbXPath("/db/sheets"));          // DFDL tree
int count  = record.size();
MbElement rec = root.getLastChild().getFirstChild().getFirstChild();
for(int i=1; i<= count; i++)//storing the unique sheet names into Set object
{
SheetName=SheetName.trim();
SheetName = rec.getFirstElementByPath("Spends").getValueAsString();
setSheetNames.add(SheetName);
rec = rec.getNextSibling();
}
 int countForSheets = setSheetNames.size();
 Iterator itr = setSheetNames.iterator();
 String newsheetname=null;
try{
while(itr.hasNext())          //Iterating unique sheet names and creating unique sheets by using Set object
 {
newsheetname = (String) itr.next();
sheetdb = (SXSSFSheet)workbook.createSheet(newsheetname);
Row rowheadSheet = sheetdb.createRow((int) 0);// rowhead1
     }
Are You really Feeling interesting than we should go some little inside ..........


Now it is the question Answer  phase Not theory but only code and practical :- 
All the ans will depends upon the tree u have :-
1.How to access DFDL element in JCN.
Ans:-    

                MbElement root = message.getRootElement();
                 java.util.List record = (java.util.List)root.evaluateXPath(new MbXPath("/db/sheets"));   // DFDL
                MbElement rec = root.getLastChild().getFirstChild().getFirstChild();//According to above Figure
                for(int i=1; i<= count; i++)                                          //For loop to access the element from the tree
                {
                String SheetName = rec.getFirstElementByPath("Spends").getValueAsString();
                //Do your required work ....................................
                rec = rec.getNextSibling();
                }


2.How to access Local Environment variables in JCN.
Ans:- String fname=(String)inAssembly.getLocalEnvironment().evaluateXPath("/File/Name");
3.How to access Environment variables in JCN.
Ans:-
String rate = inAssembly.getGlobalEnvironment().getRootElement().getFirstElementByPath("RatePerJPMile").getValue().toString();

4.How to Throw and catch the Exception.
Ans:-
1)
                try{
               
                //your work that may thorw some Exception
       
      }catch (Exception e)
       {
      throw new MbUserException(this,"evaluate()","","",e.toString(),null);
                             
      }
2) public void evaluate(MbMessageAssembly inAssembly) throws MbException....
3)You can use try and catch block.
Remember after passing from the JCN your Exception tree will be Affected.  
5.How to generate the EXCEL Sheet using JCN.
6.How to write and read from EXCEL Sheet in JCN.

Ans:- This is the Combine code for 5 and 6 for  Generating EXCEL sheet in JCN with complete code
package  abc.xyz
import java.io.ByteArrayOutputStream;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.MbBLOB;
import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbMessage;
import com.ibm.broker.plugin.MbMessageAssembly;
import com.ibm.broker.plugin.MbOutputTerminal;
import com.ibm.broker.plugin.MbUserException;
import com.ibm.broker.plugin.MbXPath;
public class ABC_JavaCompute extends MbJavaComputeNode {
                public void evaluate(MbMessageAssembly inAssembly) throws MbException {
                MbOutputTerminal out = getOutputTerminal("out");
                //String rate = inAssembly.getGlobalEnvironment().getRootElement().getFirstElementByPath("Rate").getValue().toString();
                MbMessage inMessage = inAssembly.getMessage();
                System.out.println(".................................................");
                                byte[] outdata = createFile(inMessage);
                                System.out.println(".........................................");
                                MbMessageAssembly outAssembly = null;
try {
                MbMessage outMessage = new MbMessage();
                copyMessageHeaders(inMessage, outMessage);
                outAssembly = new MbMessageAssembly(inAssembly, outMessage);
                                               
//String fname=(String)inAssembly.getLocalEnvironment().evaluateXPath("/File/Name");
// Sending the Output excel file data as a BLOB message
MbElement outRoot = outMessage.getRootElement();
MbElement outParser = outRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", outdata);
//getting the file name from Environment
//String OutputFileName = inAssembly.getGlobalEnvironment().getRootElement().getFirstElementByPath("OutputFileName").getValue().toString();
//OutputFileName = OutputFileName.substring(0, OutputFileName.lastIndexOf('.'));
// FilenameUtils.removeExtension();
//UPDATING LOCAL ENVIRONMENT with Directory values and the File Name
MbElement outLocal= outAssembly.getGlobalEnvironment().getRootElement();
MbElement destination = outLocal.createElementAsLastChild(MbElement.TYPE_NAME,"OutFileName", null);
SimpleDateFormat datef = new SimpleDateFormat("MM");
String monthName = datef.format(new Date());
int month = Integer.parseInt(monthName);
 String outputFileName = getMonth(month);
String monthNameChar = outputFileName.substring(0, 3).toUpperCase();
SimpleDateFormat year = new SimpleDateFormat("yy");
String yearName = year.format(new Date());
destination.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"OutputFileName","FileName"+monthNameChar+yearName+".xlsx");
}
catch (MbException e) {
// Re-throw to allow Broker handling of MbException
                throw e;
                } catch (RuntimeException e) {
                // Re-throw to allow Broker handling of RuntimeException
                throw e;
} catch (Exception e) {
                throw new MbUserException(this, "evaluate()", "", "", e.toString(),null);
}
out.propagate(outAssembly);
                                System.out.println("exit from.................JCN");
                }
public void copyMessageHeaders(MbMessage inMessage, MbMessage outMessage)
                                throws MbException {
MbElement outRoot = outMessage.getRootElement();
MbElement header = inMessage.getRootElement().getFirstChild();
while (header != null && header.getNextSibling() != null) // stop before
{
outRoot.addAsLastChild(header.copy());
header = header.getNextSibling();
}
}
private String getMonth(int month)
                {
                 return new DateFormatSymbols().getMonths()[month-1];
                }
private byte[] createFile(MbMessage message)
{
byte[] output = null;
try{
SXSSFWorkbook workbook = new SXSSFWorkbook(10000000);
 SXSSFSheet  sheetdb = null;
Set<String> setSheetNames =  new TreeSet<String>();
 String SheetName = null;
MbElement root1 = message.getRootElement();
 java.util.List record1 = (java.util.List)root1.evaluateXPath(new MbXPath("/db/sheets"));
  int count1  = record1.size();
MbElement rec1 = root1.getLastChild().getFirstChild().getFirstChild();
for(int i=1; i<= count1; i++)//storing the unique sheet names into Set object
     {
SheetName = rec1.getFirstElementByPath("Spends").getValueAsString();
SheetName=SheetName.trim();
setSheetNames.add(SheetName);
rec1 = rec1.getNextSibling();
}
int countForSheets = setSheetNames.size();
Iterator itr = setSheetNames.iterator();
String newsheetname=null;
try{
while(itr.hasNext())//Iterating unique sheet names and creating unique sheets by using Set object
{
newsheetname = (String) itr.next();
sheetdb = (SXSSFSheet)workbook.createSheet(newsheetname);
Row rowheadSheet = sheetdb.createRow((int) 0);// rowhead1
createRowHead(sheetdb, rowheadSheet);
}
}catch(Exception e){}
root1=null;
rec1=null;
record1=null;
MbElement root = message.getRootElement();
java.util.List record = (java.util.List)root.evaluateXPath(new MbXPath("/_Invoice/body"));
int count  = record.size();
MbElement rec = root.getLastChild().getFirstChild().getNextSibling().getFirstChild();
//This is For sheet 1
SXSSFSheet  sheetdblast=null;
for (int i = 0; i < count; i++) {
String sheetNameUnique = rec.getFirstElementByPath("sheetNameUnique").getValueAsString();
sheetdblast = (SXSSFSheet) workbook.getSheet(sheetNameUnique);
int rowNumber = sheetdblast.getLastRowNum();
Row row = sheetdblast.createRow((int)1+rowNumber);
Row rowForHeader = sheetdblast.getRow(0);
String JPPercentage=null;
String JetPercentage=null;
String PartnerPercentage=null;
try{
JPPercentage =rec.getFirstElementByPath("JPPercentage").getValueAsString();
}catch(Exception e){}try{
JetPercentage=rec.getFirstElementByPath("JetPercentage").getValueAsString();
}catch(Exception e){}try{
PartnerPercentage =rec.getFirstElementByPath("PartnerPercentage").getValueAsString();
}catch(Exception e){}try{
rowForHeader.getCell(7).setCellValue("BilledMiles - JP "+"("+JPPercentage+"%)");
}catch(Exception e){}try{
rowForHeader.getCell(8).setCellValue("BilledMiles - 9W"+"("+JPPercentage+"%)");
}catch(Exception e){}try{
rowForHeader.getCell(9).setCellValue("BilledMiles - EBL"+"("+PartnerPercentage+"%)");
}catch(Exception e){}
double RateFinal=0.0;
double TotalMiles=0.0;
double JPMiles=0.0;
double PartnerMiles=0.0;
double JetMiles=0.0;
try{
String MemberNumber=rec.getFirstElementByPath("JpNumber").getValueAsString();
double MemberNumber123=Double.parseDouble(MemberNumber);
row.createCell(0).setCellValue(MemberNumber123);
}catch(Exception e){}try{
row.createCell(1).setCellValue(rec.getFirstElementByPath("Name").getValueAsString());
}catch(Exception e){}try{
row.createCell(2).setCellValue(rec.getFirstElementByPath("ActivityCode").getValueAsString());
}catch(Exception e){}try{
String Year=rec.getFirstElementByPath("Year").getValueAsString();
double Year123=Double.parseDouble(Year);
row.createCell(3).setCellValue(Year123);
}catch(Exception e){}try{
String Month=rec.getFirstElementByPath("Month").getValueAsString();
double Month123=Double.parseDouble(Month);
row.createCell(4).setCellValue(Month123);
}catch(Exception e){}try{
String Date=rec.getFirstElementByPath("Date").getValueAsString();
double Date123=Double.parseDouble(Date);
row.createCell(5).setCellValue(Date123);
}catch(Exception e){}try{
String  TotalMiles123=rec.getFirstElementByPath("TotalMiles").getValueAsString();
TotalMiles=Double.parseDouble(TotalMiles123);
row.createCell(6).setCellValue(TotalMiles);
}catch(Exception e){}
try{
String JPPercentage123=rec.getFirstElementByPath("JPPercentage").getValueAsString();
double JPPercentageFinal=Double.parseDouble(JPPercentage123);
JPMiles=TotalMiles*JPPercentageFinal/100;
    row.createCell(7).setCellValue(JPMiles);
}catch(Exception e){}
try{
String JetPercentage123=rec.getFirstElementByPath("JetPercentage").getValueAsString();
double JetPercentageFinal=Double.parseDouble(JetPercentage123);
JetMiles=TotalMiles*JetPercentageFinal/100;
row.createCell(8).setCellValue(JetMiles);
}catch(Exception e){}
try{
String PartnerPercentage123=rec.getFirstElementByPath("PartnerPercentage").getValueAsString();
double PartnerPercentageFinal=Double.parseDouble(PartnerPercentage123);
PartnerMiles=TotalMiles*PartnerPercentageFinal/100;
row.createCell(9).setCellValue(PartnerMiles);
}catch(Exception e){}    

try{
String Rate=rec.getFirstElementByPath("Rate").getValueAsString();
RateFinal=Double.parseDouble(Rate);
row.createCell(10).setCellValue(RateFinal);
}catch(Exception e){}try{
                 row.createCell(11).setCellValue(rec.getFirstElementByPath("TransactionDate").getValueAsString());
}catch(Exception e){}
                                               
                                               
try{
double AmountJP=JPMiles*RateFinal;
row.createCell(12).setCellValue(AmountJP);
}catch(Exception e){}
try{
double AmountJET=JetMiles*RateFinal;
row.createCell(13).setCellValue(AmountJET);
}catch(Exception e){}
try{
double AmountEBL=PartnerMiles*RateFinal;
row.createCell(14).setCellValue(AmountEBL);
}catch(Exception e){}
                               
try{
                                       row.createCell(15).setCellValue(rec.getFirstElementByPath("Description").getValueAsString());
}catch(Exception e){}
rec = rec.getNextSibling(); 
}
root =null;
record = null;
rec = null;
                                    

MbElement rootLast = message.getRootElement();
java.util.List recordLast = (java.util.List)rootLast.evaluateXPath(new MbXPath("/db/sheets"));
int countsheet  = recordLast.size();
MbElement recLast = rootLast.getLastChild().getFirstChild().getFirstChild();
int countForSheets123 = setSheetNames.size();
Iterator itr123 = setSheetNames.iterator();
while(itr123.hasNext())//Iterating unique sheet names and creating unique sheets by using Set object
{
newsheetname = (String) itr123.next();
  //for(int recordTotal=0;recordTotal<countsheet ;recordTotal++){
try{
  Sheet worksheet =  workbook.getSheet(newsheetname);
  int rowsCount = worksheet.getPhysicalNumberOfRows();
Cell cell1=null;
// Row getRow = worksheet.createRow((int)rowsCount);
Row getRow =null;
double Totalmiles2=0;
double Totalmiles1=0;
  //worksheet.getLastRowNum()
for (int x = 0; x<rowsCount; x++)
{
  try
  {
getRow = worksheet.getRow(x);
String Totalmiles = getRow.getCell((int) 6).toString();
  try
  {
  Totalmiles2=Double.valueOf(Totalmiles);
  Totalmiles1+=Totalmiles2;
}catch(Exception e){
System.out.println("String Contain Empty value or null");
}
}catch(Exception e){}
}
//Calculating the Total of jetpriviledge miles
double JPMiles1=0;
double JPMiles2=0;
                                                    
for (int x = 0; x<rowsCount; x++)
{
try{
getRow = worksheet.getRow(x);
String JPMiles= getRow.getCell((int) 7).toString();
try{                 JPMiles2=Double.valueOf(JPMiles);
JPMiles1+=JPMiles2;                                                                                                                     
}catch(Exception e){
  System.out.println("String Contain Empty value or null");
}
}catch(Exception e){}
cell1 = getRow.createCell(12);
cell1.setCellValue(AmountTotalJP1);
cell1 = getRow.createCell(13);
cell1.setCellValue(AmountTotalJET1);
//int x=worksheet.getLastRowNum();
//getRow = worksheet.getRow(x);
cell1 = getRow.createCell(14);
   cell1.setCellValue(AmountTotalPartner1);
}catch(Exception e){}
}             
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
                        workbook.write(bOut);
                output= bOut.toByteArray();
                 } catch ( Exception ex ) {
         System.out.println(ex);
     }
return output;
}
//This below code is for creating header in Excel Sheet
rowheadSheet.createCell(12).setCellValue("Amount-asd  ");
rowheadSheet.createCell(13).setCellValue("Amount-dfg  ");
rowheadSheet.createCell(14).setCellValue("Amount - gfh ");
rowheadSheet.createCell(15).setCellValue("Description   ");
for(int colNum = 0; colNum<rowheadSheet.getLastCellNum();colNum++)
{
firstSheet.autoSizeColumn(colNum );



7.How to access the header in JCN.
Ans: - Please refer to the above code with ---------Green------------color
8.How to porcess the result to out terminal in JCN.
Ans:-  - Please refer to the above code with ---------Red------------color
9.Benefit of using JCN.
Ans:- IF u like java than U can understand that  whatever u can do with java u can implement in JCN .
10.Drawback of using JCN.
Ans:-  Understanding and accessing the element  in JCN is difficult  and if some where NULLPointer Exception Will come than that will be like a chunk of bone in your neck.........


This will continue....................................................