FileDocCategorySizeDatePackage
POIFSReaderRegistry.javaAPI DocApache Poi 3.0.16151Mon Jan 01 12:39:36 GMT 2007org.apache.poi.poifs.eventfilesystem

POIFSReaderRegistry

public class POIFSReaderRegistry extends Object
A registry for POIFSReaderListeners and the DocumentDescriptors of the documents those listeners are interested in
author
Marc Johnson (mjohnson at apache dot org)
version
%I%, %G%

Fields Summary
private Set
omnivorousListeners
private Map
selectiveListeners
private Map
chosenDocumentDescriptors
Constructors Summary
POIFSReaderRegistry()
Construct the registry

        omnivorousListeners       = new HashSet();
        selectiveListeners        = new HashMap();
        chosenDocumentDescriptors = new HashMap();
    
Methods Summary
private voiddropDocument(org.apache.poi.poifs.eventfilesystem.POIFSReaderListener listener, org.apache.poi.poifs.filesystem.DocumentDescriptor descriptor)

        Set listeners = ( Set ) chosenDocumentDescriptors.get(descriptor);

        listeners.remove(listener);
        if (listeners.size() == 0)
        {
            chosenDocumentDescriptors.remove(descriptor);
        }
    
java.util.IteratorgetListeners(org.apache.poi.poifs.filesystem.POIFSDocumentPath path, java.lang.String name)
get am iterator of listeners for a particular document

param
path the document path
param
name the name of the document
return
an Iterator POIFSReaderListeners; may be empty

        Set rval               = new HashSet(omnivorousListeners);
        Set selectiveListeners =
            ( Set ) chosenDocumentDescriptors.get(new DocumentDescriptor(path,
                name));

        if (selectiveListeners != null)
        {
            rval.addAll(selectiveListeners);
        }
        return rval.iterator();
    
voidregisterListener(org.apache.poi.poifs.eventfilesystem.POIFSReaderListener listener, org.apache.poi.poifs.filesystem.POIFSDocumentPath path, java.lang.String documentName)
register a POIFSReaderListener for a particular document

param
listener the listener
param
path the path of the document of interest
param
documentName the name of the document of interest

        if (!omnivorousListeners.contains(listener))
        {

            // not an omnivorous listener (if it was, this method is a
            // no-op)
            Set descriptors = ( Set ) selectiveListeners.get(listener);

            if (descriptors == null)
            {

                // this listener has not registered before
                descriptors = new HashSet();
                selectiveListeners.put(listener, descriptors);
            }
            DocumentDescriptor descriptor = new DocumentDescriptor(path,
                                                documentName);

            if (descriptors.add(descriptor))
            {

                // this listener wasn't already listening for this
                // document -- add the listener to the set of
                // listeners for this document
                Set listeners =
                    ( Set ) chosenDocumentDescriptors.get(descriptor);

                if (listeners == null)
                {

                    // nobody was listening for this document before
                    listeners = new HashSet();
                    chosenDocumentDescriptors.put(descriptor, listeners);
                }
                listeners.add(listener);
            }
        }
    
voidregisterListener(org.apache.poi.poifs.eventfilesystem.POIFSReaderListener listener)
register for all documents

param
listener the listener who wants to get all documents

        if (!omnivorousListeners.contains(listener))
        {

            // wasn't already listening for everything, so drop
            // anything listener might have been listening for and
            // then add the listener to the set of omnivorous
            // listeners
            removeSelectiveListener(listener);
            omnivorousListeners.add(listener);
        }
    
private voidremoveSelectiveListener(org.apache.poi.poifs.eventfilesystem.POIFSReaderListener listener)

        Set selectedDescriptors = ( Set ) selectiveListeners.remove(listener);

        if (selectedDescriptors != null)
        {
            Iterator iter = selectedDescriptors.iterator();

            while (iter.hasNext())
            {
                dropDocument(listener, ( DocumentDescriptor ) iter.next());
            }
        }