ptolemy.actor.lib.io
Class DirectoryListing

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.actor.lib.Source
                              extended byptolemy.actor.lib.io.DirectoryListing
All Implemented Interfaces:
Actor, Changeable, java.lang.Cloneable, Debuggable, DebugListener, Derivable, Executable, java.io.FilenameFilter, Instantiable, ModelErrorHandler, MoMLExportable, Nameable, java.io.Serializable, TypedActor

public class DirectoryListing
extends Source
implements java.io.FilenameFilter

Given a URL or directory name, this actor produces an array of file names in that directory that match an (optional) pattern. The file names that are returned are absolute. The pattern is a regular expression. For a reference on regular expression syntax see: http://java.sun.com/docs/books/tutorial/extra/regex/index.html.

FIXME: Useful options would be to output only files or only directories.

Since:
Ptolemy II 4.0
Version:
$Id: DirectoryListing.java,v 1.11.2.1 2004/07/16 15:19:57 cxh Exp $
Author:
Christopher Hylands, Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Red (liuj)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
 FileParameter directoryOrURL
          The directory name or URL from which to read.
 TypedIOPort directoryOrURLPort
          An input port for optionally providing a directory name.
 StringParameter pattern
          If non-empty, then only output file and directory names that match the specified (regular expression) pattern.
 
Fields inherited from class ptolemy.actor.lib.Source
output, trigger
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
DirectoryListing(CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 boolean accept(java.io.File directory, java.lang.String name)
          Return true if the specified name matches the specified pattern, or if no pattern has been specified.
 void attributeChanged(Attribute attribute)
          Override the base class to locally cache parameter values.
 void fire()
          Output the data read in the prefire.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, initialize, inputPortList, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
initialize, iterate, postfire, prefire, preinitialize, stop, stopFire, terminate, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

directoryOrURL

public FileParameter directoryOrURL
The directory name or URL from which to read. This is a string with any form accepted by FileParameter.

See Also:
FileParameter

directoryOrURLPort

public TypedIOPort directoryOrURLPort
An input port for optionally providing a directory name. This has type string.


pattern

public StringParameter pattern
If non-empty, then only output file and directory names that match the specified (regular expression) pattern. The default value of this parameter is the empty String "", which indicates that everything matches.

Constructor Detail

DirectoryListing

public DirectoryListing(CompositeEntity container,
                        java.lang.String name)
                 throws IllegalActionException,
                        NameDuplicationException
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

accept

public boolean accept(java.io.File directory,
                      java.lang.String name)
Return true if the specified name matches the specified pattern, or if no pattern has been specified.

Specified by:
accept in interface java.io.FilenameFilter
Parameters:
directory - The directory in which the file was found.
name - The name of the file or directory.

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
Override the base class to locally cache parameter values.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that has changed.
Throws:
IllegalActionException - If the specified attribute is URL and the file cannot be opened.

fire

public void fire()
          throws IllegalActionException
Output the data read in the prefire.

Specified by:
fire in interface Executable
Overrides:
fire in class Source
Throws:
IllegalActionException - If there's no director or if the directory or URL is invalid.