⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 todolistcreatorinterfaceimpl.java

📁 java的客户端程序
💻 JAVA
字号:
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import ssd8exercise5creator.*;
import ssd8exercise5.*;
import java.io.*;
import java.util.*;

/**
 * class <em>TodolistCreatorInterfaceImpl</em> represents the implementation 
 * of the remote methods defined in <em>TodolistCreatorInterface.idl</em>
 *
 * @author iCarnegie (VP)
 * @version 1.0
 */

public class TodolistCreatorInterfaceImpl extends _TodolistCreatorInterfaceImplBase {
    
    /*
     * Creator has an orb.
     */
    ORB orb;

    /*
     * Object reference.
     */
    org.omg.CORBA.Object objRef;

    /*
     * Naming component reference.
     */
    NamingContext ncRef;

    /*
     * Name component
     */
    NameComponent nc;

	
    /**
     * constructor
     */
    public TodolistCreatorInterfaceImpl( String args[] ) {
	
	/*
	 * Create and initialize the orb.
	 */
	try {
	    orb = ORB.init( args, null );
	} catch( Exception e ) {
	    e.printStackTrace();
	}
    }

     /**
     * Register a new user.
     * @param username String user name to register
     * @param password String password of new user
     * @return boolean success of registration
     */
    public boolean register( String username, String password ) {	

	/*
	 * If the user name is not being used, then 
	 * place it in the hash map with the username as the key
	 * and the password as the value.  Also, create a new
	 * to do list object and add it to the orb.
	 */
	TodolistInterface toDoList;
	try {		
	    /*
	     * Get the root naming context.
	     */
	    objRef = orb.resolve_initial_references( "NameService" );
	    ncRef = NamingContextHelper.narrow( objRef );

	    /*
	     * Find the object named TodolistCreator.
	     */
	    nc = new NameComponent(username,"");
      	    NameComponent trypath[] = { nc };	       
	    toDoList = TodolistInterfaceHelper.narrow(ncRef.resolve(trypath));
	    return false;
	} catch( org.omg.CosNaming.NamingContextPackage.NotFound nf ) {
	    try {
		TodolistInterfaceImpl newTodolist = new TodolistInterfaceImpl( username, password );
		orb.connect( newTodolist );
		objRef = orb.resolve_initial_references( "NameService" );
		ncRef = NamingContextHelper.narrow( objRef );
		nc = new NameComponent( username ,"");
		NameComponent path[] = { nc };	       
		ncRef.rebind( path, newTodolist );
		return true;
	    } catch( Exception e ) {
		e.printStackTrace();
		return false;
	    }
	} catch( org.omg.CORBA.ORBPackage.InvalidName in ){
	    in.printStackTrace();
	    return false;
	} catch( org.omg.CosNaming.NamingContextPackage.CannotProceed cp ) {
	    cp.printStackTrace();
	    return false;
	} catch( org.omg.CosNaming.NamingContextPackage.InvalidName in2 ) {
	    in2.printStackTrace();
	    return false;
	}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -