1 package org.jacorb.orb; 2 3 22 23 import java.io.*; 24 import java.lang.reflect.*; 25 26 import org.apache.avalon.framework.logger.Logger; 27 import org.apache.avalon.framework.configuration.Configurable; 28 import org.apache.avalon.framework.configuration.ConfigurationException; 29 30 import org.omg.GIOP.*; 31 import org.omg.Messaging.ExceptionHolder; 32 import org.omg.CORBA.ExceptionList ; 33 import org.omg.CORBA.SystemException ; 34 import org.omg.CORBA.UnknownUserException ; 35 import org.omg.CORBA.UserException ; 36 37 import org.jacorb.ir.*; 38 import org.jacorb.orb.giop.*; 39 import org.jacorb.util.ObjectUtil; 40 41 49 public class ExceptionHolderImpl 50 extends org.omg.Messaging.ExceptionHolder 51 implements Configurable 52 { 53 private Logger logger = null; 54 55 61 public ExceptionHolderImpl( ReplyInputStream is ) 62 { 63 int status = is.getStatus().value(); 64 if ( status == ReplyStatusType_1_2._USER_EXCEPTION ) 65 { 66 is_system_exception = false; 67 } 68 else if ( status == ReplyStatusType_1_2._SYSTEM_EXCEPTION ) 69 { 70 is_system_exception = true; 71 } 72 else 73 { 74 throw new RuntimeException ( "attempt to create ExceptionHolder " + 75 "for non-exception reply" ); 76 } 77 byte_order = is.littleEndian; 78 marshaled_exception = is.getBody(); 79 } 80 81 public ExceptionHolderImpl(org.omg.CORBA.SystemException ex) 82 { 83 is_system_exception = true; 84 byte_order = false; 85 86 CDROutputStream output = new CDROutputStream(); 87 SystemExceptionHelper.write(output, ex); 88 marshaled_exception = output.getBufferCopy(); 89 } 90 91 94 public ExceptionHolderImpl() 95 { 96 super(); 97 } 98 99 public void configure(org.apache.avalon.framework.configuration.Configuration configuration) 100 throws org.apache.avalon.framework.configuration.ConfigurationException 101 { 102 logger = 103 ((org.jacorb.config.Configuration)configuration).getNamedLogger("jacorb.orb.exc_holder"); 104 } 105 106 107 public void raise_exception() 108 throws UserException 109 { 110 CDRInputStream input = 111 new CDRInputStream (null, marshaled_exception, byte_order); 112 if ( is_system_exception ) 113 { 114 throw SystemExceptionHelper.read( input ); 115 } 116 else 117 { 118 input.mark( 0 ); 119 String id = input.read_string(); 120 try 121 { 122 input.reset(); 123 } 124 catch( IOException ioe ) 125 { 126 if (logger.isWarnEnabled()) 127 logger.warn( "Unexpected IOException: " + ioe.getMessage() ); 128 } 129 130 org.omg.CORBA.UserException result = null; 131 try 132 { 133 result = exceptionFromHelper( id, input ); 134 } 135 catch( Exception e ) 136 { 137 throw new org.omg.CORBA.UnknownUserException (); 138 } 139 throw result; 140 } 141 } 142 143 public void raise_exception_with_list( ExceptionList exc_list ) 144 throws UserException 145 { 146 throw new org.omg.CORBA.NO_IMPLEMENT ( 147 "raise_exception_with_list not yet implemented" ); 148 } 149 150 153 public String toString() 154 { 155 StringBuffer result = new StringBuffer (); 156 for (int i=0; i<marshaled_exception.length; i++) 157 { 158 result.append (marshaled_exception[i] + 159 "(" + (char)marshaled_exception[i] + ") "); 160 } 161 return result.toString(); 162 } 163 164 169 public org.omg.CORBA.UserException exceptionFromHelper 170 ( String id, 171 org.omg.CORBA.portable.InputStream input ) 172 throws ClassNotFoundException , 173 NoSuchMethodException , 174 IllegalAccessException , 175 InvocationTargetException 176 { 177 String name = RepositoryID.className(id, "Helper", null); 178 179 Class helper = ObjectUtil.classForName (name); 181 182 184 Method readMethod = 187 helper.getMethod( "read", 188 new Class []{ 189 ObjectUtil.classForName("org.omg.CORBA.portable.InputStream") 190 } ); 191 java.lang.Object result = 192 readMethod.invoke( null, 193 new java.lang.Object []{ input } 194 ); 195 return ( org.omg.CORBA.UserException ) result; 196 } 197 198 201 public byte[] marshal() 202 { 203 byte[] buffer = 204 BufferManager.getInstance() 205 .getBuffer( marshaled_exception.length + 128 ); 206 CDROutputStream output = new CDROutputStream( buffer ); 207 output.write_value( this, "IDL:omg.org/Messaging/ExceptionHolder:1.0" ); 208 return buffer; 209 } 210 } 211 | Popular Tags |