001: package com.sun.portal.netfile.applet.java2.model;
002:
003: import java.util.Iterator;
004: import java.util.Set;
005: import java.util.Hashtable;
006: import java.util.TreeMap;
007: import java.io.File;
008:
009: public abstract class NetFileNode {
010:
011: private String name;
012: private TreeMap children;
013: private NetFileNode parent;
014:
015: private String iconName;
016: private String openIconName;
017:
018: public NetFileNode(String name, String iconName, String openIconName) {
019: this .name = name;
020: this .iconName = iconName;
021: this .openIconName = openIconName;
022: children = new TreeMap();
023: }
024:
025: public String getName() {
026: return name;
027: }
028:
029: public String getIconName() {
030: return iconName;
031: }
032:
033: public String getOpenIconName() {
034: return openIconName;
035: }
036:
037: protected void setIconNames(String iconName, String openIconName) {
038: this .iconName = iconName;
039: this .openIconName = openIconName;
040: }
041:
042: protected void addChildNode(NetFileNode child) {
043: children.put(child.getName(), child);
044: child.setParent(this );
045: }
046:
047: protected NetFileNode getChildNode(String nodeName) {
048: return (NetFileNode) children.get(nodeName);
049: }
050:
051: protected NetFileNode removeChildNode(String nodeName) {
052: NetFileNode node = getChildNode(nodeName);
053: if (node == null) {
054: return null;
055: }
056: node.delinkFromParent();
057: children.remove(nodeName);
058: return node;
059: }
060:
061: public void removeAllChildren() {
062: Set nodes = children.keySet();
063: for (Iterator it = nodes.iterator(); it.hasNext();) {
064: String nodeName = (String) it.next();
065: NetFileNode node = getChildNode(nodeName);
066: node.delinkFromParent();
067: }
068: children.clear();
069:
070: }
071:
072: public NetFileNode removeFromParent() {
073: return parent.removeChildNode(name);
074: }
075:
076: private void delinkFromParent() {
077: parent = null;
078: }
079:
080: private void setParent(NetFileNode parent) {
081: this .parent = parent;
082: }
083:
084: protected NetFileNode getParent() {
085: return parent;
086: }
087:
088: protected NetFileNode[] getAllChildren(Object[] type) {
089: return (NetFileNode[]) children.values().toArray(type);
090:
091: }
092:
093: public String toString() {
094: return name;
095: }
096:
097: public String getFQName() {
098: return parent.getFQName() + "/" + name;
099: }
100:
101: public String getLocalPath() {
102: if (parent == null || parent.getLocalPath() == "") {
103: return name;
104: } else if (parent.getLocalPath() == "/") {
105: return File.separator + name;
106: } else if (parent.getLocalPath().endsWith("\\")) {
107: return parent.getLocalPath() + name;
108: } else {
109: return parent.getLocalPath() + File.separator + name;
110: }
111: }
112:
113: public abstract Hashtable toHashtable();
114: }
|