FileDocCategorySizeDatePackage
FileSystemEventHandlerBase.javaAPI DocphoneME MR2 API (J2ME)5096Wed May 02 18:00:28 BST 2007javax.microedition.io.file

FileSystemEventHandlerBase

public abstract class FileSystemEventHandlerBase extends Object implements EventListener
File system event handler.

Fields Summary
private static SecurityToken
classSecurityToken
Security token to allow access to implementation APIs
private static EventListener
listener
The EventListener to receive the MM events.
Constructors Summary
public FileSystemEventHandlerBase()
Default constructor. Registers current isolate as interested in receiving mount/unmount events.



                    
      
        registerListener();
    
Methods Summary
private native voidfinalize()
Performs clean up upon object destruction. Removes current isolate from the list of isolates interested in receiving mount/unmount events.

public booleanpreprocess(Event event, Event waitingEvent)
Preprocess an event that is being posted to the event queue. This method will get called in the thread that posted the event.

param
event event being posted
param
waitingEvent previous event of this type waiting in the queue to be processed
return
true to allow the post to continue, false to not post the event to the queue

        if (event.getType() != EventTypes.FC_DISKS_CHANGED_EVENT) {
            return false;
        }

        if (waitingEvent != null) {
            return false;
        }

        return true;
    
public voidprocess(Event event)
Process an event. This method will get called in the event queue processing thread.

param
event event to process

        if (event.getType() != EventTypes.FC_DISKS_CHANGED_EVENT) {
            return;
        }

        // Get up-to-date roots list from OS
        Vector newRoots = Protocol.listRoots();

        // Get cached roots list from FileSystemRegistry
        Vector oldRoots = new Vector(newRoots.size() + 1);
        for (Enumeration e = FileSystemRegistry.listCachedRoots();
                e.hasMoreElements();) {
            oldRoots.addElement(e.nextElement());
        }

        // Find all removed roots and notify FileSystemRegistry about them
        for (int i = 0; i < oldRoots.size(); i++) {
            String root = (String)oldRoots.elementAt(i);
            if (!newRoots.contains(root)) {
                FileSystemRegistry.removeRoot(root);
            } else {
                newRoots.removeElement(root);
            }
        }

        // Notify FileSystemRegistry about all added roots if any
        for (int i = 0; i < newRoots.size(); i++) {
            String root = (String)newRoots.elementAt(i);
            FileSystemRegistry.addRoot(root);
        }
    
private native voidregisterListener()
Registers current isolate as interested in receiving mount/unmount events.

static voidsetListener(EventListener l)
Register the event listener in the event queue. Security note: access specifier for this method is 'package private' so only classes from this package can access it.

param
l EventListener for the MM events.

        // Listener can be set only once.
        if (listener != null) {
            return;
        }
        listener = l;

        EventQueue evtq = EventQueue.getEventQueue(classSecurityToken);
        evtq.registerEventListener(EventTypes.FC_DISKS_CHANGED_EVENT, listener);