News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Invoking a Control Method in Java

Started by thiruvasagamani, Aug 19, 2008, 11:12 AM

Previous topic - Next topic

thiruvasagamani

Invoking a Control Method

Once you've added a Java control to your application, you can invoke the methods of the Java control from Source view using the standard Java dot notation. For example, assume that you have added the CustomerDb Java control and declared a variable for the control as custDb, and that the control defines a method as follows:

String [] getAllCustomerNames()

You can invoke this method from your code as follows:

String [] custNames;

custNames = custDb.getAllCustomerNames();
Overriding Control Property Settings

Note that when you declare a control (a JCS or JCX file) within a client you can override the control's default properties.

Suppose you have a database control with the connection property defined so that the data-source-jndi-name attribute points at the data source dataSource.

    DatabaseControl.jcx

    /**
     * @jc:connection data-source-jndi-name="dataSource"
     */
    public interface DBControl extends com.bea.control.ControlExtension, DatabaseControl

The database control is declared with its default properties in the following way.

    MyWebService.jws

   /**
      * @common:control
    */
   private DatabaseControl dbControl;   

To override the default connection property on the database control, use the following declaration.

   /**
      * @common:control
    * @jc:connection data-source-jndi-name="myOtherDataSource"
    */
   private DatabaseControl dbControl;   

In the above declaration, the database control will use myOtherDataSource instead of its default dataSource. This override value will apply to all method calls from within MyWebService.jws.

There are two important caveats when overriding control properties in this way.

(1) The property must be at the class level, not the method level. Only those properties that are scoped to the entire control class may be overriden in this way.

(2) The override occurs at the property level, not at the attribute level. It not possible to override only a single attribute on a property. You must override all of the property's attribute values. For example, suppose that the connection property had three attributes instead of just one.

    DatabaseControl.jcx

    /**
     * @jc:connection data-source-jndi-name="dataSource" attribute2="value2" attribute3="value3"
     */
    public interface DBControl extends com.bea.control.ControlExtension, DatabaseControl

In this case, when you override the connection property, you override all of that property's attributes, not merely the data-source-jndi-name attribute. In short, the following override sets the data-source-jndi-name attribute to myOtherDataSource and attribute2 and attribute3 to null.

    MyWebService.jws

   /**
      * @common:control
    * @jc:connection data-source-jndi-name="myOtherDataSource"
    */
   private DatabaseControl dbControl;   

For this reason, you should specify all of the attributes when you override a control property.

   /**
      * @common:control
    * @jc:connection data-source-jndi-name="myOtherDataSource" attribute2="otherVal2" attribute3="otherVal3"
    */
   private DatabaseControl dbControl;   
Thiruvasakamani Karnan