Powered By Blogger

Jun 20, 2014

Writing a Custom Mediator - UI Component


When considering the UI component there are three main classes as listed below

  • DataMapperMediator
  • DataMapperMediatorActivator
  • DataMapperMediatorService

DataMapperMediator


In this class both serialize method and build method are included in the DataMapperMediator UI class. This class can be found in org.wso2.carbon.mediator.datamapper.ui package and this should inherit from org.wso2.carbon.mediator.service.ui.AbstractMediator.


serialize method is similar to serializeSpecificMediator method in DataMapperMediatorSerializer class in backend component and build method is similar to createSpecificMediator method in DataMapperMediatorFactory class in backend component.


public class DataMapperMediator extends AbstractMediator {
    public String getTagLocalName() {
    }
    public OMElement serialize(OMElement parent) {
    }
    public void build(OMElement omElement) {
    }
}

DataMapperMediatorService

DataMapperMediatorService is the class which implements the required settings of the UI. Every Mediator Service should inherit the org.wso2.carbon.mediator.service.AbstractMediatorService class.

public class DataMapperMediatorService extends AbstractMediatorService {

    public String getTagLocalName() {
        return "datamapper";
    }

    public String getDisplayName() {
        return "DataMapper";
    }

    public String getLogicalName() {
        return "DataMapperMediator";
    }

    public String getGroupName() {
        return "Transform";
    }

    public Mediator getMediator() {
        return new DataMapperMediator();
    }
}


DataMapperMediatorActivator

Unlike other Carbon bundles where Bundle Activator is defined in the backend bundle, in a mediator class, the Bundle Activator is defined in the  UI bundle. Mainly the Bundle Activator should inherit the org.osgi.framework.BundleActivator class and should implement start and stop methods. 

public class DataMapperMediatorActivator implements BundleActivator {

    private static final Log log = LogFactory.getLog(DataMapperMediatorActivator.class);

    /**
     * Start method of the DataMapperMediator
     */
    public void start(BundleContext bundleContext) throws Exception {

        if (log.isDebugEnabled()) {
            log.debug("Starting the DataMapper mediator component ...");
        }

        bundleContext.registerService(
                MediatorService.class.getName(), new DataMapperMediatorService(), null);

        if (log.isDebugEnabled()) {
            log.debug("Successfully registered the DataMapper mediator service");
        }
    }

    /**
     * Terminate method of the DataMapperMediator
     */
    public void stop(BundleContext bundleContext) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Stopped the DataMapper mediator component ...");
        }
    }
}

Also the edit-mediator.jsp JSP located in the resources package in org.wso2.carbon.mediator.datamapper.ui component and update-mediator.jsp JSP adjacent to the edit-mediator.jsp JSP are used to handle the changes made on UI.


You can find the source of the UI component at [1]

[1] https://github.com/sohaniwso2/FinalDMMediator/tree/master/datamapper/org.wso2.carbon.mediator.datamapper.ui

No comments:

Post a Comment