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

Quick Search    Search Deep

Source code: org/vrspace/server/command/Administrator/chClass.java


1   package org.vrspace.server.command.Administrator;
2   import org.vrspace.server.*;
3   import org.vrspace.util.*;
4   import org.vrspace.attributes.*;
5   
6   /**
7   This command changes class of an object. It actually removes the object,
8   creates new object, and stores it to the database.
9   Also updates Transform if object implements HasTransform, takes care of
10  AuthInfo too.<br>
11  @see org.vrspace.server.Transform
12  @see org.vrspace.attributes.HasTransform
13  @see org.vrspace.server.Dispatcher
14  @see org.vrspace.server.AuthInfo
15  */
16  public class chClass implements Command {
17    /**
18    Syntax: chClass className id newClass
19    */
20    public void exec( Request r ) throws Exception {
21      String oldClass = r.getArguments()[0];
22      long id = Long.parseLong(r.getArguments()[1]);
23      String newClass = r.getArguments()[2];
24      Dispatcher d = r.getClient().getDispatcher();
25      VRObject o = d.get( r.getClient(), oldClass, id );
26      Transform t = null;
27      VRObject newObj = VRObject.newInstance(newClass);
28      newObj.setFields( o );
29      newObj.db_id = 0;
30      if ( o instanceof Client && ((Client)o).isOnline() ) {
31        throw new RequestException( r, "Client is online!" );
32      }
33      d.put( r.getClient(), newObj );
34      if ( o instanceof HasTransform ) {
35        t = ((HasTransform)o).getTransform();
36        t.removeMember( o );
37      }
38      d.remove( r.getClient(), o);
39      if ( newObj instanceof HasTransform ) {
40        if ( t == null ) {
41          t = new Transform();
42        }
43        t.addMember( newObj );
44      }
45      if ( t != null && t.getChildren().length == 0 ) {
46        d.removeTransform( r.getClient(), t );
47      }
48      if ( o instanceof Client && newObj instanceof Client ) {
49        ((Client)newObj).updateAuthInfo( (Client) o );
50      }
51    }
52  }