/** * Return a description of the workspace. The level of detail depends on the argument, which is an * or-ing of the static final constants defined in the NamedObj class. If the contents are * requested, then the items in the directory are also described. Zero, one or two brackets can be * specified to surround the returned description. If one is specified it is the the leading * bracket. This is used by derived classes that will append to the description. Those derived * classes are responsible for the closing bracket. An argument other than 0, 1, or 2 is taken to * be equivalent to 0. * * @param detail The level of detail. * @param indent The amount of indenting. * @param bracket The number of surrounding brackets (0, 1, or 2). * @return A description of the workspace. */ protected synchronized String _description(int detail, int indent, int bracket) { StringBuffer result = new StringBuffer(NamedObj._getIndentPrefix(indent)); if ((bracket == 1) || (bracket == 2)) { result.append("{"); } if ((detail & NamedObj.CLASSNAME) != 0) { result.append(getClass().getName()); if ((detail & NamedObj.FULLNAME) != 0) { result.append(" "); } } if ((detail & NamedObj.FULLNAME) != 0) { result.append(("{" + getFullName() + "}")); } if ((detail & NamedObj.CONTENTS) != 0) { if ((detail & (NamedObj.CLASSNAME | NamedObj.FULLNAME)) != 0) { result.append(" "); } result.append("directory {\n"); Enumeration enumeration = directory(); while (enumeration.hasMoreElements()) { NamedObj obj = (NamedObj) enumeration.nextElement(); // If deep is not set, then zero-out the contents flag // for the next round. if ((detail & NamedObj.DEEP) == 0) { detail &= ~NamedObj.CONTENTS; } result.append((obj._description(detail, indent + 1, 2) + "\n")); } result.append("}"); } if (bracket == 2) { result.append("}"); } return result.toString(); }
/** * Add an item to the directory. The names of the objects in the directory are not required to be * unique. Only items with no container can be added. Items with a container are still viewed as * being within the workspace, but they are not explicitly listed in the directory. Instead, their * top-level container is expected to be listed (although this is not enforced). Increment the * version number. * * @param item Item to list in the directory. * @exception IllegalActionException If the item has a container, is already in the directory, or * is not in this workspace. */ public synchronized void add(NamedObj item) throws IllegalActionException { if (item.workspace() != this) { throw new IllegalActionException( this, item, "Cannot add an item to the directory of a workspace " + "that it is not in."); } if (item.getContainer() != null) { throw new IllegalActionException( this, item, "Cannot add an object with a container to a workspace " + "directory."); } if (_directory.indexOf(item) >= 0) { throw new IllegalActionException( this, item, "Object is already listed in the workspace directory."); } _directory.add(item); incrVersion(); }