Anonymous avatar Anonymous committed aa40177

remove util (factored out as clj-argutil)

Comments (0)

Files changed (1)

src/main/clj/org/bituf/clj_dbcp/util.clj

-(ns org.bituf.clj-dbcp.util
-  "Miscellaneous utility functions that may be useful while using Clj-DBCP, e.g.
-  1. Reading properties files
-  2. JNDI tree printing (diagnostics only - NOT RECOMMENDED FOR PRODUCTION USE)
-     Adapted from: http://tripoverit.blogspot.com/2007/03/print-jndi-tree.html"
-  (:import (javax.naming Binding Context InitialContext))
-  (:import (javax.naming NameClassPair NamingEnumeration)))
-
-
-;; ===== Properties handling =====
-
-(defn property-map
-  "Transform a given Properties instance to a map."
-  [^java.util.Properties properties]
-  (let [ks (into [] (.stringPropertyNames properties))
-        vs (into [] (map #(.getProperty properties %) ks))]
-    (zipmap ks vs)))
-
-
-(defn strkey-to-keyword
-  "Given a map with every key a string, convert keys to keywords.
-  Input: {\"a\" 10 \"b\" \"20\"}
-  Returns: {:a 10 :b \"20\"}"
-  [m]
-  (assert (map? m))
-  (into {} (map #(let [k (first %)]
-                   (assert (string? k))
-                   [(keyword k) (last %)]) (seq m))))
-
-
-(defn true-value?
-  "Tell whether a given value is equivalent to true."
-  [any]
-  (if (string? any)
-    (or
-      (= "true" (.toLowerCase any))
-      (= "on"   (.toLowerCase any)))
-    (if (number? any)
-      (> any 0)
-      (true? any))))
-
-
-;; ===== JNDI diagnostic functions (NOT RECOMMENDED FOR PRODUCTION USE) =====
-
-(def *root-context* nil)
-
-
-(defmacro with-root-context
-  [root-context & body]
-  `(do
-    (assert (not (nil? ~root-context)))
-    (assert (instance? Context ~root-context))
-    (binding [*root-context* ~root-context]
-      ~@body)))
-
-
-(def indent (atom 0))
-
-
-(defn increase-indent []
-  (swap! indent #(+ % 4)))
-
-
-(defn decrease-indent []
-  (swap! indent #(- % 4)))
-
-
-(defn print-entry
-  [^NameClassPair next-elem]
-  (let [indent-str (apply str
-                     (take @indent
-                       (repeat " ")))]
-    (println indent-str "-->"
-      (.getName next-elem)
-      " (" (type next-elem) "->" (.getClassName next-elem) ")"
-      )))
-
-
-(declare print-jndi-tree)
-
-
-(defn print-ne
-  [^NamingEnumeration ne ^String parent-ctx]
-  (loop []
-    (when (.hasMoreElements ne)
-      (let [next-elem (.nextElement ne)]
-        (print-entry next-elem)
-        (increase-indent)
-        (if (or (instance? Context next-elem)
-              (and (instance? NameClassPair next-elem)
-                (instance? Context (.getObject next-elem))))
-          (print-jndi-tree
-            (if (zero? (.length parent-ctx))
-              (.getName next-elem)
-              (str parent-ctx "/" (.getName next-elem))))
-          (println "** Not drilling "
-            (type (.getObject next-elem))))
-        (decrease-indent))
-      (recur))))
-
-
-(defn print-jndi-tree
-  ([^String ct]
-    (assert (not (nil? ct)))
-    (if (instance? Context *root-context*)
-      (print-ne (.list *root-context* ct) ct)
-      (print-entry *root-context*)))
-  ([]
-   (print-jndi-tree "")))
-
-
-(defn find-jndi-subcontext
-  "Find subcontext in a given JNDI context.
-  context  JNDI context
-  args     string keys"
-  [^Context context & args]
-  (assert (not (nil? args)))
-  (assert (not (some nil? args)))
-  (let [lufn (fn [ctx k] (.lookup ctx k))
-        nctx (reduce lufn context args)]
-    nctx))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.