Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/vrspace/server/command/upload.java


1   package org.vrspace.server.command;
2   
3   import org.vrspace.server.*;
4   import org.vrspace.server.object.File;
5   import org.vrspace.util.Logger;
6   
7   /**
8    * Request format: upload className path<br>
9    * className is expected to be File or one of its subclasses.
10   * The command creates a new instance of className in the database with name
11   * equal to path.  Then it calls set_upload on the new object with the given path.
12   *
13   * @see org.vrspace.server.BinarySession
14   * @see org.vrspace.server.object.File
15  */
16  public class upload implements Command {
17    /**
18     * Request format: upload <className> <filename>
19     */
20    public void exec ( Request req ) throws Exception {
21      Client     client     = req.getClient();
22      Dispatcher dispatcher = client.getDispatcher();
23      String     className  = req.getArguments()[0];
24      
25      // This allows spaces in the objects name
26      String path = req.getEventValue().substring( className.length() + 1 ).trim();
27  
28      File obj = null;
29      try {
30        obj = (File) dispatcher.getByName( client, className, path );
31      } catch ( Exception e ) {
32      }
33      
34      // Create a new instance of the object, makes its name equal to path, and
35      // set the client as an owner.
36      if ( obj == null ) {
37        obj = (File) Class.forName( "org.vrspace.server.object." + className ).newInstance();
38        obj.name = path;
39        dispatcher.put( client, obj );
40        client.addOwned( obj );
41      }
42      
43      Logger.logDebug( "upload " + obj.getClassName() + "[" + obj.db_id + "]=" + obj.name );
44      
45      // Send a response to the client so they know the id of the new object
46      client.getSession().sendResponse( 
47        new Request( client, 
48                     "upload " + obj.getClassName() + " "  + obj.db_id + " " + obj.name
49        )
50      );
51      
52      // Call the upload command on the new File
53      if ( obj instanceof File ) {
54        ( (File) obj ).set_upload( 
55          new Request( req, obj.getClassName() + " " + obj.db_id + " upload " + path ),
56          path
57        );
58      }
59      
60    } // exec
61    
62  } // upload