Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 43330 invoked from network); 12 Mar 2010 16:59:14 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 12 Mar 2010 16:59:14 -0000 Received: (qmail 67415 invoked by uid 500); 12 Mar 2010 16:58:36 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 67347 invoked by uid 500); 12 Mar 2010 16:58:36 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 67340 invoked by uid 99); 12 Mar 2010 16:58:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Mar 2010 16:58:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Mar 2010 16:58:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9491F238897A; Fri, 12 Mar 2010 16:58:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r922338 [1/2] - in /commons/sandbox/convert: branches/ tags/ trunk/ trunk/src/ trunk/src/META-INF/ trunk/src/META-INF/services/ trunk/src/java/ trunk/src/java/org/ trunk/src/java/org/apache/ trunk/src/java/org/apache/commons/ trunk/src/java... Date: Fri, 12 Mar 2010 16:58:09 -0000 To: commits@commons.apache.org From: adrianc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100312165809.9491F238897A@eris.apache.org> Author: adrianc Date: Fri Mar 12 16:58:07 2010 New Revision: 922338 URL: http://svn.apache.org/viewvc?rev=922338&view=rev Log: Initial commit of the convert sandbox project. I copied over the structure of the dormant convert project and replaced the old source code with the new code. The project doesn't build yet and the unit tests are incomplete. Added: commons/sandbox/convert/branches/ commons/sandbox/convert/tags/ commons/sandbox/convert/trunk/ (with props) commons/sandbox/convert/trunk/.classpath (with props) commons/sandbox/convert/trunk/.project (with props) commons/sandbox/convert/trunk/LICENSE.txt (with props) commons/sandbox/convert/trunk/NOTICE.txt (with props) commons/sandbox/convert/trunk/build.xml (with props) commons/sandbox/convert/trunk/checkstyle.xml (with props) commons/sandbox/convert/trunk/project.properties (with props) commons/sandbox/convert/trunk/project.xml (with props) commons/sandbox/convert/trunk/src/ commons/sandbox/convert/trunk/src/META-INF/ commons/sandbox/convert/trunk/src/META-INF/services/ commons/sandbox/convert/trunk/src/META-INF/services/org.apache.commons.convert.ConverterLoader (with props) commons/sandbox/convert/trunk/src/java/ commons/sandbox/convert/trunk/src/java/org/ commons/sandbox/convert/trunk/src/java/org/apache/ commons/sandbox/convert/trunk/src/java/org/apache/commons/ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractConverter.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractLocalizedConverter.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/BooleanConverters.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/CollectionConverters.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConversionException.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converter.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterCreator.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterLoader.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converters.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/DateTimeConverters.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/GenericSingletonToList.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/GenericSingletonToSet.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/LocalizedConverter.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/MiscConverters.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/NetConverters.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/NumberConverters.java (with props) commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Util.java (with props) commons/sandbox/convert/trunk/src/test/ commons/sandbox/convert/trunk/src/test/org/ commons/sandbox/convert/trunk/src/test/org/apache/ commons/sandbox/convert/trunk/src/test/org/apache/commons/ commons/sandbox/convert/trunk/src/test/org/apache/commons/convert/ commons/sandbox/convert/trunk/src/test/org/apache/commons/convert/TestDateTimeConverters.java (with props) commons/sandbox/convert/trunk/xdocs/ commons/sandbox/convert/trunk/xdocs/class-diagram.png (with props) commons/sandbox/convert/trunk/xdocs/images/ commons/sandbox/convert/trunk/xdocs/images/convert-logo-white.png (with props) commons/sandbox/convert/trunk/xdocs/images/convert-logo-white.xcf (with props) commons/sandbox/convert/trunk/xdocs/index.xml (with props) commons/sandbox/convert/trunk/xdocs/navigation.xml (with props) commons/sandbox/convert/trunk/xdocs/style/ commons/sandbox/convert/trunk/xdocs/style/project.css Propchange: commons/sandbox/convert/trunk/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Fri Mar 12 16:58:07 2010 @@ -0,0 +1 @@ +target Added: commons/sandbox/convert/trunk/.classpath URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/.classpath?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/.classpath (added) +++ commons/sandbox/convert/trunk/.classpath Fri Mar 12 16:58:07 2010 @@ -0,0 +1,10 @@ + + + + + + + + + + Propchange: commons/sandbox/convert/trunk/.classpath ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/.classpath ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/.classpath ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/.project URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/.project?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/.project (added) +++ commons/sandbox/convert/trunk/.project Fri Mar 12 16:58:07 2010 @@ -0,0 +1,17 @@ + + + Convert + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + Propchange: commons/sandbox/convert/trunk/.project ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/.project ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/.project ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/LICENSE.txt URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/LICENSE.txt?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/LICENSE.txt (added) +++ commons/sandbox/convert/trunk/LICENSE.txt Fri Mar 12 16:58:07 2010 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) 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. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. Propchange: commons/sandbox/convert/trunk/LICENSE.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/LICENSE.txt ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/LICENSE.txt ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/NOTICE.txt URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/NOTICE.txt?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/NOTICE.txt (added) +++ commons/sandbox/convert/trunk/NOTICE.txt Fri Mar 12 16:58:07 2010 @@ -0,0 +1,2 @@ +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). Propchange: commons/sandbox/convert/trunk/NOTICE.txt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/NOTICE.txt ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/NOTICE.txt ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/build.xml URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/build.xml?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/build.xml (added) +++ commons/sandbox/convert/trunk/build.xml Fri Mar 12 16:58:07 2010 @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Propchange: commons/sandbox/convert/trunk/build.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/build.xml ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/build.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: commons/sandbox/convert/trunk/checkstyle.xml URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/checkstyle.xml?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/checkstyle.xml (added) +++ commons/sandbox/convert/trunk/checkstyle.xml Fri Mar 12 16:58:07 2010 @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Propchange: commons/sandbox/convert/trunk/checkstyle.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/checkstyle.xml ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/checkstyle.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: commons/sandbox/convert/trunk/project.properties URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/project.properties?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/project.properties (added) +++ commons/sandbox/convert/trunk/project.properties Fri Mar 12 16:58:07 2010 @@ -0,0 +1,24 @@ +# Copyright 2003-2004 The Apache Software Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +maven.xdoc.jsl=../commons-build/commons-site.jsl +maven.xdoc.date=bottom +maven.xdoc.poweredby.image=maven-feather.png +maven.xdoc.version=${pom.currentVersion} +maven.xdoc.developmentProcessUrl=http://commons.apache.org/charter.html +maven.xdoc.includeProjectDocumentation=yes + +maven.checkstyle.properties=checkstyle.xml +maven.changelog.factory=org.apache.maven.svnlib.SvnChangeLogFactory + Propchange: commons/sandbox/convert/trunk/project.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/project.properties ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/project.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/project.xml URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/project.xml?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/project.xml (added) +++ commons/sandbox/convert/trunk/project.xml Fri Mar 12 16:58:07 2010 @@ -0,0 +1,62 @@ + + + + ../commons-build/sandbox-project.xml + Commons Convert + commons-convert + + /images/convert-logo-white.png + + 0.1 + 2003 + Commons Convert + Java Conversion Utilities + http://commons.apache.org/sandbox/convert/ + + jakarta.apache.org + /www/commons.apache.org/sandbox/convert/ + + + + Adrian Crum + adrianc + Apache Software Foundation + + + Adam Heath + doogie + Apache Software Foundation + + + + + + Scott Gray + + + + + + + + + + **/Test*.java + + + + + + maven-changelog-plugin + maven-changes-plugin + maven-checkstyle-plugin + maven-jcoverage-plugin + maven-developer-activity-plugin + maven-file-activity-plugin + maven-javadoc-plugin + maven-junit-report-plugin + maven-jxr-plugin + maven-license-plugin + + + Propchange: commons/sandbox/convert/trunk/project.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/project.xml ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/project.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: commons/sandbox/convert/trunk/src/META-INF/services/org.apache.commons.convert.ConverterLoader URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/META-INF/services/org.apache.commons.convert.ConverterLoader?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/src/META-INF/services/org.apache.commons.convert.ConverterLoader (added) +++ commons/sandbox/convert/trunk/src/META-INF/services/org.apache.commons.convert.ConverterLoader Fri Mar 12 16:58:07 2010 @@ -0,0 +1,23 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.commons.convert.BooleanConverters +org.apache.commons.convert.CollectionConverters +org.apache.commons.convert.DateTimeConverters +org.apache.commons.convert.MiscConverters +org.apache.commons.convert.NetConverters +org.apache.commons.convert.NumberConverters Propchange: commons/sandbox/convert/trunk/src/META-INF/services/org.apache.commons.convert.ConverterLoader ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/src/META-INF/services/org.apache.commons.convert.ConverterLoader ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/src/META-INF/services/org.apache.commons.convert.ConverterLoader ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractConverter.java URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractConverter.java?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractConverter.java (added) +++ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractConverter.java Fri Mar 12 16:58:07 2010 @@ -0,0 +1,53 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.commons.convert; + +/** Abstract Converter class. This class handles converter registration + * and it implements the canConvert, getSourceClass, + * and getTargetClass methods. + */ +public abstract class AbstractConverter implements Converter, ConverterLoader { + private final Class sourceClass; + private final Class targetClass; + + protected AbstractConverter(Class sourceClass, Class targetClass) { + this.sourceClass = sourceClass; + this.targetClass = targetClass; + } + + public void loadConverters() { + Converters.registerConverter(this); + } + + public T convert(Class targetClass, S obj) throws ConversionException { + return convert(obj); + } + + public boolean canConvert(Class sourceClass, Class targetClass) { + return Util.instanceOf(sourceClass, this.getSourceClass()) && Util.instanceOf(targetClass, this.getTargetClass()); + } + + public Class getSourceClass() { + return sourceClass; + } + + public Class getTargetClass() { + return targetClass; + } +} Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractConverter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractConverter.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractConverter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractLocalizedConverter.java URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractLocalizedConverter.java?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractLocalizedConverter.java (added) +++ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractLocalizedConverter.java Fri Mar 12 16:58:07 2010 @@ -0,0 +1,40 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.commons.convert; + +import java.util.Locale; +import java.util.TimeZone; + +/** Abstract LocalizedConverter class. This class handles converter registration + * and it implements the canConvert, getSourceClass, + * and getTargetClass methods. + */ +public abstract class AbstractLocalizedConverter extends AbstractConverter implements LocalizedConverter { + protected AbstractLocalizedConverter(Class sourceClass, Class targetClass) { + super(sourceClass, targetClass); + } + + public T convert(Class targetClass, S obj, Locale locale, TimeZone timeZone) throws ConversionException { + return convert(obj, locale, timeZone); + } + + public T convert(Class targetClass, S obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException { + return convert(obj, locale, timeZone, formatString); + } +} Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractLocalizedConverter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractLocalizedConverter.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/AbstractLocalizedConverter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/BooleanConverters.java URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/BooleanConverters.java?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/BooleanConverters.java (added) +++ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/BooleanConverters.java Fri Mar 12 16:58:07 2010 @@ -0,0 +1,78 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.commons.convert; + +/** Boolean Converter classes. */ +public class BooleanConverters implements ConverterLoader { + public static class BooleanToInteger extends AbstractConverter { + public BooleanToInteger() { + super(Boolean.class, Integer.class); + } + + public Integer convert(Boolean obj) throws ConversionException { + return obj.booleanValue() ? 1 : 0; + } + } + + public static class BooleanToList extends GenericSingletonToList { + public BooleanToList() { + super(Boolean.class); + } + } + + public static class BooleanToSet extends GenericSingletonToSet { + public BooleanToSet() { + super(Boolean.class); + } + } + + public static class BooleanToString extends AbstractConverter { + public BooleanToString() { + super(Boolean.class, String.class); + } + + public String convert(Boolean obj) throws ConversionException { + return obj.booleanValue() ? "true" : "false"; + } + } + + public static class IntegerToBoolean extends AbstractConverter { + public IntegerToBoolean() { + super(Integer.class, Boolean.class); + } + + public Boolean convert(Integer obj) throws ConversionException { + return obj.intValue() == 0 ? false : true; + } + } + + public static class StringToBoolean extends AbstractConverter { + public StringToBoolean() { + super(String.class, Boolean.class); + } + + public Boolean convert(String obj) throws ConversionException { + return "TRUE".equals(obj.trim().toUpperCase()); + } + } + + public void loadConverters() { + Converters.loadContainedConverters(BooleanConverters.class); + } +} Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/BooleanConverters.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/BooleanConverters.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/BooleanConverters.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/CollectionConverters.java URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/CollectionConverters.java?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/CollectionConverters.java (added) +++ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/CollectionConverters.java Fri Mar 12 16:58:07 2010 @@ -0,0 +1,140 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.commons.convert; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** Collection Converter classes. */ +public class CollectionConverters implements ConverterLoader { + public static class ArrayCreator implements ConverterCreator, ConverterLoader { + public void loadConverters() { + Converters.registerCreator(this); + } + + public Converter createConverter(Class sourceClass, Class targetClass) { + if (!sourceClass.isArray()) { + return null; + } + if (targetClass != List.class) { + return null; + } + if (!(sourceClass.getComponentType() instanceof Object)) { + return null; + } + return Util.cast(new ArrayClassToList(sourceClass, targetClass)); + } + } + + private static class ArrayClassToList extends AbstractConverter { + public ArrayClassToList(Class sourceClass, Class targetClass) { + super(sourceClass, targetClass); + } + + public boolean canConvert(Class sourceClass, Class targetClass) { + return sourceClass == this.getSourceClass() && targetClass == this.getTargetClass(); + } + + public T convert(S obj) throws ConversionException { + List list = new ArrayList(); + int len = Array.getLength(obj); + for (int i = 0; i < len; i++) { + list.add(Array.get(obj, i)); + } + return Util.cast(list); + } + } + + public static class ArrayToList extends AbstractConverter> { + public ArrayToList() { + super(Object[].class, List.class); + } + + @Override + public boolean canConvert(Class sourceClass, Class targetClass) { + if (!sourceClass.isArray()) { + return false; + } + if (!List.class.isAssignableFrom(targetClass)) { + return false; + } + if (Object[].class.isAssignableFrom(sourceClass)) { + return true; + } + return false; + } + + public List convert(T[] obj) throws ConversionException { + return Arrays.asList(obj); + } + } + + public static class ListToString extends AbstractConverter, String> { + public ListToString() { + super(List.class, String.class); + } + + public String convert(List obj) throws ConversionException { + return obj.toString(); + } + } + + public static class MapToList extends AbstractConverter, List>> { + public MapToList() { + super(Map.class, List.class); + } + + public List> convert(Map obj) throws ConversionException { + List> tempList = new ArrayList>(); + tempList.add(obj); + return tempList; + } + } + + public static class MapToSet extends AbstractConverter, Set>> { + public MapToSet() { + super(Map.class, Set.class); + } + + public Set> convert(Map obj) throws ConversionException { + Set> tempSet = new HashSet>(); + tempSet.add(obj); + return tempSet; + } + } + + public static class MapToString extends AbstractConverter, String> { + public MapToString() { + super(Map.class, String.class); + } + + public String convert(Map obj) throws ConversionException { + return obj.toString(); + } + } + + public void loadConverters() { + Converters.loadContainedConverters(CollectionConverters.class); + } +} Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/CollectionConverters.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/CollectionConverters.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/CollectionConverters.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConversionException.java URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConversionException.java?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConversionException.java (added) +++ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConversionException.java Fri Mar 12 16:58:07 2010 @@ -0,0 +1,35 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.commons.convert; + +/** ConversionException class. */ +@SuppressWarnings("serial") +public class ConversionException extends Exception { + public ConversionException(String message, Throwable cause) { + super(message, cause); + } + + public ConversionException(String message) { + super(message); + } + + public ConversionException(Throwable cause) { + super(cause); + } +} Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConversionException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConversionException.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConversionException.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converter.java URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converter.java?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converter.java (added) +++ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converter.java Fri Mar 12 16:58:07 2010 @@ -0,0 +1,68 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.commons.convert; + +/** Converter interface. Classes implement this interface to convert one + * Java object type to another. + * + * @param The source object type + * @param The target object type + */ +public interface Converter { + /** Returns true if this object can convert + * sourceClass to targetClass. + *

Implementations can accomodate class hierarchy ranges + * by converting super classes or interfaces.

+ * + * @param sourceClass The source Class + * @param targetClass The target Class + * @return true if this object can convert + * sourceClass to targetClass. + */ + public boolean canConvert(Class sourceClass, Class targetClass); + + /** Converts obj to T. + * + * @param obj The source Object to convert + * @return The converted Object + * @throws ConversionException + */ + public T convert(S obj) throws ConversionException; + + /** Converts obj to T. + * + * @param targetClass The Class to convert to + * @param obj The source Object to convert + * @return The converted Object + * @throws ConversionException + */ + public T convert(Class targetClass, S obj) throws ConversionException; + + /** Returns the source Class for this converter. + * + * @return The source Class for this converter + */ + public Class getSourceClass(); + + /** Returns the target Class for this converter. + * + * @return The target Class for this converter + */ + public Class getTargetClass(); +} Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converter.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converter.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterCreator.java URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterCreator.java?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterCreator.java (added) +++ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterCreator.java Fri Mar 12 16:58:07 2010 @@ -0,0 +1,34 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.commons.convert; + +/** ConverterCreator interface. Classes implement this interface to create a + * converter that can convert one Java object type to another. + */ +public interface ConverterCreator { + /** Creates a Converter that can convert the sourceClass to + * the targetClass. Returns null if this creater + * doesn't support the class pair. + * + * @param sourceClass The source Class to convert + * @param targetClass The target Class to convert to + * @return a converter that can convert Objects + */ + public Converter createConverter(Class sourceClass, Class targetClass); +} Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterCreator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterCreator.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterCreator.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterLoader.java URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterLoader.java?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterLoader.java (added) +++ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterLoader.java Fri Mar 12 16:58:07 2010 @@ -0,0 +1,35 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.commons.convert; + +/** Converter loader interface. Applications implement this + * interface to load their Java object converters. + * + */ +public interface ConverterLoader { + /** Create and register converters with the Java object type + * conversion framework. If the converter extends one of the + * converter abstract classes, then the converter will register + * itself when an instance is created. Otherwise, call + * {@link org.ofbiz.base.conversion.Converters#registerConverter(Converter)} + * with the Converter instance. + * + */ + public void loadConverters(); +} Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterLoader.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterLoader.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/ConverterLoader.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converters.java URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converters.java?rev=922338&view=auto ============================================================================== --- commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converters.java (added) +++ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converters.java Fri Mar 12 16:58:07 2010 @@ -0,0 +1,235 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.apache.commons.convert; + +import java.lang.reflect.Modifier; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import javax.imageio.spi.ServiceRegistry; + +/** A Converter factory and repository. */ +public class Converters { + protected static final String DELIMITER = "->"; + protected static final ConcurrentHashMap> converterMap = new ConcurrentHashMap>(); + protected static final Set creators = Collections.synchronizedSet(new HashSet()); + protected static final Set noConversions = Collections.synchronizedSet(new HashSet()); + + static { + registerCreator(new PassThruConverterCreator()); + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + Iterator converterLoaders = ServiceRegistry.lookupProviders(ConverterLoader.class, loader); + while (converterLoaders.hasNext()) { + try { + ConverterLoader converterLoader = converterLoaders.next(); + converterLoader.loadConverters(); + } catch (Exception e) { +// Debug.logError(e, module); + } + } + } + + private Converters() {} + + /** Returns an appropriate Converter instance for + * sourceClass and targetClass. If no matching + * Converter is found, the method throws + * ClassNotFoundException. + * + *

This method is intended to be used when the source or + * target Object types are unknown at compile time. + * If the source and target Object types are known + * at compile time, then one of the "ready made" converters should be used.

+ * + * @param sourceClass The object class to convert from + * @param targetClass The object class to convert to + * @return A matching Converter instance + * @throws ClassNotFoundException + */ + public static Converter getConverter(Class sourceClass, Class targetClass) throws ClassNotFoundException { + String key = sourceClass.getName().concat(DELIMITER).concat(targetClass.getName()); +// if (Debug.verboseOn()) { +// Debug.logVerbose("Getting converter: " + key, module); +// } +OUTER: + do { + Converter result = converterMap.get(key); + if (result != null) { + return Util.cast(result); + } + if (noConversions.contains(key)) { + throw new ClassNotFoundException("No converter found for " + key); + } + for (Converter value : converterMap.values()) { + if (value.canConvert(sourceClass, targetClass)) { + converterMap.putIfAbsent(key, value); + continue OUTER; + } + } + for (ConverterCreator value : creators) { + result = createConverter(value, sourceClass, targetClass); + if (result != null) { + converterMap.putIfAbsent(key, result); + continue OUTER; + } + } + if (noConversions.add(key)) { + /* + Debug.logWarning("*** No converter found, converting from " + + sourceClass.getName() + " to " + targetClass.getName() + + ". Please report this message to the developer community so " + + "a suitable converter can be created. ***", module); + */ + } + throw new ClassNotFoundException("No converter found for " + key); + } while (true); + } + + private static Converter createConverter(ConverterCreator creater, Class sourceClass, Class targetClass) { + return creater.createConverter(sourceClass, targetClass); + } + + /** Load all classes that implement Converter and are + * contained in containerClass. + * + * @param containerClass + */ + public static void loadContainedConverters(Class containerClass) { + // This only returns -public- classes and interfaces + for (Class clz: containerClass.getClasses()) { + try { + // non-abstract, which means no interfaces or abstract classes + if ((clz.getModifiers() & Modifier.ABSTRACT) == 0) { + Object value; + try { + value = clz.getConstructor().newInstance(); + } catch (NoSuchMethodException e) { + // ignore this, as this class might be some other helper class, + // with a non-pubilc constructor + continue; + } + if (value instanceof ConverterLoader) { + ConverterLoader loader = (ConverterLoader) value; + loader.loadConverters(); + } + } + } catch (Exception e) { +// Debug.logError(e, module); + } + } + } + + /** Registers a ConverterCreater instance to be used by the + * {@link org.ofbiz.base.conversion.Converters#getConverter(Class, Class)} + * method, when a converter can't be found. + * + * @param The source object type + * @param The target object type + * @param creator The ConverterCreater instance to register + */ + public static void registerCreator(ConverterCreator creator) { + creators.add(creator); + } + + /** Registers a Converter instance to be used by the + * {@link org.ofbiz.base.conversion.Converters#getConverter(Class, Class)} + * method. + * + * @param The source object type + * @param The target object type + * @param converter The Converter instance to register + */ + public static void registerConverter(Converter converter) { + registerConverter(converter, converter.getSourceClass(), converter.getTargetClass()); + } + + public static void registerConverter(Converter converter, Class sourceClass, Class targetClass) { + StringBuilder sb = new StringBuilder(); + if (sourceClass != null) { + sb.append(sourceClass.getName()); + } else { + sb.append(""); + } + sb.append(DELIMITER); + if (targetClass != null) { + sb.append(targetClass.getName()); + } else { + sb.append(""); + } + String key = sb.toString(); + if (converterMap.putIfAbsent(key, converter) == null) { +// if (Debug.verboseOn()) { +// Debug.logVerbose("Registered converter " + converter.getClass().getName(), module); +// } + } + } + + protected static class PassThruConverterCreator implements ConverterCreator{ + protected PassThruConverterCreator() { + } + + public Converter createConverter(Class sourceClass, Class targetClass) { + if (sourceClass == targetClass || targetClass == Object.class || Util.instanceOf(sourceClass, targetClass)) { + return new PassThruConverter(sourceClass, targetClass); + } else { + return null; + } + } + } + + /** Pass thru converter used when the source and target java object + * types are the same. The convert method returns the + * source object. + * + */ + protected static class PassThruConverter implements Converter { + private final Class sourceClass; + private final Class targetClass; + + public PassThruConverter(Class sourceClass, Class targetClass) { + this.sourceClass = sourceClass; + this.targetClass = targetClass; + } + + public boolean canConvert(Class sourceClass, Class targetClass) { + return this.sourceClass == sourceClass && this.targetClass == targetClass; + } + + @SuppressWarnings("unchecked") + public T convert(S obj) throws ConversionException { + return (T) obj; + } + + @SuppressWarnings("unchecked") + public T convert(Class targetClass, S obj) throws ConversionException { + return (T) obj; + } + + public Class getSourceClass() { + return sourceClass; + } + + public Class getTargetClass() { + return targetClass; + } + } +} Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converters.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converters.java ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/Converters.java ------------------------------------------------------------------------------ svn:mime-type = text/plain