Sun Java System Mobile Enterprise Platform 1.0 Developer's Guide for Enterprise Connectors

Extending the BusinessObject Class to Access a Sun JCA Adapter

The BusinessObject class for an Enterprise Connector that accesses a Sun JCA Adapter may have straightforward implementations of the BusinessObject methods, but it may also require some additional utility methods. A SAP BAPI Customer object, for example, implements a large number of getter and setter methods for its properties. Its serialize and deserialize methods can be relatively simple.

The Customer object implementations of the getInsertCommand, getUpdateCommand, and getDeleteCommand methods call the constructors for the command classes, as expected. However, here the constructors take two arguments, and the second argument is the value returned by a utility method.

    /**
     * {@inheritDoc}
     */
    @Override
    public CustomerInsertCommand getInsertCommand() {
        return new CustomerInsertCommand(this, getInsertCustomer());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CustomerUpdateCommand getUpdateCommand() {
        return new CustomerUpdateCommand(this, getUpdateCustomer());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CustomerDeleteCommand getDeleteCommand() {
        return new CustomerDeleteCommand(this, getDeleteCustomer());
    }

The utility methods use the provider class's getSAPCustomerClient method to retrieve first the customer communication object, and then the CreateFromData1 object. For example, the getInsertCustomer method begins as follows:

    /**
     * Returns a Customer CreateFromData1 object to be used for insert.
     */
    public customer.Customer.CreateFromData1 getInsertCustomer() {
        customer.Customer.CreateFromData1 cfd = getBusinessObjectProvider()
                .getSAPCustomerClient().getCreateFromData1();

The rest of the getInsertCustomer method uses the CreateFromData1 object to assign the Customer properties to the SAP BAPI customer object. Finally, it returns the CreateFromData1 object.

       // Set import parameters
        cfd.getImportParams().getPI_COPYREFERENCE().setREF_CUSTMR(
            CustomerProvider.REF_CUSTOMER);
        cfd.getImportParams().getPI_COPYREFERENCE().setSALESORG(getSalesOrg());
        cfd.getImportParams().getPI_COPYREFERENCE().setDISTR_CHAN(getDistChannel());
        cfd.getImportParams().getPI_COPYREFERENCE().setDIVISION(getDivision());

        // Required import parameters
        cfd.getImportParams().getPI_COMPANYDATA().setNAME(getCustomerName());
        cfd.getImportParams().getPI_COMPANYDATA().setLANGU_ISO(getLanguageKey());
        cfd.getImportParams().getPI_COMPANYDATA().setCURRENCY(getCurrencyKey());
        cfd.getImportParams().getPI_COMPANYDATA().setCOUNTRY(getCountryKey());
        cfd.getImportParams().getPI_COMPANYDATA().setPOSTL_COD1(getPostalCode());
        cfd.getImportParams().getPI_COMPANYDATA().setCITY(getCity());

        // Additional import parameters
        cfd.getImportParams().getPI_COMPANYDATA().setSTREET(getStreet());
        cfd.getImportParams().getPI_COMPANYDATA().setREGION(getRegion());
        cfd.getImportParams().getPI_COMPANYDATA().setTEL1_NUMBR(getTelephone());
        cfd.getImportParams().getPI_COMPANYDATA().setFAX_NUMBER(getFaxNumber());

        return cfd;
    }

The getUpdateCustomer method is almost identical to the getInsertCustomer method except that it also marks the fields as having changed:

        // Mark fields to be changed
        String ex = "X";
        cfd.getImportParams().getPI_COMPANYDATAX().setNAME(ex);
        cfd.getImportParams().getPI_COMPANYDATAX().setLANGU_ISO(ex);
        cfd.getImportParams().getPI_COMPANYDATAX().setCURRENCY(ex);
        cfd.getImportParams().getPI_COMPANYDATAX().setCOUNTRY(ex);
        cfd.getImportParams().getPI_COMPANYDATAX().setPOSTL_COD1(ex);
        cfd.getImportParams().getPI_COMPANYDATAX().setCITY(ex);
        cfd.getImportParams().getPI_COMPANYDATAX().setSTREET(ex);
        cfd.getImportParams().getPI_COMPANYDATAX().setREGION(ex);
        cfd.getImportParams().getPI_COMPANYDATAX().setTEL1_NUMBR(ex);
        cfd.getImportParams().getPI_COMPANYDATAX().setFAX_NUMBER(ex);

Similarly, the getDeleteCustomer method informs SAP to delete a record by changing its name to begin with the string DELETED:

        // Mark customer as deleted by prepending "DELETE" to the name
        setCustomerName("DELETED " + getCustomerName());
        logger.fine("Changing NAME field to [" + getCustomerName() + "].");
        cfd.getImportParams().getPI_COMPANYDATA().setNAME(getCustomerName());
        cfd.getImportParams().getPI_COMPANYDATAX().setNAME("X");
        cfd.getImportParams().getPI_COMPANYDATA().setLANGU_ISO(getLanguageKey());
        cfd.getImportParams().getPI_COMPANYDATA().setCURRENCY(getCurrencyKey());
        cfd.getImportParams().getPI_COMPANYDATA().setCOUNTRY(getCountryKey());
        cfd.getImportParams().getPI_COMPANYDATA().setPOSTL_COD1(getPostalCode());
        cfd.getImportParams().getPI_COMPANYDATA().setCITY(getCity());
        cfd.getImportParams().setCUSTOMERNO(getCustomerNumber());
        cfd.getImportParams().setPI_SALESORG(getSalesOrg());
        cfd.getImportParams().setPI_DISTR_CHAN(getDistChannel());
        cfd.getImportParams().setPI_DIVISION(getDivision());