Transports and Interfaces: Siebel eBusiness Application Integration Volume III > Integrating with J2EE Application Server > The Siebel Resource Adapter >

Using Java Code Generated by Siebel eBusiness Applications


The following two sections contain code samples for both managed and non-managed environments.

Managed Code Sample

The following is a code sample using the Siebel Resource Adapter in a managed environment. The SiebelAccountBean class, which is described in this section, provides code examples that show how to perform the following tasks:

The following code uses the code generation facilities provided in Siebel Tools. For more information, see The Siebel JavaBean Wizard for both business services and integration objects. By using the code generation facilities, many of the complexities of the J2EE Connector specification (Interactions, ConnectionSpec, CCI) have been abstracted and encapsulated into a consistent, JavaBean-based interface.

/* import declaration here */

import com.siebel.service.jca.siebelaccount.Siebel_AccountBusServAdapter;

import com.siebel.service.jca.siebelaccount.QueryByExampleInput;

import com.siebel.service.jca.siebelaccount.QueryByExampleOutput;

import com.siebel.local.accountinterface.*;

import com.siebel.local.contactinterface.Account_InterfaceIO;

import com.siebel.local.contactinterface.AccountIC;

import com.siebel.integration.jca.cci.SiebelConnectionFactory;

import com.siebel.data.SiebelException;

/* ... */

..."

  /* Get account list using query parameter*/

  public Vector getAccountList(String queryParam) throws RemoteException {

  QueryByExampleInput   qbeIn  = new QueryByExampleInput();

  QueryByExampleOutput  qbeOut = new QueryByExampleOutput();

  Account_InterfaceIO acctIO = new Account_InterfaceIO();

  AccountIC             acctIC = new AccountIC();

  Vector                ioc    = null;

  /* query on accounts based upon the inputs provided */

  acctIC.setfName(queryParam);

  acctIO.addfintObjInst(acctIC);

  qbeIn.setfSiebelMessage(acctIO);

  try {

      /* establish connection */

      getConnectionFactory(jndiName);

      /* initialize business service using default constructor */

      Siebel_AccountBusServAdapter svc = new Siebel_AccountBusServAdapter();

      /* set connection specific user properties. if not specified, values specified in siebel.properties will be used. */

      svc.setConnectString(CONNECT_STRING);

      svc.setUserName(USER_NAME);

      svc.setPassword(PASSWORD);

      svc.setLanguage(LANGUAGE);

      /* set the connection factory to be used for the request. */

      svc.setConnectionFactory(m_cf);

      /* invoke QueryByExample method */

      qbeOut = svc.mQueryByExample(qbeIn);

      acctIO = null;

      /* process output and return to client as a Vector */

      acctIO = new Sample_AccountIO(qbeOut.getfSiebelMessage().toPropertySet());

      ioc = acctIO.getfintObjInst();

      return ioc;

     }catch(Exception e) {

        return ioc;

     }/* try-catch */

   }/* getAccountList(...) */

   /* function to obtain a connectionFactory reference */

   private void getConnectionFactory(String name) throws Exception {

   SiebelConnectionFactory   connectionFactory  = null;

   InitialContext            context            = null;

   Object                    reference          = null;

   try {

        context = new InitialContext();

       }catch(Exception e) {

        System.out.println("Could not acquire the initial context");

      }/* try-catch */

   try {

      reference = context.lookup(name);

      connectionFactory = (SiebelConnectionFactory)PortableRemote

      Object.narrow(reference, ConnectionFactory.class);

      }catch(Exception e) {

      System.out.println("Unable to obtain intial reference to

      connection factory");

      }/* try-catch */

      m_ctx = context;

      m_cf = connectionFactory;

   }/* getConnectionFactory(...) */

   public javax.ejb.SessionContext getSessionContext() { return mySessionCtx; }

   public void setSessionContext(javax.ejb.SessionContext ctx) { mySessionCtx =  ctx; }

   public void ejbActivate() {  }

   public void ejbCreate() throws javax.ejb.CreateException { }

      public void ejbPassivate() {  }

      public void ejbRemove() { }

      protected SiebelConnectionFactory  m_cf          = null;

      protected InitialContext           m_ctx         = null;

      private javax.ejb.SessionContext   mySessionCtx  = null;

}/* public class SiebelBean implements SessionBean */

Non-Managed Code Sample

The following is a code sample using the Siebel Resource Adapter in a non-managed environment. The JCASiebelAccount class (implemented below) provides code examples that show how to perform the following tasks:

The following code uses the code generation facilities provided in Siebel Tools. For more information, see The Siebel JavaBean Wizard for both business services and integration objects. By using the code generation facilities, many of the complexities of the J2EE Connector specification (Interactions, ConnectionSpec, CCI) have been abstracted and encapsulated into a consistent, JavaBean-based interface.

package com.siebel.service.jca.siebelaccount;

/* import required classes here */

public class JCASiebelAccount {

public static void main(String[] args) {

Siebel_AccountBusServAdapter svc = new

Siebel_AccountBusServAdapter("siebel.properties");

QueryByExampleInput  qbeIn = new QueryByExampleInput();

QueryByExampleOutput  qbeOut = new QueryByExampleOutput();

AccountIC  acctIC = new AccountIC();

Account_InterfaceIO acctIO = new Account_InterfaceIO();

SiebelConnectionFactory  m_cf = null;

Vector     ioc = null;

/* query on accounts that start with 'Ai'. */

acctIC.setfName("Ai*");

acctIO.addfintObjInst(acctIC);

qbeIn.setfSiebelMessage(acctIO);

try {

/* establish connection factory and connection */

m_cf = new SiebelNoTxConnectionFactory(new SiebelNoTxManagedConnectionFactory());

svc.setConnectionFactory(m_cf);

/* invoking QueryById method */

qbeOut = svc.mQueryByExample(qbeIn);

acctIO = null;

acctIC = null;

acctIO = new Sample_AccountIO(qbeOut.getfSiebelMessage().toPropertySet());

ioc = acctIO.getfintObjInst();

/* loop through all accounts returned */

if(!ioc.isEmpty()) {

for(int i=0; i < ioc.size(); i++) {

  acctIC = ((AccountIC)ioc.get(i));

  System.out.println(i + " " + acctIC.getfName() + " " +acctIC.getfLocation());

}/* for */

}/* if */

}catch(SiebelException se) {

System.out.println(se.getDetailedMessage());

}/* try-catch */

}/* main */

}/* public class JCASiebelAccount */


 Transports and Interfaces: Siebel eBusiness Application Integration Volume III 
 Published: 23 June 2003