Loading...
Select Version
&pagelevel(4)&pagelevel
Auf der Grundlage der generierten Klassen können Anwendungen erstellt werden. Nachfolgend ein Beispiel eines EJB für Outbound Kommunikation, dem die Klasse EmployeeRecord zugrunde liegt.
package net.fsc.jca.beanconnect.qa;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import de.siemens.cob2java.cobtypes.*; // Runtime of Cobol2Java
import de.siemens.cob2java.test.EmployeeRecord
public class EmployeeServiceBean implements SessionBean
{
private net.fsc.jca.communication.EISConnectionFactory cf;
public void ejbCreate() throws javax.ejb.CreateException
{
try {
javax.naming.Context ic = new
javax.naming.InitialContext();
cf =(net.fsc.jca.communication.EISConnectionFactory)
ic.lookup
("java:comp/env/eis/myEIS");
} catch (javax.naming.NamingException ex) {
throw new javax.ejb.CreateException
("NamingException:"+ex);
}
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}
public void ejbRemove()
{
}
public void setSessionContext(SessionContext ctx)
{
}
public String addSalary(String employeeNr, int
salaryIncrease)
{
String retValue = "";
net.fsc.jca.communication.EISConnection con = null;
try {
con = cf.getConnection();
con.setServiceName("EMPLOYEE");
// Create EmployeeRecord and accept the encoding setting
// of the connection
EmployeeRecord employee = new EmployeeRecord();
try
{ employee.setEncoding( con.getEncoding() ); }
catch (net.fsc.beanta.encoding.EncoderException encEx) {
// todo Error handling
} // catch EncoderException
employee.setEncodingActive( con.isEncodingActive() );
// Fetch the required EmployeeData
employee.setEmployeeNumber( employeeNr );
con.sndRecord( employee );
con.rcvRecord( employee );
// Increase the salary and send modification
int oldSalary =employee.getSalaryInfo().
getAnnualSalary().intValue();
employee.getSalaryInfo().setAnnualSalary( oldSalary+
salaryIncrease );
con.sndRecord( employee );
con.rcvRecord( employee );
retValue="Salary for "+employee.getLastName()+"
increased from "+oldSalary +" to "+
employee.getSalaryInfo().getAnnualSalary();
con.close();
} // try
catch (net.fsc.jca.communication.EISConnectionException
eisEx) {
if (con != null) {
try { con.close();
} catch(Throwable thr) { }
}
throw new javax.ejb.EJBException
("EISConnectionException:"+eisEx);
} // catch EISConnectionException
catch (de.siemens.cob2java.cobtypes.
Cob2JavaException cobEx) {
if (con != null) {
try { con.close();
} catch(Throwable thr) { }
}
throw new javax.ejb.EJBException("Cob2JavaException:
"+cobEx);
} // catch Cob2JavaException
return retValue;
} // addSalary
}