PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/library/error/error_handler.e

http://github.com/jocelyn/EiffelWebReloaded
Specman e | 161 lines | 123 code | 28 blank | 10 comment | 5 complexity | a3491dffee795ad1459a85d82051fcb3 MD5 | raw file
  1note
  2	description : "Objects that handle error..."
  3	legal: "See notice at end of class."
  4	status: "See notice at end of class."
  5	date: "$Date$"
  6	revision: "$Revision$"
  7
  8class
  9	ERROR_HANDLER
 10
 11inherit
 12	ANY
 13
 14	DEBUG_OUTPUT
 15
 16create
 17	make
 18
 19feature {NONE} -- Initialization
 20
 21	make
 22			-- Initialize `Current'.
 23		do
 24			create {ARRAYED_LIST [ERROR]} errors.make (3)
 25			create error_added_actions
 26		end
 27
 28feature -- Status
 29
 30	has_error: BOOLEAN
 31			-- Has error?
 32		do
 33			Result := count > 0
 34		end
 35
 36	count: INTEGER
 37		do
 38			Result := errors.count
 39		end
 40
 41feature {ERROR_HANDLER, ERROR_VISITOR} -- Restricted access
 42
 43	errors: LIST [ERROR]
 44			-- Errors container
 45
 46feature -- Status report
 47
 48	debug_output: STRING
 49			-- String that should be displayed in debugger to represent `Current'.
 50		do
 51			if has_error then
 52				Result := count.out +  " errors"
 53			else
 54				Result := "no error"
 55			end
 56		end
 57
 58feature -- Events
 59
 60	error_added_actions: ACTION_SEQUENCE [TUPLE [ERROR]]
 61			-- Actions triggered when a new error is added
 62
 63feature {NONE} -- Event: implementation
 64
 65	on_error_added (e: ERROR)
 66			-- Error `e' was just added
 67		do
 68			error_added_actions.call ([e])
 69		end
 70
 71feature -- Basic operation
 72
 73	add_error (a_error: ERROR)
 74			-- Add `a_error' to the stack of error
 75		do
 76			errors.force (a_error)
 77			on_error_added (a_error)
 78		end
 79
 80	add_error_details, add_custom_error (a_code: INTEGER; a_name: STRING; a_message: detachable STRING_32)
 81			-- Add custom error to the stack of error
 82		local
 83			e: ERROR_CUSTOM
 84		do
 85			create e.make (a_code, a_name, a_message)
 86			add_error (e)
 87		end
 88
 89	append (other: ERROR_HANDLER)
 90			-- Append errors from `a_err_handler'
 91		local
 92			other_errs: LIST [ERROR]
 93		do
 94			other_errs := other.errors
 95			if other_errs.count > 0 then
 96				from
 97					other_errs.start
 98				until
 99					other_errs.after
100				loop
101					add_error (other_errs.item)
102					other_errs.forth
103				end
104			end
105		ensure
106			other_error_appended: other.has_error implies has_error
107			new_count: count = old count + other.count
108		end
109
110feature -- Access
111
112	as_single_error: detachable ERROR
113		do
114			if count > 1 then
115				create {ERROR_GROUP} Result.make (errors)
116			elseif count > 0 then
117				Result := errors.first
118			end
119		ensure
120			has_error_implies_result_attached: has_error implies Result /= Void
121		end
122
123	as_string_representation: STRING
124		require
125			has_error
126		do
127			if attached as_single_error as e then
128				Result := e.string_representation
129			else
130				check has_error: False end
131				Result := "Error occured"
132			end
133		end
134
135feature -- Element changes
136
137	concatenate
138			-- Concatenate into a single error if any
139		do
140			if count > 1 and then attached as_single_error as e then
141				wipe_out
142				errors.force (e)
143			end
144		end
145
146	reset, wipe_out
147		do
148			errors.wipe_out
149		end
150
151note
152	copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
153	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
154	source: "[
155			Eiffel Software
156			5949 Hollister Ave., Goleta, CA 93117 USA
157			Telephone 805-685-1006, Fax 805-685-6869
158			Website http://www.eiffel.com
159			Customer support http://support.eiffel.com
160		]"
161end