diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 0d1a34a..0000000 --- a/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -epl.html linguist-vendored=true diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE deleted file mode 100644 index 686625a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE +++ /dev/null @@ -1,14 +0,0 @@ -Hi! Thanks for your interest in contributing to this project. - -Clojure contrib projects do not use GitHub issues or pull requests, and -require a signed Contributor Agreement. If you would like to contribute, -please read more about the CA and sign that first (this can be done online). - -Then go to this project's issue tracker in JIRA to create tickets, update -tickets, or submit patches. For help in creating tickets and patches, -please see: - -- Signing the CA: https://clojure.org/community/contributing -- Creating Tickets: https://clojure.org/community/creating_tickets -- Developing Patches: https://clojure.org/community/developing_patches -- Contributing FAQ: https://clojure.org/community/contributing diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml deleted file mode 100644 index bd38321..0000000 --- a/.github/workflows/doc-build.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: Build API Docs - -on: - workflow_dispatch: - -jobs: - call-doc-build-workflow: - uses: clojure/build.ci/.github/workflows/doc-build.yml@master - with: - project: clojure/java.data diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index e2718bd..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Release on demand - -on: - workflow_dispatch: - inputs: - releaseVersion: - description: "Version to release" - required: true - snapshotVersion: - description: "Snapshot version after release" - required: true - -jobs: - call-release: - uses: clojure/build.ci/.github/workflows/release.yml@master - with: - releaseVersion: ${{ github.event.inputs.releaseVersion }} - snapshotVersion: ${{ github.event.inputs.snapshotVersion }} - secrets: inherit \ No newline at end of file diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml deleted file mode 100644 index 2472957..0000000 --- a/.github/workflows/snapshot.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: Snapshot on demand - -on: [workflow_dispatch] - -jobs: - call-snapshot: - uses: clojure/build.ci/.github/workflows/snapshot.yml@master - secrets: inherit diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 1fa127c..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: Test - -on: [push] - -jobs: - call-test: - uses: clojure/build.ci/.github/workflows/test.yml@master diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 023f853..0000000 --- a/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -.calva/output-window -.calva/repl.calva-repl -.classpath -.clj-kondo/.cache -.cpcache/ -.lsp/.cache -.nrepl-port -.portal -.project -.settings -.socket-repl-port -/target diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index fbca448..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,58 +0,0 @@ -## Change Log - -* Release 1.3.113 on 2025-01-23 - * In builders, for overloaded setters (for which we have matching properties), try to pick the "obviously better" match (using `instance?` against the property value), and only throw if we can't pick one [JDATA-25](https://clojure.atlassian.net/browse/JDATA-25). - * In builders, ignore setters for which we do not have matching properties [JDATA-24](https://clojure.atlassian.net/browse/JDATA-24). - -* Release 1.2.107 on 2024-02-19 - * Update parent pom and tools.logging versions - -* Release 1.1.103 on 2023-12-16 - * IMPORTANT: `org.clojure/tools.logging` is no longer a dependency. If you currently bind `*to-java-object-missing-setter*` to `:log` and you do not otherwise have a dependency on `org.clojure/tools.logging` you will need to add that to your project's direct dependencies. - -* Release 1.0.95 on 2021-12-12 - * Update `org.clojure/tools.logging` to `1.2.1`. - -* Release 1.0.92 on 2021-10-16 - * Support `to-java` for `java.util.Properties` and a hash map JDATA-22. - -* Release 1.0.86 on 2020-07-17 - * Add `from-java-deep` to guarantee deep conversion with same options as `from-java-shallow` [JDATA-21](https://clojure.atlassian.net/browse/JDATA-21). - * Fixes bug in `from-java-shallow` for getters returning `Boolean` (the value was not canonicalized so `false` could be truthy). - -* Release 1.0.78 on 2020-05-31 - * Make exception handling in shallow conversions configurable: an `:exceptions` option may be `:group`, `:omit`, `:quaify`, or `:return`. - * Fix bug in shallow array handling. - -* Release 1.0.73 on 2020-05-31 - * Add `from-java-shallow` to provide functionality similar to `clojure.core/bean` (a shallow conversion) but with options to control behavior (so "dangerous" methods that appear as getters can be omitted). - * Bump `org.clojure/tools.logging` to `1.1.0`. - * Move change log to a separate file. - * Improve documentation around property naming and how it corresponds to setter function names. - -* Release 1.0.64 on 2020-02-18 - * Switch to 1.0.x versioning. - * Bump `org.clojure/tools.logging` to `0.6.0`. - * Add basic tests for the builder [JDATA-20](https://clojure.atlassian.net/browse/JDATA-20). - -* Release 0.2.0 on 2020-01-02 - * Add `clojure.java.data.builder/to-java` to construct Java objects from builders using hash maps of properties JDATA-18. - -* Release 0.1.5 on 2019-12-20 - * Add `set-properties` to populate an existing object JDATA-15. - * Add `:clojure.java.data/constructor` metadata support JDATA-16. - -* Release 0.1.4 on 2019-10-13 - * Fix Clojure hash map conversion problems JDATA-14 (problems introduced in 0.1.3) - -* Release 0.1.3 on 2019-10-13 - * Fix `java.util.Map`/Clojure hash map setter handling JDATA-6. - * Fix `Boolean` conversion JDATA-10. - * Fix `SQLException` handling JDATA-12. - -* Release 0.1.2 on 2019-10-12 - * Fix reflection warnings JDATA-2 and JDATA-13. - -* Release 0.1.1 on 2012-04-29 - * Initial release. - * Clojure 1.2 compatibility. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 0aa519c..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,12 +0,0 @@ -This is a [Clojure contrib] project. - -Under the Clojure contrib [guidelines], this project cannot accept -pull requests. All patches must be submitted via [JIRA]. - -See [Contributing] on the Clojure website for -more information on how to contribute. - -[Clojure contrib]: https://clojure.org/community/contrib_libs -[Contributing]: https://clojure.org/community/contributing -[JIRA]: https://clojure.atlassian.net/browse/JDATA -[guidelines]: https://clojure.org/community/contrib_howto diff --git a/LICENSE b/LICENSE deleted file mode 100644 index e246f6a..0000000 --- a/LICENSE +++ /dev/null @@ -1,205 +0,0 @@ -Eclipse Public License - v 1.0 - -THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC -LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM -CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. - -1. DEFINITIONS - -"Contribution" means: - -a) in the case of the initial Contributor, the initial code and documentation - distributed under this Agreement, and -b) in the case of each subsequent Contributor: - i) changes to the Program, and - ii) additions to the Program; - - where such changes and/or additions to the Program originate from and are - distributed by that particular Contributor. A Contribution 'originates' - from a Contributor if it was added to the Program by such Contributor - itself or anyone acting on such Contributor's behalf. Contributions do not - include additions to the Program which: (i) are separate modules of - software distributed in conjunction with the Program under their own - license agreement, and (ii) are not derivative works of the Program. - -"Contributor" means any person or entity that distributes the Program. - -"Licensed Patents" mean patent claims licensable by a Contributor which are -necessarily infringed by the use or sale of its Contribution alone or when -combined with the Program. - -"Program" means the Contributions distributed in accordance with this -Agreement. - -"Recipient" means anyone who receives the Program under this Agreement, -including all Contributors. - -2. GRANT OF RIGHTS - a) Subject to the terms of this Agreement, each Contributor hereby grants - Recipient a non-exclusive, worldwide, royalty-free copyright license to - reproduce, prepare derivative works of, publicly display, publicly - perform, distribute and sublicense the Contribution of such Contributor, - if any, and such derivative works, in source code and object code form. - b) Subject to the terms of this Agreement, each Contributor hereby grants - Recipient a non-exclusive, worldwide, royalty-free patent license under - Licensed Patents to make, use, sell, offer to sell, import and otherwise - transfer the Contribution of such Contributor, if any, in source code and - object code form. This patent license shall apply to the combination of - the Contribution and the Program if, at the time the Contribution is - added by the Contributor, such addition of the Contribution causes such - combination to be covered by the Licensed Patents. The patent license - shall not apply to any other combinations which include the Contribution. - No hardware per se is licensed hereunder. - c) Recipient understands that although each Contributor grants the licenses - to its Contributions set forth herein, no assurances are provided by any - Contributor that the Program does not infringe the patent or other - intellectual property rights of any other entity. Each Contributor - disclaims any liability to Recipient for claims brought by any other - entity based on infringement of intellectual property rights or - otherwise. As a condition to exercising the rights and licenses granted - hereunder, each Recipient hereby assumes sole responsibility to secure - any other intellectual property rights needed, if any. For example, if a - third party patent license is required to allow Recipient to distribute - the Program, it is Recipient's responsibility to acquire that license - before distributing the Program. - d) Each Contributor represents that to its knowledge it has sufficient - copyright rights in its Contribution, if any, to grant the copyright - license set forth in this Agreement. - -3. REQUIREMENTS - -A Contributor may choose to distribute the Program in object code form under -its own license agreement, provided that: - - a) it complies with the terms and conditions of this Agreement; and - b) its license agreement: - i) effectively disclaims on behalf of all Contributors all warranties - and conditions, express and implied, including warranties or - conditions of title and non-infringement, and implied warranties or - conditions of merchantability and fitness for a particular purpose; - ii) effectively excludes on behalf of all Contributors all liability for - damages, including direct, indirect, special, incidental and - consequential damages, such as lost profits; - iii) states that any provisions which differ from this Agreement are - offered by that Contributor alone and not by any other party; and - iv) states that source code for the Program is available from such - Contributor, and informs licensees how to obtain it in a reasonable - manner on or through a medium customarily used for software exchange. - -When the Program is made available in source code form: - - a) it must be made available under this Agreement; and - b) a copy of this Agreement must be included with each copy of the Program. - Contributors may not remove or alter any copyright notices contained - within the Program. - -Each Contributor must identify itself as the originator of its Contribution, -if -any, in a manner that reasonably allows subsequent Recipients to identify the -originator of the Contribution. - -4. COMMERCIAL DISTRIBUTION - -Commercial distributors of software may accept certain responsibilities with -respect to end users, business partners and the like. While this license is -intended to facilitate the commercial use of the Program, the Contributor who -includes the Program in a commercial product offering should do so in a manner -which does not create potential liability for other Contributors. Therefore, -if a Contributor includes the Program in a commercial product offering, such -Contributor ("Commercial Contributor") hereby agrees to defend and indemnify -every other Contributor ("Indemnified Contributor") against any losses, -damages and costs (collectively "Losses") arising from claims, lawsuits and -other legal actions brought by a third party against the Indemnified -Contributor to the extent caused by the acts or omissions of such Commercial -Contributor in connection with its distribution of the Program in a commercial -product offering. The obligations in this section do not apply to any claims -or Losses relating to any actual or alleged intellectual property -infringement. In order to qualify, an Indemnified Contributor must: -a) promptly notify the Commercial Contributor in writing of such claim, and -b) allow the Commercial Contributor to control, and cooperate with the -Commercial Contributor in, the defense and any related settlement -negotiations. The Indemnified Contributor may participate in any such claim at -its own expense. - -For example, a Contributor might include the Program in a commercial product -offering, Product X. That Contributor is then a Commercial Contributor. If -that Commercial Contributor then makes performance claims, or offers -warranties related to Product X, those performance claims and warranties are -such Commercial Contributor's responsibility alone. Under this section, the -Commercial Contributor would have to defend claims against the other -Contributors related to those performance claims and warranties, and if a -court requires any other Contributor to pay any damages as a result, the -Commercial Contributor must pay those damages. - -5. NO WARRANTY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR -IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, -NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each -Recipient is solely responsible for determining the appropriateness of using -and distributing the Program and assumes all risks associated with its -exercise of rights under this Agreement , including but not limited to the -risks and costs of program errors, compliance with applicable laws, damage to -or loss of data, programs or equipment, and unavailability or interruption of -operations. - -6. DISCLAIMER OF LIABILITY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY -CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION -LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE -EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY -OF SUCH DAMAGES. - -7. GENERAL - -If any provision of this Agreement is invalid or unenforceable under -applicable law, it shall not affect the validity or enforceability of the -remainder of the terms of this Agreement, and without further action by the -parties hereto, such provision shall be reformed to the minimum extent -necessary to make such provision valid and enforceable. - -If Recipient institutes patent litigation against any entity (including a -cross-claim or counterclaim in a lawsuit) alleging that the Program itself -(excluding combinations of the Program with other software or hardware) -infringes such Recipient's patent(s), then such Recipient's rights granted -under Section 2(b) shall terminate as of the date such litigation is filed. - -All Recipient's rights under this Agreement shall terminate if it fails to -comply with any of the material terms or conditions of this Agreement and does -not cure such failure in a reasonable period of time after becoming aware of -such noncompliance. If all Recipient's rights under this Agreement terminate, -Recipient agrees to cease use and distribution of the Program as soon as -reasonably practicable. However, Recipient's obligations under this Agreement -and any licenses granted by Recipient relating to the Program shall continue -and survive. - -Everyone is permitted to copy and distribute copies of this Agreement, but in -order to avoid inconsistency the Agreement is copyrighted and may only be -modified in the following manner. The Agreement Steward reserves the right to -publish new versions (including revisions) of this Agreement from time to -time. No one other than the Agreement Steward has the right to modify this -Agreement. The Eclipse Foundation is the initial Agreement Steward. The -Eclipse Foundation may assign the responsibility to serve as the Agreement -Steward to a suitable separate entity. Each new version of the Agreement will -be given a distinguishing version number. The Program (including -Contributions) may always be distributed subject to the version of the -Agreement under which it was received. In addition, after a new version of the -Agreement is published, Contributor may elect to distribute the Program -(including its Contributions) under the new version. Except as expressly -stated in Sections 2(a) and 2(b) above, Recipient receives no rights or -licenses to the intellectual property of any Contributor under this Agreement, -whether expressly, by implication, estoppel or otherwise. All rights in the -Program not expressly granted under this Agreement are reserved. - -This Agreement is governed by the laws of the State of New York and the -intellectual property laws of the United States of America. No party to this -Agreement will bring a legal action under this Agreement more than one year -after the cause of action arose. Each party waives its rights to a jury trial in -any resulting litigation. - - diff --git a/README.md b/README.md deleted file mode 100644 index 148d4e8..0000000 --- a/README.md +++ /dev/null @@ -1,185 +0,0 @@ -# java.data - -Functions for recursively converting Java beans to Clojure and vice -versa. - -You can perform shallow conversions and deep conversions, and `java.data` -provides quite a bit of control over the conversion process. - -Conversion of Clojure maps etc to specific Java types is generally fairly -straightforward, either via regular construction or via "builder" APIs. - -Some Java types, however, are going to be difficult to convert to Clojure, -e.g., Protobuf is particularly problematic because it is all recursive metadata -about types and values: even when you use `:omit` to avoid deep recursion in -an automated conversion, you are not necessarily going to get a useful result. - -## Releases and Dependency Information - -This project follows the version scheme MAJOR.MINOR.COMMITS where MAJOR and MINOR provide some relative indication of the size of the change, but do not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). COMMITS is an ever-increasing counter of commits since the beginning of this repository. - -Latest stable release: 1.3.113 - -* [All Released Versions](https://search.maven.org/#search%7Cga%7C1%7Corg.clojure%20java.data) -* [Development Snapshot Versions](https://repository.sonatype.org/index.html#nexus-search;gav~org.clojure~java.data~~~) - -### [CLI/`deps.edn`](https://clojure.org/reference/deps_and_cli) dependency information: - -```clojure -org.clojure/java.data {:mvn/version "1.3.113"} -``` - -### Leiningen - -```clojure -[org.clojure/java.data "1.3.113"] -``` - -### Maven - -```xml - - org.clojure - java.data - 1.3.113 - -``` - -## Example Usage - -```clojure -(require '[clojure.java.data :as j]) - -;; construct YourJavaClass instance from Clojure data structure -;; (usually a Clojure hash map of properties to set on the instance): -(j/to-java YourJavaClass clojure-property-map) - -;; the 0-arity constructor is called to construct the instance -;; and then the properties are added by calling setters - -;; note that keys in the property map must follow the :camelCase -;; naming of the Java fields to which they correspond, so that -;; the appropriate setter methods can be invoked, e.g., -(j/to-java SomeJavaClass {:stuff 42 :moreStuff "13"}) -;; this is equivalent to: -(let [obj (SomeJavaClass.)] - (.setStuff obj 42) - (.setMoreStuff obj "13")) - -;; represent a javaValue instance in a Clojure data structure: -(j/from-java javaValue) - -;; from-java is the legacy, default API and offers no control over the -;; conversion process; from-java-shallow and from-java-deep accept options -;; that provide control over which properties to omit, how to handle property -;; methods that fail, etc, and should be preferred over the default from-java - -;; populate javaValue instance from a Clojure property hash map -;; (calls a setter for each key/value pair in the hash map): -(j/set-properties javaValue clojure-property-map) - -;; provide constructor arguments via metadata: -(j/to-java YourJavaClass - (with-meta clojure-property-map - {::j/constructor ["constructor" "arguments"]})) -;; constructor arguments must match the parameter types -;; so you may need type hints and coercions on them -``` - -Representing an instance of `YourJavaClass` in a Clojure data structure - -```clojure -(defmethod j/from-java YourJavaClass [instance] - ; your custom logic for turning this instance into a clojure data structure -) -``` - -Constructing an instance of `YourJavaClass` from a Clojure data structure - -```clojure -(defmethod j/to-java [YourJavaClass clojure.lang.APersistentMap] [clazz props] - ; your custom logic for constructing an instance from a property map -) -``` - -### Usage with Builder Classes - -As of 0.2.0, `java.data` adds a new namespace and a new `to-java` -function that supports the Builder Pattern. Instead of just creating an instance -of the specified class and then setting properties on it, this variant works -with an associated "builder" class (or instance), setting properties on it, -and then producing an instance of the specified class from it. - -In Java, that typically looks like: - -```java -MyClass foo = new MyClass.Builder() - .fooBar( 42 ) - .quux( "stuff" ) - .build(); -``` - -That becomes: - -```clojure -(require '[clojure.java.data.builder :as builder]) - -(def foo (builder/to-java MyClass {:fooBar 42 :quux "stuff"})) -``` - -By default, this assumes `MyClass` has a nested class called `Builder`, and the -property methods could be `.fooBar`, `.setFooBar`, or `.withFooBar` (and -`.quux`, `.setQuux`, or `.withQuux`), and then a `.build` method -that produces the `MyClass` object. - -You can also specify an options hash map containing any of the following: - -* `:builder-class` -- the class that should be used for the builder process; by default it will assume an inner class of `clazz` called `Builder`, -* `:builder-props` -- properties used to construct and initialize an instance of the builder class; defaults to an empty hash map; may have `:clojure.java.data/constructor` as metadata to provide constructor arguments for the builder instance, -* `:build-fn` -- the name of the method in the `Builder` class to use to complete the builder process and return the desired class; by default it will try to deduce it, preferring `build` if we find multiple candidates, -* `:ignore-setters?` -- a flag to indicate that methods on the builder class that begin with `set` should be ignored, which may be necessary to avoid ambiguous methods that look like builder properties; by default `setFooBar` and `withQuuxIt` will be treated as builder properties `fooBar` and `quuxIt` if they accept a single argument and return a builder instance. - -Additional arities allow you to specify a builder instance, for cases where the -builder is not simply constructed from a (nested) class, and both a builder class -and a builder instance for more complex cases: - -```clojure -;; requires the options hash map, even if it is empty: -(builder/to-java MyClass (MyClass/builder) {:bar 42 :quux "stuff"} {}) - -;; for cases where the type of the builder instance differs from the actual -;; builder class that should be used for property method return types: -(builder/to-java MyClass MyClassBuilder (MyClass/builder) {:bar 42 :quux "stuff"} {}) -``` - -## Feature comparison to `clojure.core/bean` - -Clojure core provides a `bean` function which has some overlap with java.data. Below is a more detailed comparison: - -Dimension | `bean` | `java.data` --- | ------ | ----------- -find fields | bean introspector | bean introspector - "class" -depth | 1 | recursive without cycle detection -field names | keyword | keyword -extensibility | none | multimethod on class -special casing | none | arrays, iterable, maps, enums, Instant, SQLException, XMLGregorianCalendar -map keys | unhandled | untouched -exception defense | none | none - -## Developer Information - -* [GitHub project](https://github.com/clojure/java.data) -* [Bug Tracker](https://clojure.atlassian.net/browse/JDATA) -* [Continuous Integration](https://github.com/clojure/java.data/actions/workflows/test.yml) - -## Copyright and License - -Copyright (c) Rich Hickey and contributors. All rights reserved. - -The use and distribution terms for this software are covered by the -[Eclipse Public License -1.0](https://opensource.org/license/epl-1-0/) which can be -found in the file epl.html at the root of this distribution. By using -this software in any fashion, you are agreeing to be bound by the -terms of this license. You must not remove this notice, or any other, -from this software. diff --git a/api-index.html b/api-index.html new file mode 100644 index 0000000..fa3cf76 --- /dev/null +++ b/api-index.html @@ -0,0 +1,231 @@ + + + + Index - java.data 1.0.96-SNAPSHOT API documentation + + + + + + + + + +
+ +
+ +
+
+
+
+
+ +

Index of Public Functions and Variables - java.data 1.0.96-SNAPSHOT (in development)

+This page has an alphabetical index of all the documented functions and variables +in java.data. + + +

+

+Shortcuts:
+A B C D + E F G H + I J K L + M +
+N O P Q + R S T U + V W X Y + Z +
+Other +
+
+ +
+

A

+
+
+  
+
+

B

+
+
+  
+
+

C

+
+
+  
+
+

D

+
+
+  
+
+

E

+
+
+  
+
+

F

+
+ from-java                    multimethod   clojure.java.data  Convert a Java object to a Clojure map..
+ from-java-deep               multimethod   clojure.java.data  Convert a Java object to a Clojure map (converting...
+ from-java-shallow            multimethod   clojure.java.data  Convert a Java object to a Clojure map (but do not...
+
+  
+
+

G

+
+
+  
+
+

H

+
+
+  
+
+

I

+
+
+  
+
+

J

+
+
+  
+
+

K

+
+
+  
+
+

L

+
+
+  
+
+

M

+
+
+  
+
+

N

+
+
+  
+
+

O

+
+
+  
+
+

P

+
+
+  
+
+

Q

+
+
+  
+
+

R

+
+
+  
+
+

S

+
+ set-properties               function      clojure.java.data  Given an existing Java object and a Clojure map, u...
+
+  
+
+

T

+
+ *to-java-object-missing-setter* dynamic var clojure.java.data Specify the behavior of missing setters in to-java...
+ to-java                      multimethod   clojure.java.data  Convert Clojure data to an instance of the specifi...
+ to-java                      function      clojure.java.data.builder Given a class and a hash map of properties,...
+
+  
+
+

U

+
+
+  
+
+

V

+
+
+  
+
+

W

+
+
+  
+
+

X

+
+
+  
+
+

Y

+
+
+  
+
+

Z

+
+
+  
+
+

Other

+
+
+  
+
+ +
+
+
+
+
+ +
+
Logo & site design by Tom Hickey.
+ Clojure auto-documentation system by Tom Faulhaber.
+
+ + + + \ No newline at end of file diff --git a/deps.edn b/deps.edn deleted file mode 100644 index 3ffcee7..0000000 --- a/deps.edn +++ /dev/null @@ -1 +0,0 @@ -{:paths ["src/main/clojure"]} diff --git a/epl.html b/epl.html deleted file mode 100644 index fd39122..0000000 --- a/epl.html +++ /dev/null @@ -1,261 +0,0 @@ - - - - - - -Eclipse Public License - Version 1.0 - - - - - - -

Eclipse Public License - v 1.0

- -

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE -PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR -DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS -AGREEMENT.

- -

1. DEFINITIONS

- -

"Contribution" means:

- -

a) in the case of the initial Contributor, the initial -code and documentation distributed under this Agreement, and

-

b) in the case of each subsequent Contributor:

-

i) changes to the Program, and

-

ii) additions to the Program;

-

where such changes and/or additions to the Program -originate from and are distributed by that particular Contributor. A -Contribution 'originates' from a Contributor if it was added to the -Program by such Contributor itself or anyone acting on such -Contributor's behalf. Contributions do not include additions to the -Program which: (i) are separate modules of software distributed in -conjunction with the Program under their own license agreement, and (ii) -are not derivative works of the Program.

- -

"Contributor" means any person or entity that distributes -the Program.

- -

"Licensed Patents" mean patent claims licensable by a -Contributor which are necessarily infringed by the use or sale of its -Contribution alone or when combined with the Program.

- -

"Program" means the Contributions distributed in accordance -with this Agreement.

- -

"Recipient" means anyone who receives the Program under -this Agreement, including all Contributors.

- -

2. GRANT OF RIGHTS

- -

a) Subject to the terms of this Agreement, each -Contributor hereby grants Recipient a non-exclusive, worldwide, -royalty-free copyright license to reproduce, prepare derivative works -of, publicly display, publicly perform, distribute and sublicense the -Contribution of such Contributor, if any, and such derivative works, in -source code and object code form.

- -

b) Subject to the terms of this Agreement, each -Contributor hereby grants Recipient a non-exclusive, worldwide, -royalty-free patent license under Licensed Patents to make, use, sell, -offer to sell, import and otherwise transfer the Contribution of such -Contributor, if any, in source code and object code form. This patent -license shall apply to the combination of the Contribution and the -Program if, at the time the Contribution is added by the Contributor, -such addition of the Contribution causes such combination to be covered -by the Licensed Patents. The patent license shall not apply to any other -combinations which include the Contribution. No hardware per se is -licensed hereunder.

- -

c) Recipient understands that although each Contributor -grants the licenses to its Contributions set forth herein, no assurances -are provided by any Contributor that the Program does not infringe the -patent or other intellectual property rights of any other entity. Each -Contributor disclaims any liability to Recipient for claims brought by -any other entity based on infringement of intellectual property rights -or otherwise. As a condition to exercising the rights and licenses -granted hereunder, each Recipient hereby assumes sole responsibility to -secure any other intellectual property rights needed, if any. For -example, if a third party patent license is required to allow Recipient -to distribute the Program, it is Recipient's responsibility to acquire -that license before distributing the Program.

- -

d) Each Contributor represents that to its knowledge it -has sufficient copyright rights in its Contribution, if any, to grant -the copyright license set forth in this Agreement.

- -

3. REQUIREMENTS

- -

A Contributor may choose to distribute the Program in object code -form under its own license agreement, provided that:

- -

a) it complies with the terms and conditions of this -Agreement; and

- -

b) its license agreement:

- -

i) effectively disclaims on behalf of all Contributors -all warranties and conditions, express and implied, including warranties -or conditions of title and non-infringement, and implied warranties or -conditions of merchantability and fitness for a particular purpose;

- -

ii) effectively excludes on behalf of all Contributors -all liability for damages, including direct, indirect, special, -incidental and consequential damages, such as lost profits;

- -

iii) states that any provisions which differ from this -Agreement are offered by that Contributor alone and not by any other -party; and

- -

iv) states that source code for the Program is available -from such Contributor, and informs licensees how to obtain it in a -reasonable manner on or through a medium customarily used for software -exchange.

- -

When the Program is made available in source code form:

- -

a) it must be made available under this Agreement; and

- -

b) a copy of this Agreement must be included with each -copy of the Program.

- -

Contributors may not remove or alter any copyright notices contained -within the Program.

- -

Each Contributor must identify itself as the originator of its -Contribution, if any, in a manner that reasonably allows subsequent -Recipients to identify the originator of the Contribution.

- -

4. COMMERCIAL DISTRIBUTION

- -

Commercial distributors of software may accept certain -responsibilities with respect to end users, business partners and the -like. While this license is intended to facilitate the commercial use of -the Program, the Contributor who includes the Program in a commercial -product offering should do so in a manner which does not create -potential liability for other Contributors. Therefore, if a Contributor -includes the Program in a commercial product offering, such Contributor -("Commercial Contributor") hereby agrees to defend and -indemnify every other Contributor ("Indemnified Contributor") -against any losses, damages and costs (collectively "Losses") -arising from claims, lawsuits and other legal actions brought by a third -party against the Indemnified Contributor to the extent caused by the -acts or omissions of such Commercial Contributor in connection with its -distribution of the Program in a commercial product offering. The -obligations in this section do not apply to any claims or Losses -relating to any actual or alleged intellectual property infringement. In -order to qualify, an Indemnified Contributor must: a) promptly notify -the Commercial Contributor in writing of such claim, and b) allow the -Commercial Contributor to control, and cooperate with the Commercial -Contributor in, the defense and any related settlement negotiations. The -Indemnified Contributor may participate in any such claim at its own -expense.

- -

For example, a Contributor might include the Program in a commercial -product offering, Product X. That Contributor is then a Commercial -Contributor. If that Commercial Contributor then makes performance -claims, or offers warranties related to Product X, those performance -claims and warranties are such Commercial Contributor's responsibility -alone. Under this section, the Commercial Contributor would have to -defend claims against the other Contributors related to those -performance claims and warranties, and if a court requires any other -Contributor to pay any damages as a result, the Commercial Contributor -must pay those damages.

- -

5. NO WARRANTY

- -

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS -PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS -OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, -ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY -OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely -responsible for determining the appropriateness of using and -distributing the Program and assumes all risks associated with its -exercise of rights under this Agreement , including but not limited to -the risks and costs of program errors, compliance with applicable laws, -damage to or loss of data, programs or equipment, and unavailability or -interruption of operations.

- -

6. DISCLAIMER OF LIABILITY

- -

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT -NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING -WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR -DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED -HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

- -

7. GENERAL

- -

If any provision of this Agreement is invalid or unenforceable under -applicable law, it shall not affect the validity or enforceability of -the remainder of the terms of this Agreement, and without further action -by the parties hereto, such provision shall be reformed to the minimum -extent necessary to make such provision valid and enforceable.

- -

If Recipient institutes patent litigation against any entity -(including a cross-claim or counterclaim in a lawsuit) alleging that the -Program itself (excluding combinations of the Program with other -software or hardware) infringes such Recipient's patent(s), then such -Recipient's rights granted under Section 2(b) shall terminate as of the -date such litigation is filed.

- -

All Recipient's rights under this Agreement shall terminate if it -fails to comply with any of the material terms or conditions of this -Agreement and does not cure such failure in a reasonable period of time -after becoming aware of such noncompliance. If all Recipient's rights -under this Agreement terminate, Recipient agrees to cease use and -distribution of the Program as soon as reasonably practicable. However, -Recipient's obligations under this Agreement and any licenses granted by -Recipient relating to the Program shall continue and survive.

- -

Everyone is permitted to copy and distribute copies of this -Agreement, but in order to avoid inconsistency the Agreement is -copyrighted and may only be modified in the following manner. The -Agreement Steward reserves the right to publish new versions (including -revisions) of this Agreement from time to time. No one other than the -Agreement Steward has the right to modify this Agreement. The Eclipse -Foundation is the initial Agreement Steward. The Eclipse Foundation may -assign the responsibility to serve as the Agreement Steward to a -suitable separate entity. Each new version of the Agreement will be -given a distinguishing version number. The Program (including -Contributions) may always be distributed subject to the version of the -Agreement under which it was received. In addition, after a new version -of the Agreement is published, Contributor may elect to distribute the -Program (including its Contributions) under the new version. Except as -expressly stated in Sections 2(a) and 2(b) above, Recipient receives no -rights or licenses to the intellectual property of any Contributor under -this Agreement, whether expressly, by implication, estoppel or -otherwise. All rights in the Program not expressly granted under this -Agreement are reserved.

- -

This Agreement is governed by the laws of the State of New York and -the intellectual property laws of the United States of America. No party -to this Agreement will bring a legal action under this Agreement more -than one year after the cause of action arose. Each party waives its -rights to a jury trial in any resulting litigation.

- - - - diff --git a/index.html b/index.html new file mode 100644 index 0000000..8aacb2c --- /dev/null +++ b/index.html @@ -0,0 +1,291 @@ + + + + clojure.java.data - java.data 1.0.96-SNAPSHOT API documentation + + + + + + + + + +
+ +
+ +
+
+
+
+
+ +

API for clojure.java.data + - java.data 1.0.96-SNAPSHOT (in development) +

+by Cosmin Stejerean, Sean Corfield
+
Full namespace name: clojure.java.data +

+

Overview

+ +
Support for recursively converting Java beans to Clojure and vice versa.
+ + +
+ + + +
+

+

Public Variables and Functions

+
+
+
+

*to-java-object-missing-setter*

+ dynamic var
+

+    
Specify the behavior of missing setters in to-java in the
+default object case, using one of :ignore, :log, :error
+

+    
+    
+    Source
+  
+
+
+

from-java

+ multimethod
+
No usage documentation available
+
Convert a Java object to a Clojure map.
+

+    
+    
+    Source
+  
+
+
+

from-java-deep

+ multimethod
+
No usage documentation available
+
Convert a Java object to a Clojure map (converting deeply).
+
+The second argument is a hash map that offers some control over the
+conversion:
+* :add-class -- if true, add :class with the actual class of the object
+        being converted -- this mimics clojure.core/bean.
+* :exceptions -- controls how getter exceptions should be handled:
+        * :group -- return an :exceptions hash map in the object that
+              contains all the properties that failed, with their exceptions,
+        * :omit -- ignore exceptions and omit the properties that caused them,
+        * :qualify -- return the exception as :<property>/exception and
+              omit the property itself,
+        * :return -- simply return the exception as the value of the property.
+* :omit -- a set of properties (keywords) to omit from the conversion
+        so that unsafe methods are not called (this applies across the whole
+        recursive/deep conversion).
+

+    
+    
+    Source
+  
+
+
+

from-java-shallow

+ multimethod
+
No usage documentation available
+
Convert a Java object to a Clojure map (but do not convert deeply).
+
+The second argument is a hash map that offers some control over the
+conversion:
+* :add-class -- if true, add :class with the actual class of the object
+        being converted -- this mimics clojure.core/bean.
+* :exceptions -- controls how getter exceptions should be handled:
+        * :group -- return an :exceptions hash map in the object that
+              contains all the properties that failed, with their exceptions,
+        * :omit -- ignore exceptions and omit the properties that caused them,
+        * :qualify -- return the exception as :<property>/exception and
+              omit the property itself,
+        * :return -- simply return the exception as the value of the property.
+* :omit -- a set of properties (keywords) to omit from the conversion
+        so that unsafe methods are not called.
+

+    
+    
+    Source
+  
+
+
+

set-properties

+ function
+
Usage: (set-properties instance props)
+
+
Given an existing Java object and a Clojure map, use reflection to
+set the properties.
+

+    
+    
+    Source
+  
+
+
+

to-java

+ multimethod
+
No usage documentation available
+
Convert Clojure data to an instance of the specified Java class.
+Several basic types have obvious conversions, but for a hash map
+reflection is used to set the properties. If the class is an interface, we
+can't create an instance of it, unless the Clojure map already implements it.
+
+When java.time.Instant is available (Java 8+), we can convert a hash map
+containing :nano and :epochSecond to Instant, as this is the reverse of
+Instant->map.
+
+A XMLGregorianCalendar object can be constructed from the following keys
+:year, :month, :day, :hour, :minute, :second, and :timezone.
+

+    
+    
+    Source
+  
+
+ +
+

clojure.java.data.builder

+
A variant of clojure.java.data/to-java that uses a Builder class
+to build the requested class from a hash map of properties.
+ + +
+ + +
+

+

Public Variables and Functions

+
+
+
+

to-java

+ function
+
Usage: (to-java clazz props)
+       (to-java clazz props opts)
+       (to-java clazz instance props opts)
+       (to-java clazz builder instance props opts)
+
+
Given a class and a hash map of properties, figure out the Builder class,
+figure out the setters for the Builder, construct an instance of it and
+produce an instance of the original class. A hash map of options may also
+be provided.
+
+Alternatively, given a class, a builder instance, a hash map of properties,
+and a hash map of options, figure out the setters for the builder class,
+and use the builder instance to produce an instance of the original class.
+
+Finally, given a class, a builder class, a builder instance (possibly of a
+different class), a hash map of properties, and a hash map of options,
+figure out the setters for the builder class, and use the builder instance
+to produce an instance of the original class.
+
+The following options may be provided:
+* :builder-class -- the class that should be used for the builder process;
+    by default we'll assume an inner class of clazz called 'Builder',
+* :builder-props -- properties used to construct and initialize an instance
+    of the builder class; defaults to an empty hash map; may have
+    :clojure.java.data/constructor as metadata to provide constructor
+    arguments for the builder instance,
+* :build-fn -- the name of the method in the Builder class to use to
+    complete the builder process and return the desired class;
+    by default we'll try to deduce it, preferring 'build' if we find
+    multiple candidates,
+* :ignore-setters? -- a flag to indicate that methods on the builder
+    class that begin with 'set' should be ignored, which may be
+    necessary to avoid ambiguous methods that look like builder properties;
+    by default 'setFooBar` will be treated as a builder property 'fooBar'
+    if it accepts a single argument and returns a builder instance.
+

+    
+    
+    Source
+  
+
+ + +
+
+
+
+
+ +
+
Logo & site design by Tom Hickey.
+ Clojure auto-documentation system by Tom Faulhaber.
+
+ + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 6f23cd8..0000000 --- a/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - 4.0.0 - - java.data - 1.3.114-SNAPSHOT - java.data - - https://github.com/clojure/java.data/ - Utilities for working with Java beans from Clojure - - - org.clojure - pom.contrib - 1.3.0 - - - - - Cosmin Stejerean - - - Sean Corfield - - - - - scm:git:git@github.com:clojure/java.data.git - scm:git:git@github.com:clojure/java.data.git - git@github.com:clojure/java.data.git - HEAD - - - - - org.clojure - tools.logging - 1.3.0 - test - - - diff --git a/src/main/clojure/clojure/java/data.clj b/src/main/clojure/clojure/java/data.clj deleted file mode 100644 index 48dea8f..0000000 --- a/src/main/clojure/clojure/java/data.clj +++ /dev/null @@ -1,517 +0,0 @@ -;; Copyright (c) Cosmin Stejerean, Sean Corfield. All rights reserved. -;; The use and distribution terms for this software are covered by the -;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are agreeing to -;; be bound by the terms of this license. You must not remove this notice, -;; or any other, from this software. - -(ns - ^{:author "Cosmin Stejerean, Sean Corfield", - :doc "Support for recursively converting Java beans to Clojure and vice versa."} - clojure.java.data - (:require [clojure.string :as str])) - -(set! *warn-on-reflection* true) - -(def ^:dynamic - *to-java-object-missing-setter* - "Specify the behavior of missing setters in to-java in the - default object case, using one of :ignore, :log, :error - - The default (:ignore) is to ignore missing setters. - * :log uses clojure.tools.logging/info to log a message. - * :error throws a NoSuchFieldException. - - If you bind this to :log, you must have org.clojure/tools.logging - as a dependency in your project. Otherwise, :log will behave like - :error and throw a NoSuchFieldException." - :ignore) - -(defmulti to-java - "Convert Clojure data to an instance of the specified Java class. - Several basic types have obvious conversions, but for a hash map - reflection is used to set the properties. If the class is an interface, we - can't create an instance of it, unless the Clojure map already implements it. - - When java.time.Instant is available (Java 8+), we can convert a hash map - containing :nano and :epochSecond to Instant, as this is the reverse of - Instant->map. - - A XMLGregorianCalendar object can be constructed from the following keys - :year, :month, :day, :hour, :minute, :second, and :timezone." - (fn [destination-type value] [destination-type (class value)])) -(defmulti from-java - "Convert a Java object to a Clojure map." - class) -(defmulti from-java-deep - "Convert a Java object to a Clojure map (converting deeply). - - The second argument is a hash map that offers some control over the - conversion: - * :add-class -- if true, add :class with the actual class of the object - being converted -- this mimics clojure.core/bean. - * :exceptions -- controls how getter exceptions should be handled: - * :group -- return an :exceptions hash map in the object that - contains all the properties that failed, with their exceptions, - * :omit -- ignore exceptions and omit the properties that caused them, - * :qualify -- return the exception as :/exception and - omit the property itself, - * :return -- simply return the exception as the value of the property. - * :omit -- a set of properties (keywords) to omit from the conversion - so that unsafe methods are not called (this applies across the whole - recursive/deep conversion)." - (fn [obj _] (class obj))) -(defmulti from-java-shallow - "Convert a Java object to a Clojure map (but do not convert deeply). - - The second argument is a hash map that offers some control over the - conversion: - * :add-class -- if true, add :class with the actual class of the object - being converted -- this mimics clojure.core/bean. - * :exceptions -- controls how getter exceptions should be handled: - * :group -- return an :exceptions hash map in the object that - contains all the properties that failed, with their exceptions, - * :omit -- ignore exceptions and omit the properties that caused them, - * :qualify -- return the exception as :/exception and - omit the property itself, - * :return -- simply return the exception as the value of the property. - * :omit -- a set of properties (keywords) to omit from the conversion - so that unsafe methods are not called." - (fn [obj _] (class obj))) - -(defn- get-property-descriptors [clazz] - (.getPropertyDescriptors (java.beans.Introspector/getBeanInfo clazz))) - -(comment - (mapv bean (.getPropertyDescriptors (java.beans.Introspector/getBeanInfo java.sql.Statement)))) - -;; getters - -(defn- is-getter [^java.lang.reflect.Method method] - (and method - (= 0 (alength ^"[Ljava.lang.Class;" (.getParameterTypes method))))) - -(defn- make-getter-fn [^java.lang.reflect.Method method] - (fn [instance] - (from-java (.invoke method instance nil)))) - -(defn- make-deep-getter-fn [^java.lang.reflect.Method method opts] - (fn [instance] - (from-java-deep (.invoke method instance nil) opts))) - -(defn- make-shallow-getter-fn [^java.lang.reflect.Method method] - (fn [instance] - (let [r (.invoke method instance nil)] - (if (instance? Boolean r) - (boolean r) - r)))) - -(defn- add-getter-fn [the-map ^java.beans.PropertyDescriptor prop-descriptor] - (let [name (.getName prop-descriptor) - method (.getReadMethod prop-descriptor)] - (if (and (is-getter method) (not (= "class" name))) - (assoc the-map (keyword name) (make-getter-fn method)) - the-map))) - -(defn- add-deep-getter-fn [the-map ^java.beans.PropertyDescriptor prop-descriptor opts] - (let [name (.getName prop-descriptor) - method (.getReadMethod prop-descriptor)] - (if (and (is-getter method) (not (= "class" name))) - (assoc the-map (keyword name) (make-deep-getter-fn method opts)) - the-map))) - -(defn- add-shallow-getter-fn [the-map ^java.beans.PropertyDescriptor prop-descriptor] - (let [name (.getName prop-descriptor) - method (.getReadMethod prop-descriptor)] - (if (and (is-getter method) (not (= "class" name))) - (assoc the-map (keyword name) (make-shallow-getter-fn method)) - the-map))) - -;; setters - -(defn- is-setter [^java.lang.reflect.Method method] - (and method (= 1 (alength (. method (getParameterTypes)))))) - -(defn- get-setter-type [^java.lang.reflect.Method method] - (get (.getParameterTypes method) 0)) - -(defn- make-setter-fn [^java.lang.reflect.Method method] - (fn [instance value] - (.invoke method instance (into-array [(to-java (get-setter-type method) value)])))) - -(defn- add-setter-fn [the-map ^java.beans.PropertyDescriptor prop-descriptor] - (let [name (.getName prop-descriptor) - method (.getWriteMethod prop-descriptor)] - (if (is-setter method) - (assoc the-map (keyword name) (make-setter-fn method)) - the-map))) - -(defn- add-array-methods [^Class acls] - (let [cls (.getComponentType acls) - to (fn [_ sequence] (into-array cls (map (partial to-java cls) - sequence))) - from (fn [obj] (map from-java obj)) - from-deep (fn [obj opts] (map #(from-java-deep % opts) obj)) - from-shallow (fn [obj opts] (map #(from-java-shallow % opts) obj))] - (.addMethod ^clojure.lang.MultiFn to-java [acls Iterable] to) - (.addMethod ^clojure.lang.MultiFn from-java acls from) - (.addMethod ^clojure.lang.MultiFn from-java-deep acls from-deep) - (.addMethod ^clojure.lang.MultiFn from-java-shallow acls from-shallow) - {:to to :from from :from-deep from-deep :from-shallow from-shallow})) - -;; constructor support - -(defn- find-matching-constructors [^Class clazz args] - (let [n (count args)] - (filter (fn [^java.lang.reflect.Constructor ctr] - (and (= n (.getParameterCount ctr)) - (let [pts (map vector (.getParameterTypes ctr) args)] - (every? (fn [[^Class pt arg]] - ;; watch out for boxed types in Clojure - ;; passed to primitive constructor parameters - (cond (.isPrimitive pt) - (and arg ; cannot pass nil to primitive - (or (instance? Number arg) - (instance? Boolean arg))) - (nil? arg) - true ; null is assignable to any non-primitive - :else - (.isAssignableFrom pt (class arg)))) - pts)))) - (.getConstructors clazz)))) - -(defn- find-constructor ^java.lang.reflect.Constructor [^Class clazz args] - (let [candidates (find-matching-constructors clazz args)] - (condp = (count candidates) - 0 (throw (IllegalArgumentException. - (str (.getName clazz) " has no matching constructor" - " for the given argument list"))) - 1 (first candidates) - (throw (IllegalArgumentException. - (str (.getName clazz) " constructor is ambiguous" - " for the given argument list")))))) - -(comment - (find-constructor String ["arg"]) - (find-constructor String [(.getBytes "arg")]) - (find-constructor String [(.getBytes "arg") (int 0) (int 3)]) - (find-constructor String ["too" "many" "arguments"])) - -;; common to-java definitions - -(defmethod to-java :default [^Class cls value] - (if (.isArray cls) - ;; no method for this array type yet - ((:to (add-array-methods cls)) cls value) - value)) - -(defmethod to-java [Enum String] [^Class enum value] - (.invoke (.getDeclaredMethod enum "valueOf" (into-array [String])) - nil (into-array [value]))) - -(declare log-or-throw) -(defmacro defn-log-or-throw [] - (try - (require 'clojure.tools.logging) - `(defn ~'log-or-throw [message#] - (clojure.tools.logging/info message#)) - (catch Throwable _ - `(defn ~'log-or-throw [message#] - (throw (new NoSuchFieldException message#)))))) -(defn-log-or-throw) - -(defn- throw-log-or-ignore-missing-setter [key ^Class clazz] - (let [message (str "Missing setter for " key " in " (.getCanonicalName clazz))] - (cond (= *to-java-object-missing-setter* :error) - (throw (new NoSuchFieldException message)) - (= *to-java-object-missing-setter* :log) - (log-or-throw message)))) - -(comment - (binding [*to-java-object-missing-setter* :log] - (throw-log-or-ignore-missing-setter :foo String)) - ) - -;; feature testing macro, based on suggestion from Chas Emerick: - -(defmacro ^{:private true} when-available - [sym & body] - (try - (when (resolve sym) - (list* 'do body)) - (catch ClassNotFoundException _#))) - -(defmacro ^{:private true} when-not-available - [sym & body] - (try - (when-not (resolve sym) - (list* 'do body)) - (catch ClassNotFoundException _#))) - -;; Clojure hash map conversions - -(when-available - java.time.Instant - (defmethod to-java [java.time.Instant clojure.lang.APersistentMap] [_ props] - (when-not (and (:nano props) (:epochSecond props)) - (throw (IllegalArgumentException. "java.time.Instant requires :nano and :epochSecond"))) - (java.time.Instant/ofEpochSecond (:epochSecond props) (:nano props)))) - -(defn- set-properties-on - "Given an instance, its class, and a hash map of properties, - call the appropriate setters and return the populated object. - - Used by to-java and set-properties below." - [instance ^Class clazz props] - (let [setter-map (reduce add-setter-fn {} (get-property-descriptors clazz))] - (doseq [[key value] props] - (let [setter (get setter-map (keyword key))] - (if (nil? setter) - (throw-log-or-ignore-missing-setter key clazz) - (apply setter [instance value])))) - instance)) - -(defmethod to-java [java.util.Properties clojure.lang.APersistentMap] - [_ props] - (reduce-kv (fn [^java.util.Properties p k v] - (if (or (symbol? k) (keyword? k)) - (.setProperty p (name k) (str v)) - (.setProperty p (str k) (str v))) - p) - (java.util.Properties.) - props)) - -(defmethod to-java [Object clojure.lang.APersistentMap] [^Class clazz props] - (if (.isInterface clazz) - (if (instance? clazz props) - (condp = clazz - ;; make a fresh (mutable) hash map from the Clojure map - java.util.Map (java.util.HashMap. ^java.util.Map props) - ;; Iterable, Serializable, Runnable, Callable - ;; we should probably figure out actual objects to create... - props) - (throw (IllegalArgumentException. - (str (.getName clazz) " is an interface " - "and cannot be constructed from " - (str/join ", " (map name (keys props))))))) - (let [ctr-args (::constructor (meta props)) - ctr (when ctr-args (find-constructor clazz ctr-args)) - instance (try - (if ctr - (.newInstance ctr (object-array ctr-args)) - (.newInstance clazz)) - (catch Throwable t - (throw (IllegalArgumentException. - (str (.getName clazz) - " cannot be constructed") - t))))] - (set-properties-on instance clazz props)))) - -(when-available - biginteger - (defmethod to-java [java.math.BigInteger Object] [_ value] (biginteger value))) - -(when-not-available - biginteger - (defmethod to-java [java.math.BigInteger Object] [_ value] (bigint value))) - -;; set properties on existing objects - -(defn set-properties - "Given an existing Java object and a Clojure map, use reflection to - set the properties." - [instance props] - (set-properties-on instance (class instance) props)) - -;; common from-java definitions - -(defmethod from-java :default [^Object instance] - (let [clazz (.getClass instance)] - (if (.isArray clazz) - ((:from (add-array-methods clazz)) instance) - (let [getter-map (reduce add-getter-fn {} (get-property-descriptors clazz))] - (into {} (for [[key getter-fn] (seq getter-map)] [key (getter-fn instance)])))))) - -(defmethod from-java-deep :default [^Object instance opts] - (let [clazz (.getClass instance)] - (if (.isArray clazz) - ((:from-deep (add-array-methods clazz)) instance opts) - (let [getter-map (reduce #(add-deep-getter-fn %1 %2 opts) {} (get-property-descriptors clazz)) - exs (atom []) - pairs (for [[key getter-fn] (seq getter-map) - :when (not (contains? (:omit opts) key)) - :let [[k v] - (if-let [exh (:exceptions opts)] - (try - [key (getter-fn instance)] - (catch Throwable t - (case exh - :group (swap! exs conj [key t]) - :omit nil - :qualify [(keyword (name key) - "exception") t] - :return [key t]))) - [key (getter-fn instance)])] - :when k] - [k v])] - (cond-> {} - (:add-class opts) (assoc :class (class instance)) - (seq @exs) (assoc :exceptions (into {} @exs)) - (seq pairs) (into pairs)))))) - -(defmethod from-java-shallow :default [^Object instance opts] - (let [clazz (.getClass instance)] - (if (.isArray clazz) - ((:from-shallow (add-array-methods clazz)) instance opts) - (let [getter-map (reduce add-shallow-getter-fn {} (get-property-descriptors clazz)) - exs (atom []) - pairs (for [[key getter-fn] (seq getter-map) - :when (not (contains? (:omit opts) key)) - :let [[k v] - (if-let [exh (:exceptions opts)] - (try - [key (getter-fn instance)] - (catch Throwable t - (case exh - :group (swap! exs conj [key t]) - :omit nil - :qualify [(keyword (name key) - "exception") t] - :return [key t]))) - [key (getter-fn instance)])] - :when k] - [k v])] - (cond-> {} - (:add-class opts) (assoc :class (class instance)) - (seq @exs) (assoc :exceptions (into {} @exs)) - (seq pairs) (into pairs)))))) - -(doseq [clazz [String Character Byte Short Integer Long Float Double - java.math.BigInteger java.math.BigDecimal]] - (derive clazz ::do-not-convert)) - -(defmacro ^{:private true} defnumber [box prim prim-getter] - `(let [conv# (fn [_# ^Number number#] - (~(symbol (str box) "valueOf") - (. number# ~prim-getter)))] - (.addMethod ^clojure.lang.MultiFn to-java [~prim Number] conv#) - (.addMethod ^clojure.lang.MultiFn to-java [~box Number] conv#))) - -(defmacro ^{:private true} defnumbers [& boxes] - (cons `do - (for [box boxes - :let [^Class box-cls (resolve box) - ^Class prim-cls (.get (.getField box-cls "TYPE") - box-cls) - ;; Clojure 1.3: (assert (class? box-cls) (str box ": no class found")) - _ (assert (class? box-cls)) - ;; Clojure 1.3: (assert (class? prim-cls) (str box " has no TYPE field")) - _ (assert (class? prim-cls)) - prim-getter (symbol (str (.getName prim-cls) "Value"))]] - `(defnumber ~box ~(symbol (str box) "TYPE") ~prim-getter)))) - -(defnumbers Byte Short Integer Long Float Double) - -(defmethod from-java ::do-not-convert [value] value) -(prefer-method from-java ::do-not-convert Object) - -(defmethod from-java-deep ::do-not-convert [value _] value) -(prefer-method from-java-deep ::do-not-convert Object) - -(defmethod from-java-shallow ::do-not-convert [value _] value) -(prefer-method from-java-shallow ::do-not-convert Object) - -(defmethod from-java Iterable [instance] - (for [each (seq instance)] (from-java each))) -(prefer-method from-java Iterable Object) - -(defmethod from-java-deep Iterable [instance opts] - (for [each (seq instance)] (from-java-deep each opts))) -(prefer-method from-java-deep Iterable Object) - -(defmethod from-java-shallow Iterable [instance opts] - (for [each (seq instance)] (from-java-shallow each opts))) -(prefer-method from-java-shallow Iterable Object) - -(defmethod from-java java.util.Map [instance] (into {} instance)) -(prefer-method from-java java.util.Map Iterable) - -(defmethod from-java-deep java.util.Map [instance opts] - (reduce (fn [m [k v]] - (assoc m (from-java-deep k opts) (from-java-deep v opts))) - {} - instance)) -(prefer-method from-java-deep java.util.Map Iterable) - -(defmethod from-java-shallow java.util.Map [instance _] (into {} instance)) -(prefer-method from-java-shallow java.util.Map Iterable) - -(defmethod from-java nil [_] nil) -(defmethod from-java java.sql.SQLException [^Object ex] - ((get-method from-java :default) ex)) -(defmethod from-java Boolean [value] (boolean value)) -(defmethod from-java Enum [enum] (str enum)) - -(defmethod from-java-deep nil [_ _] nil) -(defmethod from-java-deep java.sql.SQLException [^Object ex opts] - ((get-method from-java-deep :default) ex opts)) -(defmethod from-java-deep Boolean [value _] (boolean value)) -(defmethod from-java-deep Enum [enum _] (str enum)) - -(defmethod from-java-shallow nil [_ _] nil) -(defmethod from-java-shallow java.sql.SQLException [^Object ex opts] - ((get-method from-java-shallow :default) ex opts)) -(defmethod from-java-shallow Boolean [value _] (boolean value)) -(defmethod from-java-shallow Enum [enum _] (str enum)) - -;; definitions for interfacting with XMLGregorianCalendar - -(defmethod to-java [javax.xml.datatype.XMLGregorianCalendar clojure.lang.APersistentMap] [^Class clazz props] - (let [^javax.xml.datatype.XMLGregorianCalendar instance (.newInstance clazz) - undefined javax.xml.datatype.DatatypeConstants/FIELD_UNDEFINED - getu #(get %1 %2 undefined) - y (getu props :year)] - ;; .setYear is unique in having an overload on int and BigInteger - ;; whereas the other setters only have an int version so avoiding - ;; reflection means special treatment for .setYear - (if (instance? java.math.BigInteger y) - (.setYear instance ^java.math.BigInteger y) - (.setYear instance ^int y)) - (doto instance - (.setMonth (getu props :month)) - (.setDay (getu props :day)) - (.setHour (getu props :hour)) - (.setMinute (getu props :minute)) - (.setSecond (getu props :second)) - (.setTimezone (getu props :timezone))))) - -(defn- from-xml-gregorian-calendar - "Turn an XMLGregorianCalendar object into a clojure map of year, month, day, hour, minute, second and timezone " - [^javax.xml.datatype.XMLGregorianCalendar obj] - (let [date {:year (.getYear obj) - :month (.getMonth obj) - :day (.getDay obj)} - time {:hour (.getHour obj) - :minute (.getMinute obj) - :second (.getSecond obj)} - tz {:timezone (.getTimezone obj)} - is-undefined? #(= javax.xml.datatype.DatatypeConstants/FIELD_UNDEFINED %1)] - (conj {} - (when-not (is-undefined? (:year date)) - date) - (when-not (is-undefined? (:hour time)) - time) - (when-not (is-undefined? (:timezone tz)) - tz)))) - -(defmethod from-java javax.xml.datatype.XMLGregorianCalendar - [obj] (from-xml-gregorian-calendar obj)) -(defmethod from-java-deep javax.xml.datatype.XMLGregorianCalendar - [obj {:keys [add-class]}] - (cond-> (from-xml-gregorian-calendar obj) - add-class (assoc :class (class obj)))) -(defmethod from-java-shallow javax.xml.datatype.XMLGregorianCalendar - [obj {:keys [add-class]}] - (cond-> (from-xml-gregorian-calendar obj) - add-class (assoc :class (class obj)))) diff --git a/src/main/clojure/clojure/java/data/builder.clj b/src/main/clojure/clojure/java/data/builder.clj deleted file mode 100644 index 1bba3d0..0000000 --- a/src/main/clojure/clojure/java/data/builder.clj +++ /dev/null @@ -1,201 +0,0 @@ -;; Copyright (c) Sean Corfield. All rights reserved. -;; The use and distribution terms for this software are covered by the -;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are agreeing to -;; be bound by the terms of this license. You must not remove this notice, -;; or any other, from this software. - -(ns - ^{:author "Sean Corfield", - :doc "A variant of clojure.java.data/to-java that uses a Builder class - to build the requested class from a hash map of properties."} - clojure.java.data.builder - (:require [clojure.java.data :as j])) - -(set! *warn-on-reflection* true) - -(defn- get-builder-class [^Class clazz] - (try - (resolve (symbol (str (.getName clazz) "$Builder"))) - (catch Throwable _))) - -(defn- get-builder ^java.lang.reflect.Method [^Class clazz methods opts] - (let [build-name (:build-fn opts) - candidates - (filter (fn [^java.lang.reflect.Method m] - (and (= 0 (alength ^"[Ljava.lang.Class;" (.getParameterTypes m))) - (= clazz (.getReturnType m)) - (or (nil? build-name) - (= build-name (.getName m))))) - methods)] - (case (count candidates) - 0 (throw (IllegalArgumentException. - (str "Cannot find builder method that returns " - (.getName clazz)))) - 1 (first candidates) - (let [builds (filter (fn [^java.lang.reflect.Method m] - (= "build" (.getName m))) - candidates)] - (case (count builds) - 0 (throw (IllegalArgumentException. - (str "Cannot find 'build' method that returns " - (.getName clazz)))) - (first builds)))))) - -(defn- find-setters [^Class builder methods props opts] - (let [candidates - (filter (fn [^java.lang.reflect.Method m] - (and (= 1 (alength ^"[Ljava.lang.Class;" (.getParameterTypes m))) - (= builder (.getReturnType m)) - (or (not (re-find #"^set[A-Z]" (.getName m))) - (not (:ignore-setters? opts))))) - methods)] - (->> candidates - (reduce - (fn [setter-map ^java.lang.reflect.Method m] - (let [prop (keyword - (cond (re-find #"^set[A-Z]" (.getName m)) - (let [^String n (subs (.getName m) 3)] - (str (Character/toLowerCase (.charAt n 0)) (subs n 1))) - (re-find #"^with[A-Z]" (.getName m)) - (let [^String n (subs (.getName m) 4)] - (str (Character/toLowerCase (.charAt n 0)) (subs n 1))) - :else - (.getName m)))] - (if (contains? props prop) - (if (contains? setter-map prop) - (let [clazz1 (#'j/get-setter-type (second (get setter-map prop))) - clazz2 (#'j/get-setter-type m) - p-val (get props prop)] - (cond (and (instance? clazz1 p-val) - (not (instance? clazz2 p-val))) - setter-map ; existing setter is a better match: - (and (not (instance? clazz1 p-val)) - (instance? clazz2 p-val)) - ;; this setter is a better match: - (assoc setter-map prop [(#'j/make-setter-fn m) m]) - :else ; neither is an obviously better match: - (throw (IllegalArgumentException. - (str "Duplicate setter found for " prop - " in " (.getName builder) " class"))))) - (assoc setter-map prop [(#'j/make-setter-fn m) m])) - ;; if we are not trying to set this property, ignore the setter: - setter-map))) - {}) - (reduce-kv - (fn [m k v] - (assoc m k (first v))) - {})))) - -(defn- build-on [instance setters ^Class clazz props] - (reduce-kv (fn [builder k v] - (if-let [setter (get setters (keyword k))] - (apply setter [instance v]) - (#'j/throw-log-or-ignore-missing-setter k clazz))) - instance - props)) - -(comment - ;; given a class, see if it has a nested Builder class - ;; otherwise we'll need to be told the builder class - ;; and possibly how to create it - (get-builder-class java.util.Locale) - - ;; from the builder class, look for arity-0 methods then return - ;; the original class -- if there's only one, use it, if there - ;; are multiple and one is called "build", use it, else error - (get-builder java.util.Locale (.getMethods java.util.Locale$Builder) {}) - - ;; setters on a builder will have single arguments and will - ;; return the builder class, and will either be: - ;; * B propertyName( T ) - ;; * B setPropertyName( T ) - ;; treat both as setters; thrown exception if they clash - ;; (maybe an option to ignore setXyz( T ) methods?) - (find-setters java.util.Locale$Builder (.getMethods java.util.Locale$Builder) {} {}) - - ;; general pattern will be to: - ;; * get the builder class somehow - ;; * get its public methods - ;; * identify its builder method (or be told it) - ;; * identity its setters by name - ;; * construct the builder (or be given an instance?) - ;; * reduce over the input hash map, - ;; * -- if setter matches key, - ;; * -- then invoke, use result (use j/to-java to build value here?) - ;; * -- else either log, ignore, or throw (per j/*to-java-object-missing-setter*) - ;; * invoke builder on result, return that - (let [clazz java.util.Locale - props {:language "fr"} - opts {} - ^Class builder (get-builder-class clazz)] - (.invoke (get-builder clazz (.getMethods builder) opts) - (build-on (j/to-java builder ^clojure.lang.APersistentMap {}) - (find-setters builder (.getMethods builder) props opts) - builder - props) - nil))) - -(defn to-java - "Given a class and a hash map of properties, figure out the Builder class, - figure out the setters for the Builder, construct an instance of it and - produce an instance of the original class. A hash map of options may also - be provided. - - Alternatively, given a class, a builder instance, a hash map of properties, - and a hash map of options, figure out the setters for the builder class, - and use the builder instance to produce an instance of the original class. - - Finally, given a class, a builder class, a builder instance (possibly of a - different class), a hash map of properties, and a hash map of options, - figure out the setters for the builder class, and use the builder instance - to produce an instance of the original class. - - The following options may be provided: - * :builder-class -- the class that should be used for the builder process; - by default we'll assume an inner class of clazz called 'Builder', - * :builder-props -- properties used to construct and initialize an instance - of the builder class; defaults to an empty hash map; may have - :clojure.java.data/constructor as metadata to provide constructor - arguments for the builder instance, - * :build-fn -- the name of the method in the Builder class to use to - complete the builder process and return the desired class; - by default we'll try to deduce it, preferring 'build' if we find - multiple candidates, - * :ignore-setters? -- a flag to indicate that methods on the builder - class that begin with 'set' should be ignored, which may be - necessary to avoid ambiguous methods that look like builder properties; - by default 'setFooBar` will be treated as a builder property 'fooBar' - if it accepts a single argument and returns a builder instance." - ([clazz props] (to-java clazz props {})) - ([^Class clazz props opts] - (if-let [builder (or (:builder-class opts) (get-builder-class clazz))] - (to-java clazz builder (j/to-java builder (get opts :builder-props {})) props opts) - (throw (IllegalArgumentException. - (str "Unable to deduce a builder class for " (.getName clazz)))))) - ([clazz instance props opts] - (let [builder (or (:builder-class opts) (class instance))] - (to-java clazz builder instance props opts))) - ([^Class clazz ^Class builder instance props opts] - (.invoke (get-builder clazz (.getMethods builder) opts) - (build-on instance - (find-setters builder (.getMethods builder) props opts) - builder - props) - nil))) - -(comment - (to-java java.util.Locale {:language "fr" :region "EG"} - ;; these options are all defaults - {:builder-class java.util.Locale$Builder - :builder-props {} - :build-fn "build"}) - (to-java java.util.Locale (java.util.Locale$Builder.) {:language "fr" :region "EG"} - ;; these options are all defaults - {#_#_:builder-class java.util.Locale$Builder}) - (to-java java.util.Locale (java.util.Locale$Builder.) {:language "fr" :region "EG"} - ;; these options are all defaults - {:builder-class java.util.Locale$Builder - :builder-props {} - :build-fn "build"})) diff --git a/src/test/clojure/.gitignore b/src/test/clojure/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/clojure/clojure/java/data/builder_test.clj b/src/test/clojure/clojure/java/data/builder_test.clj deleted file mode 100644 index eedb8a8..0000000 --- a/src/test/clojure/clojure/java/data/builder_test.clj +++ /dev/null @@ -1,41 +0,0 @@ -;; Copyright (c) Sean Corfield. All rights reserved. -;; The use and distribution terms for this software are covered by the -;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are agreeing to -;; be bound by the terms of this license. You must not remove this notice, -;; or any other, from this software. - -(ns - ^{:author "Sean Corfield", - :doc "Tests for the builder aspects of java.data."} - clojure.java.data.builder-test - (:require [clojure.java.data.builder :as b] - [clojure.test :refer [deftest is]])) - -(deftest locale-builder-tests - (let [l (b/to-java java.util.Locale - {:language "fr" :region "FR"})] - (is (= "fr" (.getLanguage l))) - (is (= "FR" (.getCountry l)))) - (let [l (b/to-java java.util.Locale - {:language "fr" :region "FR"} - {:builder-class java.util.Locale$Builder - :builder-props {} - :build-fn "build"})] - (is (= "fr" (.getLanguage l))) - (is (= "FR" (.getCountry l)))) - (let [l (b/to-java java.util.Locale - (java.util.Locale$Builder.) - {:language "fr" :region "FR"} - {})] - (is (= "fr" (.getLanguage l))) - (is (= "FR" (.getCountry l)))) - (let [l (b/to-java java.util.Locale - (java.util.Locale$Builder.) - {:language "fr" :region "FR"} - {:builder-class java.util.Locale$Builder - :builder-props {} - :build-fn "build"})] - (is (= "fr" (.getLanguage l))) - (is (= "FR" (.getCountry l))))) diff --git a/src/test/clojure/clojure/java/test_data.clj b/src/test/clojure/clojure/java/test_data.clj deleted file mode 100644 index bcbc559..0000000 --- a/src/test/clojure/clojure/java/test_data.clj +++ /dev/null @@ -1,376 +0,0 @@ -;; Copyright (c) Cosmin Stejerean, Sean Corfield. All rights reserved. -;; The use and distribution terms for this software are covered by the -;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) -;; which can be found in the file epl-v10.html at the root of this -;; distribution. By using this software in any fashion, you are agreeing to -;; be bound by the terms of this license. You must not remove this notice, -;; or any other, from this software. - -(ns clojure.java.test-data - (:require [clojure.java.data :as j - :refer [from-java from-java-deep from-java-shallow - set-properties to-java - *to-java-object-missing-setter*]] - [clojure.string :as str] - [clojure.tools.logging :refer [log* info]] - [clojure.test :refer [deftest is testing]]) - (:import (clojure.java.data.test Person Address State Primitive - TestBean6 TestBean9))) - -(deftest clojure-to-java - (let [person (to-java Person {:name "Bob" - :age 30 - :address {:line1 "123 Main St" - :city "Dallas" - :state "TX" - :zip "75432"}})] - (is (= "Bob" (.getName person))) - (is (= 30 (.getAge person))) - (is (= "123 Main St" (.. person getAddress getLine1))) - (is (= "Dallas" (.. person getAddress getCity))) - (is (= State/TX (.. person getAddress getState))) - (is (= "75432" (.. person getAddress getZip))))) - -(deftest clojure-to-java-error-on-missing-setter - (binding [*to-java-object-missing-setter* :error] - (is (thrown-with-msg? NoSuchFieldException #"Missing setter for :foobar in clojure.java.data.test.Person" - (to-java Person {:name "Bob" :foobar "Baz"}))))) - - -(deftest clojure-to-java-ignore-on-missing-setter - (binding [*to-java-object-missing-setter* :ignore] - (let [person (to-java Person {:name "Bob" :foobar "Baz"})] - (is (= "Bob" (.getName person)))))) - -(defmacro with-temporary-root [[var-name new-value] & body] - `(let [current-var# ~var-name] - (alter-var-root (var ~var-name) (fn [ignore#] ~new-value)) - ~@body - (alter-var-root (var ~var-name) (fn [ignore#] current-var#)))) - - -(deftest clojure-to-java-log-on-missing-setter - (binding [*to-java-object-missing-setter* :log] - (with-temporary-root [log* (fn [log level throwable message] - (throw (new Exception (str "invoked " level))))] - (is (thrown-with-msg? Exception #"invoked :info" - (to-java Person {:name "Bob" :foobar "Baz"})))))) - -;; feature testing macro, based on suggestion from Chas Emerick: -(defmacro ^{:private true} when-available - [sym & body] - (try - (when (resolve sym) - (list* 'do body)) - (catch ClassNotFoundException _#))) - -(defmacro ^{:private true} when-not-available - [sym & body] - (try - (when-not (resolve sym) - (list* 'do body)) - (catch ClassNotFoundException _#))) - -(when-available - biginteger - (defn- to-BigInteger [v] (biginteger v))) - -(when-not-available - biginteger - (defn- to-BigInteger [v] (bigint v))) - -(deftest java-to-clojure - (testing "regular" - (let [address (new Address "123 Main St" "Dallas" State/TX "75432") - person (from-java (Person. "Bob" (to-BigInteger 30) address))] - (is (= "Bob" (:name person))) - (is (= 30 (:age person))) - (is (= "123 Main St" (:line1 (:address person)))) - (is (= "TX" (:state (:address person)))))) - (testing "deep" - (let [address (new Address "123 Main St" "Dallas" State/TX "75432") - person (from-java-deep (Person. "Bob" (to-BigInteger 30) address) {})] - (is (= "Bob" (:name person))) - (is (= 30 (:age person))) - (is (= "123 Main St" (:line1 (:address person)))) - (is (= "TX" (:state (:address person)))))) - (testing "shallow" - (let [address (new Address "123 Main St" "Dallas" State/TX "75432") - person (from-java-shallow (Person. "Bob" (to-BigInteger 30) address) {})] - (is (= "Bob" (:name person))) - (is (= 30 (:age person))) - (is (instance? Address (:address person)))))) - -(deftest primitives - (testing "regular" - (let [datum {:boolMember true - :boolArray [true false] - :charMember \H - :charArray (map identity "Hello World") - :byteMember 127 - :byteArray [1 2 3] - :shortMember 15000 - :shortArray [13000 14000 15000] - :intMember 18000 - :intArray [1 2 3] - :longMember 60000000 - :longArray [1 2 3] - :floatMember 1.5 - :floatArray [1.5 2.5 3.5] - :doubleMember 1.5 - :doubleArray [1.5 2.0 2.5] - :nestedIntArray [[1 2] [3] [4 5 6] []] - :stringArray ["Argument" "Vector"]}] - (is (= datum - (from-java (to-java Primitive datum)))))) - (testing "deep" - (let [datum {:boolMember true - :boolArray [true false] - :charMember \H - :charArray (map identity "Hello World") - :byteMember 127 - :byteArray [1 2 3] - :shortMember 15000 - :shortArray [13000 14000 15000] - :intMember 18000 - :intArray [1 2 3] - :longMember 60000000 - :longArray [1 2 3] - :floatMember 1.5 - :floatArray [1.5 2.5 3.5] - :doubleMember 1.5 - :doubleArray [1.5 2.0 2.5] - :nestedIntArray [[1 2] [3] [4 5 6] []] - :stringArray ["Argument" "Vector"]}] - (is (= datum - (from-java-deep (to-java Primitive datum) {}))))) - (testing "shallow" - (let [datum {:boolMember true - :boolArray [true false] - :charMember \H - :charArray (map identity "Hello World") - :byteMember 127 - :byteArray [1 2 3] - :shortMember 15000 - :shortArray [13000 14000 15000] - :intMember 18000 - :intArray [1 2 3] - :longMember 60000000 - :longArray [1 2 3] - :floatMember 1.5 - :floatArray [1.5 2.5 3.5] - :doubleMember 1.5 - :doubleArray [1.5 2.0 2.5] - :nestedIntArray [[1 2] [3] [4 5 6] []] - :stringArray ["Argument" "Vector"]}] - (reduce-kv (fn [_ k v] - (if (.endsWith ^String (name k) "Array") - (if (= k :nestedIntArray) - (is (= (get datum k) (map #(into [] %) v))) - (is (= (get datum k) (seq v)))) - (is (= (get datum k) v)))) - nil - (from-java-shallow (to-java Primitive datum) {}))))) - -(deftest java-map - (let [datum {"a" "one" "b" 2 "c" (java.net.URI. "")}] - (testing "regular" ; is actually shallow on hash maps - (is (= datum (from-java (to-java java.util.Map datum))))) - (testing "deep" - (is (= (update datum "c" from-java) - (from-java-deep (to-java java.util.Map datum) {})))) - (testing "shallow" - (is (= datum (from-java-shallow (to-java java.util.Map datum) {})))))) - -(deftest jdata-6 - (testing "regular" - (let [bean-instance (TestBean6.) - _ (. bean-instance setFoo {"bar" "baz"}) - bean-instance-as-map (from-java bean-instance) - new-bean-instance (to-java TestBean6 bean-instance-as-map)] - (is (= {"bar" "baz"} (:foo bean-instance-as-map))) - (is (= {"bar" "baz"} (.getFoo new-bean-instance))))) - (testing "deep" - (let [bean-instance (TestBean6.) - _ (. bean-instance setFoo {"bar" "baz"}) - bean-instance-as-map (from-java-deep bean-instance {}) - new-bean-instance (to-java TestBean6 bean-instance-as-map)] - (is (= {"bar" "baz"} (:foo bean-instance-as-map))) - (is (= {"bar" "baz"} (.getFoo new-bean-instance))))) - (testing "shallow" - (let [bean-instance (TestBean6.) - _ (. bean-instance setFoo {"bar" "baz"}) - bean-instance-as-map (from-java-shallow bean-instance {}) - new-bean-instance (to-java TestBean6 bean-instance-as-map)] - (is (= {"bar" "baz"} (:foo bean-instance-as-map))) - (is (= {"bar" "baz"} (.getFoo new-bean-instance)))))) - -(deftest jdata-8-11-date - (testing "regular" - (let [d (java.util.Date.)] - (is (= d (to-java java.util.Date (from-java d)))))) - (testing "deep" - (let [d (java.util.Date.)] - (is (= d (to-java java.util.Date (from-java-deep d {})))))) - (testing "shallow" - (let [d (java.util.Date.)] - (is (= d (to-java java.util.Date (from-java-shallow d {}))))))) - -(when-available - java.time.Instant - (deftest jdata-8-11-instant - (testing "regular" - (let [t (java.time.Instant/now)] - (is (= t (to-java java.time.Instant (from-java t)))))) - (testing "deep" - (let [t (java.time.Instant/now)] - (is (= t (to-java java.time.Instant (from-java-deep t {})))))) - (testing "shallow" - (let [t (java.time.Instant/now)] - (is (= t (to-java java.time.Instant (from-java-shallow t {})))))))) - -(deftest jdata-9 - (let [bean-instance (TestBean9.) - _ (.setAString bean-instance "something") - _ (.setABool bean-instance true) - _ (.setABoolean bean-instance false)] - (testing "regular" - (is (= {:AString "something" :ABool true} - ;; :ABoolean missing because 'is' Boolean is not a getter - (from-java bean-instance)))) - (testing "deep" - (is (= {:AString "something" :ABool true} - ;; :ABoolean missing because 'is' Boolean is not a getter - (from-java-deep bean-instance {})))) - (testing "shallow" - (is (= {:AString "something" :ABool true} - ;; :ABoolean missing because 'is' Boolean is not a getter - (from-java-shallow bean-instance {})))))) - -(deftest jdata-10 - (testing "regular" - (is (if (:absolute (from-java (java.net.URI. ""))) false true)) - (is (if (:opaque (from-java (java.net.URI. ""))) false true))) - (testing "deep" - (is (if (:absolute (from-java-deep (java.net.URI. "") {})) false true)) - (is (if (:opaque (from-java-deep (java.net.URI. "") {})) false true))) - (testing "shallow" - (is (if (:absolute (from-java-shallow (java.net.URI. "") {})) false true)) - (is (if (:opaque (from-java-shallow (java.net.URI. "") {})) false true)))) - -(deftest jdata-12 - (let [eek1 (java.sql.SQLException. "SQL 1") - eek2 (java.sql.SQLException. "SQL 2") - eek3 (java.sql.SQLException. "SQL 3")] - (.setNextException eek1 eek2) - (.setNextException eek2 eek3) - (testing "regular" - (let [ex (from-java eek1)] - (is (= "SQL 1" (get-in ex [:message]))) - (is (= "SQL 2" (get-in ex [:nextException :message]))) - (is (= "SQL 3" (get-in ex [:nextException :nextException :message]))) - (is (nil? (get-in ex [:nextException :nextException :nextException]))))) - (testing "deep" - (let [ex (from-java-deep eek1 {})] - (is (= "SQL 1" (get-in ex [:message]))) - (is (= "SQL 2" (get-in ex [:nextException :message]))) - (is (= "SQL 3" (get-in ex [:nextException :nextException :message]))) - (is (nil? (get-in ex [:nextException :nextException :nextException]))))) - (testing "shallow" - (let [ex (from-java-shallow eek1 {})] - (is (= "SQL 1" (get-in ex [:message]))) - (is (instance? java.sql.SQLException (get ex :nextException))))))) - -;; set-properties tests - -(deftest jdata-15 - (testing "flat maps" - (let [address (set-properties (new Address) - {:line1 "123 Main St" - :city "Dallas" - :state "TX" - :zip "75432"}) - person (set-properties (new Person) - {:name "Bob" - :age 30 - :address address})] - (is (= "Bob" (.getName person))) - (is (= 30 (.getAge person))) - (is (= "123 Main St" (.. person getAddress getLine1))) - (is (= "Dallas" (.. person getAddress getCity))) - (is (= State/TX (.. person getAddress getState))) - (is (= "75432" (.. person getAddress getZip))))) - (testing "nested map" - (let [person (set-properties (new Person) - {:name "Bob" - :age 30 - :address {:line1 "123 Main St" - :city "Dallas" - :state "TX" - :zip "75432"}})] - (is (= "Bob" (.getName person))) - (is (= 30 (.getAge person))) - (is (= "123 Main St" (.. person getAddress getLine1))) - (is (= "Dallas" (.. person getAddress getCity))) - (is (= State/TX (.. person getAddress getState))) - (is (= "75432" (.. person getAddress getZip)))))) - -;; constructor tests - -(deftest jdata-16 - (testing "just constructor arguments" - (let [^Address address (to-java Address - (with-meta {} - {::j/constructor ["123 Main St" - "Dallas" - (to-java State "TX") - "75432"]})) - person (to-java Person - (with-meta {} - {::j/constructor ["Bob" (biginteger 30) address]}))] - (is (= "Bob" (.getName person))) - (is (= 30 (.getAge person))) - (is (= "123 Main St" (.. person getAddress getLine1))) - (is (= "Dallas" (.. person getAddress getCity))) - (is (= State/TX (.. person getAddress getState))) - (is (= "75432" (.. person getAddress getZip))))) - (testing "mixed constructor arguments and properties" - (let [person (to-java Person - (with-meta {:address {:line1 "123 Main St" - :city "Dallas" - :state "TX" - :zip "75432"}} - {::j/constructor ["Bob" (biginteger 30) nil]}))] - (is (= "Bob" (.getName person))) - (is (= 30 (.getAge person))) - (is (= "123 Main St" (.. person getAddress getLine1))) - (is (= "Dallas" (.. person getAddress getCity))) - (is (= State/TX (.. person getAddress getState))) - (is (= "75432" (.. person getAddress getZip)))) - (let [person (to-java Person - (with-meta {:address {:line1 "123 Main St" - :city "Dallas" - :state "TX" - :zip "75432"} - :age 30} - {::j/constructor ["Bob" nil nil]}))] - (is (= "Bob" (.getName person))) - (is (= 30 (.getAge person))) - (is (= "123 Main St" (.. person getAddress getLine1))) - (is (= "Dallas" (.. person getAddress getCity))) - (is (= State/TX (.. person getAddress getState))) - (is (= "75432" (.. person getAddress getZip)))))) - -(deftest jdata-22 - (testing "Properties with String keys" - (let [props (to-java java.util.Properties {"a" 1 "b" "two"})] - (is (= #{"a" "b"} (.stringPropertyNames props))) - (is (= "1" (.getProperty props "a"))) - (is (= "two" (.getProperty props "b"))) - (is (= "nope" (.getProperty props "c" "nope"))))) - (testing "Properties with Keyword keys" - (let [props (to-java java.util.Properties {:a 1 :b "two"})] - (is (= #{"a" "b"} (.stringPropertyNames props))) - (is (= "1" (.getProperty props "a"))) - (is (= "two" (.getProperty props "b"))) - (is (= "nope" (.getProperty props "c" "nope")))))) diff --git a/src/test/java/.gitignore b/src/test/java/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/java/clojure/java/data/test/Address.java b/src/test/java/clojure/java/data/test/Address.java deleted file mode 100644 index 168a36d..0000000 --- a/src/test/java/clojure/java/data/test/Address.java +++ /dev/null @@ -1,50 +0,0 @@ -package clojure.java.data.test; - -public class Address { - private String line1; - private String city; - private State state; - private String zip; - - public Address() { - } - - public Address(String line1, String city, State state, String zip) { - this.line1 = line1; - this.city = city; - this.state = state; - this.zip = zip; - } - - public String getLine1() { - return line1; - } - - public void setLine1(String line1) { - this.line1 = line1; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } - - public State getState() { - return state; - } - - public void setState(State state) { - this.state = state; - } - - public String getZip() { - return zip; - } - - public void setZip(String zip) { - this.zip = zip; - } -} diff --git a/src/test/java/clojure/java/data/test/Person.java b/src/test/java/clojure/java/data/test/Person.java deleted file mode 100644 index fa9c560..0000000 --- a/src/test/java/clojure/java/data/test/Person.java +++ /dev/null @@ -1,42 +0,0 @@ -package clojure.java.data.test; - -import java.math.BigInteger; - -public class Person { - private String name; - private BigInteger age; - private Address address; - - public Person() { - } - - public Person(String name, BigInteger age, Address address) { - this.name = name; - this.age = age; - this.address = address; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public BigInteger getAge() { - return age; - } - - public void setAge(BigInteger age) { - this.age = age; - } - - public Address getAddress() { - return address; - } - - public void setAddress(Address address) { - this.address = address; - } -} diff --git a/src/test/java/clojure/java/data/test/Primitive.java b/src/test/java/clojure/java/data/test/Primitive.java deleted file mode 100644 index c1d2abf..0000000 --- a/src/test/java/clojure/java/data/test/Primitive.java +++ /dev/null @@ -1,133 +0,0 @@ -package clojure.java.data.test; - -public class Primitive { - private boolean boolMember; - private boolean[] boolArray; - private char charMember; - private char[] charArray; - - private byte byteMember; - private byte[] byteArray; - private short shortMember; - private short[] shortArray; - private int intMember; - private int[] intArray; - private long longMember; - private long[] longArray; - private float floatMember; - private float[] floatArray; - private double doubleMember; - private double[] doubleArray; - - private int[][] nestedIntArray; - private String[] stringArray; - - public boolean isBoolMember() { - return boolMember; - } - public void setBoolMember(boolean boolMember) { - this.boolMember = boolMember; - } - public boolean[] getBoolArray() { - return boolArray; - } - public void setBoolArray(boolean[] boolArray) { - this.boolArray = boolArray; - } - public char getCharMember() { - return charMember; - } - public void setCharMember(char charMember) { - this.charMember = charMember; - } - public char[] getCharArray() { - return charArray; - } - public void setCharArray(char[] charArray) { - this.charArray = charArray; - } - public byte getByteMember() { - return byteMember; - } - public void setByteMember(byte byteMember) { - this.byteMember = byteMember; - } - public byte[] getByteArray() { - return byteArray; - } - public void setByteArray(byte[] byteArray) { - this.byteArray = byteArray; - } - public short getShortMember() { - return shortMember; - } - public void setShortMember(short shortMember) { - this.shortMember = shortMember; - } - public short[] getShortArray() { - return shortArray; - } - public void setShortArray(short[] shortArray) { - this.shortArray = shortArray; - } - public int getIntMember() { - return intMember; - } - public void setIntMember(int intMember) { - this.intMember = intMember; - } - public int[] getIntArray() { - return intArray; - } - public void setIntArray(int[] intArray) { - this.intArray = intArray; - } - public long getLongMember() { - return longMember; - } - public void setLongMember(long longMember) { - this.longMember = longMember; - } - public long[] getLongArray() { - return longArray; - } - public void setLongArray(long[] longArray) { - this.longArray = longArray; - } - public float getFloatMember() { - return floatMember; - } - public void setFloatMember(float floatMember) { - this.floatMember = floatMember; - } - public float[] getFloatArray() { - return floatArray; - } - public void setFloatArray(float[] floatArray) { - this.floatArray = floatArray; - } - public double getDoubleMember() { - return doubleMember; - } - public void setDoubleMember(double doubleMember) { - this.doubleMember = doubleMember; - } - public double[] getDoubleArray() { - return doubleArray; - } - public void setDoubleArray(double[] doubleArray) { - this.doubleArray = doubleArray; - } - public int[][] getNestedIntArray() { - return nestedIntArray; - } - public void setNestedIntArray(int[][] nestedIntArray) { - this.nestedIntArray = nestedIntArray; - } - public String[] getStringArray() { - return stringArray; - } - public void setStringArray(String[] stringArray) { - this.stringArray = stringArray; - } -} diff --git a/src/test/java/clojure/java/data/test/State.java b/src/test/java/clojure/java/data/test/State.java deleted file mode 100644 index 7851698..0000000 --- a/src/test/java/clojure/java/data/test/State.java +++ /dev/null @@ -1,55 +0,0 @@ -package clojure.java.data.test; - -public enum State { - AL, - AK, - AZ, - AR, - CA, - CO, - CT, - DE, - DC, - FL, - GA, - HI, - ID, - IL, - IN, - IA, - KS, - KY, - LA, - ME, - MD, - MA, - MI, - MN, - MS, - MO, - MT, - NE, - NV, - NH, - NJ, - NM, - NY, - NC, - ND, - OH, - OK, - OR, - PA, - RI, - SC, - SD, - TN, - TX, - UT, - VT, - VA, - WA, - WV, - WI, - WY -} diff --git a/src/test/java/clojure/java/data/test/TestBean6.java b/src/test/java/clojure/java/data/test/TestBean6.java deleted file mode 100644 index 5cb1d70..0000000 --- a/src/test/java/clojure/java/data/test/TestBean6.java +++ /dev/null @@ -1,15 +0,0 @@ -package clojure.java.data.test; -import java.util.Map; - -public class TestBean6 { - - private java.util.Map foo; - - public void setFoo(Map foo) { - this.foo = foo; - } - - public Map getFoo() { - return foo; - } -} diff --git a/src/test/java/clojure/java/data/test/TestBean9.java b/src/test/java/clojure/java/data/test/TestBean9.java deleted file mode 100644 index 36ea315..0000000 --- a/src/test/java/clojure/java/data/test/TestBean9.java +++ /dev/null @@ -1,34 +0,0 @@ -package clojure.java.data.test; -import java.util.Map; - -public class TestBean9 { - - private boolean aBool; - private Boolean aBoolean; - private String aString; - - public void setABool(boolean b) { - this.aBool = b; - } - - public boolean isABool() { - return aBool; - } - - public void setABoolean(Boolean b) { - this.aBoolean = b; - } - - // not a getter because 'is' only works for primitive boolean - public Boolean isABoolean() { - return aBoolean; - } - - public void setAString(String s) { - this.aString = s; - } - - public String getAString() { - return aString; - } -} diff --git a/static/clojure-icon.gif b/static/clojure-icon.gif new file mode 100644 index 0000000..84eee16 Binary files /dev/null and b/static/clojure-icon.gif differ diff --git a/static/clojure.css b/static/clojure.css new file mode 100644 index 0000000..d40ea35 --- /dev/null +++ b/static/clojure.css @@ -0,0 +1,53 @@ + +body {margin: 0;padding: 0;background-color: #e3e3e3;border-top: 4px solid #b3ccfe;color: #272727} +body, .wiki, #Content, .wikipage {font-family: "Lucida Grande","Trebuchet MS","Bitstream Vera Sans",Verdana,Helvetica,sans-serif;font-size: 12px;line-height: 18px;} +#leftcolumn .wiki_link, #toc, #toc a, .toc-header {font-size: 11px;line-height: 18px;text-decoration: none} +img {border: 0;} +#AllContentContainer {max-width: 96em;min-width: 663px;background: #fff url(space/content-background.gif) right repeat-y;padding: 0 40px 18px 0;} + +#Header {position: relative;clear: both;overflow: auto;height: 110px} +#Logo {position: absolute;top: 0;left: 0;padding: 10px 0 0 62px;width: 138px;height: 100px} +#Header h1 {float: left;border: 0;margin: 0;padding: 0;position: absolute;top: 50;left: 200px; height: 60px} +#Header h1 a:link, #Header h1 a:visited, #Header h1 a:hover {color:#000000; text-decoration: none;} +#Resources {min-height: 110px;width: 234px;padding: 5px 0;float: right;border-bottom: 1px solid #abc4e2;background: #e4eaf7 url(space/resources-background.gif) repeat-y;overflow: auto;} +#Resources ul {margin: 0;padding: 0 25px;list-style: none;} +#ResourcesB {float: right;} +#Resources a {text-decoration: none;} +#Resources a:link, #Resources a:visited, #Resources a:hover, #Resources a:active {color: #4c5770;} +#Resources a:hover {text-decoration: underline;} + +#leftcolumn {margin: 0 0 0 22px;float: left;width: 168px;padding-bottom: 18px;background: #c5d2eb url(space/left-nav-bottom.gif) bottom no-repeat;} + +#leftcolumn ul {list-style: none;margin: 0;padding: 0;} + +#leftcolumn a, #leftcolumn .toc-header {font-weight: bold;display: block;background: transparent url(space/left-nav-divider.gif) repeat-x;padding: 6px 0 0 17px;margin: 12px 0 0 0;} +#leftcolumn li a {font-weight: normal;background:none;margin: 0;padding: 0 0 0 17px;} +#leftcolumn br {display: none;} +#leftcolumn .menu {margin-top: 14px;background: #fff url(space/left-nav-background.gif) repeat-y;} + +#leftcolumn a:link , #leftcolumn a:visited , #leftcolumn a:active {color: #666;} +#leftcolumn a:hover {text-decoration: underline;color: #222;} + +#rightcolumn {margin-left: 220px;} + +.wiki #toc {border: none;margin: 0 0 30px 18px;width: 222px;padding: 0 0 17px 12px;background: transparent url(space/toc-background.gif) repeat-y;border-bottom: 1px solid #d6d6d6;} +.wiki #toc h1, .wiki #toc div {margin: 0;padding: 0;} +.wiki #toc h1 {font-size: 14px;line-height: 18px;font-family: Georgia, "Times New Roman", Times, serif;font-style: italic;font-weight: normal;color: #969696;padding: 10px 0 8px 11px;} +.wiki #toc a:link, .wiki #toc a:visited, .wiki #toc a:active {color: #646464;} +.wiki #toc a:hover {background: none;color: #333333;} + +.wiki pre {font-family: Inconsolata, Monaco, Consolas, "Lucida Console", "Courier New", Courier, monospace;background-color: transparent;border: 0px;color: #000000} +#DesignedBy { clear: both; text-align: right; margin-top: 18px;} +#DesignedBy, #DesignedBy a, #DesignedBy a:link, #DesignedBy a:visited, #DesignedBy a:hover, #DesignedBy a:active { color: #999; } + +#WikiHeaderNavContainer { height: 36px; position: relative; } +#leftcolumn .WikiActions a {display: inline;} + +.comment { color: gray; } +.string { color: teal; } +.function { color: #00c; } +.macro, .specialops { color: #60c; } +.parens { color: #000; } +.keyword { color: #c09; } +.brackets { color: #006; } +.curlybrackets { color: #906; } diff --git a/static/favicon.png b/static/favicon.png new file mode 100644 index 0000000..b1653e8 Binary files /dev/null and b/static/favicon.png differ diff --git a/static/internal.css b/static/internal.css new file mode 100644 index 0000000..08ce7fb --- /dev/null +++ b/static/internal.css @@ -0,0 +1,18 @@ +/* *** MISC STUFF USED ALL OVER *** */ +.nowrap { white-space: nowrap; } +.hidden { display: none; } +tr td .sm { font-size: 90%; } +.grey { color: #666; } +.smgrey { color: #666; font-size: 80%; } +.grey a { color: #666; } +.textentry { font-family: arial, helvetica, sans-serif; border: 1px solid #999; } +.nopad { padding: 0; margin: 0; } +.bblack { color: #000; font-size: 1.1em; font-weight: bold; } +.bblacklight { color: #000; font-size: 1.1em; } + +/* IE6 min-height: http://www.dustindiaz.com/min-height-fast-hack */ +#content_view { display: block; padding-bottom: 2em; width: 100%; min-height: 600px; height: auto !important; height: 600px; } + +/* Used with .innerContentBox and #WikiAds to position the ad column */ +.contentBox { position: relative; min-height: 600px; height: auto !important; height: 600px; } + diff --git a/static/space/content-background.gif b/static/space/content-background.gif new file mode 100644 index 0000000..0786c72 Binary files /dev/null and b/static/space/content-background.gif differ diff --git a/static/space/left-nav-background.gif b/static/space/left-nav-background.gif new file mode 100644 index 0000000..e6e5904 Binary files /dev/null and b/static/space/left-nav-background.gif differ diff --git a/static/space/left-nav-bottom.gif b/static/space/left-nav-bottom.gif new file mode 100644 index 0000000..061c089 Binary files /dev/null and b/static/space/left-nav-bottom.gif differ diff --git a/static/space/left-nav-divider.gif b/static/space/left-nav-divider.gif new file mode 100644 index 0000000..1854e56 Binary files /dev/null and b/static/space/left-nav-divider.gif differ diff --git a/static/space/resources-background.gif b/static/space/resources-background.gif new file mode 100644 index 0000000..9657769 Binary files /dev/null and b/static/space/resources-background.gif differ diff --git a/static/space/toc-background.gif b/static/space/toc-background.gif new file mode 100644 index 0000000..0b7c95b Binary files /dev/null and b/static/space/toc-background.gif differ diff --git a/static/wiki.css b/static/wiki.css new file mode 100644 index 0000000..1cb1bdd --- /dev/null +++ b/static/wiki.css @@ -0,0 +1,22 @@ +/* Wiki Rendered Styles */ +.wiki { line-height: 150%; font-family: arial, helvetica, sans-serif; font-size: small; } +.wiki h1 { font-weight: bold; padding: 5px 0 0 0; margin: 0; font-size: 1.4em; } +.wiki h2 { font-weight: bold; padding: 5px 0 0 0; margin: 0; font-size: 1.3em; } +.wiki h3 { font-weight: bold; padding: 5px 0 0 0; margin: 0; font-size: 1.1em; } +.wiki h4 { font-weight: normal; padding: 5px 0 0 0; margin: 0; font-size: 1.066em; } +.wiki h5 { font-weight: normal; padding: 5px 0 0 0; margin: 0; font-size: 1.033em; } +.wiki h6 { font-weight: normal; padding: 5px 0 0 0; margin: 0; font-size: 1.0em; } +.wiki table { border-collapse: collapse; margin: 10px 0; font-size: small; } +.wiki p { margin: 0; padding: 0; padding: 5px 0; } +.wiki td { border: 1px solid #DDD; } +.wiki #toc { border: 1px solid #AAA; background: #fff; padding: 5px; margin: 0 0 10px 10px; width: 25%; float: right; clear: right;} +.wiki #toc h1 { font-weight: normal; font-size: 1.2em; padding: 0; } +.wiki #toc a:hover { color: #00D; background: #FFD; } + +.wiki hr { height: 1px; color: #AAA; background-color: #AAA; border: 0; margin: 0 10px; } +.wiki ul { padding: .5em 0 0 3em; margin: 0; } +.wiki ol { padding: .5em 0 0 3em; margin: 0; } +.wiki ul.quotelist { list-style: none; } +.wiki tt { font-size: small; } +.wiki img { border: 0; padding: 4px; } +