Wednesday, 4 January 2012

Create Custom Datasource Adaptor for Forms and deploy it as SBO

Here is a simple example for creating a datasource form adaptor and implementing as  SBO and using it in forms. In this example, the value entered in one field will be copied and set as the value of another field in the same form. The output value can be manipulated as your requirement and also any docbase object can be accessed from this SBO.

Step 1: Create Interface class
package com.test;

import com.documentum.fc.client.IDfService;
import com.documentum.xforms.engine.adaptor.IDocbaseAdaptor;
import com.documentum.xforms.engine.adaptor.IServiceAdaptor;
import com.documentum.xforms.engine.adaptor.datasource.IDataSourceAdaptor;

public interface ITestDataSourceAdaptor extends IDfService, IDataSourceAdaptor, IDocbaseAdaptor, IServiceAdaptor {

}

Compile and create a Jar file named ‘ITestDataSourceAdaptor.jar’

Step 2: Create Implementation class

In this example we are getting the input value and setting the same value as the output.
package com.test;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.documentum.fc.client.DfService;
import com.documentum.tools.adaptor.AdaptorException;
import com.documentum.tools.adaptor.IAdaptorParameter;
import com.documentum.tools.adaptor.configuration.IAdaptorConfiguration;

public class TestDataSourceAdaptor extends DfService implements ITestDataSourceAdaptor {
     
public void init(IAdaptorConfiguration adaptor) throws AdaptorException {
                       
      }
     
public Document execute(IAdaptorParameter[] parameters) throws AdaptorException {     
String value = null;
for (int j = 0; j < parameters.length; j++)
{
            IAdaptorParameter parameter = parameters[j];
            value = parameter.getValue();      
            }
                       
            Document doc = null;
            try
            {
           
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

            doc = factory.newDocumentBuilder().newDocument();
            Element root =(Element)doc.createElement("data");
            doc.appendChild(root);
            Element item = (Element)doc.createElement("item");
            root.appendChild(item);
            Element customvalue = (Element)doc.createElement("customvalue");
      if ( value != null && value.length() > 0 )
      {
      customvalue.setTextContent(value);
      }
     
      item.appendChild(customvalue) ;
}
      catch (Exception e)
      {
      throw new AdaptorException(e);
      }
      return doc;


//The document returned is in the form of
// <data> <item><customvalue>value</customvalue></item></data>

      }
     
      public void destroy() throws AdaptorException {
                       
      }

      public void setDocbaseName(String arg0) {
                       
      }    
}

Compile and create a Jar file named ‘TestDataSourceAdaptor.jar’ 

 
Step 3: Create jar definitions
·         Create Jar definition for ITestDataSourceAdaptor.jar in Composer
·         Create Jar Definition for TestDataSourceAdaptor.jar in Composer

Jar Definition

Step 4 : Create a Module

·         Create a Module in composer with below details

-          Name  -  com.test. ITestDataSourceAdaptor  (fully qualified name of the interface class)
-          Type – SBO
-          Add TestDataSourceAdaptor implementation jar definition to ‘Implementation Jars’
-          Add ITestDataSourceAdaptor Interface jar to ‘Interface Jars’
-          Any other jar definitions needed for this module should also be included. For our example, ‘XFormsEngine.jar’ needs to be added.
·         Install the Documentum Project.

SBO Creation


Step 5: Create adaptor in Forms Builder

In Forms Builder Navigate to File -> Adaptor and create new adaptor with below details

Adaptor type  : DataSource
Adaptor name : <Any name> TestDataSourceAdaptor
Class Name : <SBO Module name> com.test.ITestDataSourceAdaptor
Type : SBO
Input : <key/value> pair of the input to the adaptor. For example , ponumber
Output type : Complex Type. In that the Groups and Items should be defined in the same format as written in Adaptor. In our example it is <data> <item><customvalue>value</customvalue></item></data>

Adaptor Creation

Adaptor Input

Adaptor Output Type



Step 6: Map the Adaptor to the text field
In the form, the adaptor should be mapped in the ‘Special’ tab of the field as shown below. As per below setting, the adaptor will be executed when the input value changes. 

Field Configuration

In this example, the value entered in the Input Value field will be reflected in Custom Output field.

2 Comments:

At 5 January 2012 at 01:47 , Anonymous Anonymous said...

Useful

 
At 7 August 2012 at 05:02 , Anonymous Anonymous said...

Very useful, thanks.

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home