Skip to end of metadata
Go to start of metadata

In order to "open" a Datastore and browse through the objects, this MetadataBrowsing Interface has to be implemented. It has two major methods, one is the getRootNodes() returning the topmost element(s) and the other the expandNode(). The getRootNodes() will return a MetadataNode called "RootNode" with the text shown in the image "Files - Contains all files of the configured directory". And the expandNode() method is called when the user clicks on the plus sign left of the RootNode() to expand all objects. So it will return FileNode objects, one for each file found in the configured directory.

package com.acta.adapter.sf;

import java.io.File;
import java.util.Vector;

import com.acta.adapter.sdk.Adapter;
import com.acta.adapter.sdk.AdapterEnvironment;
import com.acta.adapter.sdk.AdapterException;
import com.acta.adapter.sdk.MetadataBrowsing;
import com.acta.adapter.sdk.MetadataBrowsingIcons;
import com.acta.adapter.sdk.MetadataNode;
import com.acta.adapter.sdk.Session;

public class SFBrowse implements MetadataBrowsing, MetadataBrowsingIcons
{

    private AdapterEnvironment  _adapterEnvironment  ;
    private SFSession           _session ;
    private String              _directory ;

    public void initialize ( Adapter adapter, AdapterEnvironment adapterEnvironment, Session session )
    {
        _adapterEnvironment = adapterEnvironment ;
        _session = (SFSession)session ;
        _directory = _session.getDirectory()  ;
    }

    public void start() throws AdapterException
    {
    }

    public void stop() throws AdapterException
    {
    }

    public Vector getRootNodes () throws AdapterException
    {
        Vector v = new Vector () ;
        RootNode rn = new RootNode () ;
        rn.setDirectory(_directory);
        v.addElement ( rn ) ;
        return v ;
    }

    public Vector expandNode ( MetadataNode node ) throws AdapterException
    {
        Vector v = new Vector () ;
        try
        {
            if ( node instanceof com.acta.adapter.sf.RootNode )
            {
                // Expand the root node
                RootNode rn = (RootNode)node ;
                File f = new File ( _directory ) ;
                // find all table files with the first letter in the range ...
                String filesList[] = f.list() ;
                if ( null != filesList && filesList.length > 0 )
                {
                    for ( int i = 0; i < filesList.length ; i++ )
                    {
                        FileNode fn = new FileNode ( filesList[i] );
                        v.addElement(fn);
                    }
                }
            }
        }
        catch ( Exception e )
        {
            throw new AdapterException ( "Error when browse metadata. Check directory " + _directory ) ;
        }
        return v ;
    }

    public String [] getIcons ()
    {
        String [] arr = {"Icon1.bmp" };
        return arr ;
    }

}

 

 

  • No labels