diff src/clojure/contrib/condition/Condition.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/contrib/condition/Condition.clj	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,43 @@
     1.4 +;;  Copyright (c) Stephen C. Gilardi. All rights reserved.  The use and
     1.5 +;;  distribution terms for this software are covered by the Eclipse Public
     1.6 +;;  License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
     1.7 +;;  be found in the file epl-v10.html at the root of this distribution.  By
     1.8 +;;  using this software in any fashion, you are agreeing to be bound by the
     1.9 +;;  terms of this license.  You must not remove this notice, or any other,
    1.10 +;;  from this software.
    1.11 +;;
    1.12 +;;  Condition.clj
    1.13 +;;
    1.14 +;;  Used by clojure.contrib.condition to implement a "Throwable map"
    1.15 +;;
    1.16 +;;  scgilardi (gmail)
    1.17 +;;  Created 09 June 2009
    1.18 +
    1.19 +(ns clojure.contrib.condition.Condition
    1.20 +  (:gen-class :extends Throwable
    1.21 +              :implements [clojure.lang.IMeta]
    1.22 +              :state state
    1.23 +              :init init
    1.24 +              :post-init post-init
    1.25 +              :constructors {[clojure.lang.IPersistentMap]
    1.26 +                             [String Throwable]}))
    1.27 +
    1.28 +(defn -init
    1.29 +  "Constructs a Condition object with condition (a map) as its
    1.30 +  metadata. Also initializes the superclass with the values at :message
    1.31 +  and :cause, if any, so they are also available via .getMessage and
    1.32 +  .getCause."
    1.33 +  [condition]
    1.34 +  [[(:message condition) (:cause condition)] (atom condition)])
    1.35 +
    1.36 +(defn -post-init
    1.37 +  "Adds :stack-trace to the condition. Drops the bottom 3 frames because
    1.38 +  they are always the same: implementation details of Condition and raise."
    1.39 +  [this condition]
    1.40 +  (swap! (.state this) assoc
    1.41 +         :stack-trace (into-array (drop 3 (.getStackTrace this)))))
    1.42 +
    1.43 +(defn -meta
    1.44 +  "Returns this object's metadata, the condition"
    1.45 +  [this]
    1.46 +  @(.state this))