Obtain an Instance of Provider for Service UI

You can specify and Object type argument in the constructor of your service UI. When your UI is invoked, an instance of your service item will be passed via this Object. Cast it to the type ServiceItem, then use the service field on it to obtain an instance of your service proxy.

public class YourGuiClass extends JPanel { 

    public YourGuiClass(Object obj) { 

        svcItem = (ServiceItem) obj;
        YourServiceType svc = (YourServiceType) svcItem.service;

    }
}

In order for SORCER Service Browser (SSB) to provide you with a GUI to your service, you need to setup your main service UI class as described here. You can place your GUI within a JPanel Swing component. Simply make the main class of your GUI extend JPanel to do this. To set the name of the tab that your GUI will be on in SSB, call the JPanel method

    getAccessibleContext().setAccessibleName("Tab name goes here");

See as an example examples/service/src/main/java/sorcer/provider/adder/ui/AdderUI.java

Define a UIDescriptor for Provider

In order to allow SSB to find your service UI, you need to place the following public method in your main GUI class. Use whichever net.jini.lookup.ui class that you want to specify what role your GUI should use. The MainUI is for the standard user interface used by ordinary clients of the service. The AdminUI is for use by the service’s administrator. The AboutUI role is for information about the service, which is presentable by a user interface object

import net.jini.lookup.entry.UIDescriptor;
import net.jini.lookup.ui.MainUI;
import net.jini.lookup.ui.AdminUI;
import net.jini.lookup.ui.AboutUI;

public static UIDescriptor getUIDescriptor() { 
    UIDescriptor uiDesc = null;
    try {
        String serverVersion = System.getProperty("sorcer.version");
        uiDesc = UIDescriptorFactory.getUIDescriptor(MainUI.ROLE,
                    new UIComponentFactory(new URL[] { 
                        new URL(Sorcer.getWebsterUrl() + "/JarFileWithYourGui-" + serverVersion + ".jar") },
                        YourGuiClass.class.getName()));;
    } catch (Exception ex) { 
        logger.throwing(YourGuiClass.class.getName(), "getUIDescriptor", ex); }
    return uiDesc;
}

You will need to have a reference to this method in your provider config file as an Entry element.
The syntax for a provide config file is very much like a regular Java properties file. You can even specify complex objects within your config file rather than simple primitive data types (see for example examples/service/configs/adder-prv.config).

Remember to import your GUI class too.

import your.gui.class.package.*;

    entries = new Entry[] { YourGuiClass.getUIDescriptor(), ServiceProvider.getUIDescriptor() };

Also remember to include the classpath and codebase dependency on your GUI jar for your provider.

Back to top

Version: 1.0-SNAPSHOT. Last Published: 2020-01-18.