FileDocCategorySizeDatePackage
RegistryExplorerFrame.javaAPI DocExample3397Thu Nov 08 00:22:50 GMT 2001com.ora.rmibook.chapter14

RegistryExplorerFrame

public class RegistryExplorerFrame extends JFrame

Fields Summary
private JTextArea
_resultsArea
private JTextField
_portTextField
private JButton
_queryRegistryButton
Constructors Summary
public RegistryExplorerFrame()

        buildGUI();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new ExitOnClose());
    
Methods Summary
private voidbuildGUI()

        JPanel mainPanel = new JPanel(new BorderLayout());

        _resultsArea = new JTextArea();
        mainPanel.add(new JScrollPane(_resultsArea), BorderLayout.CENTER);
        _queryRegistryButton = new JButton("Check Registry Contents");
        _queryRegistryButton.addActionListener(new QueryRegistry());
        mainPanel.add(_queryRegistryButton, BorderLayout.SOUTH);
        getContentPane().add(mainPanel);
        setSize(250, 200);
    
private voiddisplayInformationForName(java.lang.String name)

        Object value = Naming.lookup(name);

        if (null == value) {
            _resultsArea.append("Server named " + name + " is not in registry\n");
            return;
        }
        Collection interfaces = getRemoteInterfacesForObject(value);

        if (null == interfaces) {
            _resultsArea.append("Object named " + name + " is not a server\n");
            return;
        }
        _resultsArea.append("Server named " + name + " implements the following remote interfaces\n");
        Iterator i = interfaces.iterator();

        while (i.hasNext()) {
            _resultsArea.append("\t" + i.next() + "\n");
        }
        return;
    
private java.util.CollectiongetRemoteInterfacesForObject(java.lang.Object object)

        Class objectType = object.getClass();
        Class[] interfaces = objectType.getInterfaces();
        Class remoteInterface = Remote.class;

        if ((null == interfaces) || (0 == interfaces.length)) {
            return null;
        }
        ArrayList returnValue = new ArrayList();
        int counter;

        for (counter = 0; counter < interfaces.length; counter++) {
            if (remoteInterface.isAssignableFrom(interfaces[counter])) {
                returnValue.add(interfaces[counter]);
            }
        }
        return returnValue;