Transports and Interfaces: Siebel eBusiness Application Integration Volume III > Integrating with J2EE Application Server > Using the Java Data Bean >

Using Java Code Generated by Siebel eBusiness Applications


Set up the development environment as described in Using the Java Data Bean. If you are using an Integrated Development Environment (IDE), be sure to include the .jar files in the classpath or input classes for your project. Refer to your IDE documentation on how to include external class/jar files in to your project.

NOTE:  A javadoc jar file (Siebel_JavaDoc.zip) is installed when you choose to install the Siebel Java Integrator option (a component of the Tools or Siebel Server installer). This jar file is in the same location as the SiebelJI* jar files under the INSTALLED_DIR\classes directory. This jar file contains the up-to-date java doc for the Siebel Java Data Bean, Siebel Resource Adapter, and dependent classes.

Sample Java Code 1

The following is a code sample that describes the use of the Siebel Java Data Bean in a Servlet. The Java Data Bean can be used in a similar way in Java Server Pages (JSPs) or in Enterprise JavaBeans (EJBs).

import com.siebel.data.*;

...

SiebelDataBean m_dataBean = null;

SiebelBusObject sbo_busObject = null;

SiebelBusComp sbc_busComp = null;

try {

  boolean result;

...

  String userLoginName =...

  String strJdbLoginUser =...

  String strJdbLoginPwd =...

...

  m_dataBean = new SiebelDataBean();

  result = m_dataBean.login("siebel://GatewayServer/EnterpriseName/AppObjMgr/SiebelServer",strJdbLoginUser, strJdbLoginPwd, "enu");

  SiebelBusObject sbo_busObject = m_dataBean.getBusObject("Contact");

  SiebelBusComp sbc_busComp = sbo_busObject.getBusComp("Contact");

  sbc_busComp.setViewMode(3);

  sbc_busComp.clearToQuery();

  sbc_busComp.activateField("First Name");

  sbc_busComp.activateField("Last Name");

  sbc_busComp.activateField("Id");

  sbc_busComp.setSearchSpec("Login Name",userLoginName);

  sbc_busComp.executeQuery2(true,true);

  "

if (sbc_busComp.firstRecord()) {

System.out.println("Contact ID: "+sbc_busComp.getFieldValue("Id")+" ; First Name:"+sbc_busComp.getFieldValue("First Name")+ " ;Last Name:"+sbc_busComp.getFieldValue("Last Name"));

}

sbc_busComp.release();

sbo_busObject.release();

m_dataBean.logoff();

} catch (SiebelException se) {

System.err.println("Error:"+se.getErrorMessage());

se.printStackTrace();

}

About the Code Sample

The code sample above shows a simple use of the Java Data Bean from a Java Servlet to search for a particular login name in the Contact business component. The first step in using the Java data bean is to log into the Object Manager of the Siebel application. The first parameter, the connection string, specifies the protocol, machine name, enterprise name, object manager name, and the server name. After you are logged in to the Object Manager, you can use the getBusObject and getBusComp methods to obtain the business object and business component objects.

NOTE:  You may have to change this based on your login permissions.

The code sample activates fields to allow the query to retrieve data for the specified fields, specifies the search criteria, and executes the query. For additional details on these methods, see Siebel Object Interfaces Reference. If the query is successful, the first and last name of the contact is printed to the System.out.

If the query results in multiple records, the record set can be iterated as follows:

if (sbc_busComp.firstRecord()) {

//obtain the fields/values from this record

...

while (sbc_busComp.nextRecord()){

      //obtain the fields/values from this record

     ...

    }          

  }

Code Sample Using Integration Object JavaBeans

The following is a code sample invoking the QueryByExample method of the Siebel Account business service. The JDBSiebelAccount class, which is described in the section 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 Siebel property sets and business service interfaces have been abstracted, providing a standards-based JavaBean interface.

/* import declaration here */

public class JDBSiebelAccount {

  public static void main(String[] args) {

    Siebel_AccountBusServAdapter svc   = null;

    QueryByExampleInput qbeIn   = new QueryByExampleInput();

    QueryByExampleOutput qbeOut = new QueryByExampleOutput();

    AccountIC acctIC = new AccountIC();

    Sample_AccountIO acctIO = new Sample_AccountIO();

    Vector ioc   = null;

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

    acctIC.setfName("Ai*");

    acctIO.addfintObjInst(acctIC);

    qbeIn.setfSiebelMessage(acctIO);

    try {

        /* initialize the Siebel Account service using the user name, password, connect stringm language constructor. The logoff method will be invoked when class destroyed*/

        svc = new Siebel_AccountBusServAdapter("username", "password","siebel://namesrvr/entserver/objectmanager/siebelserver","lang");

  

    /* 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 */

Code Sample Using the JavaBean Wizard

The following is a code example using the Java Data Bean and JavaBeans based upon the Sample Account integration object and EAI Siebel Adapter business service. The DataBeanDemo 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 various Siebel APIs (property set, business services) have been abstracted and encapsulated into a JavaBean-based interface.

/* import declaration here */

public class DataBeanDemo {

  

  private String   userName   = "SADMIN";

  private String   passwd     = "SADMIN";

  private String   lang       = "enu";

  private String   connStr    = "siebel://GatewayServer/EnterpriseName/AppObjMgr/SiebelServer";

  private String   intObjName = "Sample Account";

  public static void main(String[] args) {

    DataBeanDemo demo = new DataBeanDemo();

  }

/* main */

  public DataBeanDemo() {

    SiebelDataBean     m_dataBean  = null;

    EAI_Siebel_AdapterBusServAdapter  svc    = null;

    QueryPageInput     qpInput    = new QueryPageInput();

    QueryPageOutput    qpOutput   = new QueryPageOutput();

    int     rowNum    = 0;

    int     pageSize  = 10;

    Sample_AccountIO  acctIO  = null;

    Vector     ioc    = null;

    

    try {

      /* instantiate the Siebel Data Bean */

      m_dataBean = new SiebelDataBean();

      

      /* login to Siebel using connect string, user name, password, lang constructor */

      m_dataBean.login(connStr, userName, passwd, lang);

      

      /* construct the EAI Siebel Adapter, using the data bean constructor */

      svc = new EAI_Siebel_AdapterBusServAdapter(m_dataBean);

      svc.initialize();

      

      /* set QueryPage parameters to be used by the Siebel Adapter.QueryPage method. The request will return 10 records, starting at record 0, using the Sample Account integration object*/

    qpInput.setfPageSize(java.lang.Integer.toString(pageSize));

    qpInput.setfOutputIntObjectName(intObjName);

    qpInput.setfStartRowNum(java.lang.Integer.toString(rowNum));

    qpOutput = svc.mQueryPage(qpInput);

      /* construct the integration object using the output of the QueryPage method, and the property set constructor*/

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

      

      /* convert the results of the integration object to a vector for processing*/

      ioc = acctIO.getfintObjInst();

      

      /* Loop through the result set, printing out account name and location */

      if (!ioc.isEmpty()) {

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

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

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

        }/* for */

      }/* if */

      

      /* logout once the request has been completed */

      m_dataBean.logoff();

    } catch (SiebelException e) {

      e.printStackTrace();

      try {

        /* if an error occurs, make sure that the connection is closed */

        m_dataBean.logoff();

      } catch (SiebelException obj) {

        System.out.println(obj.getErrorMessage());

      }/* try-catch */

    }/* try-catch */

  }/* public DataBeanDemo */

}/* public class DataBeanDemo */


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