In the previous steps you built a control that encapsulates some useful business logic. In this step, you’ll compile the Investigate Java control into a JAR file for greater portability.
For many needs, it’s perfectly fine to use the control’s source files directly within the same project as the control's container or client, as is the case with Investigate's web service container, InvestigateTest.jws. But what if you’re designing a control that might be useful from many containers? It could get tedious to copy a set of source files from project to project. To solve this problem we will package the control in a JAR file that’s much easier to copy into different containers.
You begin the process of packaging by moving the control into its own control project. A control project includes files and annotations that support the control as a separately distributable package. You can even develop the sources for multiple controls within a single project, and package them all in a single JAR file for distribution.
Before you compile the Investigate Java control, you will add one more layer of functionality. You will add a property to the Investigate control, which will allow developers using the control to change the way it functions.
You'll start by creating a project in which to further develop your Java control's source files.
The tasks in the step are:
To Move Investigate to a Control Project
In this task you will move two items. First you will move the test web service InvestigateTest.jws into its own folder. Second you will move the Investigate Java control into its own Control project. It is necessary to separate the Investigate Java control from its test web service because web services aren't enabled in Control projects.
To Set Investigate's Properties
These properties provide information that WebLogic Workshop will present to
a developer using the Investigate Java control. The label
corresponds to the control's name on menus and palettes; the icon-16
attribute value is a relative path to the image associated with the control
in the IDE. Finally, if you look at the InvestigateImpl.jcs source code, you'll
see that the values for these attributes have been written into the source
as annotation attributes.
WebLogic Workshop creates the new XML file and displays it in the main work area. It contains a simple XML declaration and sample tags.
<?xml version="1.0" ?> <control-tags xmlns="http://www.bea.com/2003/03/controls/"> <control-tag name="error-message"> <description>Properties relating to the error message.</description> <attribute name="phone-number" required="false"> <description> Sets the phone number to call in case of an error. </description> <type> <text/> </type> <default-value>(555) 555-5555</default-value> </attribute> </control-tag> </control-tags>The <control-tag> element has a name attribute that specifies what the property will be called (error-message). The <description> element describes the property. The <attribute> element defines an attribute for the property: phone-number. The <attribute> element's "required" attribute is set to false, meaning that it's not necessary for a developer using the control to actually set the attribute in order for the control to work. As a result, the <default-value> element must be included here so that WebLogic Workshop knows what value to use if the developer doesn't explicitly set it. Finally, the <type> element specifies the attribute's type, similar to a data type. WebLogic Workshop will use this <type> value to do a bit of validation when the developer tries to set its value.
private String _phoneNumber;
/** * @common:operation * @common:message-buffer enable="true" */ public void requestCreditReport(String taxID) { _phoneNumber = context.getControlAttribute("jc:error-message", "phone-number"); m_currentApplicant.taxID = taxID; /* * Retrieve data from the database and store it in the rec object. */ Record rec = bankruptciesDB.checkForBankruptcies(taxID);
Note that this is a distributable JAR file: place it the the Libraries folder of any application to use the functionality of the Investigate Java control. (Note that any application that uses the JAR file must also have access to the Database, web service, JMS application, and EJB application that are used by the Java control.)
Also note that once you have compiled a Java control, WebLogic Workshop uses the JAR version by default, instead of working directly from the source code contained in the control project. For this reason, you could remove the control project from your application, and your test web service would still run successfully, because it would use the JAR version of the Java control.