orber_exceptions.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 716 行 · 第 1/2 页
ERL
716 行
%%--------------------------------------------------------------------%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %% $Id$%%%%-----------------------------------------------------------------%% File: orber_exceptions.erl%% %% Description:%%%%------------------------------------------------------------------module(orber_exceptions).-include_lib("orber/include/corba.hrl").-include_lib("orber/src/orber_iiop.hrl").-include_lib("orber/src/ifr_objects.hrl").-include_lib("orber/include/ifr_types.hrl").%%-----------------------------------------------------------------%% External exports%%------------------------------------------------------------------export([dissect/1, get_def/1, get_name/2, type/1, is_system_exception/1]).%%-----------------------------------------------------------------%% Internal exports%%------------------------------------------------------------------export(['UNKNOWN'/1, 'BAD_PARAM'/1, 'NO_MEMORY'/1, 'IMP_LIMIT'/1, 'COMM_FAILURE'/1, 'INV_OBJREF'/1, 'NO_PERMISSION'/1, 'INTERNAL'/1, 'MARSHAL'/1, 'INITIALIZE'/1, 'NO_IMPLEMENT'/1, 'BAD_TYPECODE'/1, 'BAD_OPERATION'/1, 'NO_RESOURCES'/1, 'NO_RESPONSE'/1, 'PERSIST_STORE'/1, 'BAD_INV_ORDER'/1, 'TRANSIENT'/1, 'FREE_MEM'/1, 'INV_IDENT'/1, 'INV_FLAG'/1, 'INTF_REPOS'/1, 'BAD_CONTEXT'/1, 'OBJ_ADAPTER'/1, 'DATA_CONVERSION'/1, 'OBJECT_NOT_EXIST'/1, 'TRANSACTION_REQUIRED'/1, 'TRANSACTION_ROLLEDBACK'/1, 'INVALID_TRANSACTION'/1, 'INV_POLICY'/1, 'CODESET_INCOMPATIBLE'/1, 'REBIND'/1, 'TIMEOUT'/1, 'TRANSACTION_UNAVAILABLE'/1, 'TRANSACTION_MODE'/1, 'BAD_QOS'/1]).-define(DEBUG_LEVEL, 5).%%-----------------------------------------------------------------%% Function : is_system_exception%% Arguments : Exception - record()%% Returns : true | false%% Raises : %% Description: Check if CORBA system exception or user defined%%-----------------------------------------------------------------is_system_exception({'EXCEPTION', E}) -> is_system_exception(E);is_system_exception(E) when tuple(E) -> ?SYSTEM_EXCEPTION == type(element(1, E));is_system_exception(_E) -> corba:raise(#'BAD_PARAM'{completion_status=?COMPLETED_NO}).%%-----------------------------------------------------------------%% Function : type%% Arguments : ExceptionName - atom()%% Returns : ?SYSTEM_EXCEPTION | ?USER_EXCEPTION%% Raises : %% Description: Check if CORBA system exception or user defined%%-----------------------------------------------------------------type('UNKNOWN') -> ?SYSTEM_EXCEPTION;type('BAD_PARAM') -> ?SYSTEM_EXCEPTION;type('NO_MEMORY') -> ?SYSTEM_EXCEPTION;type('IMP_LIMIT') -> ?SYSTEM_EXCEPTION;type('COMM_FAILURE') -> ?SYSTEM_EXCEPTION;type('INV_OBJREF') -> ?SYSTEM_EXCEPTION;type('NO_PERMISSION') -> ?SYSTEM_EXCEPTION;type('INTERNAL') -> ?SYSTEM_EXCEPTION;type('MARSHAL') -> ?SYSTEM_EXCEPTION;type('INITIALIZE') -> ?SYSTEM_EXCEPTION;type('NO_IMPLEMENT') -> ?SYSTEM_EXCEPTION;type('BAD_TYPECODE') -> ?SYSTEM_EXCEPTION;type('BAD_OPERATION') -> ?SYSTEM_EXCEPTION;type('NO_RESOURCES') -> ?SYSTEM_EXCEPTION;type('NO_RESPONSE') -> ?SYSTEM_EXCEPTION;type('PERSIST_STORE') -> ?SYSTEM_EXCEPTION;type('BAD_INV_ORDER') -> ?SYSTEM_EXCEPTION;type('TRANSIENT') -> ?SYSTEM_EXCEPTION;type('FREE_MEM') -> ?SYSTEM_EXCEPTION;type('INV_IDENT') -> ?SYSTEM_EXCEPTION;type('INV_FLAG') -> ?SYSTEM_EXCEPTION;type('INTF_REPOS') -> ?SYSTEM_EXCEPTION;type('BAD_CONTEXT') -> ?SYSTEM_EXCEPTION;type('OBJ_ADAPTER') -> ?SYSTEM_EXCEPTION;type('DATA_CONVERSION') -> ?SYSTEM_EXCEPTION;type('OBJECT_NOT_EXIST') -> ?SYSTEM_EXCEPTION;type('TRANSACTION_REQUIRED') -> ?SYSTEM_EXCEPTION;type('TRANSACTION_ROLLEDBACK') -> ?SYSTEM_EXCEPTION;type('INVALID_TRANSACTION') -> ?SYSTEM_EXCEPTION;type('INV_POLICY') -> ?SYSTEM_EXCEPTION;type('CODESET_INCOMPATIBLE') -> ?SYSTEM_EXCEPTION;type('REBIND') -> ?SYSTEM_EXCEPTION;type('TIMEOUT') -> ?SYSTEM_EXCEPTION;type('TRANSACTION_UNAVAILABLE') -> ?SYSTEM_EXCEPTION;type('TRANSACTION_MODE') -> ?SYSTEM_EXCEPTION;type('BAD_QOS') -> ?SYSTEM_EXCEPTION;type(_) -> ?USER_EXCEPTION.%%-----------------------------------------------------------------%% Function : get_def%% Arguments : Exception - record()%% Returns : {Type, TypeCode, Exc}%% Raises : %% Description: Returns the TC for the supplied exception%%-----------------------------------------------------------------get_def(Exception) -> [Exc, TypeId | _] = tuple_to_list(Exception), case type(Exc) of ?SYSTEM_EXCEPTION -> {?SYSTEM_EXCEPTION, get_system_exception_def(Exc), Exception}; ?USER_EXCEPTION -> case orber:light_ifr() of true -> case catch orber_ifr:get_tc(TypeId, ?IFR_ExceptionDef) of {'EXCEPTION', NewExc} -> {?SYSTEM_EXCEPTION, get_system_exception_def(NewExc), NewExc}; TC -> {?USER_EXCEPTION, TC, Exception} end; false -> case mnesia:dirty_index_read(ir_ExceptionDef, TypeId, #ir_ExceptionDef.id) of [ExcDef] when record(ExcDef, ir_ExceptionDef) -> {?USER_EXCEPTION, ExcDef#ir_ExceptionDef.type, Exception}; Other -> orber:dbg("[~p] ~p:get_user_exception_type(~p).~n" "IFR Id not found: ~p", [?LINE, ?MODULE, TypeId, Other], ?DEBUG_LEVEL), NewExc = #'UNKNOWN'{minor=(?CORBA_OMGVMCID bor 1), completion_status=?COMPLETED_MAYBE}, {?SYSTEM_EXCEPTION, get_system_exception_def(NewExc), NewExc} end end end.%%-----------------------------------------------------------------%% Function : get_name%% Arguments : TypeId - string()%% Type - ?SYSTEM_EXCEPTION ( | ?USER_EXCEPTION)%% Returns : ExceptionName - atom()%% Raises : #'UNKNOWN'{}%% Description: Extract exception name%%-----------------------------------------------------------------get_name(TypeId, ?SYSTEM_EXCEPTION) -> ExcName = case string:tokens(TypeId, ":/") of [_IDL, _OMGORG, _CORBA, Name, _Version] when list(Name) -> list_to_atom(Name); [_IDL, _CORBA, Name, _Version] when list(Name) -> %% We should remove this case but we keep it for now due to backward %% compatible reasons. list_to_atom(Name); Other -> %% The CORBA-spec states that this exception should be raised if %% it's a system exception we do not support. orber:dbg("[~p] ~p:get_system_exception_name(~p).~n" "Unknown System Exception: ~p", [?LINE, ?MODULE, TypeId, Other], ?DEBUG_LEVEL), corba:raise(#'UNKNOWN'{minor=(?CORBA_OMGVMCID bor 2), completion_status=?COMPLETED_MAYBE}) end, case type(ExcName) of ?SYSTEM_EXCEPTION -> ExcName; What -> orber:dbg("[~p] ~p:get_system_exception_name(~p).~n" "Unknown System Exception: ~p", [?LINE, ?MODULE, TypeId, What], ?DEBUG_LEVEL), corba:raise(#'UNKNOWN'{minor=(?CORBA_OMGVMCID bor 2), completion_status=?COMPLETED_MAYBE}) end. %%-----------------------------------------------------------------%% Generate system exception TypeCode%%-----------------------------------------------------------------get_system_exception_def(ExcName) when atom(ExcName) -> Name = atom_to_list(ExcName), {'tk_except', "IDL:omg.org/CORBA/" ++ Name ++ ":1.0", Name, [{"minor",'tk_ulong'}, {"completed", {'tk_enum', "", "completion_status", ["COMPLETED_YES", "COMPLETED_NO", "COMPLETED_MAYBE"]}}]};get_system_exception_def(Exc) -> get_system_exception_def(element(1, Exc)).%%-----------------------------------------------------------------%% Mapping minor codes to a printable string.%%-----------------------------------------------------------------dissect({'EXCEPTION', Exc}) -> dissect(Exc);dissect(Exception) when tuple(Exception) -> [Exc, TypeId | _] = tuple_to_list(Exception), case type(Exc) of ?USER_EXCEPTION -> {ok, lists:flatten(io_lib:format("~n------------- EXCEPTION INFO --------------User Defined Exception.: ~pIFR Id.................: ~s-------------------------------------------~n", [Exc, TypeId]))}; ?SYSTEM_EXCEPTION -> case map_exc(Exception) of {ok, String} -> {ok, lists:flatten(String)}; {error, Reason} -> {error, Reason} end end;dissect(_What) -> {error, "Not a correct exception supplied to orber_exceptions:dissect/1"}. map_exc({Name, _, Minor, Status}) when integer(Minor) -> case lookup_vendor(Minor) of {true, Vendor, VMCID} -> case catch ?MODULE:Name(Minor) of MinorInfo when list(MinorInfo) -> {ok, io_lib:format("~n------------- EXCEPTION INFO --------------Vendor.....: ~sVMCID......: ~sException..: ~pStatus.....: ~pMinor Code.: ~pInfo.......: ~s-------------------------------------------~n", [Vendor, VMCID, Name, Status, (Minor band 16#fff), MinorInfo])}; _ -> {ok, io_lib:format("~n------------- EXCEPTION INFO --------------Vendor.....: ~sVMCID......: ~sException..: ~pStatus.....: ~pMinor Code.: ~pInfo.......: -------------------------------------~n", [Vendor, VMCID, Name, Status, (Minor band 16#fff)])} end; {false, Vendor, VMCID} -> {ok, io_lib:format("~n------------- EXCEPTION INFO --------------Vendor.....: ~sVMCID......: ~sException..: ~pStatus.....: ~pMinor Code.: ~pInfo.......: --------------------------------------------~n", [Vendor, VMCID, Name, Status, (Minor band 16#fff)])} end;map_exc(_) -> {error, "Not a correct exception supplied to orber_exceptions:map_exc/1"}. lookup_vendor(Minor) when (?ORBER_VMCID bxor Minor) < 16#0fff -> {true, "Orber", "0x45520000"};lookup_vendor(Minor) when (?CORBA_OMGVMCID bxor Minor) < 16#0fff -> {true, "OMG", "0x4f4d0000"};lookup_vendor(Minor) when (?IONA_VMCID_1 bxor Minor) < 16#0fff -> {false, "IONA", "0x4f4f0000"};lookup_vendor(Minor) when (?IONA_VMCID_2 bxor Minor) < 16#0fff -> {false, "IONA", "0x49540000"};lookup_vendor(Minor) when (?SUN_VMCID bxor Minor) < 16#0fff -> {false, "SUN", "0x53550000"};lookup_vendor(Minor) when (?BORLAND_VMCID bxor Minor) < 16#0fff -> {false, "Borland", "0x56420000"};lookup_vendor(Minor) when (?TAO_VMCID bxor Minor) < 16#0fff -> {false, "TAO", "0x54410000"};lookup_vendor(Minor) when (?PRISMTECH_VMCID bxor Minor) < 16#0fff -> {false, "PrismTech", "0x50540000"};lookup_vendor(Minor) when integer(Minor), Minor =< ?ULONGMAX -> {false, "undefined", extract_VMCID(Minor)};lookup_vendor(Minor) when integer(Minor), Minor =< ?ULONGMAX -> {false, "Unknown", "Unable to extract it"}.extract_VMCID(Int) -> int_to_hex_str(3, ((Int bsr 8) band 16#fffff0), ["00"]).int_to_hex_str(0, _, Acc) -> lists:flatten(["0x" | Acc]);int_to_hex_str(N, Int, Acc) -> int_to_hex_str(N-1, (Int bsr 8), [int_to_hex((16#ff band Int))|Acc]). int_to_hex(B) when B < 256, B >= 0 -> N1 = B div 16, N2 = B rem 16, [code_character(N1), code_character(N2)].code_character(N) when N < 10 -> $0 + N;code_character(N) -> $a + (N - 10).%% The following functions all maps to a system exception. %% UNKNOWN - OMG'UNKNOWN'(?CORBA_OMGVMCID bor 1) -> "Unlisted user exception received by client";'UNKNOWN'(?CORBA_OMGVMCID bor 2) -> "Non-standard System Exceptionnot supported";%% UNKNOWN - Orber'UNKNOWN'(?ORBER_VMCID bor 1) -> "Missing beam-file. Unable to extract TC.";'UNKNOWN'(_) -> "-".%% BAD_PARAM - OMG'BAD_PARAM'(?CORBA_OMGVMCID bor 1) -> "Failure to register, unregister, or lookup value factory";'BAD_PARAM'(?CORBA_OMGVMCID bor 2) -> "RID already defined in IFR";'BAD_PARAM'(?CORBA_OMGVMCID bor 3) -> "Name already used in the context in IFR";'BAD_PARAM'(?CORBA_OMGVMCID bor 4) -> "Target is not a valid container";'BAD_PARAM'(?CORBA_OMGVMCID bor 5) -> "Name clash in inherited context";
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?