1

我正在开发一个 CORBA 客户端和服务器应用程序,使用以下 idl

1) 备份服务器.idl

// BackupServer.idl

  #ifndef BackupServer_idl
  #define BackupServer_idl

  #include "BackupDaemon.idl"
  #include "BackupExceptions.idl"

  // A BackupServer provides clients with visibility to Backup objects.
 interface BackupServer {

     // Register the given Backup Daemon with this BackupServer. The Backup will
     // be listed by getBackupDeamons() until unregisterBackup() is called with
     // that Backup.
     void registerBackupDaemon(in BackupDaemon bd)
             raises (InvalidBackupDaemonException);

     // Unregister the given Backup from this BackupServer. If the Backup
     // was not previously registered, this operation does nothing.
     void unregisterBackupDaemon(in string backupDaemonMacAddress)
             raises (InvalidBackupDaemonException);

     // Return a list of all Backups currently registered with this
     // BackupServer.
     BackupDaemonList getBackupDeamons();
 };

 #endif

2)BackupDaemon.idl

      // BackupDaemon.idl

  // Forward declaration of BackupDaemon interface.
  interface BackupDaemon;

  #ifndef BackupDaemon_idl
  #define BackupDaemon_idl

  // sequence of BackupDaemons
 typedef sequence<BackupDaemon> BackupDaemonList;

 #include "BackupExceptions.idl"


 interface BackupDaemon {

     // This BackupDaemon's name.
     attribute string backupDaemonUser;
     attribute string backupDaemonIP;
     attribute string backupDaemonHostName;
     attribute string backupDaemonBackupType;
     attribute string backupDaemonType;
     attribute string backupDaemonTime;
     attribute string backupDaemonPath;
     attribute boolean backupDaemonScheduled;
     attribute string backupDaemonPort;
     attribute string backupDaemonMacAddress;


     boolean startBackup(in string backupPath,in string backupDaemonMacAddress);


     void deleteBackup(in string backupPath,in string backupDaemonMacAddress)
             raises (InvalidBackupPathException);


 };

 #endif 

3) BackupExceptions.idl

  // BackupExceptions.idl

  #ifndef BackupExceptions_idl
  #define BackupExceptions_idl

  exception InvalidBackupPathException {

 };


 exception InvalidBackupDaemonException {

 };
 #endif

一切都很好,但我的问题是:-如何将 BackupDaemon 对象从我的客户端实现传递到服务器?

我试过那个代码: -

 // BackupDaemonMain.java



  import org.omg.CORBA.ORB;
  import org.omg.CosNaming.NameComponent;
  import org.omg.CosNaming.NamingContext;
  import org.omg.CosNaming.NamingContextHelper;


 // BackupDaemonMain is a simple client of a BackupServer.
 public class BackupDaemonMain {

     // Create a new BackupDaemonMain.
     BackupDaemonMain() {

     }

     // Run the BackupDaemonMain.
     public void run() {

         connect();

         if (myBackupServer != null) {
             doSomething();
         }
     }

     // Connect to the BackupServer.
     protected void connect() {

         try {

             // Get the root naming context.

             org.omg.CORBA.Object obj = ourORB.
                     resolve_initial_references("NameService");
             NamingContext namingContext = NamingContextHelper.narrow(obj);

             // Attempt to locate a BackupServer object in the naming
             // context.
             NameComponent nameComponent = new NameComponent("BackupServer","");
             NameComponent path[] = { nameComponent };
             myBackupServer = BackupServerHelper.narrow(namingContext.resolve(path));
         } catch (Exception ex) {
             System.err.println("Couldn't resolve BackupServer: " + ex);
             myBackupServer = null;
             return;
         }

         System.out.println("Succesfully bound to a BackupServer.");
     }

     // Do some cool things with the BackupServer.
     protected void doSomething() {

         try {
 **BackupDaemonImpl bd=new BackupDaemonImpl();
 bd.setORB(ourORB);**
 bd.backupDaemonUser("backupDaemonUser");
  bd.backupDaemonIP("backupDaemonIP");
   bd.backupDaemonHostName("backupDaemonHostName");
    bd.backupDaemonBackupType("backupDaemonBackupType");
     bd.backupDaemonType("backupDaemonType");
  bd.backupDaemonTime("backupDaemonTime");
   bd.backupDaemonPath("backupDaemonPath");
    bd.backupDaemonScheduled(true);
       bd.backupDaemonPort("backupDaemonPort");
    bd.backupDaemonMacAddress("backupDaemonMacAddress");


       // Get the valid stock symbols from the BackupServer.
             myBackupServer.registerBackupDaemon(bd);

           /*  // Display the stock symbols and their values.
             for (int i = 0; i < stockSymbols.length; i++) {
                 System.out.println(stockSymbols[i] + " " +
                         myBackupServer.getStockValue(stockSymbols[i]));
             }*/
         } catch (Exception ex) {
             System.err.println("Fatal error: " + ex);
         }
     }

     // Start up a BackupDaemonMain.
     public static void main(String args[]) {

         // Initialize the ORB.
         ourORB = ORB.init(args, null);

         BackupDaemonMain stockClient = new BackupDaemonMain();

         stockClient.run();

         // This simply waits forever so that the DOS window doesn't
         // disappear (for developers using Windows IDEs).
         while (true)
             ;
     }

     // My ORB.
     public static ORB ourORB;

     // My BackupServer.
     private BackupServer myBackupServer;
 } 

但我得到这个错误

 bd.setORB(ourORB);
   ^
  symbol:   method setORB(ORB)
  location: variable bd of type BackupDaemonImpl
BackupDaemonMain.java:73: error: method registerBackupDaemon in interface Backup
ServerOperations cannot be applied to given types;
             myBackupServer.registerBackupDaemon(bd);
                           ^
  required: BackupDaemon
  found: BackupDaemonImpl
  reason: actual argument BackupDaemonImpl cannot be converted to BackupDaemon b
y method invocation conversion
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

教程或类似错误解决方案的任何帮助。提前致谢。

4

0 回答 0