下面列出了怎么用org.omg.CORBA.UserException的API类实例代码及写法,或者点击链接到github查看源代码。
static int run(ORB orb, String[] args) throws UserException {
//
// Resolve Root POA
//
POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
//
// Get a reference to the POA manager
//
POAManager manager = poa.the_POAManager();
//
// Create implementation object
//
BankImpl bankImpl = new BankImpl(poa);
byte[] oid = "Bank".getBytes();
poa.activate_object_with_id(oid, bankImpl);
org.omg.CORBA.Object ref = poa.create_reference_with_id(oid, BankHelper.id());
// Register in NameService
org.omg.CORBA.Object nsObj = orb.resolve_initial_references("NameService");
NamingContextExt rootContext = NamingContextExtHelper.narrow(nsObj);
NameComponent[] nc = rootContext.to_name("Bank");
rootContext.rebind(nc, ref);
//
// Run implementation
//
manager.activate();
System.out.println("Server ready...");
orb.run();
return 0;
}
static int run(ORB orb, String[] args) throws UserException {
// Get "hello" object
// Resolve the HelloWorldImpl by using INS's corbaname url.
// The URL locates the NameService running on localhost
// and listening on 1050 and resolve 'HelloWorld'
// from that NameService
org.omg.CORBA.Object obj = orb.string_to_object("corbaname::localhost:1050#HelloWorld");
if (obj == null) {
System.err.println("Client: Could not resolve target object");
return 1;
}
HelloWorld hello = HelloWorldHelper.narrow(obj);
// Test our narrowed "hello" object
System.out.println("Invoking greetMe...");
String result = null;
if (args.length > 0) {
result = hello.greetMe(args[args.length - 1]);
} else {
result = hello.greetMe("World");
}
System.out.println("greetMe.result = " + result);
return 0;
}
static int run(ORB orb, String[] args) throws UserException {
// Resolve Root POA
POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
// Get a reference to the POA manager
POAManager manager = poa.the_POAManager();
// Create implementation object
HelloWorldImpl hwImpl = new HelloWorldImpl(poa);
byte[] oid = "HelloWorld".getBytes();
poa.activate_object_with_id(oid, hwImpl);
org.omg.CORBA.Object ref = poa.create_reference_with_id(oid, HelloWorldHelper.id());
// Register in NameService
org.omg.CORBA.Object nsObj = orb.resolve_initial_references("NameService");
NamingContextExt rootContext = NamingContextExtHelper.narrow(nsObj);
NameComponent[] nc = rootContext.to_name("HelloWorld");
rootContext.rebind(nc, ref);
// Run implementation
manager.activate();
System.out.println("Server ready...");
orb.run();
return 0;
}
public void invokeClientPIStartingPoint()
throws RemarshalException
{
if( !hasClientInterceptors ) return;
if( !isClientPIEnabledForThisThread() ) return;
// Invoke the starting interception points and record exception
// and reply status info in the info object:
ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
interceptorInvoker.invokeClientInterceptorStartingPoint( info );
// Check reply status. If we will not have another chance later
// to invoke the client ending points, do it now.
short replyStatus = info.getReplyStatus();
if( (replyStatus == SYSTEM_EXCEPTION.value) ||
(replyStatus == LOCATION_FORWARD.value) )
{
// Note: Transport retry cannot happen here since this happens
// before the request hits the wire.
Exception exception = invokeClientPIEndingPoint(
convertPIReplyStatusToReplyMessage( replyStatus ),
info.getException() );
if( exception == null ) {
// Do not throw anything. Otherwise, it must be a
// SystemException, UserException or RemarshalException.
} if( exception instanceof SystemException ) {
throw (SystemException)exception;
} else if( exception instanceof RemarshalException ) {
throw (RemarshalException)exception;
} else if( (exception instanceof UserException) ||
(exception instanceof ApplicationException) ) {
// It should not be possible for an interceptor to throw
// a UserException. By asserting instead of throwing the
// UserException, we need not declare anything but
// RemarshalException in the throws clause.
throw wrapper.exceptionInvalid() ;
}
}
else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
throw wrapper.replyStatusNotInit() ;
}
}
public void invokeClientPIStartingPoint()
throws RemarshalException
{
if( !hasClientInterceptors ) return;
if( !isClientPIEnabledForThisThread() ) return;
// Invoke the starting interception points and record exception
// and reply status info in the info object:
ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
interceptorInvoker.invokeClientInterceptorStartingPoint( info );
// Check reply status. If we will not have another chance later
// to invoke the client ending points, do it now.
short replyStatus = info.getReplyStatus();
if( (replyStatus == SYSTEM_EXCEPTION.value) ||
(replyStatus == LOCATION_FORWARD.value) )
{
// Note: Transport retry cannot happen here since this happens
// before the request hits the wire.
Exception exception = invokeClientPIEndingPoint(
convertPIReplyStatusToReplyMessage( replyStatus ),
info.getException() );
if( exception == null ) {
// Do not throw anything. Otherwise, it must be a
// SystemException, UserException or RemarshalException.
} if( exception instanceof SystemException ) {
throw (SystemException)exception;
} else if( exception instanceof RemarshalException ) {
throw (RemarshalException)exception;
} else if( (exception instanceof UserException) ||
(exception instanceof ApplicationException) ) {
// It should not be possible for an interceptor to throw
// a UserException. By asserting instead of throwing the
// UserException, we need not declare anything but
// RemarshalException in the throws clause.
throw wrapper.exceptionInvalid() ;
}
}
else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
throw wrapper.replyStatusNotInit() ;
}
}
public void invokeClientPIStartingPoint()
throws RemarshalException
{
if( !hasClientInterceptors ) return;
if( !isClientPIEnabledForThisThread() ) return;
// Invoke the starting interception points and record exception
// and reply status info in the info object:
ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
interceptorInvoker.invokeClientInterceptorStartingPoint( info );
// Check reply status. If we will not have another chance later
// to invoke the client ending points, do it now.
short replyStatus = info.getReplyStatus();
if( (replyStatus == SYSTEM_EXCEPTION.value) ||
(replyStatus == LOCATION_FORWARD.value) )
{
// Note: Transport retry cannot happen here since this happens
// before the request hits the wire.
Exception exception = invokeClientPIEndingPoint(
convertPIReplyStatusToReplyMessage( replyStatus ),
info.getException() );
if( exception == null ) {
// Do not throw anything. Otherwise, it must be a
// SystemException, UserException or RemarshalException.
} if( exception instanceof SystemException ) {
throw (SystemException)exception;
} else if( exception instanceof RemarshalException ) {
throw (RemarshalException)exception;
} else if( (exception instanceof UserException) ||
(exception instanceof ApplicationException) ) {
// It should not be possible for an interceptor to throw
// a UserException. By asserting instead of throwing the
// UserException, we need not declare anything but
// RemarshalException in the throws clause.
throw wrapper.exceptionInvalid() ;
}
}
else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
throw wrapper.replyStatusNotInit() ;
}
}
public void invokeClientPIStartingPoint()
throws RemarshalException
{
if( !hasClientInterceptors ) return;
if( !isClientPIEnabledForThisThread() ) return;
// Invoke the starting interception points and record exception
// and reply status info in the info object:
ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
interceptorInvoker.invokeClientInterceptorStartingPoint( info );
// Check reply status. If we will not have another chance later
// to invoke the client ending points, do it now.
short replyStatus = info.getReplyStatus();
if( (replyStatus == SYSTEM_EXCEPTION.value) ||
(replyStatus == LOCATION_FORWARD.value) )
{
// Note: Transport retry cannot happen here since this happens
// before the request hits the wire.
Exception exception = invokeClientPIEndingPoint(
convertPIReplyStatusToReplyMessage( replyStatus ),
info.getException() );
if( exception == null ) {
// Do not throw anything. Otherwise, it must be a
// SystemException, UserException or RemarshalException.
} if( exception instanceof SystemException ) {
throw (SystemException)exception;
} else if( exception instanceof RemarshalException ) {
throw (RemarshalException)exception;
} else if( (exception instanceof UserException) ||
(exception instanceof ApplicationException) ) {
// It should not be possible for an interceptor to throw
// a UserException. By asserting instead of throwing the
// UserException, we need not declare anything but
// RemarshalException in the throws clause.
throw wrapper.exceptionInvalid() ;
}
}
else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
throw wrapper.replyStatusNotInit() ;
}
}
public void invokeClientPIStartingPoint()
throws RemarshalException
{
if( !hasClientInterceptors ) return;
if( !isClientPIEnabledForThisThread() ) return;
// Invoke the starting interception points and record exception
// and reply status info in the info object:
ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
interceptorInvoker.invokeClientInterceptorStartingPoint( info );
// Check reply status. If we will not have another chance later
// to invoke the client ending points, do it now.
short replyStatus = info.getReplyStatus();
if( (replyStatus == SYSTEM_EXCEPTION.value) ||
(replyStatus == LOCATION_FORWARD.value) )
{
// Note: Transport retry cannot happen here since this happens
// before the request hits the wire.
Exception exception = invokeClientPIEndingPoint(
convertPIReplyStatusToReplyMessage( replyStatus ),
info.getException() );
if( exception == null ) {
// Do not throw anything. Otherwise, it must be a
// SystemException, UserException or RemarshalException.
} if( exception instanceof SystemException ) {
throw (SystemException)exception;
} else if( exception instanceof RemarshalException ) {
throw (RemarshalException)exception;
} else if( (exception instanceof UserException) ||
(exception instanceof ApplicationException) ) {
// It should not be possible for an interceptor to throw
// a UserException. By asserting instead of throwing the
// UserException, we need not declare anything but
// RemarshalException in the throws clause.
throw wrapper.exceptionInvalid() ;
}
}
else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
throw wrapper.replyStatusNotInit() ;
}
}
public void invokeClientPIStartingPoint()
throws RemarshalException
{
if( !hasClientInterceptors ) return;
if( !isClientPIEnabledForThisThread() ) return;
// Invoke the starting interception points and record exception
// and reply status info in the info object:
ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
interceptorInvoker.invokeClientInterceptorStartingPoint( info );
// Check reply status. If we will not have another chance later
// to invoke the client ending points, do it now.
short replyStatus = info.getReplyStatus();
if( (replyStatus == SYSTEM_EXCEPTION.value) ||
(replyStatus == LOCATION_FORWARD.value) )
{
// Note: Transport retry cannot happen here since this happens
// before the request hits the wire.
Exception exception = invokeClientPIEndingPoint(
convertPIReplyStatusToReplyMessage( replyStatus ),
info.getException() );
if( exception == null ) {
// Do not throw anything. Otherwise, it must be a
// SystemException, UserException or RemarshalException.
} if( exception instanceof SystemException ) {
throw (SystemException)exception;
} else if( exception instanceof RemarshalException ) {
throw (RemarshalException)exception;
} else if( (exception instanceof UserException) ||
(exception instanceof ApplicationException) ) {
// It should not be possible for an interceptor to throw
// a UserException. By asserting instead of throwing the
// UserException, we need not declare anything but
// RemarshalException in the throws clause.
throw wrapper.exceptionInvalid() ;
}
}
else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
throw wrapper.replyStatusNotInit() ;
}
}
public void invokeClientPIStartingPoint()
throws RemarshalException
{
if( !hasClientInterceptors ) return;
if( !isClientPIEnabledForThisThread() ) return;
// Invoke the starting interception points and record exception
// and reply status info in the info object:
ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
interceptorInvoker.invokeClientInterceptorStartingPoint( info );
// Check reply status. If we will not have another chance later
// to invoke the client ending points, do it now.
short replyStatus = info.getReplyStatus();
if( (replyStatus == SYSTEM_EXCEPTION.value) ||
(replyStatus == LOCATION_FORWARD.value) )
{
// Note: Transport retry cannot happen here since this happens
// before the request hits the wire.
Exception exception = invokeClientPIEndingPoint(
convertPIReplyStatusToReplyMessage( replyStatus ),
info.getException() );
if( exception == null ) {
// Do not throw anything. Otherwise, it must be a
// SystemException, UserException or RemarshalException.
} if( exception instanceof SystemException ) {
throw (SystemException)exception;
} else if( exception instanceof RemarshalException ) {
throw (RemarshalException)exception;
} else if( (exception instanceof UserException) ||
(exception instanceof ApplicationException) ) {
// It should not be possible for an interceptor to throw
// a UserException. By asserting instead of throwing the
// UserException, we need not declare anything but
// RemarshalException in the throws clause.
throw wrapper.exceptionInvalid() ;
}
}
else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
throw wrapper.replyStatusNotInit() ;
}
}
public void invokeClientPIStartingPoint()
throws RemarshalException
{
if( !hasClientInterceptors ) return;
if( !isClientPIEnabledForThisThread() ) return;
// Invoke the starting interception points and record exception
// and reply status info in the info object:
ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
interceptorInvoker.invokeClientInterceptorStartingPoint( info );
// Check reply status. If we will not have another chance later
// to invoke the client ending points, do it now.
short replyStatus = info.getReplyStatus();
if( (replyStatus == SYSTEM_EXCEPTION.value) ||
(replyStatus == LOCATION_FORWARD.value) )
{
// Note: Transport retry cannot happen here since this happens
// before the request hits the wire.
Exception exception = invokeClientPIEndingPoint(
convertPIReplyStatusToReplyMessage( replyStatus ),
info.getException() );
if( exception == null ) {
// Do not throw anything. Otherwise, it must be a
// SystemException, UserException or RemarshalException.
} if( exception instanceof SystemException ) {
throw (SystemException)exception;
} else if( exception instanceof RemarshalException ) {
throw (RemarshalException)exception;
} else if( (exception instanceof UserException) ||
(exception instanceof ApplicationException) ) {
// It should not be possible for an interceptor to throw
// a UserException. By asserting instead of throwing the
// UserException, we need not declare anything but
// RemarshalException in the throws clause.
throw wrapper.exceptionInvalid() ;
}
}
else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
throw wrapper.replyStatusNotInit() ;
}
}
public void invokeClientPIStartingPoint()
throws RemarshalException
{
if( !hasClientInterceptors ) return;
if( !isClientPIEnabledForThisThread() ) return;
// Invoke the starting interception points and record exception
// and reply status info in the info object:
ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
interceptorInvoker.invokeClientInterceptorStartingPoint( info );
// Check reply status. If we will not have another chance later
// to invoke the client ending points, do it now.
short replyStatus = info.getReplyStatus();
if( (replyStatus == SYSTEM_EXCEPTION.value) ||
(replyStatus == LOCATION_FORWARD.value) )
{
// Note: Transport retry cannot happen here since this happens
// before the request hits the wire.
Exception exception = invokeClientPIEndingPoint(
convertPIReplyStatusToReplyMessage( replyStatus ),
info.getException() );
if( exception == null ) {
// Do not throw anything. Otherwise, it must be a
// SystemException, UserException or RemarshalException.
} if( exception instanceof SystemException ) {
throw (SystemException)exception;
} else if( exception instanceof RemarshalException ) {
throw (RemarshalException)exception;
} else if( (exception instanceof UserException) ||
(exception instanceof ApplicationException) ) {
// It should not be possible for an interceptor to throw
// a UserException. By asserting instead of throwing the
// UserException, we need not declare anything but
// RemarshalException in the throws clause.
throw wrapper.exceptionInvalid() ;
}
}
else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
throw wrapper.replyStatusNotInit() ;
}
}
public void invokeClientPIStartingPoint()
throws RemarshalException
{
if( !hasClientInterceptors ) return;
if( !isClientPIEnabledForThisThread() ) return;
// Invoke the starting interception points and record exception
// and reply status info in the info object:
ClientRequestInfoImpl info = peekClientRequestInfoImplStack();
interceptorInvoker.invokeClientInterceptorStartingPoint( info );
// Check reply status. If we will not have another chance later
// to invoke the client ending points, do it now.
short replyStatus = info.getReplyStatus();
if( (replyStatus == SYSTEM_EXCEPTION.value) ||
(replyStatus == LOCATION_FORWARD.value) )
{
// Note: Transport retry cannot happen here since this happens
// before the request hits the wire.
Exception exception = invokeClientPIEndingPoint(
convertPIReplyStatusToReplyMessage( replyStatus ),
info.getException() );
if( exception == null ) {
// Do not throw anything. Otherwise, it must be a
// SystemException, UserException or RemarshalException.
} if( exception instanceof SystemException ) {
throw (SystemException)exception;
} else if( exception instanceof RemarshalException ) {
throw (RemarshalException)exception;
} else if( (exception instanceof UserException) ||
(exception instanceof ApplicationException) ) {
// It should not be possible for an interceptor to throw
// a UserException. By asserting instead of throwing the
// UserException, we need not declare anything but
// RemarshalException in the throws clause.
throw wrapper.exceptionInvalid() ;
}
}
else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) {
throw wrapper.replyStatusNotInit() ;
}
}
static int run(ORB orb, String[] args) throws UserException {
// Get the Bank object
org.omg.CORBA.Object obj =
orb.string_to_object("corbaname::localhost:1050#Bank");
if (obj == null) {
System.err.println("bank.Client: cannot read IOR from corbaname::localhost:1050#Bank");
return 1;
}
Bank bank = BankHelper.narrow(obj);
// Test the method Bank.create_account()
System.out.println("Creating account called \"Account1\"");
Account account1 = bank.create_account("Account1");
System.out.println("Depositing 100.00 into account \"Account1\"");
account1.deposit(100.00f);
System.out.println("Current balance of \"Account1\" is " + account1.get_balance());
System.out.println();
// Test the method Bank.create_epr_account()
System.out.println("Creating account called \"Account2\"");
org.omg.CORBA.Object account2Obj = bank.create_epr_account("Account2");
Account account2 = AccountHelper.narrow(account2Obj);
System.out.println("Depositing 5.00 into account \"Account2\"");
account2.deposit(5.00f);
System.out.println("Current balance of \"Account2\" is " + account2.get_balance());
System.out.println();
// Create two more accounts to use with the getAccount calls
Account acc3 = bank.create_account("Account3");
acc3.deposit(200.00f);
Account acc4 = bank.create_account("Account4");
acc4.deposit(400.00f);
// Test the method Bank.get_account()
System.out.println("Retrieving account called \"Account3\"");
Account account3 = bank.get_account("Account3");
System.out.println("Current balance for \"Account3\" is " + account3.get_balance());
System.out.println("Depositing 10.00 into account \"Account3\"");
account3.deposit(10.00f);
System.out.println("New balance for account \"Account3\" is " + account3.get_balance());
System.out.println();
// Test the method Bank.get_epr_account()
System.out.println("Retrieving account called \"Account4\"");
Account account4 = bank.get_account("Account4");
System.out.println("Current balance for \"Account4\" is " + account4.get_balance());
System.out.println("Withdrawing 150.00 into account \"Account4\"");
account4.deposit(-150.00f);
System.out.println("New balance for account \"Account4\" is " + account4.get_balance());
System.out.println();
bank.remove_account("Account1");
bank.remove_account("Account2");
bank.remove_account("Account3");
bank.remove_account("Account4");
return 0;
}