View Javadoc

1   /*
2    * $Id: MySpaceFolder.java,v 1.2 2004/06/14 23:08:52 jdt Exp $
3    *
4    * Copyright 2003 AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid Software License,
7    * a copy of which has been included with this distribution in the LICENSE.txt file.
8    */
9   
10  package org.astrogrid.store.delegate.myspace;
11  import java.io.FileNotFoundException;
12  import java.net.MalformedURLException;
13  import java.util.Hashtable;
14  import java.util.StringTokenizer;
15  import org.astrogrid.store.Agsl;
16  import org.astrogrid.store.Msrl;
17  import org.astrogrid.store.delegate.StoreFile;
18  
19  /***
20   * Represents a folder in myspace. Not threadsafe.
21   * See also comments on @link MySpaceFile
22   *
23   * @author mch
24   */
25  
26  
27  public class MySpaceFolder extends MySpaceFile  {
28     
29     Hashtable children = new Hashtable();
30  
31     boolean isRoot = false;
32     
33     /*** Create folder from a myspace reference.  Use to create root folders - to
34      * create entries that are children, use the constructor that tkaes a parent
35     public MySpaceFolder(Msrl givenMsrl, String givenName) {
36        this.agsl = givenMsrl.toAgsl();
37        name = givenName;
38     }
39   
40     /** Creates a folder that is a child of another one. */
41     public MySpaceFolder(MySpaceFolder parent, String childName) {
42        super(parent, childName);
43     }
44  
45     /*** Creates the root folder */
46     public MySpaceFolder(String childName) {
47        super(null, childName);
48        isRoot = true;
49     }
50  
51     /*** Adds the given StoreFile as a child that exists in this folder */
52     public void add(StoreFile child) {
53        children.put(child.getName(), child);
54     }
55  
56     /*** Returns the StoreFile representation of the child with the given filename */
57     public StoreFile getChild(String filename) {
58        return (StoreFile) children.get(filename);
59     }
60     
61     /*** Returns an array of the files in this container */
62     public StoreFile[] listFiles() {
63        return (StoreFile[]) (children.values().toArray(new StoreFile[] {}));
64     }
65  
66     /*** Returns path on server */
67     public String getPath() {
68        if (isRoot) {
69           return "";
70        }
71        else
72        {
73           return getParent().getPath()+getName()+"/";
74        }
75     }
76     
77     /*** Returns the file path */
78     public String toString()    {    return getPath();   }
79     
80     /*** Returns parent folder of this file/folder */
81     public StoreFile getParent() {   return this.parentFolder;  }
82     
83     /*** Returns true - this is a container */
84     public boolean isFolder() {      return true;   }
85     
86     /*** Returns false - this is a container */
87     public boolean isFile() {        return false;  }
88     
89     /*** Returns the filename/foldername/tablename/etc */
90     public String getName() {        return this.name; }
91     
92     /*** Returns true if this represents the same file as the given one */
93     public boolean equals(StoreFile anotherFile) {
94        if (anotherFile instanceof MySpaceFolder) {
95           return name.equals( ((MySpaceFolder) anotherFile).name) &&
96                 parentFolder.equals(((MySpaceFolder) anotherFile).parentFolder);
97        }
98        return false;
99     }
100 
101    /***
102     * Returns the folder or file matching the given path in the *children* of
103     * this folder.  So if the path is '/famous/stuff/main/' the returned StoreFile
104     * will be the MySpaceFolder instance representing the 'main' directory
105     * @todo test
106     */
107    public StoreFile findFile(String path) throws FileNotFoundException {
108       
109       //locate file
110       StringTokenizer dirTokens = new StringTokenizer(path, "/");
111       MySpaceFolder folder = this;
112       StoreFile child = null;
113       while (dirTokens.hasMoreTokens())
114       {
115          String token = dirTokens.nextToken();
116          child = folder.getChild(token);
117          if (child == null) {
118             throw new FileNotFoundException("No such token '"+token+"' in path "+path+" from "+this);
119          }
120          else {
121             if (child.isFolder()) {
122                folder = (MySpaceFolder) child;
123             }
124          }
125       }
126       
127       if (dirTokens.hasMoreTokens()) {
128          throw new FileNotFoundException("path "+path+" only partly found from "+this);
129       }
130       
131       return child;
132       
133    }
134    
135    
136 }
137 
138 /*
139  $Log: MySpaceFolder.java,v $
140  Revision 1.2  2004/06/14 23:08:52  jdt
141  Merge from branches
142  ClientServerSplit_JDT
143  and
144  MySpaceClientServerSplit_JDT
145  
146  MySpace now split into a client/delegate jar
147  astrogrid-myspace-<version>.jar
148  and a server/manager war
149  astrogrid-myspace-server-<version>.war
150 
151  Revision 1.1.2.1  2004/06/14 22:33:20  jdt
152  Split into delegate jar and server war.  
153  Delegate: astrogrid-myspace-SNAPSHOT.jar
154  Server/Manager: astrogrid-myspace-server-SNAPSHOT.war
155  
156  Package names unchanged.
157  If you regenerate the axis java/wsdd/wsdl files etc you'll need
158  to move some files around to ensure they end up in the client
159  or the server as appropriate.
160  As of this check-in the tests/errors/failures is 162/1/22 which
161  matches that before the split.
162 
163  Revision 1.4  2004/05/03 08:55:53  mch
164  Fixes to getFiles(), introduced getSize(), getOwner() etc to StoreFile
165 
166  Revision 1.3  2004/04/26 16:40:54  mch
167  More fixes to It05 delegate
168 
169  Revision 1.2  2004/04/23 11:38:19  mch
170  Fixes to return correct AGSL plus change to File model for It05 delegate
171 
172  Revision 1.1  2004/03/04 12:51:31  mch
173  Moved delegate implementations into subpackages
174 
175  Revision 1.4  2004/03/01 22:38:46  mch
176  Part II of copy from It4.1 datacenter + updates from myspace meetings + test fixes
177 
178  Revision 1.3  2004/03/01 16:38:58  mch
179  Merged in from datacenter 4.1 and odd cvs/case problems
180 
181  Revision 1.2  2004/03/01 15:15:04  mch
182  Updates to Store delegates after myspace meeting
183 
184  Revision 1.1  2004/02/24 15:59:56  mch
185  Moved It04.1 Datacenter VoSpaceClient stuff to myspace as StoreClient stuff
186 
187  Revision 1.2  2004/02/17 15:15:27  mch
188  Removed unused imports
189 
190  Revision 1.1  2004/02/15 23:16:06  mch
191  New-style VoSpace delegates.  Not agreed so private to datacenter for the moment
192 
193  */
194