Skip to content

Instantly share code, notes, and snippets.

@lstoll
Created July 3, 2012 12:39
Show Gist options
  • Save lstoll/3039506 to your computer and use it in GitHub Desktop.
Save lstoll/3039506 to your computer and use it in GitHub Desktop.
Wrapped Java API
;; Creates the wrapped object.
(def domain (JavaWrapper. (.domainLookupByID (conn "test:///default") 1))
;; Implements ILookup, so you can call getters by invoking a keyword
(:name domain) = (.getName domain)
;; Implements Associative, so you can invoke setters via assoc
(assoc domain autostart true) = (.setAutostart domain true)
;; Original Java object accessible via :o key
(:o domain)
=> #<Domain...>
;; Macro provided, to create clojure function that can invoke the Java function on the wrapped object
(defwrapperfn create)
(create domain) = (.create domain) or the the wrapped case, (.create (:o domain))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment