Source Files for Custom Controls

Custom controls consist of two Java source files: an interface class file and an implementation class file.

The interface class contains the control's publicly accessible methods. Clients of the control call the methods in the implementation class.

The implementation class contains the control's behind the scenes implementation code.

There is also a third class associated with each custom control: the generated JavaBean class. This is a build artifact created from the interface and implementation source files. The generated JavaBean class provides supplemental programmatic access to the control, especially the ability to override default annotation values in the control. For more information about this class see Overriding Control Annotation Values Through the Control JavaBean

Custom Control Interface Classes

A custom control interface class must be decorated with the @ControlInterface annotation.

package controls.hello;
 
import org.apache.beehive.controls.api.bean.ControlInterface;
 
@ControlInterface
public interface Hello {
 
    ...
 
}

The @ControlInterface annotation informs the compiler to treat this class as a part of the Control framework.

The interface class also lists the control's publicly available methods. The following example shows a control with one publicly available method.

package controls.hello;
 
import org.apache.beehive.controls.api.bean.ControlInterface;
 
@ControlInterface
public interface Hello {
 
	public String hello();
 
}

Custom Control Implementation Classes

A custom control implementation class contains the control's logic - the code that defines what the control does. In this file you define what each of the control's methods do.

The minimum requirements for a custom control implementation class are listed below.

  1. The class must be decorated with the @ControlImplementation annotation.
        import org.apache.beehive.controls.api.bean.ControlImplementation;
     
        @ControlImplementation
        public class HelloImpl
  2. The class must implement the corresponding custom control interface file.
        import org.apache.beehive.controls.api.bean.ControlImplementation;
     
        @ControlImplementation
        public class HelloImpl implements Hello
  3. The classes must either:

    (a) implement java.io.Serializable

        import java.io.Serializable;
     
        @ControlImplementation
        public class HelloImpl implements Hello, Serializable

    (b) or set @ControlImplementation(isTransient=true)
        @ControlImplementation(isTransient=true)
        public class HelloImpl implements Hello {
     
        }

Related Topics

Controls: Getting Started


Still need help? Post a question on the Workshop newsgroup.