18403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// Copyright (c) 2011, Mike Samuel
28403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// All rights reserved.
38403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel//
48403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// Redistribution and use in source and binary forms, with or without
58403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// modification, are permitted provided that the following conditions
68403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// are met:
78403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel//
88403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// Redistributions of source code must retain the above copyright
98403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// notice, this list of conditions and the following disclaimer.
108403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// Redistributions in binary form must reproduce the above copyright
118403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// notice, this list of conditions and the following disclaimer in the
128403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// documentation and/or other materials provided with the distribution.
138403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// Neither the name of the OWASP nor the names of its contributors may
148403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// be used to endorse or promote products derived from this software
158403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// without specific prior written permission.
168403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
178403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
188403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
198403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
208403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
218403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
228403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
238403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
248403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
258403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
268403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
278403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel// POSSIBILITY OF SUCH DAMAGE.
288403881c365ab36b721ccc4500af1b3a5bd25870mikesamuel
295c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.compackage org.owasp.html;
305c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com
315c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.comimport com.google.common.base.Throwables;
325c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com
334e867904c8295537803c1c8a076e130df5674b58mikesamuel/**
344e867904c8295537803c1c8a076e130df5674b58mikesamuel * Receives notification of problems.
354e867904c8295537803c1c8a076e130df5674b58mikesamuel *
364e867904c8295537803c1c8a076e130df5674b58mikesamuel * @author Mike Samuel <mikesamuel@gmail.com>
374e867904c8295537803c1c8a076e130df5674b58mikesamuel */
385c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.compublic interface Handler<T> {
394e867904c8295537803c1c8a076e130df5674b58mikesamuel
405c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  void handle(T x);
415c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com
424e867904c8295537803c1c8a076e130df5674b58mikesamuel  /** A handler that does nothing given any input. */
43f06f9a5ed2a3dfd88320a8ad14ae1c032c6a80cfmikesamuel  public static final Handler<Object> DO_NOTHING = new Handler<Object>() {
445c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com    public void handle(Object x) {
455c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com      // Really, do nothing.
465c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com    }
475c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  };
485c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com
494e867904c8295537803c1c8a076e130df5674b58mikesamuel  /**
504e867904c8295537803c1c8a076e130df5674b58mikesamuel   * A handler that re-raises an error, wrapping it in a runtime exception if
514e867904c8295537803c1c8a076e130df5674b58mikesamuel   * necessary.
524e867904c8295537803c1c8a076e130df5674b58mikesamuel   */
535c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  public static final Handler<Throwable> PROPAGATE = new Handler<Throwable>() {
545c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com    public void handle(Throwable th) {
555c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com      Throwables.propagate(th);
565c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com    }
575c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com  };
585c702c12be71d8070da9287cc4a044617dd726a7manico.james@gmail.com}
59