diff --git a/safety/Java/commons-beanutils/src/BUILDING.txt b/safety/Java/commons-beanutils/src/BUILDING.txt deleted file mode 100644 index 7513a86e3..000000000 --- a/safety/Java/commons-beanutils/src/BUILDING.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Apache BeanUtils build instructions - -Building BeanUtils requires: - - - JDK 6/OpenJDK 6 or later (recommended: JDK 8) - http://www.oracle.com/technetwork/java/javase/downloads/ - - - Apache Maven 3 or later (recommended: Maven 3.3) - https://maven.apache.org/download.cgi - -The compiled BeanUtils JAR should work with Java 6 or later. - - -To build target/commons-beanutils-*.jar - - mvn clean package - -or to install into your ~/.m2/repository - - mvn clean install - - -You can skip the unit tests by adding the parameter - - -DskipTests=true - - - -To regenerate the web site (corresponding to the official -https://commons.apache.org/proper/commons-beanutils/ ) do - - mvn clean site - -Note: the Apache Commons BeanUtils site should include a japicmp report for the -purpose of checking API version compatibility, to enable this, use Java 7 or -later and run instead: - - mvn clean package site -Pjapicmp - - diff --git a/safety/Java/commons-beanutils/src/CONTRIBUTING.md b/safety/Java/commons-beanutils/src/CONTRIBUTING.md deleted file mode 100644 index a45f937e6..000000000 --- a/safety/Java/commons-beanutils/src/CONTRIBUTING.md +++ /dev/null @@ -1,115 +0,0 @@ - - -Contributing to Apache Commons BeanUtils -====================== - -You have found a bug or you have an idea for a cool new feature? Contributing code is a great way to give something back to -the open source community. Before you dig right into the code there are a few guidelines that we need contributors to -follow so that we can have a chance of keeping on top of things. - -Getting Started ---------------- - -+ Make sure you have a [JIRA account](https://issues.apache.org/jira/). -+ Make sure you have a [GitHub account](https://github.com/signup/free). -+ If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons BeanUtils's scope. -+ Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist. - + Clearly describe the issue including steps to reproduce when it is a bug. - + Make sure you fill in the earliest version that you know has the issue. -+ Find the corresponding [repository on GitHub](https://github.com/apache/?query=commons-), -[fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository. - -Making Changes --------------- - -+ Create a _topic branch_ for your isolated work. - * Usually you should base your branch on the `master` or `trunk` branch. - * A good topic branch name can be the JIRA bug id plus a keyword, e.g. `BEANUTILS-123-InputStream`. - * If you have submitted multiple JIRA issues, try to maintain separate branches and pull requests. -+ Make commits of logical units. - * Make sure your commit messages are meaningful and in the proper format. Your commit message should contain the key of the JIRA issue. - * e.g. `BEANUTILS-123: Close input stream earlier` -+ Respect the original code style: - + Only use spaces for indentation. - + Create minimal diffs - disable _On Save_ actions like _Reformat Source Code_ or _Organize Imports_. If you feel the source code should be reformatted create a separate PR for this change first. - + Check for unnecessary whitespace with `git diff` -- check before committing. -+ Make sure you have added the necessary tests for your changes, typically in `src/test/java`. -+ Run all the tests with `mvn clean verify` to assure nothing else was accidentally broken. - -Making Trivial Changes ----------------------- - -The JIRA tickets are used to generate the changelog for the next release. - -For changes of a trivial nature to comments and documentation, it is not always necessary to create a new ticket in JIRA. -In this case, it is appropriate to start the first line of a commit with '(doc)' instead of a ticket number. - - -Submitting Changes ------------------- - -+ Sign and submit the Apache [Contributor License Agreement][cla] if you haven't already. - * Note that small patches & typical bug fixes do not require a CLA as - clause 5 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0.html#contributions) - covers them. -+ Push your changes to a topic branch in your fork of the repository. -+ Submit a _Pull Request_ to the corresponding repository in the `apache` organization. - * Verify _Files Changed_ shows only your intended changes and does not - include additional files like `target/*.class` -+ Update your JIRA ticket and include a link to the pull request in the ticket. - -If you prefer to not use GitHub, then you can instead use -`git format-patch` (or `svn diff`) and attach the patch file to the JIRA issue. - - -Additional Resources --------------------- - -+ [Contributing patches](https://commons.apache.org/patches.html) -+ [Apache Commons BeanUtils JIRA project page][jira] -+ [Contributor License Agreement][cla] -+ [General GitHub documentation](https://help.github.com/) -+ [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/) -+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) -+ `#apache-commons` IRC channel on `irc.freenode.net` - -[cla]:https://www.apache.org/licenses/#clas -[jira]:https://issues.apache.org/jira/browse/BEANUTILS diff --git a/safety/Java/commons-beanutils/src/LICENSE.txt b/safety/Java/commons-beanutils/src/LICENSE.txt deleted file mode 100644 index d64569567..000000000 --- a/safety/Java/commons-beanutils/src/LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - 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. diff --git a/safety/Java/commons-beanutils/src/NOTICE.txt b/safety/Java/commons-beanutils/src/NOTICE.txt deleted file mode 100644 index e1529d40c..000000000 --- a/safety/Java/commons-beanutils/src/NOTICE.txt +++ /dev/null @@ -1,5 +0,0 @@ -Apache Commons BeanUtils -Copyright 2000-2019 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). diff --git a/safety/Java/commons-beanutils/src/README.md b/safety/Java/commons-beanutils/src/README.md deleted file mode 100644 index 2133ad685..000000000 --- a/safety/Java/commons-beanutils/src/README.md +++ /dev/null @@ -1,105 +0,0 @@ - - -Apache Commons BeanUtils -=================== - -[![Build Status](https://travis-ci.org/apache/commons-beanutils.svg)](https://travis-ci.org/apache/commons-beanutils) -[![Coverage Status](https://coveralls.io/repos/apache/commons-beanutils/badge.svg)](https://coveralls.io/r/apache/commons-beanutils) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-beanutils2/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-beanutils2/) -[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-beanutils2/2.0.0.svg)](https://javadoc.io/doc/org.apache.commons/commons-beanutils2/2.0.0) - -Apache Commons BeanUtils provides an easy-to-use but flexible wrapper around reflection and introspection. - -Documentation -------------- - -More information can be found on the [Apache Commons BeanUtils homepage](https://commons.apache.org/proper/commons-beanutils). -The [Javadoc](https://commons.apache.org/proper/commons-beanutils/javadocs/api-release) can be browsed. -Questions related to the usage of Apache Commons BeanUtils should be posted to the [user mailing list][ml]. - -Where can I get the latest release? ------------------------------------ -You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-beanutils/download_beanutils.cgi). - -Alternatively you can pull it from the central Maven repositories: - -```xml - - org.apache.commons - commons-beanutils2 - 2.0.0 - -``` - -Contributing ------------- - -We accept Pull Requests via GitHub. The [developer mailing list][ml] is the main channel of communication for contributors. -There are some guidelines which will make applying PRs easier for us: -+ No tabs! Please use spaces for indentation. -+ Respect the code style. -+ Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. -+ Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running ```mvn clean test```. - -If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). -You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). - -License -------- -This code is under the [Apache Licence v2](https://www.apache.org/licenses/LICENSE-2.0). - -See the `NOTICE.txt` file for required notices and attributions. - -Donations ---------- -You like Apache Commons BeanUtils? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support the development. - -Additional Resources --------------------- - -+ [Apache Commons Homepage](https://commons.apache.org/) -+ [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/BEANUTILS) -+ [Apache Commons Twitter Account](https://twitter.com/ApacheCommons) -+ `#apache-commons` IRC channel on `irc.freenode.org` - -[ml]:https://commons.apache.org/mail-lists.html diff --git a/safety/Java/commons-beanutils/src/RELEASE-NOTES.txt b/safety/Java/commons-beanutils/src/RELEASE-NOTES.txt deleted file mode 100644 index 396f76ca1..000000000 --- a/safety/Java/commons-beanutils/src/RELEASE-NOTES.txt +++ /dev/null @@ -1,287 +0,0 @@ - Apache Commons BeanUtils 1.9.3 - RELEASE NOTES - -The Apache Commons team is pleased to announce the release of Apache -Commons BeanUtils 1.9.3 - -Apache Commons BeanUtils provides an easy-to-use but flexible wrapper around -reflection and introspection. - -This is a bug fix release, which also improves the tests for building on Java -8. - -Note that Java 8 and later no longer support indexed bean properties on -java.util.List, only on arrays like String[]. (BEANUTILS-492). This affects -PropertyUtils.getPropertyType() and PropertyUtils.getPropertyDescriptor(); -their javadoc have therefore been updated to reflect this change in the JDK. - - -Changes in this version include: - -Fixed Bugs: - -* BEANUTILS-477: Changed log level in FluentPropertyBeanIntrospector -* BEANUTILS-492: Fixed exception when setting indexed properties on DynaBeans. - Thanks to Bernhard Seebass. -* BEANUTILS-470: Precision lost when converting BigDecimal. Thanks to Tommy - Tynjä. -* BEANUTILS-465: Indexed List Setters fixed. Thanks to Daniel Atallah. - -Changes: -* BEANUTILS-433: Update dependency from JUnit 3.8.1 to 4.12. - Thanks to Benedikt Ritter, Gary Gregory. -* BEANUTILS-469: Update commons-logging from 1.1.1 to 1.2. - Thanks to Gary Gregory. -* BEANUTILS-474: FluentPropertyBeanIntrospector does not use the same naming - algorithm as DefaultBeanIntrospector. Thanks to Michael Grove. -* BEANUTILS-490: Update Java requirement from Java 5 to 6. - Thanks to Gary Gregory. -* BEANUTILS-482: Update commons-collections from 3.2.1 to 3.2.2 - (CVE-2015-4852). Thanks to Gary Gregory. -* BEANUTILS-490: Update java requirement to Java 6. Thanks to Gary Gregory. -* BEANUTILS-492: IndexedPropertyDescriptor tests now pass on Java 8. - Thanks to Stian Soiland-Reyes. -* BEANUTILS-495: DateConverterTestBase fails on M/d/yy in Java 9. - Thanks to Stian Soiland-Reyes. -* BEANUTILS-496: testGetDescriptorInvalidBoolean fails on Java 9. - Thanks to Stian Soiland-Reyes. - - -Historical list of changes: https://commons.apache.org/proper/commons-beanutils/changes-report.html - -For complete information on Apache Commons BeanUtils, including instructions on -how to submit bug reports, patches, or suggestions for improvement, see the -Apache Apache Commons BeanUtils website: - -https://commons.apache.org/proper/commons-beanutils/ - ------------------------------------------------------------------------------ - - Commons BeanUtils Package - Version 1.9.2 - Release Notes - -INTRODUCTION: -============ - -This document contains the release notes for this version of the Commons -BeanUtils package, and highlights changes since the previous version. - -For more information on Commons BeanUtils, see -o https://commons.apache.org/beanutils/ - -Release 1.9.2 mainly addresses a potential security issue when accessing -properties in an uncontrolled way. In a nutshell, if an application that uses -Commons BeanUtils passes property paths from an external source directly to -the getProperty() method of BeanUtilsBean, an attacker can access the class -loader via the class property available on all Java objects. - -In version 1.9.2 now a special BeanIntrospector class was added which allows -suppressing this property. Note that this BeanIntrospector is NOT enabled by -default! Commons BeanUtils is a low-level library, and on this layer it cannot -be decided whether access to a certain property is legal or not. Therefore, -an application has to activate this suppressing BeanIntrospector explicitly. -This can be done with the following lines of code: - -BeanUtilsBean bub = new BeanUtilsBean(); -bub.getPropertyUtils().addBeanIntrospector( - SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS); - -Now all access to properties has to be done via the specially configured -BeanUtilsBean instance. More information about this issue can be found at -https://issues.apache.org/jira/browse/BEANUTILS-463 or in section 2.5 of the -user's guide. - -BUGFIXES in version 1.9.2 -========================= -* [BEANUTILS-458] - BaseLocaleConverter.checkConversionResult() no longer throws a - ConversionException if the result of a conversion is null. - -New features in version 1.9.2 -============================= -* [BEANUTILS-463] - Added new SuppressPropertiesBeanIntrospector class to deal with a potential - class loader vulnerability. - ------------------------------------------------------------------------------ - - Release Notes for version 1.9.1 - -Release 1.9.1 is a bug fix release which addresses a problem with the new -feature of custom introspection introduced with release 1.9.0. It is fully -binary compatible with the previous release. The minimum required Java version -is 1.5. - -BUGFIXES in version 1.9.1 -========================= -* [BEANUTILS-456] - For PropertyDescriptors obtained via custom introspection now additional - information is stored to prevent that write methods are lost during - garbage collection. - ------------------------------------------------------------------------------ - - Release Notes for version 1.9.0 - -Release 1.9.0 contains some bug fixes and improvements that have accumulated -after the 1.8.3 release. The most obvious change is that the new version now -requires JDK 1.5 or higher, and that language features introduced with Java 5 -(mainly generics) are used. A new feature has been introduced, too: the support -for customizing bean introspection. - -Compatibility with 1.8.3 -======================== -Adding generics to the BeanUtils API has been done in a backwards compatible -way. This means that after type erasure the resulting classes look the same as -in the previous version. A drawback of this approach is that sometimes it is -not possible to use the logically correct type parameters because then -backwards compatibility would be broken. One example is the BeanMap class: The -class is now a Map while its keys actually are strings. -However, implementing Map would change the signatures of some -methods in an incompatible way. More details about limitations of the -generification can be found at -https://issues.apache.org/jira/browse/BEANUTILS-452 - -One exception from the compatibility rule is the ResultSetIterator class which -now implements the Iterator interface. This causes a change in the -return value of its next() method. ResultSetIterator is used internally as the -iterator implementation within ResultSetDynaClass (it is probably a mistake that -it is public). So chances are minimal that this change affects existing code. - -Another change which may affect compatibility is [BEANUTILS-379] (details can -be found at https://issues.apache.org/jira/browse/BEANUTILS-379). Older -versions of BeanUtils contained some classes that were copied from Commons -Collections. These classes have now been removed, and a dependency to Commons -Collections has been added; the collections jar now has to be contained in the -classpath, too. - -Except for the change on ResultSetIterator and the additional dependency to -Commons Collections, Commons BeanUtils 1.9.0 is fully binary compatible with -the previous version 1.8.3. - -Changes on Converters -===================== -The convert() method in the Converter interface now uses a type parameter in -the following way: - - T convert(Class type, Object value); - -This makes it possible to access the converter's result in a type-safe way. -Applying generics in this way revealed some inconsistencies in the Converter -implementations. There were situations in which converters could return a -result object of a different type as was requested. This was not a problem -before because the result type was just Object. Now the compiler complains if -a converter's result is not compatible with the desired target type. - -Because of that Converter implementations have been made more strict. A -converter now checks the passed in target type, and if it cannot handle it, -throws a ConversionException. This prevents unexpected results and makes -converters more reliable (it could be considered a bug that a converter returns -a result object of a different data type as the passed in target type). In a -typical scenario, when converters are accessed via ConvertUtils, this change -should not cause any problems because the converters are only called for the -data types they have been registered for. But if converters are used directly, -they might now throw ConversionExceptions when they did not in a previous -version. - -BUGFIXES in version 1.9.0 -========================= -* [BEANUTILS-454] - BeanUtilsBean.copyProperties() no longer throws a ConversionException for - null properties of certain data types. This fixes a regression introduced in - version 1.8.0. The issue is related to [BEANUTILS-387]. -* [BEANUTILS-411] - BeanUtilsBean.setProperty throws IllegalArgumentException if getter of nested - property returns null. -* [BEANUTILS-408] - MethodUtils.invokeMethod() throws NullPointerException when args==null. -* [BEANUTILS-426] - ConstructorUtils.invokeConstructor(Class klass, Object arg) throws - NullPointerException when arg==null. -* [BEANUTILS-380] - BeanMap methods should initialize the root cause of exceptions that are - thrown when running on JDK 1.4+. -* [BEANUTILS-379] - Remove copied Collection classes. -* [BEANUTILS-378] - BeanMap does not work in osgi (fixed by BEANUTILS-378). -* [BEANUTILS-381] - MethodUtils getMatchingAccessibleMethod() does not correctly handle - inheritance and method overloading. - -New features in version 1.9.0 -============================= -* [BEANUTILS-425] - Support customization of introspection mechanism. -* [BEANUTILS-428] - Provide a BeanIntrospector implementation which supports properties in a - fluent API. -* [BEANUTILS-455] - WrapDynaBeans can now be configured to use a specific instance of - PropertyUtilsBean for introspection or property access. - -Other changes in version 1.9.0 -============================== -* [BEANUTILS-452] - Add generics. -* [BEANUTILS-449] - LocaleConverters do not take the target type into account. -* [BEANUTILS-448] - LocaleConverters do not check their default value. -* [BEANUTILS-447] - LazyDynaList.toArray() is not conform to the contract defined by the - Collection interface. -* [BEANUTILS-446] - Some of the converters ignore the passed in target type. -* [BEANUTILS-445] - Converters can return an invalid result object if a default value is set. -* [BEANUTILS-441] - Replace UnmodifiableSet.decorate with Collections.unModifiableSet. -* [BEANUTILS-436] - Replace package.html with package-info.java. -* [BEANUTILS-438] - Add @Deprecated and @Override Annotations. -* [BEANUTILS-437] - Replace Date and Revision SVN keywords with Id. -* [BEANUTILS-431] - Remove @author tags and move missing authors to pom.xml. -* [BEANUTILS-432] - Switch to Java 1.5. -* [BEANUTILS-429] - Delete trailing white spaces and white spaces on empty lines from all files. -* [BEANUTILS-427] - Configure Checkstyle to check for trailing white spaces and white spaces on - empty lines. - ------------------------------------------------------------------------------ - - Release Notes for version 1.8.3 - -Compatibility with 1.8.2 -======================== -BeanUtils 1.8.3 is binary compatible release with Beanutils 1.8.2, containing only bug fixes. - -BeanUtils 1.8.3 requires a minimum of JDK 1.3. - -Memory Leak -=========== -A memory leak was found in BeanUtils 1.7.0 (see BEANUTILS-291) which was fixed -in BeanUtils 1.8.0 for JDK 1.5+. - -Testing of BeanUtils 1.8.1 revealed that the leak still appears to exist -in IBM's JDK 1.6 implementation. - - -see https://issues.apache.org/jira/browse/BEANUTILS-291 - https://issues.apache.org/jira/browse/BEANUTILS-366 - - -BUGS FIXED: -=========== - -The following is a list of the bugs fixed in this release, with their Jira issue number: - - * [BEANUTILS-373] - MethodUtils is not thread safe because WeakFastHashMap which uses WeakHashMap is not thread-safe - * [BEANUTILS-371] - Add constructors which have useColumnLabel parameter to ResultSetDynaClass and RowSetDynaClass - diff --git a/safety/Java/commons-beanutils/src/checkstyle.xml b/safety/Java/commons-beanutils/src/checkstyle.xml deleted file mode 100644 index e899d6f47..000000000 --- a/safety/Java/commons-beanutils/src/checkstyle.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/safety/Java/commons-beanutils/src/pom.xml b/safety/Java/commons-beanutils/src/pom.xml deleted file mode 100644 index 81497cb50..000000000 --- a/safety/Java/commons-beanutils/src/pom.xml +++ /dev/null @@ -1,525 +0,0 @@ - - - - - org.apache.commons - commons-parent - 50 - - 4.0.0 - commons-beanutils2 - 2.0.0-SNAPSHOT - Apache Commons BeanUtils - - 2000 - Apache Commons BeanUtils provides an easy-to-use but flexible wrapper around reflection and introspection. - https://commons.apache.org/proper/commons-beanutils/ - - - 1.8 - 1.8 - beanutils - org.apache.commons.beanutils2 - - 2.0.0 - (Java 8) - - 1.9.4 - (Java 6) - - commons-beanutils-${commons.release.2.version} - - BEANUTILS - 12310460 - - - -Xmx256M - 0.14.3 - 2.8 - utf-8 - 0.8.5 - - 2.0.0-SNAPSHOT - true - Gary Gregory - 86fdc7e2a11262cb - - - - jira - https://issues.apache.org/jira/browse/BEANUTILS - - - - scm:git:https://gitbox.apache.org/repos/asf/commons-beanutils.git - scm:git:https://gitbox.apache.org/repos/asf/commons-beanutils.git - https://gitbox.apache.org/repos/asf?p=commons-beanutils.git - - - - - apache.website - Apache Commons Beanutils Site - scm:svn:https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-beanutils - - - - - - Robert Burrell Donkin - rdonkin - rdonkin@apache.org - The Apache Software Foundation - - - Dion Gillard - dion - dion@apache.org - The Apache Software Foundation - - - Craig McClanahan - craigmcc - craigmcc@apache.org - The Apache Software Foundation - - - Geir Magnusson Jr. - geirm - geirm@apache.org - The Apache Software Foundation - - - Scott Sanders - sanders - sanders@apache.org - The Apache Software Foundation - - - James Strachan - jstrachan - jstrachan@apache.org - The Apache Software Foundation - - - Rodney Waldhoff - rwaldhoff - rwaldhoff@apache.org - The Apache Software Foundation - - - Martin van den Bemt - mvdb - mvdb@apache.org - The Apache Software Foundation - - - Yoav Shapira - yoavs - yoavs@apache.org - The Apache Software Foundation - - - Niall Pemberton - niallp - niallp@apache.org - The Apache Software Foundation - - - Simon Kitching - skitching - skitching@apache.org - The Apache Software Foundation - - - James Carman - jcarman - jcarman@apache.org - The Apache Software Foundation - - - Benedikt Ritter - britter - britter@apache.org - The Apache Software Foundation - - - Tim O'Brien - tobrien - tobrien@apache.org - The Apache Software Foundation - - - David Eric Pugh - epugh - epugh@apache.org - The Apache Software Foundation - - - Rodney Waldhoff - rwaldhoff - rwaldhoff@apache.org - The Apache Software Foundation - - - Morgan James Delagrange - morgand - morgand@apache.org - The Apache Software Foundation - - - John E. Conlon - jconlon - jconlon@apache.org - The Apache Software Foundation - - - Stephen Colebourne - scolebourne - scolebourne@apache.org - The Apache Software Foundation - - - Gary Gregory - ggregory - ggregory@apache.org - http://www.garygregory.com - -5 - The Apache Software Foundation - - - stain - Stian Soiland-Reyes - stain@apache.org - http://orcid.org/0000-0001-9842-9718 - +0 - The Apache Software Foundation - - - - - - Paul Jack - - - - Stephen Colebourne - - - - Berin Loritsch - - - - Alex Crown - - - - Marcus Zander - - - - Paul Hamamnt - - - - Rune Johannesen - - - - Clebert Suconic - - - - Norm Deane - - - - Ralph Schaer - - - - Chris Audley - - - - Rey François - - - - Gregor Raýman - - - - Jan Sorensen - - - - Eric Pabst - - - - Paulo Gaspar - - - - Michael Smith - - - - George Franciscus - - - - Erik Meade - - - - Tomas Viberg - - - - Yauheny Mikulski - - - - Michael Szlapa - - - - Juozas Baliuka - - - - Tommy Tynjä - - - - Bernhard Seebass - - - - Raviteja Lokineni - - - - Bernhard Seebass - - - - - - - commons-logging - commons-logging - 1.2 - - - commons-collections - commons-collections-testframework - 3.2.1 - test - - - junit - junit - 4.13 - test - - - - - clean apache-rat:check verify javadoc:javadoc - - - org.apache.felix - maven-bundle-plugin - - - biz.aQute.bnd - biz.aQute.bndlib - 5.1.0 - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M4 - - pertest - - ${surefire.argLine} ${argLine} - - **/*TestCase.java - - - - **/*MemoryTestCase.java - - - - true - - org.apache.commons.logging.impl.LogFactoryImpl - org.apache.commons.logging.impl.SimpleLog - WARN - - - - - - maven-assembly-plugin - - - src/main/assembly/bin.xml - src/main/assembly/src.xml - - gnu - - - - - - - org.apache.maven.plugins - maven-scm-publish-plugin - - - - - javadocs** - release-notes** - - - - - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.1.1 - - ${basedir}/checkstyle.xml - false - - - - org.apache.maven.plugins - maven-javadoc-plugin - - true - - https://docs.oracle.com/javase/8/docs/api/ - https://commons.apache.org/collections/api-release/ - - - - - org.apache.maven.plugins - maven-changes-plugin - ${commons.changes.version} - - - %URL%/%ISSUE% - - - - - - changes-report - - - - - - maven-pmd-plugin - 3.13.0 - - ${maven.compiler.target} - true - - - - pmd-report - - pmd - - - - pmd-aggregate - false - - pmd - - - true - - - - - - com.github.siom79.japicmp - japicmp-maven-plugin - ${commons.japicmp.version} - - - - org.apache.commons - commons-beanutils2 - 2.0.0-SNAPSHOT - jar - - - - - ${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging} - - - - - true - - - - - org.codehaus.mojo - findbugs-maven-plugin - ${commons.findbugs.version} - - Normal - Default - - true - -Duser.language=en - - - - - diff --git a/safety/Java/commons-beanutils/src/src/changes/changes.xml b/safety/Java/commons-beanutils/src/src/changes/changes.xml deleted file mode 100644 index ff1bc697a..000000000 --- a/safety/Java/commons-beanutils/src/src/changes/changes.xml +++ /dev/null @@ -1,662 +0,0 @@ - - - - - - - Apache Commons BeanUtils Release Notes - - - - - - New converter for Enum. - - - Double-Checked Locking anti pattern in WeakFastHashMap. - - - Update from Java 6 to 7. - - - Update from Java 7 to 8. - - - Change packaging from org.apache.commons.beanutils to org.apache.commons.beanutils2. - - - Add missing serialVersionUID to Serializable classes. - - - Add Automatic-Module-Name entry to MANIFEST.MF. - - - Remove deprecated code for 2.0.0. - - - WeakHashmap enters into infinite loop in WrapDynaClass.java. - - - BeanUtils2 mitigate CVE-2014-0114. - - - Update Apache Commons Collections from 4.3 to 4.4. - - - Convert Collections4 to java.util.function. #8. - - - Removed Commons Collections dependency. #8. - - - New converters for UUID, URI, and Path #10. - - - New converters for Java 8 Time classes #13. - - - Log at the debug level instead of info. - - - Update JUnit from 4.12 to 4.13. - - - Update Jacoco from 0.8.4 to 0.8.5. - - - Update JApiCmp from 0.12.0 to 0.14.3. - - - Update maven-surefire-plugin from 2.22.1 to 3.0.0-M4. - - - Update maven-checkstyle-plugin from 3.0.0 to 3.1.1. - - - Update maven-pmd-plugin from 3.12.0 to 3.13.0. - - - Update BC version from 1.9.3 to 1.9.4. - - - Fix typos; fix error in Javadoc; performance fix; fix code smells #25. - - - - - - BeanUtils mitigation of CVE-2014-0114. (CVE-2019-10086 for commons-beanutils). - - - - - - Update dependency from JUnit 3.8.1 to 4.12. - - - Indexed List Setters no longer work - - - Update commons-logging from 1.1.1 to 1.2. - - - Precision lost when converting BigDecimal - - - FluentPropertyBeanIntrospector does not use the same naming algorithm as DefaultBeanIntrospector. - - - Changed log level of warnings from FluentPropertyBeanIntrospector; exceptions are no longer logged with level WARN. - - - Update commons-collections from 3.2.1 to 3.2.2. (CVE-2015-4852) - - - Update Java requirement from Java 5 to 6. - - - IndexedPropertyDescriptor not supported for List in Java 8 - - - Exception when setting indexed properties: "Default conversion to ArrayList failed" - - - DateConverterTestBase fails on M/d/yy in Java 9 - - - testGetDescriptorInvalidBoolean fails on Java 9 - - - - - - Class loader vulnerability in DefaultResolver () - - - BaseLocaleConverter.checkConversionResult() fails with - ConversionException when result is null when it should not - - - - - - Write methods for PropertyDescriptors created during custom introspection are lost - - - - - - WrapDynaBeans always use the default PropertyUtilsBean instance - - - BeanUtilsBean.copyProperties() throws conversion exception for null Date - - - Add generics - - - LocaleConverters do not take the target type into account - - - LocaleConverters do not check their default value - - - LazyDynaList.toArray() is not conform to the contract defined by the - Collection interface - - - Some of the converters ignore the passed in target type - - - Converters can return an invalid result object if a default value is set - - - Replace UnmodifiableSet.decorate with Collections.unModifiableSet - - - Replace package.html with package-info.java - - - Add @Deprecated and @Override Annotations - - - Replace Date and Revision SVN keywords with Id - - - Remove @author tags and move missing authors to pom.xml - - - Switch to Java 1.5 - - - Provide a BeanIntrospector implementation which supports properties in a fluent API - - - Support customization of introspection mechanism - - - BeanUtilsBean.setProperty throws IllegalArgumentException if getter of nested property returns null - - - Delete trailing white spaces and white spaces on empty lines from all files - - - Configure Checkstyle to check for trailing white spaces and white spaces on empty lines - - - MethodUtils.invokeMethod() throws NullPointerException when args==null - - - ConstructorUtils.invokeConstructor(Class klass, Object arg) throws - NullPointerException when arg==null - - - BeanMap methods should initialize the root cause of exceptions that are thrown - when running on JDK 1.4+ - - - Remove copied Collection classes. - - - BeanMap does not work in osgi (fixed by BEANUTILS-379) - - - MethodUtils getMatchingAccessibleMethod() does not correctly handle inheritance - and method overloading. - - - - - - MethodUtils is not thread safe because WeakFastHashMap which uses WeakHashMap is not thread-safe - (duplicate of BEANUTILS-318 which was not fixed properly in BeanUtils 1.8.0). - - - Add constructors which have useColumnLabel parameter to ResultSetDynaClass and RowSetDynaClass. - - - - - - NullPointerException in BeanUtilsBean .setProperty() - - - - - - NPE in LazyDynaList - - - JDBCDynaClass throws class not found exception under java6 - - - MappedPropertyDescriptor#reLoadClass() possible NPE / odd code; also swallows Throwable - - - BeanUtilsBean.setProperty throws IllegalArgumentException if value is null - - - BeanUtilsBean.setProperty does not handle some kind of nested properties - - - MappedPropertyDescriptor throws an exception after method reference has been garbage collected - - - copyProperties throws NullPointerException if an IllegalArgumentException is thrown due to a null value parameter for a primitive - - - FloatLocaleConverter cannot parse 0 - - - Type in BooleanConverter: "Cna't convert value" - - - Avoid calling setAccessible() if not needed - - - Method createDynaProperty of JDBCDynaClass should first look for column label instead of column name in ResultSetMetadata - object.. - - - change visibility of method "evaluateValue" belongs to the class BeanPropertyValueEqualsPredicate to "protected". - - - - - - Allow access to non public class's public methods from a public sub-classes. - - - Circular Reference on WeakHashMap. - - - BeanUtilsBean.setProperty() does not support nested map. - - - Unnecessary Garbage Objects in Class PropertyUtilsBean. - - - ConvertingWrapDynaBean hides cause exceptions. - - - MethodUtils.getAccessibleMethod(Method method) could not find right public method. - - - NPE in ArrayConverter when converting a non-quoted string with underscores to a string array. - - - LocaleConvertUtilsBean.convert throws NPE on null Locale when debug logging is enabled. - - - Fix WeakHashMap is not thread safe in MethodUtils using new FastWeakHashMap. - - - PropertyUtils.getPropertyType fails for DynaBeans contained within a normal bean. - - - Iterating by a Map' key/value pairs in BeanUtilsBean and PropertyUtilsBean. - - - - - - Add plugable property name expression Resolver. - - - General Converter implementation improvements: New AbstractConverter which provides - a basic structure for Converter implementations and new NumberConverter implementation. - - - Add new generic ArrayConverter implementation. - - - Add new generic DateTimeConverter implementation. - - - Better implementation of SqlDateConverter. Modified SqlDateConverter, - SqlTimeConverter and SqlTimestampConverter to accept java.util.Date - and Calendar object instances. Added tests. - - - New Facade converter implementation - hide non-Converter public APIs. - - - Add "t/f" to BooleanConverter. - - - Support Mapped property inside a mapped property. - - - Support Indexed property inside a mapped property. - - - Support Arrays with multiple dimension. - - - Include bean class in the message of PropertyUtilsBean exceptions. - - - Provide better error message for "argument type mismatch". - - - Improved messages for unknown properties. - - - MethodUtils.invoke for static methods. - - - Log or throw exception in PropertyUtilsBean. - Added mechanism to initialize the "cause" on an Exception using reflection for JDK 1.4+ - (copied from Commons HttpClient). - - - Add lazyDynaList. - - - Provide a Map decorator for a DynaBean (enables DynaBean to be used with other teechnologies such as JSTL). - - - Implement equals() and hashCode() methods for DynaProperty. - - - - - BeanUtils's tests fail to compile under JDK 1.6 - - - Lock in BeanUtilsBean.getInstance( - - - Beanutils's describe() method cannot determine reader methods for anonymous class. - - - Added warning about describe behavior to the javadocs. - - - BeanUtilsBean's setProperty() does not convert objects using custom converters properly. - - - Fix javadoc - IllegalArgumentException in BeanUtils.copyProperties - when property types don't match. - - - Writing to a mapped property requires a setter for a map, but never uses it. - - - BeanUtilsBean.getArrayProperty() does not use ConvertUtils. - - - MappedPropertyDescriptor - replace copied code. - - - MappedPropertyDescriptor: Add comments re: * use of static variable safe in shared - classloader * memory leak possible on webapp undeploy. - - - MappedPropertyDescriptor doesn't recognize boolean property accessor. - - - Add test for MappedPropertyDescriptor with different types on get/set methods. - - - LocaleBeanUtils setProperty does not work on nested property. - - - Package scope implementation of a public interface for mapped property fails - (fixed by changes to MappedPropertyDescriptor associated with BEANUTILS-6) - - - PropertyUtils incosistency - can't use "dot" in mapped properties for setProperty - or getPropertyDescriptor (fixed by the changes for BEANUTILS-259 - Plugable Property Name Expression Resolver). - - - Public methods overridden in anonymous or private subclasses are not recognized by PropertyUtils. - - - PropertyUtilsBean's isReadable() / isWriteable() always return false for mapped properties. - - - PropertyUtilsBean isReadable() and isWriteable() methods do not work correctly for WrapDynaBean. - - - PropertyUtils.isReadable() and PropertyUtils.getProperty() not consistent. - - - PropertyUtilsBean.copyProperties does not catch NoSuchMethodException - - - PropertyUtilsBean.getIndexedProperty()'s javadoc should indicate - IndexOutOufBoundsException can be thrown rather than just - ArrayIndexOutOufBoundsException. - - - Create new methods getPropertyOfMapBean and setPropertyOfMapBean that the existing - setNestedProperty and getNestedProperty methods now call when they discover the bean - they are accessing implements Map. This makes it much easier for users to subclass - and customise this behavior of PropertyUtilsBean, eg in order to restore pre-1.5 behavior. - This patch also causes an exception to be thrown when the propertyName passed to - getPropertyOfMapBean or setPropertyOfMapBean has MAPPED_DELIM or INDEXED_DELIM chars in - it. This never worked as expected before (the whole string was treated literally as the - propertyName), so throwing an exception here should not break any existing code. It should - be of help to future developers who make this mistake though... - - - Ignore simple properties on java.util.Map objects - - Map methods are always used on a Map object. Reverts BEANUTILS-144. - See BEANUTILS-162 for discussion. - - - Correct getPropertyDescriptor() and setNestedProperty() methods to throw - a NestedNullException rather than just IllegalArgumentException (consistent - with the getNestedProperty() method). - - - Problems on indexed property with JDK 1.4. - - - BooleanArrayConverter: Use new AbstractArrayConverter constructors and - Convert strings to booleans by invoking a BooleanConverter rather than - hard-wiring the conversion. - - - BooleanConverter: Add facility for user to override the default set - of true and false string definitions and provide ability to pass special - NO_DEFAULT object as the "defaultValue" constructor parameter. - - - AbstractArrayConverter: provide ability to pass special NO_DEFAULT object as the - "defaultValue" constructor parameter. - - - DecimalLocaleConverter and subClasses never throw a ConversionException. - - - FloatLocaleConverter cannot parse negative values. - - - Improve ClassConverter robustness. - - - DateLocaleConverter does not always throw an Exception for invalid dates. - - - Don't try parsing values that are already Dates/Numbers in Date/Number locale Converters. - - - WrapDynaClass: Added comment re potential memory leak, and safety when using - shared classloader - - - Make WrapDynaBean Serializable. - - - WrapDynaBeanTestCase failing with jikes/kaffe because of static List in TestBean. - - - Misleading error message in ConvertingWrapDynaBean. - - - LazyDynaBean: don't try and instantiate properties of type Object.class. - - - LazyDynabean Javadoc corrections. - - - LazyDynaClass can create a DynaProperty with a "null" type. - - - JDBCDynaClass "lowerCase" option causes problems in RowSetDynaClass and ResultSetIterator. - - - RowSetDynaClass fails to copy ResultSet to DynaBean with Oracle 10g JDBC driver. - - - Fix BeanComparator throws wrong exception and hides cause. - - - Deprecate the public static defaultTransformers HashMap and make it unmodifiable. - - - - Merge Bean-Collections back into core BeanUtils and remove Bean-Collections sub-project. - - - Fixi the build to include all the tests and change the build.properties.sample so it's easier - to use for the default maven user (ie: it looks by default in the .maven repository) - - - Improvements to maven build. - - - Add Implementation-Vendor-Id entry to jar's manifest. - - - Resolve compiler warnings: Unused imports, un-read local variables, - field hiding, empty block, improperly used statics, uncessary semi - colons, unnecessary casts. - - - Replace use of static Log objects with instance or local variables. It isn't safe - to use static Log objects in code that might be deployed via a shared classloader - as they will bind to the Log object from the context classloader in use when the - first use happens. - - - BeanMap: Fix internal variable to not include non-existant write methods. - - ported from Commons Collections. - - - Change MethodUtils to make getMatchingAccessibleMethod() method selection more - rational. - - - - - - See href="https://commons.apache.org/beanutils/commons-beanutils-1.7.0/RELEASE-NOTES.txt - - - - - - See https://commons.apache.org/beanutils/commons-beanutils-1.6.1/RELEASE-NOTES.txt - - - - - - See https://commons.apache.org/beanutils/commons-beanutils-1.6/RELEASE-NOTES.txt - - - - - - See https://commons.apache.org/beanutils/commons-beanutils-1.5/RELEASE-NOTES.txt - - - - - - See https://commons.apache.org/beanutils/commons-beanutils-1.4.1/RELEASE-NOTES.txt - - - - - - See https://commons.apache.org/beanutils/commons-beanutils-1.4/RELEASE-NOTES.txt - - - - - - See https://commons.apache.org/beanutils/commons-beanutils-1.3/RELEASE-NOTES.txt - - - - - - See https://commons.apache.org/beanutils/commons-beanutils-1.2/RELEASE-NOTES.txt - - - - - Version 1.1 - - - - Initial Release - - - - diff --git a/safety/Java/commons-beanutils/src/src/changes/release-notes.vm b/safety/Java/commons-beanutils/src/src/changes/release-notes.vm deleted file mode 100644 index 706d3c0ce..000000000 --- a/safety/Java/commons-beanutils/src/src/changes/release-notes.vm +++ /dev/null @@ -1,122 +0,0 @@ -## 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. -## - ${project.name} ${version} - RELEASE NOTES - -The ${developmentTeam} is pleased to announce the release of ${project.name} ${version} - -$introduction.replaceAll("(? - - bin - - tar.gz - zip - - false - - - - LICENSE.txt - NOTICE.txt - RELEASE-NOTES.txt - - - - target - - - *.jar - - - - target/site/apidocs - apidocs - - - diff --git a/safety/Java/commons-beanutils/src/src/main/assembly/src.xml b/safety/Java/commons-beanutils/src/src/main/assembly/src.xml deleted file mode 100644 index ecd8d5a69..000000000 --- a/safety/Java/commons-beanutils/src/src/main/assembly/src.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - src - - tar.gz - zip - - ${artifactId}-${version}-src - - - - build.properties.sample - build.xml - checkstyle.xml - CONTRIBUTING.md - BUILDING.txt - LICENSE.txt - NOTICE.txt - pom.xml - README.md - RELEASE-NOTES.txt - - - - src - - - diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BaseDynaBeanMapDecorator.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BaseDynaBeanMapDecorator.java deleted file mode 100644 index 5658b6063..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BaseDynaBeanMapDecorator.java +++ /dev/null @@ -1,402 +0,0 @@ -/* - * 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.beanutils2; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - *

A base class for decorators providing {@code Map} behavior on - * {@link DynaBean}s.

- * - *

The motivation for this implementation is to provide access to {@link DynaBean} - * properties in technologies that are unaware of BeanUtils and {@link DynaBean}s - - * such as the expression languages of JSTL and JSF.

- * - *

This rather technical base class implements the methods of the - * {@code Map} interface on top of a {@code DynaBean}. It was introduced - * to handle generic parameters in a meaningful way without breaking - * backwards compatibility of the 1.x {@code DynaBeanMapDecorator} class: A - * map wrapping a {@code DynaBean} should be of type {@code Map}. - * However, when using these generic parameters in {@code DynaBeanMapDecorator} - * this would be an incompatible change (as method signatures would have to - * be adapted). To solve this problem, this generic base class is added - * which allows specifying the key type as parameter. This makes it easy to - * have a new subclass using the correct generic parameters while - * {@code DynaBeanMapDecorator} could still remain with compatible - * parameters.

- * - * @param the type of the keys in the decorated map - * @since BeanUtils 1.9.0 - */ -public abstract class BaseDynaBeanMapDecorator implements Map { - - private final DynaBean dynaBean; - private final boolean readOnly; - private transient Set keySet; - - - - /** - * Constructs a read only Map for the specified - * {@link DynaBean}. - * - * @param dynaBean The dyna bean being decorated - * @throws IllegalArgumentException if the {@link DynaBean} is null. - */ - public BaseDynaBeanMapDecorator(final DynaBean dynaBean) { - this(dynaBean, true); - } - - /** - * Construct a Map for the specified {@link DynaBean}. - * - * @param dynaBean The dyna bean being decorated - * @param readOnly {@code true} if the Map is read only - * otherwise {@code false} - * @throws IllegalArgumentException if the {@link DynaBean} is null. - */ - public BaseDynaBeanMapDecorator(final DynaBean dynaBean, final boolean readOnly) { - if (dynaBean == null) { - throw new IllegalArgumentException("DynaBean is null"); - } - this.dynaBean = dynaBean; - this.readOnly = readOnly; - } - - - - - - /** - * Indicate whether the Map is read only. - * - * @return {@code true} if the Map is read only, - * otherwise {@code false}. - */ - public boolean isReadOnly() { - return readOnly; - } - - - - /** - * clear() operation is not supported. - * - * @throws UnsupportedOperationException This operation is not yet supported - */ - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - /** - * Indicate whether the {@link DynaBean} contains a specified - * value for one (or more) of its properties. - * - * @param key The {@link DynaBean}'s property name - * @return {@code true} if one of the {@link DynaBean}'s - * properties contains a specified value. - */ - @Override - public boolean containsKey(final Object key) { - final DynaClass dynaClass = getDynaBean().getDynaClass(); - final DynaProperty dynaProperty = dynaClass.getDynaProperty(toString(key)); - return dynaProperty != null; - } - - /** - * Indicates whether the decorated {@link DynaBean} contains - * a specified value. - * - * @param value The value to check for. - * @return {@code true} if one of the the {@link DynaBean}'s - * properties contains the specified value, otherwise - * {@code false}. - */ - @Override - public boolean containsValue(final Object value) { - final DynaProperty[] properties = getDynaProperties(); - for (final DynaProperty property : properties) { - final String key = property.getName(); - final Object prop = getDynaBean().get(key); - if (value == null) { - if (prop == null) { - return true; - } - } else { - if (value.equals(prop)) { - return true; - } - } - } - return false; - } - - /** - *

Returns the Set of the property/value mappings - * in the decorated {@link DynaBean}.

- * - *

Each element in the Set is a {@code Map.Entry} - * type.

- * - * @return An unmodifiable set of the DynaBean - * property name/value pairs - */ - @Override - public Set> entrySet() { - final DynaProperty[] properties = getDynaProperties(); - final Set> set = new HashSet<>(properties.length); - for (final DynaProperty property : properties) { - final K key = convertKey(property.getName()); - final Object value = getDynaBean().get(property.getName()); - set.add(new MapEntry<>(key, value)); - } - return Collections.unmodifiableSet(set); - } - - /** - * Return the value for the specified key from - * the decorated {@link DynaBean}. - * - * @param key The {@link DynaBean}'s property name - * @return The value for the specified property. - */ - @Override - public Object get(final Object key) { - return getDynaBean().get(toString(key)); - } - - /** - * Indicate whether the decorated {@link DynaBean} has - * any properties. - * - * @return {@code true} if the {@link DynaBean} has - * no properties, otherwise {@code false}. - */ - @Override - public boolean isEmpty() { - return getDynaProperties().length == 0; - } - - /** - *

Returns the Set of the property - * names in the decorated {@link DynaBean}.

- * - *

N.B.For {@link DynaBean}s whose associated {@link DynaClass} - * is a {@link MutableDynaClass} a new Set is created every - * time, otherwise the Set is created only once and cached.

- * - * @return An unmodifiable set of the {@link DynaBean}s - * property names. - */ - @Override - public Set keySet() { - if (keySet != null) { - return keySet; - } - - // Create a Set of the keys - final DynaProperty[] properties = getDynaProperties(); - Set set = new HashSet<>(properties.length); - for (final DynaProperty property : properties) { - set.add(convertKey(property.getName())); - } - set = Collections.unmodifiableSet(set); - - // Cache the keySet if Not a MutableDynaClass - final DynaClass dynaClass = getDynaBean().getDynaClass(); - if (!(dynaClass instanceof MutableDynaClass)) { - keySet = set; - } - - return set; - - } - - /** - * Set the value for the specified property in - * the decorated {@link DynaBean}. - * - * @param key The {@link DynaBean}'s property name - * @param value The value for the specified property. - * @return The previous property's value. - * @throws UnsupportedOperationException if - * {@code isReadOnly()} is true. - */ - @Override - public Object put(final K key, final Object value) { - if (isReadOnly()) { - throw new UnsupportedOperationException("Map is read only"); - } - final String property = toString(key); - final Object previous = getDynaBean().get(property); - getDynaBean().set(property, value); - return previous; - } - - /** - * Copy the contents of a Map to the decorated {@link DynaBean}. - * - * @param map The Map of values to copy. - * @throws UnsupportedOperationException if - * {@code isReadOnly()} is true. - */ - @Override - public void putAll(final Map map) { - if (isReadOnly()) { - throw new UnsupportedOperationException("Map is read only"); - } - for (final Map.Entry e : map.entrySet()) { - put(e.getKey(), e.getValue()); - } - } - - /** - * remove() operation is not supported. - * - * @param key The {@link DynaBean}'s property name - * @return the value removed - * @throws UnsupportedOperationException This operation is not yet supported - */ - @Override - public Object remove(final Object key) { - throw new UnsupportedOperationException(); - } - - /** - * Returns the number properties in the decorated - * {@link DynaBean}. - * @return The number of properties. - */ - @Override - public int size() { - return getDynaProperties().length; - } - - /** - * Returns the set of property values in the - * decorated {@link DynaBean}. - * - * @return Unmodifiable collection of values. - */ - @Override - public Collection values() { - final DynaProperty[] properties = getDynaProperties(); - final List values = new ArrayList<>(properties.length); - for (final DynaProperty property : properties) { - final String key = property.getName(); - final Object value = getDynaBean().get(key); - values.add(value); - } - return Collections.unmodifiableList(values); - } - - - - /** - * Provide access to the underlying {@link DynaBean} - * this Map decorates. - * - * @return the decorated {@link DynaBean}. - */ - public DynaBean getDynaBean() { - return dynaBean; - } - - /** - * Converts the name of a property to the key type of this decorator. - * - * @param propertyName the name of a property - * @return the converted key to be used in the decorated map - */ - protected abstract K convertKey(String propertyName); - - - - /** - * Convenience method to retrieve the {@link DynaProperty}s - * for this {@link DynaClass}. - * - * @return The an array of the {@link DynaProperty}s. - */ - private DynaProperty[] getDynaProperties() { - return getDynaBean().getDynaClass().getDynaProperties(); - } - - /** - * Convenience method to convert an Object - * to a String. - * - * @param obj The Object to convert - * @return String representation of the object - */ - private String toString(final Object obj) { - return obj == null ? null : obj.toString(); - } - - /** - * Map.Entry implementation. - */ - private static class MapEntry implements Map.Entry { - - private final K key; - private final Object value; - - MapEntry(final K key, final Object value) { - this.key = key; - this.value = value; - } - - @Override - public boolean equals(final Object o) { - if (!(o instanceof Map.Entry)) { - return false; - } - final Map.Entry e = (Map.Entry)o; - return key.equals(e.getKey()) && - (value == null ? e.getValue() == null - : value.equals(e.getValue())); - } - - @Override - public int hashCode() { - return key.hashCode() + (value == null ? 0 : value.hashCode()); - } - - @Override - public K getKey() { - return key; - } - - @Override - public Object getValue() { - return value; - } - - @Override - public Object setValue(final Object value) { - throw new UnsupportedOperationException(); - } - } - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java deleted file mode 100644 index bb8c2fed4..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BasicDynaBean.java +++ /dev/null @@ -1,439 +0,0 @@ -/* - * 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.beanutils2; - -import java.io.Serializable; -import java.lang.reflect.Array; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - *

Minimal implementation of the {@code DynaBean} interface. Can be - * used as a convenience base class for more sophisticated implementations.

- * - *

IMPLEMENTATION NOTE - Instances of this class that are - * accessed from multiple threads simultaneously need to be synchronized.

- * - *

IMPLEMENTATION NOTE - Instances of this class can be - * successfully serialized and deserialized ONLY if all - * property values are {@code Serializable}.

- * - */ - -public class BasicDynaBean implements DynaBean, Serializable { - - private static final Short SHORT_ZERO = Short.valueOf((short) 0); - - private static final Long LONG_ZERO = Long.valueOf(0); - - private static final Integer INTEGER_ZERO = Integer.valueOf(0); - - private static final Float FLOAT_ZERO = Float.valueOf((float) 0.0); - - private static final Double DOUBLE_ZERO = Double.valueOf(0.0); - - private static final Character CHARACTER_ZERO = Character.valueOf((char) 0); - - private static final Byte BYTE_ZERO = Byte.valueOf((byte) 0); - - private static final long serialVersionUID = 1L; - - /** - * Construct a new {@code DynaBean} associated with the specified - * {@code DynaClass} instance. - * - * @param dynaClass The DynaClass we are associated with - */ - public BasicDynaBean(final DynaClass dynaClass) { - - super(); - this.dynaClass = dynaClass; - - } - - /** - * The {@code DynaClass} "base class" that this DynaBean - * is associated with. - */ - protected DynaClass dynaClass; - - /** - * The set of property values for this DynaBean, keyed by property name. - */ - protected HashMap values = new HashMap<>(); - - /** Map decorator for this DynaBean */ - private transient Map mapDecorator; - - /** - *

- * Return a Map representation of this DynaBean. - *

- * This, for example, could be used in JSTL in the following way to access - * a DynaBean's {@code fooProperty}: - *

  • {@code ${myDynaBean.map.fooProperty}}
- * - * @return a Map representation of this DynaBean - * @since 1.8.0 - */ - public Map getMap() { - - // cache the Map - if (mapDecorator == null) { - mapDecorator = new DynaBeanPropertyMapDecorator(this); - } - return mapDecorator; - - } - - /** - * Does the specified mapped property contain a value for the specified - * key value? - * - * @param name Name of the property to check - * @param key Name of the key to check - * @return {@code true} if the mapped property contains a value for - * the specified key, otherwise {@code false} - * - * @throws IllegalArgumentException if there is no property - * of the specified name - */ - @Override - public boolean contains(final String name, final String key) { - - final Object value = values.get(name); - if (value == null) { - throw new NullPointerException - ("No mapped value for '" + name + "(" + key + ")'"); - } else if (value instanceof Map) { - return ((Map) value).containsKey(key); - } else { - throw new IllegalArgumentException - ("Non-mapped property for '" + name + "(" + key + ")'"); - } - - } - - /** - * Return the value of a simple property with the specified name. - * - * @param name Name of the property whose value is to be retrieved - * @return The property's value - * - * @throws IllegalArgumentException if there is no property - * of the specified name - */ - @Override - public Object get(final String name) { - - // Return any non-null value for the specified property - final Object value = values.get(name); - if (value != null) { - return value; - } - - // Return a null value for a non-primitive property - final Class type = getDynaProperty(name).getType(); - if (!type.isPrimitive()) { - return value; - } - - // Manufacture default values for primitive properties - if (type == Boolean.TYPE) { - return Boolean.FALSE; - } else if (type == Byte.TYPE) { - return BYTE_ZERO; - } else if (type == Character.TYPE) { - return CHARACTER_ZERO; - } else if (type == Double.TYPE) { - return DOUBLE_ZERO; - } else if (type == Float.TYPE) { - return FLOAT_ZERO; - } else if (type == Integer.TYPE) { - return INTEGER_ZERO; - } else if (type == Long.TYPE) { - return LONG_ZERO; - } else if (type == Short.TYPE) { - return SHORT_ZERO; - } else { - return null; - } - - } - - /** - * Return the value of an indexed property with the specified name. - * - * @param name Name of the property whose value is to be retrieved - * @param index Index of the value to be retrieved - * @return The indexed property's value - * - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws IllegalArgumentException if the specified property - * exists, but is not indexed - * @throws IndexOutOfBoundsException if the specified index - * is outside the range of the underlying property - * @throws NullPointerException if no array or List has been - * initialized for this property - */ - @Override - public Object get(final String name, final int index) { - - final Object value = values.get(name); - if (value == null) { - throw new NullPointerException - ("No indexed value for '" + name + "[" + index + "]'"); - } else if (value.getClass().isArray()) { - return Array.get(value, index); - } else if (value instanceof List) { - return ((List) value).get(index); - } else { - throw new IllegalArgumentException - ("Non-indexed property for '" + name + "[" + index + "]'"); - } - - } - - /** - * Return the value of a mapped property with the specified name, - * or {@code null} if there is no value for the specified key. - * - * @param name Name of the property whose value is to be retrieved - * @param key Key of the value to be retrieved - * @return The mapped property's value - * - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws IllegalArgumentException if the specified property - * exists, but is not mapped - */ - @Override - public Object get(final String name, final String key) { - - final Object value = values.get(name); - if (value == null) { - throw new NullPointerException - ("No mapped value for '" + name + "(" + key + ")'"); - } else if (value instanceof Map) { - return ((Map) value).get(key); - } else { - throw new IllegalArgumentException - ("Non-mapped property for '" + name + "(" + key + ")'"); - } - - } - - /** - * Return the {@code DynaClass} instance that describes the set of - * properties available for this DynaBean. - * - * @return The associated DynaClass - */ - @Override - public DynaClass getDynaClass() { - - return this.dynaClass; - - } - - /** - * Remove any existing value for the specified key on the - * specified mapped property. - * - * @param name Name of the property for which a value is to - * be removed - * @param key Key of the value to be removed - * - * @throws IllegalArgumentException if there is no property - * of the specified name - */ - @Override - public void remove(final String name, final String key) { - - final Object value = values.get(name); - if (value == null) { - throw new NullPointerException - ("No mapped value for '" + name + "(" + key + ")'"); - } else if (value instanceof Map) { - ((Map) value).remove(key); - } else { - throw new IllegalArgumentException - ("Non-mapped property for '" + name + "(" + key + ")'"); - } - - } - - /** - * Set the value of a simple property with the specified name. - * - * @param name Name of the property whose value is to be set - * @param value Value to which this property is to be set - * - * @throws ConversionException if the specified value cannot be - * converted to the type required for this property - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws NullPointerException if an attempt is made to set a - * primitive property to null - */ - @Override - public void set(final String name, final Object value) { - - final DynaProperty descriptor = getDynaProperty(name); - if (value == null) { - if (descriptor.getType().isPrimitive()) { - throw new NullPointerException - ("Primitive value for '" + name + "'"); - } - } else if (!isAssignable(descriptor.getType(), value.getClass())) { - throw new ConversionException - ("Cannot assign value of type '" + - value.getClass().getName() + - "' to property '" + name + "' of type '" + - descriptor.getType().getName() + "'"); - } - values.put(name, value); - - } - - /** - * Set the value of an indexed property with the specified name. - * - * @param name Name of the property whose value is to be set - * @param index Index of the property to be set - * @param value Value to which this property is to be set - * - * @throws ConversionException if the specified value cannot be - * converted to the type required for this property - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws IllegalArgumentException if the specified property - * exists, but is not indexed - * @throws IndexOutOfBoundsException if the specified index - * is outside the range of the underlying property - */ - @Override - public void set(final String name, final int index, final Object value) { - - final Object prop = values.get(name); - if (prop == null) { - throw new NullPointerException - ("No indexed value for '" + name + "[" + index + "]'"); - } else if (prop.getClass().isArray()) { - Array.set(prop, index, value); - } else if (prop instanceof List) { - try { - @SuppressWarnings("unchecked") - final - // This is safe to cast because list properties are always - // of type Object - List list = (List) prop; - list.set(index, value); - } catch (final ClassCastException e) { - throw new ConversionException(e.getMessage()); - } - } else { - throw new IllegalArgumentException - ("Non-indexed property for '" + name + "[" + index + "]'"); - } - - } - - /** - * Set the value of a mapped property with the specified name. - * - * @param name Name of the property whose value is to be set - * @param key Key of the property to be set - * @param value Value to which this property is to be set - * - * @throws ConversionException if the specified value cannot be - * converted to the type required for this property - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws IllegalArgumentException if the specified property - * exists, but is not mapped - */ - @Override - public void set(final String name, final String key, final Object value) { - - final Object prop = values.get(name); - if (prop == null) { - throw new NullPointerException - ("No mapped value for '" + name + "(" + key + ")'"); - } else if (prop instanceof Map) { - @SuppressWarnings("unchecked") - final - // This is safe to cast because mapped properties are always - // maps of types String -> Object - Map map = (Map) prop; - map.put(key, value); - } else { - throw new IllegalArgumentException - ("Non-mapped property for '" + name + "(" + key + ")'"); - } - - } - - /** - * Return the property descriptor for the specified property name. - * - * @param name Name of the property for which to retrieve the descriptor - * @return The property descriptor - * - * @throws IllegalArgumentException if this is not a valid property - * name for our DynaClass - */ - protected DynaProperty getDynaProperty(final String name) { - - final DynaProperty descriptor = getDynaClass().getDynaProperty(name); - if (descriptor == null) { - throw new IllegalArgumentException - ("Invalid property name '" + name + "'"); - } - return descriptor; - - } - - /** - * Is an object of the source class assignable to the destination class? - * - * @param dest Destination class - * @param source Source class - * @return {@code true} if the source class is assignable to the - * destination class, otherwise {@code false} - */ - protected boolean isAssignable(final Class dest, final Class source) { - - if (dest.isAssignableFrom(source) || - dest == Boolean.TYPE && source == Boolean.class || - dest == Byte.TYPE && source == Byte.class || - dest == Character.TYPE && source == Character.class || - dest == Double.TYPE && source == Double.class || - dest == Float.TYPE && source == Float.class || - dest == Integer.TYPE && source == Integer.class || - dest == Long.TYPE && source == Long.class || - dest == Short.TYPE && source == Short.class) { - return true; - } - return false; - - } - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BasicDynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BasicDynaClass.java deleted file mode 100644 index afb46a788..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BasicDynaClass.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * 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.beanutils2; - -import java.io.Serializable; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; - -/** - *

Minimal implementation of the {@code DynaClass} interface. Can be - * used as a convenience base class for more sophisticated implementations.

- *

IMPLEMENTATION NOTE - The {@code DynaBean} - * implementation class supplied to our constructor MUST have a one-argument - * constructor of its own that accepts a {@code DynaClass}. This is - * used to associate the DynaBean instance with this DynaClass.

- * - */ - -public class BasicDynaClass implements DynaClass, Serializable { - - private static final long serialVersionUID = 1L; - - - - /** - * Construct a new BasicDynaClass with default parameters. - */ - public BasicDynaClass() { - - this(null, null, null); - - } - - /** - * Construct a new BasicDynaClass with the specified parameters. - * - * @param name Name of this DynaBean class - * @param dynaBeanClass The implementation class for new instances - */ - public BasicDynaClass(final String name, final Class dynaBeanClass) { - - this(name, dynaBeanClass, null); - - } - - /** - * Construct a new BasicDynaClass with the specified parameters. - * - * @param name Name of this DynaBean class - * @param dynaBeanClass The implementation class for new instances - * @param properties Property descriptors for the supported properties - */ - public BasicDynaClass(final String name, Class dynaBeanClass, - final DynaProperty[] properties) { - - super(); - if (name != null) { - this.name = name; - } - if (dynaBeanClass == null) { - dynaBeanClass = BasicDynaBean.class; - } - setDynaBeanClass(dynaBeanClass); - if (properties != null) { - setProperties(properties); - } - - } - - - - /** - * The constructor of the {@code dynaBeanClass} that we will use - * for creating new instances. - */ - protected transient Constructor constructor = null; - - /** - * The method signature of the constructor we will use to create - * new DynaBean instances. - */ - protected static Class[] constructorTypes = { DynaClass.class }; - - /** - * The argument values to be passed to the constructor we will use - * to create new DynaBean instances. - */ - protected Object[] constructorValues = { this }; - - /** - * The {@code DynaBean} implementation class we will use for - * creating new instances. - */ - protected Class dynaBeanClass = BasicDynaBean.class; - - /** - * The "name" of this DynaBean class. - */ - protected String name = this.getClass().getName(); - - /** - * The set of dynamic properties that are part of this DynaClass. - */ - protected DynaProperty[] properties = new DynaProperty[0]; - - /** - * The set of dynamic properties that are part of this DynaClass, - * keyed by the property name. Individual descriptor instances will - * be the same instances as those in the {@code properties} list. - */ - protected HashMap propertiesMap = new HashMap<>(); - - - - /** - * Return the name of this DynaClass (analogous to the - * {@code getName()} method of {@code java.lang.Class}, which - * allows the same {@code DynaClass} implementation class to support - * different dynamic classes, with different sets of properties. - * - * @return the name of the DynaClass - */ - @Override - public String getName() { - - return this.name; - - } - - /** - * Return a property descriptor for the specified property, if it exists; - * otherwise, return {@code null}. - * - * @param name Name of the dynamic property for which a descriptor - * is requested - * @return The descriptor for the specified property - * - * @throws IllegalArgumentException if no property name is specified - */ - @Override - public DynaProperty getDynaProperty(final String name) { - - if (name == null) { - throw new IllegalArgumentException - ("No property name specified"); - } - return propertiesMap.get(name); - - } - - /** - *

Return an array of {@code PropertyDescriptor} for the properties - * currently defined in this DynaClass. If no properties are defined, a - * zero-length array will be returned.

- * - *

FIXME - Should we really be implementing - * {@code getBeanInfo()} instead, which returns property descriptors - * and a bunch of other stuff?

- * - * @return the set of properties for this DynaClass - */ - @Override - public DynaProperty[] getDynaProperties() { - - return properties; - - } - - /** - * Instantiate and return a new DynaBean instance, associated - * with this DynaClass. - * - * @return A new {@code DynaBean} instance - * @throws IllegalAccessException if the Class or the appropriate - * constructor is not accessible - * @throws InstantiationException if this Class represents an abstract - * class, an array class, a primitive type, or void; or if instantiation - * fails for some other reason - */ - @Override - public DynaBean newInstance() - throws IllegalAccessException, InstantiationException { - - try { - // Refind the constructor after a deserialization (if needed) - if (constructor == null) { - setDynaBeanClass(this.dynaBeanClass); - } - // Invoke the constructor to create a new bean instance - return (DynaBean) constructor.newInstance(constructorValues); - } catch (final InvocationTargetException e) { - throw new InstantiationException - (e.getTargetException().getMessage()); - } - - } - - - - /** - * Return the Class object we will use to create new instances in the - * {@code newInstance()} method. This Class MUST - * implement the {@code DynaBean} interface. - * - * @return The class of the {@link DynaBean} - */ - public Class getDynaBeanClass() { - - return this.dynaBeanClass; - - } - - - - /** - * Set the Class object we will use to create new instances in the - * {@code newInstance()} method. This Class MUST - * implement the {@code DynaBean} interface. - * - * @param dynaBeanClass The new Class object - * - * @throws IllegalArgumentException if the specified Class does not - * implement the {@code DynaBean} interface - */ - protected void setDynaBeanClass(final Class dynaBeanClass) { - - // Validate the argument type specified - if (dynaBeanClass.isInterface()) { - throw new IllegalArgumentException - ("Class " + dynaBeanClass.getName() + - " is an interface, not a class"); - } - if (!DynaBean.class.isAssignableFrom(dynaBeanClass)) { - throw new IllegalArgumentException - ("Class " + dynaBeanClass.getName() + - " does not implement DynaBean"); - } - - // Identify the Constructor we will use in newInstance() - try { - this.constructor = dynaBeanClass.getConstructor(constructorTypes); - } catch (final NoSuchMethodException e) { - throw new IllegalArgumentException - ("Class " + dynaBeanClass.getName() + - " does not have an appropriate constructor"); - } - this.dynaBeanClass = dynaBeanClass; - - } - - /** - * Set the list of dynamic properties supported by this DynaClass. - * - * @param properties List of dynamic properties to be supported - */ - protected void setProperties(final DynaProperty[] properties) { - - this.properties = properties; - propertiesMap.clear(); - for (final DynaProperty property : properties) { - propertiesMap.put(property.getName(), property); - } - - } - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanAccessLanguageException.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanAccessLanguageException.java deleted file mode 100644 index 411223f0f..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanAccessLanguageException.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.beanutils2; - -/** - * Thrown to indicate that the Bean Access Language cannot execute query - * against given bean. This is a runtime exception and access languages are encouraged - * to subclass to create custom exceptions whenever appropriate. - * - * @since 1.7 - */ - -public class BeanAccessLanguageException extends IllegalArgumentException { - - private static final long serialVersionUID = 1L; - - - - /** - * Constructs a {@code BeanAccessLanguageException} without a detail message. - */ - public BeanAccessLanguageException() { - super(); - } - - /** - * Constructs a {@code BeanAccessLanguageException} without a detail message. - * - * @param message the detail message explaining this exception - */ - public BeanAccessLanguageException(final String message) { - super(message); - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanComparator.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanComparator.java deleted file mode 100644 index 381b26fb0..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanComparator.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * 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.beanutils2; - -import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.util.Comparator; - -/** - *

- * This comparator compares two beans by the specified bean property. It is also possible to compare beans based on - * nested, indexed, combined, mapped bean properties. Please see the {@link PropertyUtilsBean} documentation for all - * property name possibilities. - * - *

- *

- * Note: The BeanComparator passes the values of the specified bean property to an internal natural - * order {@link Comparator}, if no comparator is specified in the constructor. If you are comparing two beans based on a - * property that could contain "null" values, a suitable {@code Comparator} or Apache Commons Collection - * {@code ComparatorChain} should be supplied in the constructor. Note that the passed in {@code Comparator} must - * be able to handle the passed in objects. Because the type of the property to be compared is not known at compile time - * no type checks can be performed by the compiler. Thus {@code ClassCastException} exceptions can be thrown if - * unexpected property values occur. - *

- * - * @param the type of beans to be compared by this {@code Comparator} - * @param the type of property to compare - */ -public class BeanComparator implements Comparator, Serializable { - - private static final long serialVersionUID = 1L; - private String property; - private final Comparator comparator; - - /** - *

- * Constructs a Bean Comparator without a property set. - *

- *

- * Note that this is intended to be used only in bean-centric environments. - *

- *

- * Until {@link #setProperty} is called with a non-null value. this comparator will compare the Objects only. - *

- */ - public BeanComparator() { - this(null); - } - - /** - *

- * Constructs a property-based comparator for beans. This compares two beans by the property specified in the - * property parameter. This constructor creates a {@code BeanComparator} that uses a - * {@code ComparableComparator} to compare the property values. - *

- * - *

- * Passing "null" to this constructor will cause the BeanComparator to compare objects based on natural order, that - * is {@code java.lang.Comparable}. - *

- * - * @param property String Name of a bean property, which may contain the name of a simple, nested, indexed, mapped, - * or combined property. See {@link PropertyUtilsBean} for property query language syntax. If the property - * passed in is null then the actual objects will be compared - */ - public BeanComparator(final String property) { - this(property, NaturalOrderComparator.INSTANCE); - } - - /** - * Constructs a property-based comparator for beans. This constructor creates a BeanComparator that uses the - * supplied Comparator to compare the property values. - * - * @param property Name of a bean property, can contain the name of a simple, nested, indexed, mapped, or combined - * property. See {@link PropertyUtilsBean} for property query language syntax. - * @param comparator BeanComparator will pass the values of the specified bean property to this Comparator. If your - * bean property is not a comparable or contains null values, a suitable comparator may be supplied in this - * constructor. - */ - public BeanComparator(final String property, final Comparator comparator) { - setProperty(property); - this.comparator = comparator != null ? comparator : NaturalOrderComparator.INSTANCE; - } - - /** - * Sets the method to be called to compare two JavaBeans - * - * @param property String method name to call to compare If the property passed in is null then the actual objects - * will be compared - */ - public void setProperty(final String property) { - this.property = property; - } - - /** - * Gets the property attribute of the BeanComparator - * - * @return String method name to call to compare. A null value indicates that the actual objects will be compared - */ - public String getProperty() { - return property; - } - - /** - * Gets the Comparator being used to compare beans. - * - * @return the Comparator being used to compare beans - */ - public Comparator getComparator() { - return comparator; - } - - /** - * Compare two JavaBeans by their shared property. If {@link #getProperty} is null then the actual objects will be - * compared. - * - * @param o1 Object The first bean to get data from to compare against - * @param o2 Object The second bean to get data from to compare - * @return int negative or positive based on order - */ - @Override - public int compare(final T o1, final T o2) { - - if (property == null) { - // compare the actual objects - return internalCompare(o1, o2); - } - - try { - final Object value1 = PropertyUtils.getProperty(o1, property); - final Object value2 = PropertyUtils.getProperty(o2, property); - return internalCompare(value1, value2); - } catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e.getClass().getSimpleName()+": " + e.toString()); - } - } - - /** - * Two {@code BeanComparator}'s are equals if and only if the wrapped comparators and the property names to be - * compared are equal. - * - * @param o Comparator to compare to - * @return whether the the comparators are equal or not - */ - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - if (!(o instanceof BeanComparator)) { - return false; - } - - final BeanComparator beanComparator = (BeanComparator) o; - - if (!comparator.equals(beanComparator.comparator)) { - return false; - } - if (property != null) { - if (!property.equals(beanComparator.property)) { - return false; - } - } else { - return beanComparator.property == null; - } - - return true; - } - - /** - * Hashcode compatible with equals. - * - * @return the hash code for this comparator - */ - @Override - public int hashCode() { - return comparator.hashCode(); - } - - /** - * Compares the given values using the internal {@code Comparator}. Note: This comparison cannot be - * performed in a type-safe way; so {@code ClassCastException} exceptions may be thrown. - * - * @param val1 the first value to be compared - * @param val2 the second value to be compared - * @return the result of the comparison - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - private int internalCompare(final Object val1, final Object val2) { - return ((Comparator) comparator).compare(val1, val2); - } - - /** - * A {@link Comparator Comparator} that compares {@link Comparable Comparable} objects. - *

- * This Comparator is useful, for example, for enforcing the natural order in custom implementations of - * {@link java.util.SortedSet SortedSet} and {@link java.util.SortedMap SortedMap}. - *

- * - * @param the type of objects compared by this comparator - * @see java.util.Collections#reverseOrder() - */ - private static class NaturalOrderComparator> - implements Comparator, Serializable { - - /** Serialization version. */ - private static final long serialVersionUID = -291439688585137865L; - - /** The singleton instance. */ - @SuppressWarnings("rawtypes") - public static final NaturalOrderComparator INSTANCE = new NaturalOrderComparator(); - - /** - * Private constructor to prevent instantiation. Only use INSTANCE. - */ - private NaturalOrderComparator() { - super(); - } - - /** - * Compare the two {@link Comparable Comparable} arguments. This method is equivalent to: - * - *
-         * ((Comparable) obj1).compareTo(obj2)
-         * 
- */ - @Override - public int compare(final E obj1, final E obj2) { - return obj1.compareTo(obj2); - } - - @Override - public int hashCode() { - return "NaturalOrderComparator".hashCode(); - } - - @Override - public boolean equals(final Object object) { - return this == object || null != object && object.getClass().equals(this.getClass()); - } - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanIntrospectionData.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanIntrospectionData.java deleted file mode 100644 index f49928061..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanIntrospectionData.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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.beanutils2; - -import java.beans.IntrospectionException; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -/** - *

- * An internally used helper class for storing introspection information about a bean - * class. - *

- *

- * This class is used by {@link PropertyUtilsBean}. When accessing bean properties via - * reflection information about the properties available and their types and access - * methods must be present. {@code PropertyUtilsBean} stores this information in a cache - * so that it can be accessed quickly. The cache stores instances of this class. - *

- *

- * This class mainly stores information about the properties of a bean class. Per default, - * this is contained in {@code PropertyDescriptor} objects. Some additional information - * required by the {@code BeanUtils} library is also stored here. - *

- * - * @since 1.9.1 - */ -class BeanIntrospectionData { - /** An array with property descriptors for the managed bean class. */ - private final PropertyDescriptor[] descriptors; - - /** A map for remembering the write method names for properties. */ - private final Map writeMethodNames; - - /** - * Creates a new instance of {@code BeanIntrospectionData} and initializes its - * completely. - * - * @param descs the array with the descriptors of the available properties - */ - public BeanIntrospectionData(final PropertyDescriptor[] descs) { - this(descs, setUpWriteMethodNames(descs)); - } - - /** - * Creates a new instance of {@code BeanIntrospectionData} and allows setting the map - * with write method names. This constructor is mainly used for testing purposes. - * - * @param descs the array with the descriptors of the available properties - * @param writeMethNames the map with the names of write methods - */ - BeanIntrospectionData(final PropertyDescriptor[] descs, final Map writeMethNames) { - descriptors = descs; - writeMethodNames = writeMethNames; - } - - /** - * Returns the array with property descriptors. - * - * @return the property descriptors for the associated bean class - */ - public PropertyDescriptor[] getDescriptors() { - return descriptors; - } - - /** - * Returns the {@code PropertyDescriptor} for the property with the specified name. If - * this property is unknown, result is null. - * - * @param name the name of the property in question - * @return the {@code PropertyDescriptor} for this property or null - */ - public PropertyDescriptor getDescriptor(final String name) { - for (final PropertyDescriptor pd : getDescriptors()) { - if (name.equals(pd.getName())) { - return pd; - } - } - return null; - } - - /** - * Returns the write method for the property determined by the given - * {@code PropertyDescriptor}. This information is normally available in the - * descriptor object itself. However, at least by the ORACLE implementation, the - * method is stored as a {@code SoftReference}. If this reference has been freed by - * the GC, it may be the case that the method cannot be obtained again. Then, - * additional information stored in this object is necessary to obtain the method - * again. - * - * @param beanCls the class of the affected bean - * @param desc the {@code PropertyDescriptor} of the desired property - * @return the write method for this property or null if there is none - */ - public Method getWriteMethod(final Class beanCls, final PropertyDescriptor desc) { - Method method = desc.getWriteMethod(); - if (method == null) { - final String methodName = writeMethodNames.get(desc.getName()); - if (methodName != null) { - method = MethodUtils.getAccessibleMethod(beanCls, methodName, - desc.getPropertyType()); - if (method != null) { - try { - desc.setWriteMethod(method); - } catch (final IntrospectionException e) { - // ignore, in this case the method is not cached - } - } - } - } - - return method; - } - - /** - * Initializes the map with the names of the write methods for the supported - * properties. The method names - if defined - need to be stored separately because - * they may get lost when the GC claims soft references used by the - * {@code PropertyDescriptor} objects. - * - * @param descs the array with the descriptors of the available properties - * @return the map with the names of write methods for properties - */ - private static Map setUpWriteMethodNames(final PropertyDescriptor[] descs) { - final Map methods = new HashMap<>(); - for (final PropertyDescriptor pd : descs) { - final Method method = pd.getWriteMethod(); - if (method != null) { - methods.put(pd.getName(), method.getName()); - } - } - return methods; - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanIntrospector.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanIntrospector.java deleted file mode 100644 index 12bfefbef..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanIntrospector.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.beanutils2; - -import java.beans.IntrospectionException; - -/** - *

- * Definition of an interface for components that can perform introspection on - * bean classes. - *

- *

- * Before {@link PropertyUtils} can be used for interaction with a specific Java - * class, the class's properties have to be determined. This is called - * introspection and is initiated automatically on demand. - * {@code PropertyUtils} does not perform introspection on its own, but - * delegates this task to one or more objects implementing this interface. This - * makes it possible to customize introspection which may be useful for certain - * code bases using non-standard conventions for accessing properties. - *

- * - * @since 1.9 - */ -public interface BeanIntrospector { - /** - * Performs introspection on a Java class. The current class to be inspected - * can be queried from the passed in {@code IntrospectionContext} - * object. A typical implementation has to obtain this class, determine its - * properties according to the rules it implements, and add them to the - * passed in context object. - * - * @param icontext the context object for interaction with the initiator of - * the introspection request - * @throws IntrospectionException if an error occurs during introspection - */ - void introspect(IntrospectionContext icontext) - throws IntrospectionException; -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanMap.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanMap.java deleted file mode 100644 index 566f79619..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanMap.java +++ /dev/null @@ -1,733 +0,0 @@ -/* - * 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.beanutils2; - -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.AbstractMap; -import java.util.AbstractSet; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; - -/** - * An implementation of Map for JavaBeans which uses introspection to get and put properties in the bean. - *

- * If an exception occurs during attempts to get or set a property then the property is considered non existent in the - * Map - *

- */ -public class BeanMap extends AbstractMap implements Cloneable { - - private transient Object bean; - - private transient HashMap readMethods = new HashMap<>(); - private transient HashMap writeMethods = new HashMap<>(); - private transient HashMap> types = new HashMap<>(); - - /** - * An empty array. Used to invoke accessors via reflection. - */ - public static final Object[] NULL_ARGUMENTS = {}; - - /** - * Maps primitive Class types to transformers. The transformer transform strings into the appropriate primitive - * wrapper. - * - * N.B. private & unmodifiable replacement for the (public & static) defaultTransformers instance. - */ - private static final Map, Function> typeTransformers = Collections - .unmodifiableMap(createTypeTransformers()); - - private static Map, Function> createTypeTransformers() { - final Map, Function> defTransformers = new HashMap<>(); - defTransformers.put(Boolean.TYPE, input -> Boolean.valueOf(input.toString())); - defTransformers.put(Character.TYPE, input -> Character.valueOf(input.toString().charAt(0))); - defTransformers.put(Byte.TYPE, input -> Byte.valueOf(input.toString())); - defTransformers.put(Short.TYPE, input -> Short.valueOf(input.toString())); - defTransformers.put(Integer.TYPE, input -> Integer.valueOf(input.toString())); - defTransformers.put(Long.TYPE, input -> Long.valueOf(input.toString())); - defTransformers.put(Float.TYPE, input -> Float.valueOf(input.toString())); - defTransformers.put(Double.TYPE, input -> Double.valueOf(input.toString())); - return defTransformers; - } - - // Constructors - - - /** - * Constructs a new empty {@code BeanMap}. - */ - public BeanMap() { - } - - /** - * Constructs a new {@code BeanMap} that operates on the specified bean. If the given bean is - * {@code null}, then this map will be empty. - * - * @param bean the bean for this map to operate on - */ - public BeanMap(final Object bean) { - this.bean = bean; - initialise(); - } - - // Map interface - - - /** - * Renders a string representation of this object. - * - * @return a {@code String} representation of this object - */ - @Override - public String toString() { - return "BeanMap<" + bean + ">"; - } - - /** - * Clone this bean map using the following process: - * - *
    - *
  • If there is no underlying bean, return a cloned BeanMap without a bean. - * - *
  • Since there is an underlying bean, try to instantiate a new bean of the same type using Class.newInstance(). - * - *
  • If the instantiation fails, throw a CloneNotSupportedException - * - *
  • Clone the bean map and set the newly instantiated bean as the underlying bean for the bean map. - * - *
  • Copy each property that is both readable and writable from the existing object to a cloned bean map. - * - *
  • If anything fails along the way, throw a CloneNotSupportedException. - * - *
- * - * @return a cloned instance of this bean map - * @throws CloneNotSupportedException if the underlying bean cannot be cloned - */ - @Override - public Object clone() throws CloneNotSupportedException { - final BeanMap newMap = (BeanMap) super.clone(); - - if (bean == null) { - // no bean, just an empty bean map at the moment. return a newly - // cloned and empty bean map. - return newMap; - } - - Object newBean = null; - final Class beanClass = bean.getClass(); // Cannot throw Exception - try { - newBean = beanClass.newInstance(); - } catch (final Exception e) { - // unable to instantiate - final CloneNotSupportedException cnse = new CloneNotSupportedException( - "Unable to instantiate the underlying bean \"" + beanClass.getName() + "\": " + e); - BeanUtils.initCause(cnse, e); - throw cnse; - } - - try { - newMap.setBean(newBean); - } catch (final Exception exception) { - final CloneNotSupportedException cnse = new CloneNotSupportedException( - "Unable to set bean in the cloned bean map: " + exception); - BeanUtils.initCause(cnse, exception); - throw cnse; - } - - try { - // copy only properties that are readable and writable. If its - // not readable, we can't get the value from the old map. If - // its not writable, we can't write a value into the new map. - for (final String key : readMethods.keySet()) { - if (getWriteMethod(key) != null) { - newMap.put(key, get(key)); - } - } - } catch (final Exception exception) { - final CloneNotSupportedException cnse = new CloneNotSupportedException( - "Unable to copy bean values to cloned bean map: " + exception); - BeanUtils.initCause(cnse, exception); - throw cnse; - } - - return newMap; - } - - /** - * Puts all of the writable properties from the given BeanMap into this BeanMap. Read-only and Write-only properties - * will be ignored. - * - * @param map the BeanMap whose properties to put - */ - public void putAllWriteable(final BeanMap map) { - for (final String key : map.readMethods.keySet()) { - if (getWriteMethod(key) != null) { - this.put(key, map.get(key)); - } - } - } - - /** - * This method reinitializes the bean map to have default values for the bean's properties. This is accomplished by - * constructing a new instance of the bean which the map uses as its underlying data source. This behavior for - * {@code clear()} differs from the Map contract in that the mappings are not actually removed from the map - * (the mappings for a BeanMap are fixed). - */ - @Override - public void clear() { - if (bean == null) { - return; - } - - Class beanClass = null; - try { - beanClass = bean.getClass(); - bean = beanClass.newInstance(); - } catch (final Exception e) { - final UnsupportedOperationException uoe = new UnsupportedOperationException( - "Could not create new instance of class: " + beanClass); - BeanUtils.initCause(uoe, e); - throw uoe; - } - } - - /** - * Returns true if the bean defines a property with the given name. - *

- * The given name must be a {@code String}; if not, this method returns false. This method will also return - * false if the bean does not define a property with that name. - *

- * Write-only properties will not be matched as the test operates against property read methods. - * - * @param name the name of the property to check - * @return false if the given name is null or is not a {@code String}; false if the bean does not define a - * property with that name; or true if the bean does define a property with that name - */ - @Override - public boolean containsKey(final Object name) { - final Method method = getReadMethod(name); - return method != null; - } - - /** - * Returns true if the bean defines a property whose current value is the given object. - * - * @param value the value to check - * @return false true if the bean has at least one property whose current value is that object, false otherwise - */ - @Override - public boolean containsValue(final Object value) { - // use default implementation - return super.containsValue(value); - } - - /** - * Returns the value of the bean's property with the given name. - *

- * The given name must be a {@link String} and must not be null; otherwise, this method returns {@code null}. - * If the bean defines a property with the given name, the value of that property is returned. Otherwise, - * {@code null} is returned. - *

- * Write-only properties will not be matched as the test operates against property read methods. - * - * @param name the name of the property whose value to return - * @return the value of the property with that name - */ - @Override - public Object get(final Object name) { - if (bean != null) { - final Method method = getReadMethod(name); - if (method != null) { - try { - return method.invoke(bean, NULL_ARGUMENTS); - } catch (final IllegalAccessException | NullPointerException | InvocationTargetException | IllegalArgumentException e) { - logWarn(e); - } - } - } - return null; - } - - /** - * Sets the bean property with the given name to the given value. - * - * @param name the name of the property to set - * @param value the value to set that property to - * @return the previous value of that property - * @throws IllegalArgumentException if the given name is null; if the given name is not a {@link String}; if the - * bean doesn't define a property with that name; or if the bean property with that name is read-only - * @throws ClassCastException if an error occurs creating the method args - */ - @Override - public Object put(final String name, final Object value) throws IllegalArgumentException, ClassCastException { - if (bean != null) { - final Object oldValue = get(name); - final Method method = getWriteMethod(name); - if (method == null) { - throw new IllegalArgumentException( - "The bean of type: " + bean.getClass().getName() + " has no property called: " + name); - } - try { - final Object[] arguments = createWriteMethodArguments(method, value); - method.invoke(bean, arguments); - - final Object newValue = get(name); - firePropertyChange(name, oldValue, newValue); - } catch (final InvocationTargetException | IllegalAccessException e) { - final IllegalArgumentException iae = new IllegalArgumentException(e.getMessage()); - if (!BeanUtils.initCause(iae, e)) { - logInfo(e); - } - throw iae; - } - return oldValue; - } - return null; - } - - /** - * Returns the number of properties defined by the bean. - * - * @return the number of properties defined by the bean - */ - @Override - public int size() { - return readMethods.size(); - } - - /** - * Get the keys for this BeanMap. - *

- * Write-only properties are not included in the returned set of property names, although it is possible to - * set their value and to get their type. - * - * @return BeanMap keys. The Set returned by this method is not modifiable. - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - // The set actually contains strings; however, because it cannot be - // modified there is no danger in selling it as Set - @Override - public Set keySet() { - return Collections.unmodifiableSet((Set) readMethods.keySet()); - } - - /** - * Gets a Set of MapEntry objects that are the mappings for this BeanMap. - *

- * Each MapEntry can be set but not removed. - * - * @return the unmodifiable set of mappings - */ - @Override - public Set> entrySet() { - return Collections.unmodifiableSet(new AbstractSet>() { - @Override - public Iterator> iterator() { - return entryIterator(); - } - - @Override - public int size() { - return BeanMap.this.readMethods.size(); - } - }); - } - - /** - * Returns the values for the BeanMap. - * - * @return values for the BeanMap. The returned collection is not modifiable. - */ - @Override - public Collection values() { - final ArrayList answer = new ArrayList<>(readMethods.size()); - for (final Iterator iter = valueIterator(); iter.hasNext();) { - answer.add(iter.next()); - } - return Collections.unmodifiableList(answer); - } - - // Helper methods - - - /** - * Returns the type of the property with the given name. - * - * @param name the name of the property - * @return the type of the property, or {@code null} if no such property exists - */ - public Class getType(final String name) { - return types.get(name); - } - - /** - * Convenience method for getting an iterator over the keys. - *

- * Write-only properties will not be returned in the iterator. - * - * @return an iterator over the keys - */ - public Iterator keyIterator() { - return readMethods.keySet().iterator(); - } - - /** - * Convenience method for getting an iterator over the values. - * - * @return an iterator over the values - */ - public Iterator valueIterator() { - final Iterator iter = keyIterator(); - return new Iterator() { - @Override - public boolean hasNext() { - return iter.hasNext(); - } - - @Override - public Object next() { - final Object key = iter.next(); - return get(key); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("remove() not supported for BeanMap"); - } - }; - } - - /** - * Convenience method for getting an iterator over the entries. - * - * @return an iterator over the entries - */ - public Iterator> entryIterator() { - final Iterator iter = keyIterator(); - return new Iterator>() { - @Override - public boolean hasNext() { - return iter.hasNext(); - } - - @Override - public Map.Entry next() { - final String key = iter.next(); - final Object value = get(key); - // This should not cause any problems; the key is actually a - // string, but it does no harm to expose it as Object - return new Entry(BeanMap.this, key, value); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("remove() not supported for BeanMap"); - } - }; - } - - // Properties - - - /** - * Returns the bean currently being operated on. The return value may be null if this map is empty. - * - * @return the bean being operated on by this map - */ - public Object getBean() { - return bean; - } - - /** - * Sets the bean to be operated on by this map. The given value may be null, in which case this map will be empty. - * - * @param newBean the new bean to operate on - */ - public void setBean(final Object newBean) { - bean = newBean; - reinitialise(); - } - - /** - * Returns the accessor for the property with the given name. - * - * @param name the name of the property - * @return the accessor method for the property, or null - */ - public Method getReadMethod(final String name) { - return readMethods.get(name); - } - - /** - * Returns the mutator for the property with the given name. - * - * @param name the name of the property - * @return the mutator method for the property, or null - */ - public Method getWriteMethod(final String name) { - return writeMethods.get(name); - } - - // Implementation methods - - - /** - * Returns the accessor for the property with the given name. - * - * @param name the name of the property - * @return null if the name is null; null if the name is not a {@link String}; null if no such property exists; or - * the accessor method for that property - */ - protected Method getReadMethod(final Object name) { - return readMethods.get(name); - } - - /** - * Returns the mutator for the property with the given name. - * - * @param name the name of the - * @return null if the name is null; null if the name is not a {@link String}; null if no such property exists; null - * if the property is read-only; or the mutator method for that property - */ - protected Method getWriteMethod(final Object name) { - return writeMethods.get(name); - } - - /** - * Reinitializes this bean. Called during {@link #setBean(Object)}. Does introspection to find properties. - */ - protected void reinitialise() { - readMethods.clear(); - writeMethods.clear(); - types.clear(); - initialise(); - } - - private void initialise() { - if (getBean() == null) { - return; - } - - final Class beanClass = getBean().getClass(); - try { - // BeanInfo beanInfo = Introspector.getBeanInfo( bean, null ); - final BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); - final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); - if (propertyDescriptors != null) { - for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) { - if (propertyDescriptor != null) { - final String name = propertyDescriptor.getName(); - final Method readMethod = propertyDescriptor.getReadMethod(); - final Method writeMethod = propertyDescriptor.getWriteMethod(); - final Class aType = propertyDescriptor.getPropertyType(); - - if (readMethod != null) { - readMethods.put(name, readMethod); - } - if (writeMethod != null) { - writeMethods.put(name, writeMethod); - } - types.put(name, aType); - } - } - } - } catch (final IntrospectionException e) { - logWarn(e); - } - } - - /** - * Called during a successful {@link #put(String,Object)} operation. Default implementation does nothing. Override - * to be notified of property changes in the bean caused by this map. - * - * @param key the name of the property that changed - * @param oldValue the old value for that property - * @param newValue the new value for that property - */ - protected void firePropertyChange(final Object key, final Object oldValue, final Object newValue) { - // noop - } - - // Implementation classes - - - /** - * Map entry used by {@link BeanMap}. - */ - protected static class Entry extends AbstractMap.SimpleEntry { - - private static final long serialVersionUID = 1L; - private final BeanMap owner; - - /** - * Constructs a new {@code Entry}. - * - * @param owner the BeanMap this entry belongs to - * @param key the key for this entry - * @param value the value for this entry - */ - protected Entry(final BeanMap owner, final String key, final Object value) { - super(key, value); - this.owner = owner; - } - - /** - * Sets the value. - * - * @param value the new value for the entry - * @return the old value for the entry - */ - @Override - public Object setValue(final Object value) { - final String key = getKey(); - final Object oldValue = owner.get(key); - - owner.put(key, value); - final Object newValue = owner.get(key); - super.setValue(newValue); - return oldValue; - } - } - - /** - * Creates an array of parameters to pass to the given mutator method. If the given object is not the right type to - * pass to the method directly, it will be converted using {@link #convertType(Class,Object)}. - * - * @param method the mutator method - * @param value the value to pass to the mutator method - * @return an array containing one object that is either the given value or a transformed value - * @throws IllegalAccessException if {@link #convertType(Class,Object)} raises it - * @throws IllegalArgumentException if any other exception is raised by {@link #convertType(Class,Object)} - * @throws ClassCastException if an error occurs creating the method args - */ - protected Object[] createWriteMethodArguments(final Method method, Object value) - throws IllegalAccessException, ClassCastException { - try { - if (value != null) { - final Class[] paramTypes = method.getParameterTypes(); - if (paramTypes != null && paramTypes.length > 0) { - final Class paramType = paramTypes[0]; - if (!paramType.isAssignableFrom(value.getClass())) { - value = convertType(paramType, value); - } - } - } - final Object[] answer = { value }; - return answer; - } catch (final InvocationTargetException e) { - final IllegalArgumentException iae = new IllegalArgumentException(e.getMessage()); - if (!BeanUtils.initCause(iae, e)) { - logInfo(e); - } - throw iae; - } catch (final InstantiationException e) { - final IllegalArgumentException iae = new IllegalArgumentException(e.getMessage()); - if (!BeanUtils.initCause(iae, e)) { - logInfo(e); - } - BeanUtils.initCause(iae, e); - throw iae; - } - } - - /** - * Converts the given value to the given type. First, reflection is is used to find a public constructor declared by - * the given class that takes one argument, which must be the precise type of the given value. If such a constructor - * is found, a new object is created by passing the given value to that constructor, and the newly constructed - * object is returned. - *

- * - * If no such constructor exists, and the given type is a primitive type, then the given value is converted to a - * string using its {@link Object#toString() toString()} method, and that string is parsed into the correct - * primitive type using, for instance, {@link Integer#valueOf(String)} to convert the string into an - * {@code int}. - *

- * - * If no special constructor exists and the given type is not a primitive type, this method returns the original - * value. - * - * @param newType the type to convert the value to - * @param value the value to convert - * @return the converted value - * @throws NumberFormatException if newType is a primitive type, and the string representation of the given value - * cannot be converted to that type - * @throws InstantiationException if the constructor found with reflection raises it - * @throws InvocationTargetException if the constructor found with reflection raises it - * @throws IllegalAccessException never - * @throws IllegalArgumentException never - */ - protected Object convertType(final Class newType, final Object value) - throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - - // try call constructor - try { - final Constructor constructor = newType.getConstructor(value.getClass()); - return constructor.newInstance(value); - } catch (final NoSuchMethodException e) { - // try using the transformers - final Function transformer = getTypeTransformer(newType); - if (transformer != null) { - return transformer.apply(value); - } - return value; - } - } - - /** - * Returns a transformer for the given primitive type. - * - * @param aType the primitive type whose transformer to return - * @return a transformer that will convert strings into that type, or null if the given type is not a primitive type - */ - protected Function getTypeTransformer(final Class aType) { - return typeTransformers.get(aType); - } - - /** - * Logs the given exception to {@code System.out}. Used to display warnings while accessing/mutating the bean. - * - * @param ex the exception to log - */ - protected void logInfo(final Exception ex) { - // Deliberately do not use LOG4J or Commons Logging to avoid dependencies - System.out.println("INFO: Exception: " + ex); - } - - /** - * Logs the given exception to {@code System.err}. Used to display errors while accessing/mutating the bean. - * - * @param ex the exception to log - */ - protected void logWarn(final Exception ex) { - // Deliberately do not use LOG4J or Commons Logging to avoid dependencies - System.out.println("WARN: Exception: " + ex); - ex.printStackTrace(); - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanPredicate.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanPredicate.java deleted file mode 100644 index a116b3f4d..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanPredicate.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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.beanutils2; - -import java.lang.reflect.InvocationTargetException; -import java.util.function.Predicate; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - *

Predicate implementation that applies the given {@code Predicate} - * to the result of calling the given property getter. - *

- * - * @param the type of the input to the predicate - */ -public class BeanPredicate implements Predicate { - - private final Log log = LogFactory.getLog(this.getClass()); - - /** Name of the property whose value will be predicated */ - private String propertyName; - /** {@code Predicate} to be applied to the property value */ - private Predicate predicate; - - /** - * Constructs a {@code BeanPredicate} that applies the given - * {@code Predicate} to the named property value. - * @param propertyName the name of the property whose value is to be predicated, - * not null - * @param predicate the {@code Predicate} to be applied, - * not null - */ - public BeanPredicate(final String propertyName, final Predicate predicate) { - this.propertyName = propertyName; - this.predicate = predicate; - } - - /** - * Evaluates the given object by applying the {@link #getPredicate()} - * to a property value named by {@link #getPropertyName()}. - * - * @param object The object to test - * @return the result of the predicate evaluation - * @throws IllegalArgumentException when the property cannot be evaluated - */ - @Override - public boolean test(final Object object) { - boolean evaluation = false; - - try { - final T propValue = (T) PropertyUtils.getProperty(object, propertyName); - evaluation = predicate.test(propValue); - } catch (final IllegalArgumentException e) { - final String errorMsg = "Problem during evaluation."; - log.error("ERROR: " + errorMsg, e); - throw e; - } catch (final IllegalAccessException e) { - final String errorMsg = "Unable to access the property provided."; - log.error(errorMsg, e); - throw new IllegalArgumentException(errorMsg); - } catch (final InvocationTargetException e) { - final String errorMsg = "Exception occurred in property's getter"; - log.error(errorMsg, e); - throw new IllegalArgumentException(errorMsg); - } catch (final NoSuchMethodException e) { - final String errorMsg = "Property not found."; - log.error(errorMsg, e); - throw new IllegalArgumentException(errorMsg); - } - - return evaluation; - } - - /** - * Gets the name of the property whose value is to be predicated. - * in the evaluation. - * @return the property name, not null - */ - public String getPropertyName() { - return propertyName; - } - - /** - * Sets the name of the property whose value is to be predicated. - * @param propertyName the name of the property whose value is to be predicated, - * not null - */ - public void setPropertyName(final String propertyName) { - this.propertyName = propertyName; - } - - /** - * Gets the {@code Predicate} to be applied to the value of the named property - * during {@link #test(Object)}. - * @return {@code Predicate}, not null - */ - public Predicate getPredicate() { - return predicate; - } - - /** - * Sets the {@code Predicate} to be applied to the value of the named property - * during {@link #test(Object)}. - * @param predicate {@code Predicate}, not null - */ - public void setPredicate(final Predicate predicate) { - this.predicate = predicate; - } - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumer.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumer.java deleted file mode 100644 index 0b6a69891..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueChangeConsumer.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * 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.beanutils2; - -import java.lang.reflect.InvocationTargetException; -import java.util.function.Consumer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - - -/** - *

{@code Closure} that sets a property.

- *

- * An implementation of {@code java.util.function.Consumer} that updates - * a specified property on the object provided with a specified value. - * The {@code BeanPropertyValueChangeClosure} constructor takes two parameters which determine - * what property will be updated and with what value. - *

- *
- * {@code public BeanPropertyValueChangeClosure( String propertyName, Object propertyValue )} - *
- *
- * Will create a {@code Closure} that will update an object by setting the property - * specified by {@code propertyName to the value specified by propertyValue}. - *
- *
- * - *

- * Note: Property names can be a simple, nested, indexed, or mapped property as defined by - * {@code org.apache.commons.beanutils2.PropertyUtils}. If any object in the property path - * specified by {@code propertyName is null} then the outcome is based on the - * value of the {@code ignoreNull} attribute. - *

- *

- * A typical usage might look like: - *

- *

- * // create the closure
- * BeanPropertyValueChangeClosure closure =
- *    new BeanPropertyValueChangeClosure( "activeEmployee", Boolean.TRUE );
- *
- * // update the Collection
- * CollectionUtils.forAllDo( peopleCollection, closure );
- * 
- * - * This would take a {@code Collection} of person objects and update the - * {@code activeEmployee
property of each object in the Collection} to - * {@code true}. Assuming... - *
    - *
  • - * The top level object in the {@code peopleCollection} is an object which represents a - * person. - *
  • - *
  • - * The person object has a {@code setActiveEmployee( boolean )} method which updates - * the value for the object's {@code activeEmployee} property. - *
  • - *
- * - * @param The type of the input to the operation - * @param The property value type. - * - * @see org.apache.commons.beanutils2.PropertyUtils - * @see java.util.function.Consumer - */ -public class BeanPropertyValueChangeConsumer implements Consumer { - - /** For logging. */ - private final Log log = LogFactory.getLog(this.getClass()); - - /** - * The name of the property which will be updated when this {@code Closure} executes. - */ - private String propertyName; - - /** - * The value that the property specified by {@code propertyName} - * will be updated to when this {@code Closure} executes. - */ - private V propertyValue; - - /** - * Determines whether {@code null} objects in the property path will generate an - * {@code IllegalArgumentException
or not. If set to true} then if any objects - * in the property path leading up to the target property evaluate to {@code null} then the - * {@code IllegalArgumentException throw by PropertyUtils} will be logged but - * not re-thrown. If set to {@code false} then if any objects in the property path leading - * up to the target property evaluate to {@code null} then the - * {@code IllegalArgumentException throw by PropertyUtils} will be logged and - * re-thrown. - */ - private boolean ignoreNull; - - /** - * Constructor which takes the name of the property to be changed, the new value to set - * the property to, and assumes {@code ignoreNull to be false}. - * - * @param propertyName The name of the property that will be updated with the value specified by - * {@code propertyValue}. - * @param propertyValue The value that {@code propertyName} will be set to on the target - * object. - * @throws IllegalArgumentException If the propertyName provided is null or empty. - */ - public BeanPropertyValueChangeConsumer(final String propertyName, final V propertyValue) { - this(propertyName, propertyValue, false); - } - - /** - * Constructor which takes the name of the property to be changed, the new value to set - * the property to and a boolean which determines whether {@code null} objects in the - * property path will generate an {@code IllegalArgumentException} or not. - * - * @param propertyName The name of the property that will be updated with the value specified by - * {@code propertyValue}. - * @param propertyValue The value that {@code propertyName} will be set to on the target - * object. - * @param ignoreNull Determines whether {@code null} objects in the property path will - * generate an {@code IllegalArgumentException} or not. - * @throws IllegalArgumentException If the propertyName provided is null or empty. - */ - public BeanPropertyValueChangeConsumer(final String propertyName, final V propertyValue, final boolean ignoreNull) { - super(); - - if (propertyName != null && propertyName.length() > 0) { - this.propertyName = propertyName; - this.propertyValue = propertyValue; - this.ignoreNull = ignoreNull; - } else { - throw new IllegalArgumentException("propertyName cannot be null or empty"); - } - } - - /** - * Updates the target object provided using the property update criteria provided when this - * {@code BeanPropertyValueChangeClosure} was constructed. If any object in the property - * path leading up to the target property is {@code null} then the outcome will be based on - * the value of the {@code ignoreNull attribute. By default, ignoreNull} is - * {@code false and would result in an IllegalArgumentException} if an object - * in the property path leading up to the target property is {@code null}. - * - * @param object The object to be updated. - * @throws IllegalArgumentException If an IllegalAccessException, InvocationTargetException, or - * NoSuchMethodException is thrown when trying to access the property specified on the object - * provided. Or if an object in the property path provided is {@code null} and - * {@code ignoreNull is set to false}. - */ - @Override - public void accept(final Object object) { - - try { - PropertyUtils.setProperty(object, propertyName, propertyValue); - } catch (final IllegalArgumentException e) { - final String errorMsg = "Unable to execute Closure. Null value encountered in property path..."; - - if (ignoreNull) { - log.warn("WARNING: " + errorMsg + e); - } else { - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } - } catch (final IllegalAccessException e) { - final String errorMsg = "Unable to access the property provided."; - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } catch (final InvocationTargetException e) { - final String errorMsg = "Exception occurred in property's getter"; - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } catch (final NoSuchMethodException e) { - final String errorMsg = "Property not found"; - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } - } - - /** - * Returns the name of the property which will be updated when this {@code Closure} executes. - * - * @return The name of the property which will be updated when this {@code Closure} executes. - */ - public String getPropertyName() { - return propertyName; - } - - /** - * Returns the value that the property specified by {@code propertyName} - * will be updated to when this {@code Closure} executes. - * - * @return The value that the property specified by {@code propertyName} - * will be updated to when this {@code Closure} executes. - */ - public V getPropertyValue() { - return propertyValue; - } - - /** - * Returns the flag that determines whether {@code null} objects in the property path will - * generate an {@code IllegalArgumentException or not. If set to true} then - * if any objects in the property path leading up to the target property evaluate to - * {@code null then the IllegalArgumentException} throw by - * {@code PropertyUtils will be logged but not re-thrown. If set to false} then - * if any objects in the property path leading up to the target property evaluate to - * {@code null then the IllegalArgumentException} throw by - * {@code PropertyUtils} will be logged and re-thrown. - * - * @return The flag that determines whether {@code null} objects in the property path will - * generate an {@code IllegalArgumentException} or not. - */ - public boolean isIgnoreNull() { - return ignoreNull; - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicate.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicate.java deleted file mode 100644 index c376411f1..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanPropertyValueEqualsPredicate.java +++ /dev/null @@ -1,293 +0,0 @@ -/* - * 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.beanutils2; - -import java.lang.reflect.InvocationTargetException; -import java.util.Objects; -import java.util.function.Predicate; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - *

{@code Predicate} that evaluates a property value against a specified value.

- *

- * An implementation of {@code java.util.function.Predicate} that evaluates a - * property value on the object provided against a specified value and returns {@code true} - * if equal; {@code false} otherwise. - * The {@code BeanPropertyValueEqualsPredicate} constructor takes two parameters which - * determine what property will be evaluated on the target object and what its expected value should - * be. - *

- *
- *
- * - * {@code public BeanPropertyValueEqualsPredicate( String propertyName, Object propertyValue )} - * - *
- *
- * Will create a {@code Predicate} that will evaluate the target object and return - * {@code true if the property specified by propertyName} has a value which - * is equal to the the value specified by {@code propertyValue}. Or return - * {@code false} otherwise. - *
- *
- *

- * Note: Property names can be a simple, nested, indexed, or mapped property as defined by - * {@code org.apache.commons.beanutils2.PropertyUtils}. If any object in the property path - * specified by {@code propertyName is null} then the outcome is based on the - * value of the {@code ignoreNull} attribute. - *

- *

- * A typical usage might look like: - *

- *

- * // create the closure
- * BeanPropertyValueEqualsPredicate predicate =
- *    new BeanPropertyValueEqualsPredicate( "activeEmployee", Boolean.FALSE );
- *
- * // filter the Collection
- * CollectionUtils.filter( peopleCollection, predicate );
- * 
- *

- * This would take a {@code Collection} of person objects and filter out any people whose - * {@code activeEmployee property is false}. Assuming... - *

- *
    - *
  • - * The top level object in the {@code peopleCollection} is an object which represents a - * person. - *
  • - *
  • - * The person object has a {@code getActiveEmployee()} method which returns - * the boolean value for the object's {@code activeEmployee} property. - *
  • - *
- *

- * Another typical usage might look like: - *

- *

- * // create the closure
- * BeanPropertyValueEqualsPredicate predicate =
- *    new BeanPropertyValueEqualsPredicate( "personId", "456-12-1234" );
- *
- * // search the Collection
- * CollectionUtils.find( peopleCollection, predicate );
- * 
- *

- * This would search a {@code Collection} of person objects and return the first object whose - * {@code personId property value equals 456-12-1234}. Assuming... - *

- *
    - *
  • - * The top level object in the {@code peopleCollection} is an object which represents a - * person. - *
  • - *
  • - * The person object has a {@code getPersonId()} method which returns - * the value for the object's {@code personId} property. - *
  • - *
- * - * @param The type of the input to the predicate. - * @param The property value type. - * - * @see org.apache.commons.beanutils2.PropertyUtils - * @see java.util.function.Predicate - */ -public class BeanPropertyValueEqualsPredicate implements Predicate { - - /** For logging. */ - private final Log log = LogFactory.getLog(this.getClass()); - - /** - * The name of the property which will be evaluated when this {@code Predicate} is executed. - */ - private String propertyName; - - /** - * The value that the property specified by {@code propertyName} - * will be compared to when this {@code Predicate} executes. - */ - private V propertyValue; - - /** - *

Should {@code null} objects in the property path be ignored?

- *

- * Determines whether {@code null} objects in the property path will generate an - * {@code IllegalArgumentException or not. If set to true} then if any objects - * in the property path evaluate to {@code null} then the - * {@code IllegalArgumentException throw by PropertyUtils} will be logged but - * not re-thrown and {@code false will be returned. If set to false} then if - * any objects in the property path evaluate to {@code null} then the - * {@code IllegalArgumentException throw by PropertyUtils} will be logged and - * re-thrown. - *

- */ - private boolean ignoreNull; - - /** - * Constructor which takes the name of the property, its expected value to be used in evaluation, - * and assumes {@code ignoreNull to be false}. - * - * @param propertyName The name of the property that will be evaluated against the expected value. - * @param propertyValue The value to use in object evaluation. - * @throws IllegalArgumentException If the property name provided is null or empty. - */ - public BeanPropertyValueEqualsPredicate(final String propertyName, final V propertyValue) { - this(propertyName, propertyValue, false); - } - - /** - * Constructor which takes the name of the property, its expected value - * to be used in evaluation, and a boolean which determines whether {@code null} objects in - * the property path will generate an {@code IllegalArgumentException} or not. - * - * @param propertyName The name of the property that will be evaluated against the expected value. - * @param propertyValue The value to use in object evaluation. - * @param ignoreNull Determines whether {@code null} objects in the property path will - * generate an {@code IllegalArgumentException} or not. - * @throws IllegalArgumentException If the property name provided is null or empty. - */ - public BeanPropertyValueEqualsPredicate(final String propertyName, final V propertyValue, final boolean ignoreNull) { - super(); - - if (propertyName != null && propertyName.length() > 0) { - this.propertyName = propertyName; - this.propertyValue = propertyValue; - this.ignoreNull = ignoreNull; - } else { - throw new IllegalArgumentException("propertyName cannot be null or empty"); - } - } - - /** - * Evaluates the object provided against the criteria specified when this - * {@code BeanPropertyValueEqualsPredicate} was constructed. Equality is based on - * either reference or logical equality as defined by the property object's equals method. If - * any object in the property path leading up to the target property is {@code null} then - * the outcome will be based on the value of the {@code ignoreNull} attribute. By default, - * {@code ignoreNull is false} and would result in an - * {@code IllegalArgumentException} if an object in the property path leading up to the - * target property is {@code null}. - * - * @param object The object to be evaluated. - * @return True if the object provided meets all the criteria for this {@code Predicate}; - * false otherwise. - * @throws IllegalArgumentException If an IllegalAccessException, InvocationTargetException, or - * NoSuchMethodException is thrown when trying to access the property specified on the object - * provided. Or if an object in the property path provided is {@code null} and - * {@code ignoreNull is set to false}. - */ - @Override - public boolean test(final T object) { - - boolean evaluation = false; - - try { - evaluation = evaluateValue(propertyValue, - PropertyUtils.getProperty(object, propertyName)); - } catch (final IllegalArgumentException e) { - final String errorMsg = "Problem during evaluation. Null value encountered in property path..."; - - if (ignoreNull) { - log.warn("WARNING: " + errorMsg + e); - } else { - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } - } catch (final IllegalAccessException e) { - final String errorMsg = "Unable to access the property provided."; - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } catch (final InvocationTargetException e) { - final String errorMsg = "Exception occurred in property's getter"; - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } catch (final NoSuchMethodException e) { - final String errorMsg = "Property not found."; - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } - - return evaluation; - } - - /** - * Utility method which evaluates whether the actual property value equals the expected property - * value. - * - * @param expected The expected value. - * @param actual The actual value. - * @return True if they are equal; false otherwise. - */ - protected boolean evaluateValue(final V expected, final Object actual) { - return Objects.equals(expected, actual); - } - - /** - * Returns the name of the property which will be evaluated when this {@code Predicate} is - * executed. - * - * @return The name of the property which will be evaluated when this {@code Predicate} is - * executed. - */ - public String getPropertyName() { - return propertyName; - } - - /** - * Returns the value that the property specified by {@code propertyName} will be compared to - * when this {@code Predicate} executes. - * - * @return The value that the property specified by {@code propertyName} will be compared to - * when this {@code Predicate} executes. - */ - public V getPropertyValue() { - return propertyValue; - } - - /** - * Returns the flag which determines whether {@code null} objects in the property path will - * generate an {@code IllegalArgumentException or not. If set to true} then - * if any objects in the property path evaluate to {@code null} then the - * {@code IllegalArgumentException throw by PropertyUtils} will be logged but - * not re-thrown and {@code false will be returned. If set to false} then if - * any objects in the property path evaluate to {@code null} then the - * {@code IllegalArgumentException throw by PropertyUtils} will be logged and - * re-thrown. - * - * @return The flag which determines whether {@code null} objects in the property path will - * generate an {@code IllegalArgumentException} or not. - */ - public boolean isIgnoreNull() { - return ignoreNull; - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformer.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformer.java deleted file mode 100644 index c4f0ca7f6..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanToPropertyValueTransformer.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * 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.beanutils2; - -import java.lang.reflect.InvocationTargetException; -import java.util.function.Function; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - - -/** - *

{@code Transformer} that outputs a property value.

- * - *

An implementation of {@code java.util.function.Function} that transforms - * the object provided by returning the value of a specified property of the object. The - * constructor for {@code BeanToPropertyValueTransformer} requires the name of the property - * that will be used in the transformation. The property can be a simple, nested, indexed, or - * mapped property as defined by {@code org.apache.commons.beanutils2.PropertyUtils}. If any - * object in the property path specified by {@code propertyName is null} then the - * outcome is based on the value of the {@code ignoreNull} attribute. - *

- * - *

- * A typical usage might look like: - *

- *

- * // create the transformer
- * BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer( "person.address.city" );
- *
- * // transform the Collection
- * Collection peoplesCities = CollectionUtils.collect( peopleCollection, transformer );
- * 
- * - *

- * This would take a {@code Collection of person objects and return a Collection} - * of objects which represents the cities in which each person lived. Assuming... - *

    - *
  • - * The top level object in the {@code peopleCollection} is an object which represents a - * person. - *
  • - *
  • - * The person object has a {@code getAddress()} method which returns an object which - * represents a person's address. - *
  • - *
  • - * The address object has a {@code getCity()} method which returns an object which - * represents the city in which a person lives. - *
  • - *
- * - * @param the type of the input to the function - * @param the type of the result of the function - * - * @see org.apache.commons.beanutils2.PropertyUtils - * @see java.util.function.Function - */ -public class BeanToPropertyValueTransformer implements Function { - - /** For logging. */ - private final Log log = LogFactory.getLog(this.getClass()); - - /** The name of the property that will be used in the transformation of the object. */ - private String propertyName; - - /** - *

Should null objects on the property path throw an {@code IllegalArgumentException}?

- *

- * Determines whether {@code null} objects in the property path will generate an - * {@code IllegalArgumentException or not. If set to true} then if any objects - * in the property path evaluate to {@code null} then the - * {@code IllegalArgumentException throw by PropertyUtils} will be logged but - * not re-thrown and {@code null will be returned. If set to false} then if any - * objects in the property path evaluate to {@code null} then the - * {@code IllegalArgumentException throw by PropertyUtils} will be logged and - * re-thrown. - *

- */ - private boolean ignoreNull; - - /** - * Constructs a Transformer which does not ignore nulls. - * Constructor which takes the name of the property that will be used in the transformation and - * assumes {@code ignoreNull to be false}. - * - * @param propertyName The name of the property that will be used in the transformation. - * @throws IllegalArgumentException If the {@code propertyName is null} or - * empty. - */ - public BeanToPropertyValueTransformer(final String propertyName) { - this(propertyName, false); - } - - /** - * Constructs a Transformer and sets ignoreNull. - * Constructor which takes the name of the property that will be used in the transformation and - * a boolean which determines whether {@code null} objects in the property path will - * generate an {@code IllegalArgumentException} or not. - * - * @param propertyName The name of the property that will be used in the transformation. - * @param ignoreNull Determines whether {@code null} objects in the property path will - * generate an {@code IllegalArgumentException} or not. - * @throws IllegalArgumentException If the {@code propertyName is null} or - * empty. - */ - public BeanToPropertyValueTransformer(final String propertyName, final boolean ignoreNull) { - super(); - - if (propertyName != null && propertyName.length() > 0) { - this.propertyName = propertyName; - this.ignoreNull = ignoreNull; - } else { - throw new IllegalArgumentException( - "propertyName cannot be null or empty"); - } - } - - /** - * Returns the value of the property named in the transformer's constructor for - * the object provided. If any object in the property path leading up to the target property is - * {@code null then the outcome will be based on the value of the ignoreNull} - * attribute. By default, {@code ignoreNull is false} and would result in an - * {@code IllegalArgumentException} if an object in the property path leading up to the - * target property is {@code null}. - * - * @param object The object to be transformed. - * @return The value of the property named in the transformer's constructor for the object - * provided. - * @throws IllegalArgumentException If an IllegalAccessException, InvocationTargetException, or - * NoSuchMethodException is thrown when trying to access the property specified on the object - * provided. Or if an object in the property path provided is {@code null} and - * {@code ignoreNull is set to false}. - */ - @Override - public R apply(final T object) { - - R propertyValue = null; - - try { - propertyValue = (R) PropertyUtils.getProperty(object, propertyName); - } catch (final IllegalArgumentException e) { - final String errorMsg = "Problem during transformation. Null value encountered in property path..."; - - if (ignoreNull) { - log.warn("WARNING: " + errorMsg + e); - } else { - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } - } catch (final IllegalAccessException e) { - final String errorMsg = "Unable to access the property provided."; - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } catch (final InvocationTargetException e) { - final String errorMsg = "Exception occurred in property's getter"; - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } catch (final NoSuchMethodException e) { - final String errorMsg = "No property found for name [" + - propertyName + "]"; - final IllegalArgumentException iae = new IllegalArgumentException(errorMsg); - if (!BeanUtils.initCause(iae, e)) { - log.error(errorMsg, e); - } - throw iae; - } - - return propertyValue; - } - - /** - * Returns the name of the property that will be used in the transformation of the bean. - * - * @return The name of the property that will be used in the transformation of the bean. - */ - public String getPropertyName() { - return propertyName; - } - - /** - * Returns the flag which determines whether {@code null} objects in the property path will - * generate an {@code IllegalArgumentException or not. If set to true} then - * if any objects in the property path evaluate to {@code null} then the - * {@code IllegalArgumentException throw by PropertyUtils} will be logged but - * not re-thrown and {@code null will be returned. If set to false} then if any - * objects in the property path evaluate to {@code null} then the - * {@code IllegalArgumentException throw by PropertyUtils} will be logged and - * re-thrown. - * - * @return The flag which determines whether {@code null} objects in the property path will - * generate an {@code IllegalArgumentException} or not. - */ - public boolean isIgnoreNull() { - return ignoreNull; - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanUtils.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanUtils.java deleted file mode 100644 index ba2c0eacf..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanUtils.java +++ /dev/null @@ -1,441 +0,0 @@ -/* - * 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.beanutils2; - -import java.lang.reflect.InvocationTargetException; -import java.util.Map; - - - -/** - *

Utility methods for populating JavaBeans properties via reflection.

- * - *

The implementations are provided by {@link BeanUtilsBean}. - * These static utility methods use the default instance. - * More sophisticated behavior can be provided by using a {@code BeanUtilsBean} instance.

- * - * @see BeanUtilsBean - */ - -public class BeanUtils { - - - - - - - - - - - /** - *

Clone a bean based on the available property getters and setters, - * even if the bean class itself does not implement Cloneable.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean to be cloned - * @return the cloned bean - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InstantiationException if a new instance of the bean's - * class cannot be instantiated - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - * @see BeanUtilsBean#cloneBean - */ - public static Object cloneBean(final Object bean) - throws IllegalAccessException, InstantiationException, - InvocationTargetException, NoSuchMethodException { - - return BeanUtilsBean.getInstance().cloneBean(bean); - - } - - - /** - *

Copy property values from the origin bean to the destination bean - * for all cases where the property names are the same.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param dest Destination bean whose properties are modified - * @param orig Origin bean whose properties are retrieved - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws IllegalArgumentException if the {@code dest} or - * {@code orig
argument is null or if the dest} - * property type is different from the source type and the relevant - * converter has not been registered. - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @see BeanUtilsBean#copyProperties - */ - public static void copyProperties(final Object dest, final Object orig) - throws IllegalAccessException, InvocationTargetException { - - BeanUtilsBean.getInstance().copyProperties(dest, orig); - } - - - /** - *

Copy the specified property value to the specified destination bean, - * performing any type conversion that is required.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean on which setting is to be performed - * @param name Property name (can be nested/indexed/mapped/combo) - * @param value Value to be set - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @see BeanUtilsBean#copyProperty - */ - public static void copyProperty(final Object bean, final String name, final Object value) - throws IllegalAccessException, InvocationTargetException { - - BeanUtilsBean.getInstance().copyProperty(bean, name, value); - } - - - /** - *

Return the entire set of properties for which the specified bean - * provides a read method.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean whose properties are to be extracted - * @return Map of property descriptors - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - * @see BeanUtilsBean#describe - */ - public static Map describe(final Object bean) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - return BeanUtilsBean.getInstance().describe(bean); - } - - - /** - *

Return the value of the specified array property of the specified - * bean, as a String array.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean whose property is to be extracted - * @param name Name of the property to be extracted - * @return The array property value - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - * @see BeanUtilsBean#getArrayProperty - */ - public static String[] getArrayProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - return BeanUtilsBean.getInstance().getArrayProperty(bean, name); - } - - - /** - *

Return the value of the specified indexed property of the specified - * bean, as a String.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean whose property is to be extracted - * @param name {@code propertyname[index]} of the property value - * to be extracted - * @return The indexed property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - * @see BeanUtilsBean#getIndexedProperty(Object, String) - */ - public static String getIndexedProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - return BeanUtilsBean.getInstance().getIndexedProperty(bean, name); - - } - - - /** - * Return the value of the specified indexed property of the specified - * bean, as a String. The index is specified as a method parameter and - * must *not* be included in the property name expression - * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean whose property is to be extracted - * @param name Simple property name of the property value to be extracted - * @param index Index of the property value to be extracted - * @return The indexed property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - * @see BeanUtilsBean#getIndexedProperty(Object, String, int) - */ - public static String getIndexedProperty(final Object bean, - final String name, final int index) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - return BeanUtilsBean.getInstance().getIndexedProperty(bean, name, index); - - } - - - /** - *

Return the value of the specified indexed property of the specified - * bean, as a String.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean whose property is to be extracted - * @param name {@code propertyname(index)} of the property value - * to be extracted - * @return The mapped property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - * @see BeanUtilsBean#getMappedProperty(Object, String) - */ - public static String getMappedProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - return BeanUtilsBean.getInstance().getMappedProperty(bean, name); - - } - - - /** - *

Return the value of the specified mapped property of the specified - * bean, as a String.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean whose property is to be extracted - * @param name Simple property name of the property value to be extracted - * @param key Lookup key of the property value to be extracted - * @return The mapped property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - * @see BeanUtilsBean#getMappedProperty(Object, String, String) - */ - public static String getMappedProperty(final Object bean, - final String name, final String key) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - return BeanUtilsBean.getInstance().getMappedProperty(bean, name, key); - - } - - - /** - *

Return the value of the (possibly nested) property of the specified - * name, for the specified bean, as a String.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean whose property is to be extracted - * @param name Possibly nested name of the property to be extracted - * @return The nested property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws IllegalArgumentException if a nested reference to a - * property returns null - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - * @see BeanUtilsBean#getNestedProperty - */ - public static String getNestedProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - return BeanUtilsBean.getInstance().getNestedProperty(bean, name); - - } - - - /** - *

Return the value of the specified property of the specified bean, - * no matter which property reference format is used, as a String.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean whose property is to be extracted - * @param name Possibly indexed and/or nested name of the property - * to be extracted - * @return The property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - * @see BeanUtilsBean#getProperty - */ - public static String getProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - return BeanUtilsBean.getInstance().getProperty(bean, name); - - } - - - /** - *

Return the value of the specified simple property of the specified - * bean, converted to a String.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean whose property is to be extracted - * @param name Name of the property to be extracted - * @return The property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - * @see BeanUtilsBean#getSimpleProperty - */ - public static String getSimpleProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - return BeanUtilsBean.getInstance().getSimpleProperty(bean, name); - - } - - - /** - *

Populate the JavaBeans properties of the specified bean, based on - * the specified name/value pairs.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean JavaBean whose properties are being populated - * @param properties Map keyed by property name, with the - * corresponding (String or String[]) value(s) to be set - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @see BeanUtilsBean#populate - */ - public static void populate(final Object bean, final Map properties) - throws IllegalAccessException, InvocationTargetException { - - BeanUtilsBean.getInstance().populate(bean, properties); - } - - - /** - *

Set the specified property value, performing type conversions as - * required to conform to the type of the destination property.

- * - *

For more details see {@code BeanUtilsBean}.

- * - * @param bean Bean on which setting is to be performed - * @param name Property name (can be nested/indexed/mapped/combo) - * @param value Value to be set - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @see BeanUtilsBean#setProperty - */ - public static void setProperty(final Object bean, final String name, final Object value) - throws IllegalAccessException, InvocationTargetException { - - BeanUtilsBean.getInstance().setProperty(bean, name, value); - } - - /** - * If we're running on JDK 1.4 or later, initialize the cause for the given throwable. - * - * @param throwable The throwable. - * @param cause The cause of the throwable. - * @return true if the cause was initialized, otherwise false. - * @since 1.8.0 - */ - public static boolean initCause(final Throwable throwable, final Throwable cause) { - return BeanUtilsBean.getInstance().initCause(throwable, cause); - } - - /** - * Create a cache. - * @param the key type of the cache - * @param the value type of the cache - * @return a new cache - * @since 1.8.0 - */ - public static Map createCache() { - return new WeakFastHashMap<>(); - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java deleted file mode 100644 index 7ea45e33c..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean.java +++ /dev/null @@ -1,1123 +0,0 @@ -/* - * 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.beanutils2; - -import java.beans.IndexedPropertyDescriptor; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.beanutils2.expression.Resolver; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - *

JavaBean property population methods.

- * - *

This class provides implementations for the utility methods in - * {@link BeanUtils}. - * Different instances can be used to isolate caches between classloaders - * and to vary the value converters registered.

- * - * @see BeanUtils - * @since 1.7 - */ - -public class BeanUtilsBean { - - - - /** - * Contains {@code BeanUtilsBean} instances indexed by context classloader. - */ - private static final ContextClassLoaderLocal - BEANS_BY_CLASSLOADER = new ContextClassLoaderLocal() { - // Creates the default instance used when the context classloader is unavailable - @Override - protected BeanUtilsBean initialValue() { - return new BeanUtilsBean(); - } - }; - - /** - * Gets the instance which provides the functionality for {@link BeanUtils}. - * This is a pseudo-singleton - an single instance is provided per (thread) context classloader. - * This mechanism provides isolation for web apps deployed in the same container. - * - * @return The (pseudo-singleton) BeanUtils bean instance - */ - public static BeanUtilsBean getInstance() { - return BEANS_BY_CLASSLOADER.get(); - } - - /** - * Sets the instance which provides the functionality for {@link BeanUtils}. - * This is a pseudo-singleton - an single instance is provided per (thread) context classloader. - * This mechanism provides isolation for web apps deployed in the same container. - * - * @param newInstance The (pseudo-singleton) BeanUtils bean instance - */ - public static void setInstance(final BeanUtilsBean newInstance) { - BEANS_BY_CLASSLOADER.set(newInstance); - } - - - - /** - * Logging for this instance - */ - private final Log log = LogFactory.getLog(BeanUtilsBean.class); - - /** Used to perform conversions between object types when setting properties */ - private final ConvertUtilsBean convertUtilsBean; - - /** Used to access properties*/ - private final PropertyUtilsBean propertyUtilsBean; - - /** A reference to Throwable's initCause method, or null if it's not there in this JVM */ - private static final Method INIT_CAUSE_METHOD = getInitCauseMethod(); - - - - /** - *

Constructs an instance using new property - * and conversion instances.

- */ - public BeanUtilsBean() { - this(new ConvertUtilsBean(), new PropertyUtilsBean()); - } - - /** - *

Constructs an instance using given conversion instances - * and new {@link PropertyUtilsBean} instance.

- * - * @param convertUtilsBean use this {@code ConvertUtilsBean} - * to perform conversions from one object to another - * - * @since 1.8.0 - */ - public BeanUtilsBean(final ConvertUtilsBean convertUtilsBean) { - this(convertUtilsBean, new PropertyUtilsBean()); - } - - /** - *

Constructs an instance using given property and conversion instances.

- * - * @param convertUtilsBean use this {@code ConvertUtilsBean} - * to perform conversions from one object to another - * @param propertyUtilsBean use this {@code PropertyUtilsBean} - * to access properties - */ - public BeanUtilsBean( - final ConvertUtilsBean convertUtilsBean, - final PropertyUtilsBean propertyUtilsBean) { - - this.convertUtilsBean = convertUtilsBean; - this.propertyUtilsBean = propertyUtilsBean; - } - - - - /** - *

Clone a bean based on the available property getters and setters, - * even if the bean class itself does not implement Cloneable.

- * - *

- * Note: this method creates a shallow clone. - * In other words, any objects referred to by the bean are shared with the clone - * rather than being cloned in turn. - *

- * - * @param bean Bean to be cloned - * @return the cloned bean - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InstantiationException if a new instance of the bean's - * class cannot be instantiated - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - */ - public Object cloneBean(final Object bean) - throws IllegalAccessException, InstantiationException, - InvocationTargetException, NoSuchMethodException { - - if (log.isDebugEnabled()) { - log.debug("Cloning bean: " + bean.getClass().getName()); - } - Object newBean = null; - if (bean instanceof DynaBean) { - newBean = ((DynaBean) bean).getDynaClass().newInstance(); - } else { - newBean = bean.getClass().newInstance(); - } - getPropertyUtils().copyProperties(newBean, bean); - return newBean; - - } - - /** - *

Copy property values from the origin bean to the destination bean - * for all cases where the property names are the same. For each - * property, a conversion is attempted as necessary. All combinations of - * standard JavaBeans and DynaBeans as origin and destination are - * supported. Properties that exist in the origin bean, but do not exist - * in the destination bean (or are read-only in the destination bean) are - * silently ignored.

- * - *

If the origin "bean" is actually a {@code Map}, it is assumed - * to contain String-valued simple property names as the keys, pointing at - * the corresponding property values that will be converted (if necessary) - * and set in the destination bean. Note that this method - * is intended to perform a "shallow copy" of the properties and so complex - * properties (for example, nested ones) will not be copied.

- * - *

This method differs from {@code populate()}, which - * was primarily designed for populating JavaBeans from the map of request - * parameters retrieved on an HTTP request, is that no scalar->indexed - * or indexed->scalar manipulations are performed. If the origin property - * is indexed, the destination property must be also.

- * - *

If you know that no type conversions are required, the - * {@code copyProperties()} method in {@link PropertyUtils} will - * execute faster than this method.

- * - *

FIXME - Indexed and mapped properties that do not - * have getter and setter methods for the underlying array or Map are not - * copied by this method.

- * - * @param dest Destination bean whose properties are modified - * @param orig Origin bean whose properties are retrieved - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws IllegalArgumentException if the {@code dest} or - * {@code orig
argument is null or if the dest} - * property type is different from the source type and the relevant - * converter has not been registered. - * @throws InvocationTargetException if the property accessor method - * throws an exception - */ - public void copyProperties(final Object dest, final Object orig) - throws IllegalAccessException, InvocationTargetException { - - // Validate existence of the specified beans - if (dest == null) { - throw new IllegalArgumentException - ("No destination bean specified"); - } - if (orig == null) { - throw new IllegalArgumentException("No origin bean specified"); - } - if (log.isDebugEnabled()) { - log.debug("BeanUtils.copyProperties(" + dest + ", " + - orig + ")"); - } - - // Copy the properties, converting as necessary - if (orig instanceof DynaBean) { - final DynaProperty[] origDescriptors = - ((DynaBean) orig).getDynaClass().getDynaProperties(); - for (final DynaProperty origDescriptor : origDescriptors) { - final String name = origDescriptor.getName(); - // Need to check isReadable() for WrapDynaBean - // (see Jira issue# BEANUTILS-61) - if (getPropertyUtils().isReadable(orig, name) && - getPropertyUtils().isWriteable(dest, name)) { - final Object value = ((DynaBean) orig).get(name); - copyProperty(dest, name, value); - } - } - } else if (orig instanceof Map) { - @SuppressWarnings("unchecked") - final - // Map properties are always of type - Map propMap = (Map) orig; - for (final Map.Entry entry : propMap.entrySet()) { - final String name = entry.getKey(); - if (getPropertyUtils().isWriteable(dest, name)) { - copyProperty(dest, name, entry.getValue()); - } - } - } else /* if (orig is a standard JavaBean) */ { - final PropertyDescriptor[] origDescriptors = - getPropertyUtils().getPropertyDescriptors(orig); - for (final PropertyDescriptor origDescriptor : origDescriptors) { - final String name = origDescriptor.getName(); - if ("class".equals(name)) { - continue; // No point in trying to set an object's class - } - if (getPropertyUtils().isReadable(orig, name) && - getPropertyUtils().isWriteable(dest, name)) { - try { - final Object value = - getPropertyUtils().getSimpleProperty(orig, name); - copyProperty(dest, name, value); - } catch (final NoSuchMethodException e) { - // Should not happen - } - } - } - } - - } - - /** - *

Copy the specified property value to the specified destination bean, - * performing any type conversion that is required. If the specified - * bean does not have a property of the specified name, or the property - * is read only on the destination bean, return without - * doing anything. If you have custom destination property types, register - * {@link Converter}s for them by calling the {@code register()} - * method of {@link ConvertUtils}.

- * - *

IMPLEMENTATION RESTRICTIONS:

- *
    - *
  • Does not support destination properties that are indexed, - * but only an indexed setter (as opposed to an array setter) - * is available.
  • - *
  • Does not support destination properties that are mapped, - * but only a keyed setter (as opposed to a Map setter) - * is available.
  • - *
  • The desired property type of a mapped setter cannot be - * determined (since Maps support any data type), so no conversion - * will be performed.
  • - *
- * - * @param bean Bean on which setting is to be performed - * @param name Property name (can be nested/indexed/mapped/combo) - * @param value Value to be set - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - */ - public void copyProperty(final Object bean, String name, Object value) - throws IllegalAccessException, InvocationTargetException { - - // Trace logging (if enabled) - if (log.isTraceEnabled()) { - final StringBuilder sb = new StringBuilder(" copyProperty("); - sb.append(bean); - sb.append(", "); - sb.append(name); - sb.append(", "); - if (value == null) { - sb.append(""); - } else if (value instanceof String) { - sb.append((String) value); - } else if (value instanceof String[]) { - final String[] values = (String[]) value; - sb.append('['); - for (int i = 0; i < values.length; i++) { - if (i > 0) { - sb.append(','); - } - sb.append(values[i]); - } - sb.append(']'); - } else { - sb.append(value.toString()); - } - sb.append(')'); - log.trace(sb.toString()); - } - - // Resolve any nested expression to get the actual target bean - Object target = bean; - final Resolver resolver = getPropertyUtils().getResolver(); - while (resolver.hasNested(name)) { - try { - target = getPropertyUtils().getProperty(target, resolver.next(name)); - name = resolver.remove(name); - } catch (final NoSuchMethodException e) { - return; // Skip this property setter - } - } - if (log.isTraceEnabled()) { - log.trace(" Target bean = " + target); - log.trace(" Target name = " + name); - } - - // Declare local variables we will require - final String propName = resolver.getProperty(name); // Simple name of target property - Class type = null; // Java type of target property - final int index = resolver.getIndex(name); // Indexed subscript value (if any) - final String key = resolver.getKey(name); // Mapped key value (if any) - - // Calculate the target property type - if (target instanceof DynaBean) { - final DynaClass dynaClass = ((DynaBean) target).getDynaClass(); - final DynaProperty dynaProperty = dynaClass.getDynaProperty(propName); - if (dynaProperty == null) { - return; // Skip this property setter - } - type = dynaPropertyType(dynaProperty, value); - } else { - PropertyDescriptor descriptor = null; - try { - descriptor = - getPropertyUtils().getPropertyDescriptor(target, name); - if (descriptor == null) { - return; // Skip this property setter - } - } catch (final NoSuchMethodException e) { - return; // Skip this property setter - } - type = descriptor.getPropertyType(); - if (type == null) { - // Most likely an indexed setter on a POJB only - if (log.isTraceEnabled()) { - log.trace(" target type for property '" + - propName + "' is null, so skipping ths setter"); - } - return; - } - } - if (log.isTraceEnabled()) { - log.trace(" target propName=" + propName + ", type=" + - type + ", index=" + index + ", key=" + key); - } - - // Convert the specified value to the required type and store it - if (index >= 0) { // Destination must be indexed - value = convertForCopy(value, type.getComponentType()); - try { - getPropertyUtils().setIndexedProperty(target, propName, - index, value); - } catch (final NoSuchMethodException e) { - throw new InvocationTargetException - (e, "Cannot set " + propName); - } - } else if (key != null) { // Destination must be mapped - // Maps do not know what the preferred data type is, - // so perform no conversions at all - // FIXME - should we create or support a TypedMap? - try { - getPropertyUtils().setMappedProperty(target, propName, - key, value); - } catch (final NoSuchMethodException e) { - throw new InvocationTargetException - (e, "Cannot set " + propName); - } - } else { // Destination must be simple - value = convertForCopy(value, type); - try { - getPropertyUtils().setSimpleProperty(target, propName, value); - } catch (final NoSuchMethodException e) { - throw new InvocationTargetException - (e, "Cannot set " + propName); - } - } - - } - - /** - *

Return the entire set of properties for which the specified bean - * provides a read method. This map contains the to {@code String} - * converted property values for all properties for which a read method - * is provided (i.e. where the getReadMethod() returns non-null).

- * - *

This map can be fed back to a call to - * {@code BeanUtils.populate()} to re-constitute the same set of - * properties, modulo differences for read-only and write-only - * properties, but only if there are no indexed properties.

- * - *

Warning: if any of the bean property implementations - * contain (directly or indirectly) a call to this method then - * a stack overflow may result. For example:

- *

-     * class MyBean
-     * {
-     *    public Map getParameterMap()
-     *    {
-     *         BeanUtils.describe(this);
-     *    }
-     * }
-     * 
- *

- * will result in an infinite regression when {@code getParametersMap} - * is called. It is recommended that such methods are given alternative - * names (for example, {@code parametersMap}). - *

- * @param bean Bean whose properties are to be extracted - * @return Map of property descriptors - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - */ - public Map describe(final Object bean) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - if (bean == null) { - // return (Collections.EMPTY_MAP); - return new java.util.HashMap<>(); - } - - if (log.isDebugEnabled()) { - log.debug("Describing bean: " + bean.getClass().getName()); - } - - final Map description = new HashMap<>(); - if (bean instanceof DynaBean) { - final DynaProperty[] descriptors = - ((DynaBean) bean).getDynaClass().getDynaProperties(); - for (final DynaProperty descriptor : descriptors) { - final String name = descriptor.getName(); - description.put(name, getProperty(bean, name)); - } - } else { - final PropertyDescriptor[] descriptors = - getPropertyUtils().getPropertyDescriptors(bean); - final Class clazz = bean.getClass(); - for (final PropertyDescriptor descriptor : descriptors) { - final String name = descriptor.getName(); - if (getPropertyUtils().getReadMethod(clazz, descriptor) != null) { - description.put(name, getProperty(bean, name)); - } - } - } - return description; - - } - - /** - * Return the value of the specified array property of the specified - * bean, as a String array. - * - * @param bean Bean whose property is to be extracted - * @param name Name of the property to be extracted - * @return The array property value - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - */ - public String[] getArrayProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - final Object value = getPropertyUtils().getProperty(bean, name); - if (value == null) { - return null; - } else if (value instanceof Collection) { - final ArrayList values = new ArrayList<>(); - for (final Object item : (Collection) value) { - if (item == null) { - values.add(null); - } else { - // convert to string using convert utils - values.add(getConvertUtils().convert(item)); - } - } - return values.toArray(new String[values.size()]); - } else if (value.getClass().isArray()) { - final int n = Array.getLength(value); - final String[] results = new String[n]; - for (int i = 0; i < n; i++) { - final Object item = Array.get(value, i); - if (item == null) { - results[i] = null; - } else { - // convert to string using convert utils - results[i] = getConvertUtils().convert(item); - } - } - return results; - } else { - final String[] results = new String[1]; - results[0] = getConvertUtils().convert(value); - return results; - } - - } - - /** - * Return the value of the specified indexed property of the specified - * bean, as a String. The zero-relative index of the - * required value must be included (in square brackets) as a suffix to - * the property name, or {@code IllegalArgumentException} will be - * thrown. - * - * @param bean Bean whose property is to be extracted - * @param name {@code propertyname[index]} of the property value - * to be extracted - * @return The indexed property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - */ - public String getIndexedProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - final Object value = getPropertyUtils().getIndexedProperty(bean, name); - return getConvertUtils().convert(value); - - } - - /** - * Return the value of the specified indexed property of the specified - * bean, as a String. The index is specified as a method parameter and - * must *not* be included in the property name expression - * - * @param bean Bean whose property is to be extracted - * @param name Simple property name of the property value to be extracted - * @param index Index of the property value to be extracted - * @return The indexed property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - */ - public String getIndexedProperty(final Object bean, - final String name, final int index) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - final Object value = getPropertyUtils().getIndexedProperty(bean, name, index); - return getConvertUtils().convert(value); - - } - - /** - * Return the value of the specified indexed property of the specified - * bean, as a String. The String-valued key of the required value - * must be included (in parentheses) as a suffix to - * the property name, or {@code IllegalArgumentException} will be - * thrown. - * - * @param bean Bean whose property is to be extracted - * @param name {@code propertyname(index)} of the property value - * to be extracted - * @return The mapped property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - */ - public String getMappedProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - final Object value = getPropertyUtils().getMappedProperty(bean, name); - return getConvertUtils().convert(value); - - } - - /** - * Return the value of the specified mapped property of the specified - * bean, as a String. The key is specified as a method parameter and - * must *not* be included in the property name expression - * - * @param bean Bean whose property is to be extracted - * @param name Simple property name of the property value to be extracted - * @param key Lookup key of the property value to be extracted - * @return The mapped property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - */ - public String getMappedProperty(final Object bean, - final String name, final String key) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - final Object value = getPropertyUtils().getMappedProperty(bean, name, key); - return getConvertUtils().convert(value); - - } - - /** - * Return the value of the (possibly nested) property of the specified - * name, for the specified bean, as a String. - * - * @param bean Bean whose property is to be extracted - * @param name Possibly nested name of the property to be extracted - * @return The nested property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws IllegalArgumentException if a nested reference to a - * property returns null - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - */ - public String getNestedProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - final Object value = getPropertyUtils().getNestedProperty(bean, name); - return getConvertUtils().convert(value); - - } - - /** - * Return the value of the specified property of the specified bean, - * no matter which property reference format is used, as a String. - * - * @param bean Bean whose property is to be extracted - * @param name Possibly indexed and/or nested name of the property - * to be extracted - * @return The property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - */ - public String getProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - return getNestedProperty(bean, name); - - } - - /** - * Return the value of the specified simple property of the specified - * bean, converted to a String. - * - * @param bean Bean whose property is to be extracted - * @param name Name of the property to be extracted - * @return The property's value, converted to a String - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - * @throws NoSuchMethodException if an accessor method for this - * property cannot be found - */ - public String getSimpleProperty(final Object bean, final String name) - throws IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - - final Object value = getPropertyUtils().getSimpleProperty(bean, name); - return getConvertUtils().convert(value); - - } - - /** - *

Populate the JavaBeans properties of the specified bean, based on - * the specified name/value pairs. This method uses Java reflection APIs - * to identify corresponding "property setter" method names, and deals - * with setter arguments of type {@code String, boolean}, - * {@code int, long, float}, and - * {@code double}. In addition, array setters for these types (or the - * corresponding primitive types) can also be identified.

- * - *

The particular setter method to be called for each property is - * determined using the usual JavaBeans introspection mechanisms. Thus, - * you may identify custom setter methods using a BeanInfo class that is - * associated with the class of the bean itself. If no such BeanInfo - * class is available, the standard method name conversion ("set" plus - * the capitalized name of the property in question) is used.

- * - *

NOTE: It is contrary to the JavaBeans Specification - * to have more than one setter method (with different argument - * signatures) for the same property.

- * - *

WARNING - The logic of this method is customized - * for extracting String-based request parameters from an HTTP request. - * It is probably not what you want for general property copying with - * type conversion. For that purpose, check out the - * {@code copyProperties()} method instead.

- * - * @param bean JavaBean whose properties are being populated - * @param properties Map keyed by property name, with the - * corresponding (String or String[]) value(s) to be set - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - */ - public void populate(final Object bean, final Map properties) - throws IllegalAccessException, InvocationTargetException { - - // Do nothing unless both arguments have been specified - if (bean == null || properties == null) { - return; - } - if (log.isDebugEnabled()) { - log.debug("BeanUtils.populate(" + bean + ", " + - properties + ")"); - } - - // Loop through the property name/value pairs to be set - for(final Map.Entry entry : properties.entrySet()) { - // Identify the property name and value(s) to be assigned - final String name = entry.getKey(); - if (name == null) { - continue; - } - - // Perform the assignment for this property - setProperty(bean, name, entry.getValue()); - - } - - } - - /** - *

Set the specified property value, performing type conversions as - * required to conform to the type of the destination property.

- * - *

If the property is read only then the method returns - * without throwing an exception.

- * - *

If {@code null} is passed into a property expecting a primitive value, - * then this will be converted as if it were a {@code null} string.

- * - *

WARNING - The logic of this method is customized - * to meet the needs of {@code populate()}, and is probably not what - * you want for general property copying with type conversion. For that - * purpose, check out the {@code copyProperty()} method instead.

- * - *

WARNING - PLEASE do not modify the behavior of this - * method without consulting with the Struts developer community. There - * are some subtleties to its functionality that are not documented in the - * Javadoc description above, yet are vital to the way that Struts utilizes - * this method.

- * - * @param bean Bean on which setting is to be performed - * @param name Property name (can be nested/indexed/mapped/combo) - * @param value Value to be set - * - * @throws IllegalAccessException if the caller does not have - * access to the property accessor method - * @throws InvocationTargetException if the property accessor method - * throws an exception - */ - public void setProperty(final Object bean, String name, final Object value) - throws IllegalAccessException, InvocationTargetException { - - // Trace logging (if enabled) - if (log.isTraceEnabled()) { - final StringBuilder sb = new StringBuilder(" setProperty("); - sb.append(bean); - sb.append(", "); - sb.append(name); - sb.append(", "); - if (value == null) { - sb.append(""); - } else if (value instanceof String) { - sb.append((String) value); - } else if (value instanceof String[]) { - final String[] values = (String[]) value; - sb.append('['); - for (int i = 0; i < values.length; i++) { - if (i > 0) { - sb.append(','); - } - sb.append(values[i]); - } - sb.append(']'); - } else { - sb.append(value.toString()); - } - sb.append(')'); - log.trace(sb.toString()); - } - - // Resolve any nested expression to get the actual target bean - Object target = bean; - final Resolver resolver = getPropertyUtils().getResolver(); - while (resolver.hasNested(name)) { - try { - target = getPropertyUtils().getProperty(target, resolver.next(name)); - if (target == null) { // the value of a nested property is null - return; - } - name = resolver.remove(name); - } catch (final NoSuchMethodException e) { - return; // Skip this property setter - } - } - if (log.isTraceEnabled()) { - log.trace(" Target bean = " + target); - log.trace(" Target name = " + name); - } - - // Declare local variables we will require - final String propName = resolver.getProperty(name); // Simple name of target property - Class type = null; // Java type of target property - final int index = resolver.getIndex(name); // Indexed subscript value (if any) - final String key = resolver.getKey(name); // Mapped key value (if any) - - // Calculate the property type - if (target instanceof DynaBean) { - final DynaClass dynaClass = ((DynaBean) target).getDynaClass(); - final DynaProperty dynaProperty = dynaClass.getDynaProperty(propName); - if (dynaProperty == null) { - return; // Skip this property setter - } - type = dynaPropertyType(dynaProperty, value); - if (index >= 0 && List.class.isAssignableFrom(type)) { - type = Object.class; - } - } else if (target instanceof Map) { - type = Object.class; - } else if (target != null && target.getClass().isArray() && index >= 0) { - type = Array.get(target, index).getClass(); - } else { - PropertyDescriptor descriptor = null; - try { - descriptor = - getPropertyUtils().getPropertyDescriptor(target, name); - if (descriptor == null) { - return; // Skip this property setter - } - } catch (final NoSuchMethodException e) { - return; // Skip this property setter - } - if (descriptor instanceof MappedPropertyDescriptor) { - if (((MappedPropertyDescriptor) descriptor).getMappedWriteMethod() == null) { - if (log.isDebugEnabled()) { - log.debug("Skipping read-only property"); - } - return; // Read-only, skip this property setter - } - type = ((MappedPropertyDescriptor) descriptor). - getMappedPropertyType(); - } else if (index >= 0 && descriptor instanceof IndexedPropertyDescriptor) { - if (((IndexedPropertyDescriptor) descriptor).getIndexedWriteMethod() == null) { - if (log.isDebugEnabled()) { - log.debug("Skipping read-only property"); - } - return; // Read-only, skip this property setter - } - type = ((IndexedPropertyDescriptor) descriptor). - getIndexedPropertyType(); - } else if (index >= 0 && List.class.isAssignableFrom(descriptor.getPropertyType())) { - type = Object.class; - } else if (key != null) { - if (descriptor.getReadMethod() == null) { - if (log.isDebugEnabled()) { - log.debug("Skipping read-only property"); - } - return; // Read-only, skip this property setter - } - type = value == null ? Object.class : value.getClass(); - } else { - if (descriptor.getWriteMethod() == null) { - if (log.isDebugEnabled()) { - log.debug("Skipping read-only property"); - } - return; // Read-only, skip this property setter - } - type = descriptor.getPropertyType(); - } - } - - // Convert the specified value to the required type - Object newValue = null; - if (type.isArray() && index < 0) { // Scalar value into array - if (value == null) { - final String[] values = new String[1]; - values[0] = null; - newValue = getConvertUtils().convert(values, type); - } else if (value instanceof String) { - newValue = getConvertUtils().convert(value, type); - } else if (value instanceof String[]) { - newValue = getConvertUtils().convert((String[]) value, type); - } else { - newValue = convert(value, type); - } - } else if (type.isArray()) { // Indexed value into array - if (value instanceof String || value == null) { - newValue = getConvertUtils().convert((String) value, - type.getComponentType()); - } else if (value instanceof String[]) { - newValue = getConvertUtils().convert(((String[]) value)[0], - type.getComponentType()); - } else { - newValue = convert(value, type.getComponentType()); - } - } else { // Value into scalar - if (value instanceof String) { - newValue = getConvertUtils().convert((String) value, type); - } else if (value instanceof String[]) { - newValue = getConvertUtils().convert(((String[]) value)[0], - type); - } else { - newValue = convert(value, type); - } - } - - // Invoke the setter method - try { - getPropertyUtils().setProperty(target, name, newValue); - } catch (final NoSuchMethodException e) { - throw new InvocationTargetException - (e, "Cannot set " + propName); - } - - } - - /** - * Gets the {@code ConvertUtilsBean} instance used to perform the conversions. - * - * @return The ConvertUtils bean instance - */ - public ConvertUtilsBean getConvertUtils() { - return convertUtilsBean; - } - - /** - * Gets the {@code PropertyUtilsBean} instance used to access properties. - * - * @return The ConvertUtils bean instance - */ - public PropertyUtilsBean getPropertyUtils() { - return propertyUtilsBean; - } - - /** - * If we're running on JDK 1.4 or later, initialize the cause for the given throwable. - * - * @param throwable The throwable. - * @param cause The cause of the throwable. - * @return true if the cause was initialized, otherwise false. - * @since 1.8.0 - */ - public boolean initCause(final Throwable throwable, final Throwable cause) { - if (INIT_CAUSE_METHOD != null && cause != null) { - try { - INIT_CAUSE_METHOD.invoke(throwable, cause); - return true; - } catch (final Throwable e) { - return false; // can't initialize cause - } - } - return false; - } - - /** - *

Convert the value to an object of the specified class (if - * possible).

- * - * @param value Value to be converted (may be null) - * @param type Class of the value to be converted to - * @return The converted value - * - * @throws ConversionException if thrown by an underlying Converter - * @since 1.8.0 - */ - protected Object convert(final Object value, final Class type) { - final Converter converter = getConvertUtils().lookup(type); - if (converter != null) { - log.trace(" USING CONVERTER " + converter); - return converter.convert(type, value); - } - return value; - } - - /** - * Performs a type conversion of a property value before it is copied to a target - * bean. This method delegates to {@link #convert(Object, Class)}, but null - * values are not converted. This causes null values to be copied verbatim. - * - * @param value the value to be converted and copied - * @param type the target type of the conversion - * @return the converted value - */ - private Object convertForCopy(final Object value, final Class type) { - return value != null ? convert(value, type) : value; - } - - /** - * Returns a Method allowing access to - * {@link Throwable#initCause(Throwable)} method of {@link Throwable}, - * or {@code null} if the method - * does not exist. - * - * @return A {@code Method for Throwable.initCause}, or - * {@code null} if unavailable. - */ - private static Method getInitCauseMethod() { - try { - final Class[] paramsClasses = new Class[] { Throwable.class }; - return Throwable.class.getMethod("initCause", paramsClasses); - } catch (final NoSuchMethodException e) { - final Log log = LogFactory.getLog(BeanUtils.class); - if (log.isWarnEnabled()) { - log.warn("Throwable does not have initCause() method in JDK 1.3"); - } - return null; - } catch (final Throwable e) { - final Log log = LogFactory.getLog(BeanUtils.class); - if (log.isWarnEnabled()) { - log.warn("Error getting the Throwable initCause() method", e); - } - return null; - } - } - - /** - * Determines the type of a {@code DynaProperty}. Here a special treatment - * is needed for mapped properties. - * - * @param dynaProperty the property descriptor - * @param value the value object to be set for this property - * @return the type of this property - */ - private static Class dynaPropertyType(final DynaProperty dynaProperty, - final Object value) { - if (!dynaProperty.isMapped()) { - return dynaProperty.getType(); - } - return value == null ? String.class : value.getClass(); - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean2.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean2.java deleted file mode 100644 index 0a549c8ca..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/BeanUtilsBean2.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.beanutils2; - -/** - *

{@link BeanUtilsBean} implementation that creates a - * {@link ConvertUtilsBean2} and delegates conversion to - * {@link ConvertUtilsBean#convert(Object, Class)}. - *

- * - *

- * To configure this implementation for the current context ClassLoader invoke - * {@code BeanUtilsBean.setInstance(new BeanUtilsBean2());} - *

- * - *

- * BeanUtils 1.7.0 delegated all conversion to String to the converter - * registered for the {@code String.class}. One of the improvements in - * BeanUtils 1.8.0 was to upgrade the {@link Converter} implementations so - * that they could handle conversion to String for their type (e.g. - * IntegerConverter now handles conversion from an Integer to a String as - * well as String to Integer). - *

- * - *

- * In order to take advantage of these improvements BeanUtils needs to change - * how it gets the appropriate {@link Converter}. This functionality has been - * implemented in the new {@link ConvertUtilsBean#lookup(Class, Class)} and - * {@link ConvertUtilsBean#convert(Object, Class)} methods. However changing - * {@link BeanUtilsBean} to use these methods could create compatibility - * issues for existing users. In order to avoid that, this new - * {@link BeanUtilsBean} implementation has been created (and the associated - * {@link ConvertUtilsBean2}). - *

- * - * @see ConvertUtilsBean2 - * @since 1.8.0 - */ -public class BeanUtilsBean2 extends BeanUtilsBean { - - /** - *

Constructs an instance using new property - * and conversion instances.

- */ - public BeanUtilsBean2() { - super(new ConvertUtilsBean2()); - } - - /** - *

Convert the value to an object of the specified class (if - * possible).

- * - * @param value Value to be converted (may be null) - * @param type Class of the value to be converted to - * @return The converted value - */ - @Override - protected Object convert(final Object value, final Class type) { - return getConvertUtils().convert(value, type); - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConstructorUtils.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConstructorUtils.java deleted file mode 100644 index 574e79bdb..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConstructorUtils.java +++ /dev/null @@ -1,442 +0,0 @@ -/* - * 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.beanutils2; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; - -/** - *

Utility reflection methods focused on constructors, modeled after {@link MethodUtils}.

- * - *

Known Limitations

- *

Accessing Public Constructors In A Default Access Superclass

- *

There is an issue when invoking public constructors contained in a default access superclass. - * Reflection locates these constructors fine and correctly assigns them as public. - * However, an {@code IllegalAccessException} is thrown if the constructors is invoked.

- * - *

{@code ConstructorUtils} contains a workaround for this situation. - * It will attempt to call {@code setAccessible} on this constructor. - * If this call succeeds, then the method can be invoked as normal. - * This call will only succeed when the application has sufficient security privileges. - * If this call fails then a warning will be logged and the method may fail.

- * - */ -public class ConstructorUtils { - - - /** An empty class array */ - private static final Class[] EMPTY_CLASS_PARAMETERS = new Class[0]; - /** An empty object array */ - private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - - - - /** - *

Convenience method returning new instance of {@code klazz} using a single argument constructor. - * The formal parameter type is inferred from the actual values of {@code arg}. - * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.

- * - *

The signatures should be assignment compatible.

- * - * @param the type of the object to be constructed - * @param klass the class to be constructed. - * @param arg the actual argument. May be null (this will result in calling the default constructor). - * @return new instance of {@code klazz} - * - * @throws NoSuchMethodException If the constructor cannot be found - * @throws IllegalAccessException If an error occurs accessing the constructor - * @throws InvocationTargetException If an error occurs invoking the constructor - * @throws InstantiationException If an error occurs instantiating the class - * - * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) - */ - public static T invokeConstructor(final Class klass, final Object arg) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException, - InstantiationException { - - final Object[] args = toArray(arg); - return invokeConstructor(klass, args); - } - - /** - *

Returns new instance of {@code klazz created using the actual arguments args}. - * The formal parameter types are inferred from the actual values of {@code args}. - * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.

- * - *

The signatures should be assignment compatible.

- * - * @param the type of the object to be constructed - * @param klass the class to be constructed. - * @param args actual argument array. May be null (this will result in calling the default constructor). - * @return new instance of {@code klazz} - * - * @throws NoSuchMethodException If the constructor cannot be found - * @throws IllegalAccessException If an error occurs accessing the constructor - * @throws InvocationTargetException If an error occurs invoking the constructor - * @throws InstantiationException If an error occurs instantiating the class - * - * @see #invokeConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) - */ - public static T invokeConstructor(final Class klass, Object[] args) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException, - InstantiationException { - - if (null == args) { - args = EMPTY_OBJECT_ARRAY; - } - final int arguments = args.length; - final Class[] parameterTypes = new Class[arguments]; - for (int i = 0; i < arguments; i++) { - parameterTypes[i] = args[i].getClass(); - } - return invokeConstructor(klass, args, parameterTypes); - } - - /** - *

Returns new instance of {@code klazz} created using constructor - * with signature {@code parameterTypes and actual arguments args}.

- * - *

The signatures should be assignment compatible.

- * - * @param the type of the object to be constructed - * @param klass the class to be constructed. - * @param args actual argument array. May be null (this will result in calling the default constructor). - * @param parameterTypes parameter types array - * @return new instance of {@code klazz} - * - * @throws NoSuchMethodException if matching constructor cannot be found - * @throws IllegalAccessException thrown on the constructor's invocation - * @throws InvocationTargetException thrown on the constructor's invocation - * @throws InstantiationException thrown on the constructor's invocation - * @see Constructor#newInstance - */ - public static T invokeConstructor( - final Class klass, - Object[] args, - Class[] parameterTypes) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException, - InstantiationException { - - if (parameterTypes == null) { - parameterTypes = EMPTY_CLASS_PARAMETERS; - } - if (args == null) { - args = EMPTY_OBJECT_ARRAY; - } - - final Constructor ctor = - getMatchingAccessibleConstructor(klass, parameterTypes); - if (null == ctor) { - throw new NoSuchMethodException( - "No such accessible constructor on object: " + klass.getName()); - } - return ctor.newInstance(args); - } - - /** - *

Convenience method returning new instance of {@code klazz} using a single argument constructor. - * The formal parameter type is inferred from the actual values of {@code arg}. - * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.

- * - *

The signatures should match exactly.

- * - * @param the type of the object to be constructed - * @param klass the class to be constructed. - * @param arg the actual argument. May be null (this will result in calling the default constructor). - * @return new instance of {@code klazz} - * - * @throws NoSuchMethodException If the constructor cannot be found - * @throws IllegalAccessException If an error occurs accessing the constructor - * @throws InvocationTargetException If an error occurs invoking the constructor - * @throws InstantiationException If an error occurs instantiating the class - * - * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) - */ - public static T invokeExactConstructor(final Class klass, final Object arg) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException, - InstantiationException { - - final Object[] args = toArray(arg); - return invokeExactConstructor(klass, args); - } - - /** - *

Returns new instance of {@code klazz created using the actual arguments args}. - * The formal parameter types are inferred from the actual values of {@code args}. - * See {@link #invokeExactConstructor(Class, Object[], Class[])} for more details.

- * - *

The signatures should match exactly.

- * - * @param the type of the object to be constructed - * @param klass the class to be constructed. - * @param args actual argument array. May be null (this will result in calling the default constructor). - * @return new instance of {@code klazz} - * - * @throws NoSuchMethodException If the constructor cannot be found - * @throws IllegalAccessException If an error occurs accessing the constructor - * @throws InvocationTargetException If an error occurs invoking the constructor - * @throws InstantiationException If an error occurs instantiating the class - * - * @see #invokeExactConstructor(java.lang.Class, java.lang.Object[], java.lang.Class[]) - */ - public static T invokeExactConstructor(final Class klass, Object[] args) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException, - InstantiationException { - - if (null == args) { - args = EMPTY_OBJECT_ARRAY; - } - final int arguments = args.length; - final Class[] parameterTypes = new Class[arguments]; - for (int i = 0; i < arguments; i++) { - parameterTypes[i] = args[i].getClass(); - } - return invokeExactConstructor(klass, args, parameterTypes); - } - - /** - *

Returns new instance of {@code klazz} created using constructor - * with signature {@code parameterTypes} and actual arguments - * {@code args}.

- * - *

The signatures should match exactly.

- * - * @param the type of the object to be constructed - * @param klass the class to be constructed. - * @param args actual argument array. May be null (this will result in calling the default constructor). - * @param parameterTypes parameter types array - * @return new instance of {@code klazz} - * - * @throws NoSuchMethodException if matching constructor cannot be found - * @throws IllegalAccessException thrown on the constructor's invocation - * @throws InvocationTargetException thrown on the constructor's invocation - * @throws InstantiationException thrown on the constructor's invocation - * @see Constructor#newInstance - */ - public static T invokeExactConstructor( - final Class klass, - Object[] args, - Class[] parameterTypes) - throws - NoSuchMethodException, - IllegalAccessException, - InvocationTargetException, - InstantiationException { - - if (args == null) { - args = EMPTY_OBJECT_ARRAY; - } - - if (parameterTypes == null) { - parameterTypes = EMPTY_CLASS_PARAMETERS; - } - - final Constructor ctor = getAccessibleConstructor(klass, parameterTypes); - if (null == ctor) { - throw new NoSuchMethodException( - "No such accessible constructor on object: " + klass.getName()); - } - return ctor.newInstance(args); - } - - /** - * Returns a constructor with single argument. - * @param the type of the constructor - * @param klass the class to be constructed - * @param parameterType The constructor parameter type - * @return null if matching accessible constructor can not be found. - * @see Class#getConstructor - * @see #getAccessibleConstructor(java.lang.reflect.Constructor) - */ - public static Constructor getAccessibleConstructor( - final Class klass, - final Class parameterType) { - - final Class[] parameterTypes = { parameterType }; - return getAccessibleConstructor(klass, parameterTypes); - } - - /** - * Returns a constructor given a class and signature. - * @param the type to be constructed - * @param klass the class to be constructed - * @param parameterTypes the parameter array - * @return null if matching accessible constructor can not be found - * @see Class#getConstructor - * @see #getAccessibleConstructor(java.lang.reflect.Constructor) - */ - public static Constructor getAccessibleConstructor( - final Class klass, - final Class[] parameterTypes) { - - try { - return getAccessibleConstructor( - klass.getConstructor(parameterTypes)); - } catch (final NoSuchMethodException e) { - return null; - } - } - - /** - * Returns accessible version of the given constructor. - * @param the type of the constructor - * @param ctor prototype constructor object. - * @return {@code null} if accessible constructor can not be found. - * @see java.lang.SecurityManager - */ - public static Constructor getAccessibleConstructor(final Constructor ctor) { - - // Make sure we have a method to check - if (ctor == null) { - return null; - } - - // If the requested method is not public we cannot call it - if (!Modifier.isPublic(ctor.getModifiers())) { - return null; - } - - // If the declaring class is public, we are done - final Class clazz = ctor.getDeclaringClass(); - if (Modifier.isPublic(clazz.getModifiers())) { - return ctor; - } - - // what else can we do? - return null; - } - - private static Object[] toArray(final Object arg) { - Object[] args = null; - if (arg != null) { - args = new Object[] { arg }; - } - return args; - } - - - /** - *

Find an accessible constructor with compatible parameters. - * Compatible parameters mean that every method parameter is assignable from - * the given parameters. In other words, it finds constructor that will take - * the parameters given.

- * - *

First it checks if there is constructor matching the exact signature. - * If no such, all the constructors of the class are tested if their signatures - * are assignment compatible with the parameter types. - * The first matching constructor is returned.

- * - * @param the type of the class to be inspected - * @param clazz find constructor for this class - * @param parameterTypes find method with compatible parameters - * @return a valid Constructor object. If there's no matching constructor, returns {@code null}. - */ - private static Constructor getMatchingAccessibleConstructor( - final Class clazz, - final Class[] parameterTypes) { - // see if we can find the method directly - // most of the time this works and it's much faster - try { - final Constructor ctor = clazz.getConstructor(parameterTypes); - try { - // - // XXX Default access superclass workaround - // - // When a public class has a default access superclass - // with public methods, these methods are accessible. - // Calling them from compiled code works fine. - // - // Unfortunately, using reflection to invoke these methods - // seems to (wrongly) to prevent access even when the method - // modifier is public. - // - // The following workaround solves the problem but will only - // work from sufficiently privileges code. - // - // Better workarounds would be gratefully accepted. - // - ctor.setAccessible(true); - } catch (final SecurityException se) { - /* SWALLOW, if workaround fails don't fret. */ - } - return ctor; - - } catch (final NoSuchMethodException e) { /* SWALLOW */ - } - - // search through all methods - final int paramSize = parameterTypes.length; - final Constructor[] ctors = clazz.getConstructors(); - for (final Constructor ctor2 : ctors) { - // compare parameters - final Class[] ctorParams = ctor2.getParameterTypes(); - final int ctorParamSize = ctorParams.length; - if (ctorParamSize == paramSize) { - boolean match = true; - for (int n = 0; n < ctorParamSize; n++) { - if (!MethodUtils - .isAssignmentCompatible( - ctorParams[n], - parameterTypes[n])) { - match = false; - break; - } - } - - if (match) { - // get accessible version of method - final Constructor ctor = getAccessibleConstructor(ctor2); - if (ctor != null) { - try { - ctor.setAccessible(true); - } catch (final SecurityException se) { - /* Swallow SecurityException - * TODO: Why? - */ - } - @SuppressWarnings("unchecked") - final - // Class.getConstructors() actually returns constructors - // of type T, so it is safe to cast. - Constructor typedCtor = (Constructor) ctor; - return typedCtor; - } - } - } - } - - return null; - } - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ContextClassLoaderLocal.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ContextClassLoaderLocal.java deleted file mode 100644 index cb61ea930..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ContextClassLoaderLocal.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * 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.beanutils2; - -import java.util.Map; -import java.util.WeakHashMap; - -/** - * An instance of this class represents a value that is provided per (thread) - * context classloader. - * - *

Occasionally it is necessary to store data in "global" variables - * (including uses of the Singleton pattern). In applications which have only - * a single classloader such data can simply be stored as "static" members on - * some class. When multiple classloaders are involved, however, this approach - * can fail; in particular, this doesn't work when the code may be run within a - * servlet container or a j2ee container, and the class on which the static - * member is defined is loaded via a "shared" classloader that is visible to all - * components running within the container. This class provides a mechanism for - * associating data with a ClassLoader instance, which ensures that when the - * code runs in such a container each component gets its own copy of the - * "global" variable rather than unexpectedly sharing a single copy of the - * variable with other components that happen to be running in the same - * container at the same time (eg servlets or EJBs.)

- * - *

This class is strongly patterned after the java.lang.ThreadLocal - * class, which performs a similar task in allowing data to be associated - * with a particular thread.

- * - *

When code that uses this class is run as a "normal" application, ie - * not within a container, the effect is identical to just using a static - * member variable to store the data, because Thread.getContextClassLoader - * always returns the same classloader (the system classloader).

- * - *

Expected usage is as follows:

- *
- * 
- *  public class SomeClass {
- *    private static final ContextClassLoaderLocal<String> global
- *      = new ContextClassLoaderLocal<String>() {
- *          protected String initialValue() {
- *              return new String("Initial value");
- *          };
- *
- *    public void testGlobal() {
- *      String s = global.get();
- *      System.out.println("global value:" + s);
- *      buf.set("New Value");
- *    }
- * 
- * 
- * - *

Note: This class takes some care to ensure that when - * a component which uses this class is "undeployed" by a container the - * component-specific classloader and all its associated classes (and their - * static variables) are garbage-collected. Unfortunately there is one - * scenario in which this does not work correctly and there - * is unfortunately no known workaround other than ensuring that the - * component (or its container) calls the "unset" method on this class for - * each instance of this class when the component is undeployed. The problem - * occurs if: - *

    - *
  • the class containing a static instance of this class was loaded via - * a shared classloader, and
  • - *
  • the value stored in the instance is an object whose class was loaded - * via the component-specific classloader (or any of the objects it refers - * to were loaded via that classloader).
  • - *
- *

The result is that the map managed by this object still contains a strong - * reference to the stored object, which contains a strong reference to the - * classloader that loaded it, meaning that although the container has - * "undeployed" the component the component-specific classloader and all the - * related classes and static variables cannot be garbage-collected. This is - * not expected to be an issue with the commons-beanutils library as the only - * classes which use this class are BeanUtilsBean and ConvertUtilsBean and - * there is no obvious reason for a user of the beanutils library to subclass - * either of those classes.

- * - *

Note: A WeakHashMap bug in several 1.3 JVMs results in - * a memory leak for those JVMs.

- * - *

Note: Of course all of this would be unnecessary if - * containers required each component to load the full set of classes it - * needs, ie avoided providing classes loaded via a "shared" classloader.

- * - * @param the type of data stored in an instance - * @see java.lang.Thread#getContextClassLoader - */ -public class ContextClassLoaderLocal { - private final Map valueByClassLoader = new WeakHashMap<>(); - private boolean globalValueInitialized = false; - private T globalValue; - - /** - * Construct a context classloader instance - */ - public ContextClassLoaderLocal() { - super(); - } - - /** - * Returns the initial value for this ContextClassLoaderLocal - * variable. This method will be called once per Context ClassLoader for - * each ContextClassLoaderLocal, the first time it is accessed - * with get or set. If the programmer desires ContextClassLoaderLocal variables - * to be initialized to some value other than null, ContextClassLoaderLocal must - * be subclassed, and this method overridden. Typically, an anonymous - * inner class will be used. Typical implementations of initialValue - * will call an appropriate constructor and return the newly constructed - * object. - * - * @return a new Object to be used as an initial value for this ContextClassLoaderLocal - */ - protected T initialValue() { - return null; - } - - /** - * Gets the instance which provides the functionality for {@link BeanUtils}. - * This is a pseudo-singleton - an single instance is provided per (thread) context classloader. - * This mechanism provides isolation for web apps deployed in the same container. - * @return the object currently associated with the context-classloader of the current thread. - */ - public synchronized T get() { - // synchronizing the whole method is a bit slower - // but guarantees no subtle threading problems, and there's no - // need to synchronize valueByClassLoader - - // make sure that the map is given a change to purge itself - valueByClassLoader.isEmpty(); - try { - - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - if (contextClassLoader != null) { - - T value = valueByClassLoader.get(contextClassLoader); - if (value == null - && !valueByClassLoader.containsKey(contextClassLoader)) { - value = initialValue(); - valueByClassLoader.put(contextClassLoader, value); - } - return value; - - } - - } catch (final SecurityException e) { /* SWALLOW - should we log this? */ } - - // if none or exception, return the globalValue - if (!globalValueInitialized) { - globalValue = initialValue(); - globalValueInitialized = true; - }//else already set - return globalValue; - } - - /** - * Sets the value - a value is provided per (thread) context classloader. - * This mechanism provides isolation for web apps deployed in the same container. - * - * @param value the object to be associated with the entrant thread's context classloader - */ - public synchronized void set(final T value) { - // synchronizing the whole method is a bit slower - // but guarantees no subtle threading problems - - // make sure that the map is given a change to purge itself - valueByClassLoader.isEmpty(); - try { - - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - if (contextClassLoader != null) { - valueByClassLoader.put(contextClassLoader, value); - return; - } - - } catch (final SecurityException e) { /* SWALLOW - should we log this? */ } - - // if in doubt, set the global value - globalValue = value; - globalValueInitialized = true; - } - - /** - * Unsets the value associated with the current thread's context classloader - */ - public synchronized void unset() { - try { - - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - unset(contextClassLoader); - - } catch (final SecurityException e) { /* SWALLOW - should we log this? */ } - } - - /** - * Unsets the value associated with the given classloader - * @param classLoader The classloader to unset for - */ - public synchronized void unset(final ClassLoader classLoader) { - valueByClassLoader.remove(classLoader); - } -} \ No newline at end of file diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConversionException.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConversionException.java deleted file mode 100644 index d6b031d42..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConversionException.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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.beanutils2; - -/** - *

A ConversionException indicates that a call to - * {@code Converter.convert()} has failed to complete successfully. - * - * @since 1.3 - */ - -public class ConversionException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - - - /** - * Construct a new exception with the specified message. - * - * @param message The message describing this exception - */ - public ConversionException(final String message) { - - super(message); - - } - - /** - * Construct a new exception with the specified message and root cause. - * - * @param message The message describing this exception - * @param cause The root cause of this exception - */ - public ConversionException(final String message, final Throwable cause) { - - super(message); - this.cause = cause; - - } - - /** - * Construct a new exception with the specified root cause. - * - * @param cause The root cause of this exception - */ - public ConversionException(final Throwable cause) { - - super(cause.getMessage()); - this.cause = cause; - - } - - - - /** - * The root cause of this {@code ConversionException}, compatible with - * JDK 1.4's extensions to {@code java.lang.Throwable}. - */ - protected Throwable cause = null; - - /** - * Return the root cause of this conversion exception. - * @return the root cause of this conversion exception - */ - @Override - public Throwable getCause() { - return this.cause; - } - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java deleted file mode 100644 index 4d5ee2289..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtils.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * 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.beanutils2; - -/** - *

Utility methods for converting String scalar values to objects of the - * specified Class, String arrays to arrays of the specified Class.

- * - *

For more details, see {@code ConvertUtilsBean} which provides the - * implementations for these methods.

- * - * @see ConvertUtilsBean - */ - -public class ConvertUtils { - - - - - - - - - - /** - *

Convert the specified value into a String.

- * - *

For more details see {@code ConvertUtilsBean}.

- * - * @param value Value to be converted (may be null) - * @return The converted String value or null if value is null - * - * @see ConvertUtilsBean#convert(Object) - */ - public static String convert(final Object value) { - return ConvertUtilsBean.getInstance().convert(value); - } - - - /** - *

Convert the specified value to an object of the specified class (if - * possible). Otherwise, return a String representation of the value.

- * - *

For more details see {@code ConvertUtilsBean}.

- * - * @param value Value to be converted (may be null) - * @param clazz Java class to be converted to (must not be null) - * @return The converted value - * - * @see ConvertUtilsBean#convert(String, Class) - */ - public static Object convert(final String value, final Class clazz) { - return ConvertUtilsBean.getInstance().convert(value, clazz); - } - - - /** - *

Convert an array of specified values to an array of objects of the - * specified class (if possible).

- * - *

For more details see {@code ConvertUtilsBean}.

- * - * @param values Array of values to be converted - * @param clazz Java array or element class to be converted to (must not be null) - * @return The converted value - * - * @see ConvertUtilsBean#convert(String[], Class) - */ - public static Object convert(final String[] values, final Class clazz) { - return ConvertUtilsBean.getInstance().convert(values, clazz); - } - - /** - *

Convert the value to an object of the specified class (if - * possible).

- * - * @param value Value to be converted (may be null) - * @param targetType Class of the value to be converted to (must not be null) - * @return The converted value - * - * @throws ConversionException if thrown by an underlying Converter - */ - public static Object convert(final Object value, final Class targetType) { - return ConvertUtilsBean.getInstance().convert(value, targetType); - } - - /** - *

Remove all registered {@link Converter}s, and re-establish the - * standard Converters.

- * - *

For more details see {@code ConvertUtilsBean}.

- * - * @see ConvertUtilsBean#deregister() - */ - public static void deregister() { - ConvertUtilsBean.getInstance().deregister(); - } - - - /** - *

Remove any registered {@link Converter} for the specified destination - * {@code Class}.

- * - *

For more details see {@code ConvertUtilsBean}.

- * - * @param clazz Class for which to remove a registered Converter - * @see ConvertUtilsBean#deregister(Class) - */ - public static void deregister(final Class clazz) { - ConvertUtilsBean.getInstance().deregister(clazz); - } - - - /** - *

Look up and return any registered {@link Converter} for the specified - * destination class; if there is no registered Converter, return - * {@code null}.

- * - *

For more details see {@code ConvertUtilsBean}.

- * - * @param clazz Class for which to return a registered Converter - * @return The registered {@link Converter} or {@code null} if not found - * @see ConvertUtilsBean#lookup(Class) - */ - public static Converter lookup(final Class clazz) { - return ConvertUtilsBean.getInstance().lookup(clazz); - } - - /** - * Look up and return any registered {@link Converter} for the specified - * source and destination class; if there is no registered Converter, - * return {@code null}. - * - * @param sourceType Class of the value being converted - * @param targetType Class of the value to be converted to - * @return The registered {@link Converter} or {@code null} if not found - */ - public static Converter lookup(final Class sourceType, final Class targetType) { - return ConvertUtilsBean.getInstance().lookup(sourceType, targetType); - } - - /** - *

Register a custom {@link Converter} for the specified destination - * {@code Class}, replacing any previously registered Converter.

- * - *

For more details see {@code ConvertUtilsBean}.

- * - * @param converter Converter to be registered - * @param clazz Destination class for conversions performed by this - * Converter - * @see ConvertUtilsBean#register(Converter, Class) - */ - public static void register(final Converter converter, final Class clazz) { - ConvertUtilsBean.getInstance().register(converter, clazz); - } - - - /** - * Change primitive Class types to the associated wrapper class. This is - * useful for concrete converter implementations which typically treat - * primitive types like their corresponding wrapper types. - * - * @param The type to be checked. - * @param type The class type to check. - * @return The converted type. - * @since 1.9 - */ - // All type casts are safe because the TYPE members of the wrapper types - // return their own class. - @SuppressWarnings("unchecked") - public static Class primitiveToWrapper(final Class type) { - if (type == null || !type.isPrimitive()) { - return type; - } - - if (type == Integer.TYPE) { - return (Class) Integer.class; - } else if (type == Double.TYPE) { - return (Class) Double.class; - } else if (type == Long.TYPE) { - return (Class) Long.class; - } else if (type == Boolean.TYPE) { - return (Class) Boolean.class; - } else if (type == Float.TYPE) { - return (Class) Float.class; - } else if (type == Short.TYPE) { - return (Class) Short.class; - } else if (type == Byte.TYPE) { - return (Class) Byte.class; - } else if (type == Character.TYPE) { - return (Class) Character.class; - } else { - return type; - } - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java deleted file mode 100644 index 54117cd75..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean.java +++ /dev/null @@ -1,725 +0,0 @@ -/* - * 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.beanutils2; - -import java.io.File; -import java.lang.reflect.Array; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.net.URI; -import java.net.URL; -import java.nio.file.Path; -import java.sql.Timestamp; -import java.time.Duration; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.MonthDay; -import java.time.OffsetDateTime; -import java.time.OffsetTime; -import java.time.Period; -import java.time.Year; -import java.time.YearMonth; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.util.Calendar; -import java.util.Collection; -import java.util.UUID; - -import org.apache.commons.beanutils2.converters.ArrayConverter; -import org.apache.commons.beanutils2.converters.BigDecimalConverter; -import org.apache.commons.beanutils2.converters.BigIntegerConverter; -import org.apache.commons.beanutils2.converters.BooleanConverter; -import org.apache.commons.beanutils2.converters.ByteConverter; -import org.apache.commons.beanutils2.converters.CalendarConverter; -import org.apache.commons.beanutils2.converters.CharacterConverter; -import org.apache.commons.beanutils2.converters.ClassConverter; -import org.apache.commons.beanutils2.converters.ConverterFacade; -import org.apache.commons.beanutils2.converters.DateConverter; -import org.apache.commons.beanutils2.converters.DoubleConverter; -import org.apache.commons.beanutils2.converters.EnumConverter; -import org.apache.commons.beanutils2.converters.DurationConverter; -import org.apache.commons.beanutils2.converters.FileConverter; -import org.apache.commons.beanutils2.converters.FloatConverter; -import org.apache.commons.beanutils2.converters.IntegerConverter; -import org.apache.commons.beanutils2.converters.LocalDateConverter; -import org.apache.commons.beanutils2.converters.LocalDateTimeConverter; -import org.apache.commons.beanutils2.converters.LocalTimeConverter; -import org.apache.commons.beanutils2.converters.LongConverter; -import org.apache.commons.beanutils2.converters.MonthDayConverter; -import org.apache.commons.beanutils2.converters.OffsetDateTimeConverter; -import org.apache.commons.beanutils2.converters.OffsetTimeConverter; -import org.apache.commons.beanutils2.converters.PathConverter; -import org.apache.commons.beanutils2.converters.PeriodConverter; -import org.apache.commons.beanutils2.converters.ShortConverter; -import org.apache.commons.beanutils2.converters.SqlDateConverter; -import org.apache.commons.beanutils2.converters.SqlTimeConverter; -import org.apache.commons.beanutils2.converters.SqlTimestampConverter; -import org.apache.commons.beanutils2.converters.StringConverter; -import org.apache.commons.beanutils2.converters.URIConverter; -import org.apache.commons.beanutils2.converters.URLConverter; -import org.apache.commons.beanutils2.converters.UUIDConverter; -import org.apache.commons.beanutils2.converters.YearConverter; -import org.apache.commons.beanutils2.converters.YearMonthConverter; -import org.apache.commons.beanutils2.converters.ZoneIdConverter; -import org.apache.commons.beanutils2.converters.ZoneOffsetConverter; -import org.apache.commons.beanutils2.converters.ZonedDateTimeConverter; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - *

Utility methods for converting String scalar values to objects of the - * specified Class, String arrays to arrays of the specified Class. The - * actual {@link Converter} instance to be used can be registered for each - * possible destination Class. Unless you override them, standard - * {@link Converter} instances are provided for all of the following - * destination Classes:

- *
    - *
  • java.lang.BigDecimal (no default value)
  • - *
  • java.lang.BigInteger (no default value)
  • - *
  • boolean and java.lang.Boolean (default to false)
  • - *
  • byte and java.lang.Byte (default to zero)
  • - *
  • char and java.lang.Character (default to a space)
  • - *
  • java.lang.Class (no default value)
  • - *
  • double and java.lang.Double (default to zero)
  • - *
  • float and java.lang.Float (default to zero)
  • - *
  • int and java.lang.Integer (default to zero)
  • - *
  • long and java.lang.Long (default to zero)
  • - *
  • short and java.lang.Short (default to zero)
  • - *
  • java.lang.String (default to null)
  • - *
  • java.lang.Enum (default to null)
  • - *
  • java.io.File (no default value)
  • - *
  • java.nio.file.Path (no default value)
  • - *
  • java.net.URL (no default value)
  • - *
  • java.net.URI (no default value)
  • - *
  • java.util.UUID (no default value)
  • - *
  • java.sql.Date (no default value)
  • - *
  • java.sql.Time (no default value)
  • - *
  • java.sql.Timestamp (no default value)
  • - *
  • java.time.LocalDate (no default value)
  • - *
  • java.time.LocalDateTime (no default value)
  • - *
  • java.time.LocalTime (no default value)
  • - *
  • java.time.OffsetDateTime (no default value)
  • - *
  • java.time.OffsetTime (no default value)
  • - *
  • java.time.ZonedDateTime (no default value)
  • - *
  • java.time.Duration (no default value)
  • - *
  • java.time.MonthDay (no default value)
  • - *
  • java.time.Period (no default value)
  • - *
  • java.time.Year (no default value)
  • - *
  • java.time.YearMonth (no default value)
  • - *
  • java.time.ZoneId (no default value)
  • - *
  • java.time.ZoneOffset (no default value)
  • - *
- * - *

For backwards compatibility, the standard Converters for primitive - * types (and the corresponding wrapper classes) return a defined - * default value when a conversion error occurs. If you prefer to have a - * {@link ConversionException} thrown instead, replace the standard Converter - * instances with instances created with the zero-arguments constructor. For - * example, to cause the Converters for integers to throw an exception on - * conversion errors, you could do this:

- *
- *   // No-args constructor gets the version that throws exceptions
- *   Converter myConverter =
- *    new org.apache.commons.beanutils2.converter.IntegerConverter();
- *   ConvertUtils.register(myConverter, Integer.TYPE);    // Native type
- *   ConvertUtils.register(myConverter, Integer.class);   // Wrapper class
- * 
- * - *

- * Converters generally treat null input as if it were invalid - * input, ie they return their default value if one was specified when the - * converter was constructed, and throw an exception otherwise. If you prefer - * nulls to be preserved for converters that are converting to objects (not - * primitives) then register a converter as above, passing a default value of - * null to the converter constructor (and of course registering that converter - * only for the .class target). - *

- * - *

- * When a converter is listed above as having no default value, then that - * converter will throw an exception when passed null or an invalid value - * as its input. In particular, by default the BigInteger and BigDecimal - * converters have no default (and are therefore somewhat inconsistent - * with the other numerical converters which all have zero as their default). - *

- * - *

- * Converters that generate arrays of each of the primitive types are - * also automatically configured (including String[]). When passed null - * or invalid input, these return an empty array (not null). See class - * AbstractArrayConverter for the supported input formats for these converters. - *

- * - * @since 1.7 - */ - -public class ConvertUtilsBean { - - private static final Integer ZERO = Integer.valueOf(0); - private static final Character SPACE = Character.valueOf(' '); - - - /** - * Get singleton instance - * @return The singleton instance - */ - protected static ConvertUtilsBean getInstance() { - return BeanUtilsBean.getInstance().getConvertUtils(); - } - - - - /** - * The set of {@link Converter}s that can be used to convert Strings - * into objects of a specified Class, keyed by the destination Class. - */ - private final WeakFastHashMap, Converter> converters = - new WeakFastHashMap<>(); - - /** - * The {@code Log} instance for this class. - */ - private final Log log = LogFactory.getLog(ConvertUtilsBean.class); - - - - /** Construct a bean with standard converters registered */ - public ConvertUtilsBean() { - converters.setFast(false); - deregister(); - converters.setFast(true); - } - - - - /** - * Convert the specified value into a String. If the specified value - * is an array, the first element (converted to a String) will be - * returned. The registered {@link Converter} for the - * {@code java.lang.String} class will be used, which allows - * applications to customize Object->String conversions (the default - * implementation simply uses toString()). - * - * @param value Value to be converted (may be null) - * @return The converted String value or null if value is null - */ - public String convert(Object value) { - - if (value == null) { - return null; - } else if (value.getClass().isArray()) { - if (Array.getLength(value) < 1) { - return null; - } - value = Array.get(value, 0); - if (value == null) { - return null; - } - final Converter converter = lookup(String.class); - return converter.convert(String.class, value); - } else { - final Converter converter = lookup(String.class); - return converter.convert(String.class, value); - } - - } - - /** - * Convert the specified value to an object of the specified class (if - * possible). Otherwise, return a String representation of the value. - * - * @param value Value to be converted (may be null) - * @param clazz Java class to be converted to (must not be null) - * @return The converted value - * - * @throws ConversionException if thrown by an underlying Converter - */ - public Object convert(final String value, final Class clazz) { - - if (log.isDebugEnabled()) { - log.debug("Convert string '" + value + "' to class '" + - clazz.getName() + "'"); - } - Converter converter = lookup(clazz); - if (converter == null) { - converter = lookup(String.class); - } - if (log.isTraceEnabled()) { - log.trace(" Using converter " + converter); - } - return converter.convert(clazz, value); - - } - - /** - * Convert an array of specified values to an array of objects of the - * specified class (if possible). If the specified Java class is itself - * an array class, this class will be the type of the returned value. - * Otherwise, an array will be constructed whose component type is the - * specified class. - * - * @param values Array of values to be converted - * @param clazz Java array or element class to be converted to (must not be null) - * @return The converted value - * - * @throws ConversionException if thrown by an underlying Converter - */ - public Object convert(final String[] values, final Class clazz) { - - Class type = clazz; - if (clazz.isArray()) { - type = clazz.getComponentType(); - } - if (log.isDebugEnabled()) { - log.debug("Convert String[" + values.length + "] to class '" + - type.getName() + "[]'"); - } - Converter converter = lookup(type); - if (converter == null) { - converter = lookup(String.class); - } - if (log.isTraceEnabled()) { - log.trace(" Using converter " + converter); - } - final Object array = Array.newInstance(type, values.length); - for (int i = 0; i < values.length; i++) { - Array.set(array, i, converter.convert(type, values[i])); - } - return array; - - } - - /** - * Convert the value to an object of the specified class (if - * possible). If no converter for the desired target type is registered, - * the passed in object is returned unchanged. - * - * @param value Value to be converted (may be null) - * @param targetType Class of the value to be converted to (must not be null) - * @return The converted value - * - * @throws ConversionException if thrown by an underlying Converter - */ - public Object convert(final Object value, final Class targetType) { - - final Class sourceType = value == null ? null : value.getClass(); - - if (log.isDebugEnabled()) { - if (value == null) { - log.debug("Convert null value to type '" + - targetType.getName() + "'"); - } else { - log.debug("Convert type '" + sourceType.getName() + "' value '" + value + - "' to type '" + targetType.getName() + "'"); - } - } - - Object converted = value; - Converter converter = lookup(sourceType, targetType); - if (converter != null) { - if (log.isTraceEnabled()) { - log.trace(" Using converter " + converter); - } - converted = converter.convert(targetType, value); - } - if (String.class.equals(targetType) && converted != null && - !(converted instanceof String)) { - - // NOTE: For backwards compatibility, if the Converter - // doesn't handle conversion-->String then - // use the registered String Converter - converter = lookup(String.class); - if (converter != null) { - if (log.isTraceEnabled()) { - log.trace(" Using converter " + converter); - } - converted = converter.convert(String.class, converted); - } - - // If the object still isn't a String, use toString() method - if (converted != null && !(converted instanceof String)) { - converted = converted.toString(); - } - - } - return converted; - - } - - /** - * Remove all registered {@link Converter}s, and re-establish the - * standard Converters. - */ - public void deregister() { - - converters.clear(); - - registerPrimitives(false); - registerStandard(false, false); - registerOther(true); - registerArrays(false, 0); - register(BigDecimal.class, new BigDecimalConverter()); - register(BigInteger.class, new BigIntegerConverter()); - } - - /** - * Register the provided converters with the specified defaults. - * - * @param throwException {@code true} if the converters should - * throw an exception when a conversion error occurs, otherwise - * {@code false} if a default value should be used. - * @param defaultNull {@code true}if the standard converters - * (see {@link ConvertUtilsBean#registerStandard(boolean, boolean)}) - * should use a default value of {@code null
, otherwise false}. - * N.B. This values is ignored if {@code throwException is true} - * @param defaultArraySize The size of the default array value for array converters - * (N.B. This values is ignored if {@code throwException is true}). - * Specifying a value less than zero causes a {@code null} value to be used for - * the default. - */ - public void register(final boolean throwException, final boolean defaultNull, final int defaultArraySize) { - registerPrimitives(throwException); - registerStandard(throwException, defaultNull); - registerOther(throwException); - registerArrays(throwException, defaultArraySize); - } - - /** - * Register the converters for primitive types. - *

- * This method registers the following converters: - *
    - *
  • {@code Boolean.TYPE} - {@link BooleanConverter}
  • - *
  • {@code Byte.TYPE} - {@link ByteConverter}
  • - *
  • {@code Character.TYPE} - {@link CharacterConverter}
  • - *
  • {@code Double.TYPE} - {@link DoubleConverter}
  • - *
  • {@code Float.TYPE} - {@link FloatConverter}
  • - *
  • {@code Integer.TYPE} - {@link IntegerConverter}
  • - *
  • {@code Long.TYPE} - {@link LongConverter}
  • - *
  • {@code Short.TYPE} - {@link ShortConverter}
  • - *
- * @param throwException {@code true} if the converters should - * throw an exception when a conversion error occurs, otherwise - * {@code false} if a default value should be used. - */ - private void registerPrimitives(final boolean throwException) { - register(Boolean.TYPE, throwException ? new BooleanConverter() : new BooleanConverter(Boolean.FALSE)); - register(Byte.TYPE, throwException ? new ByteConverter() : new ByteConverter(ZERO)); - register(Character.TYPE, throwException ? new CharacterConverter() : new CharacterConverter(SPACE)); - register(Double.TYPE, throwException ? new DoubleConverter() : new DoubleConverter(ZERO)); - register(Float.TYPE, throwException ? new FloatConverter() : new FloatConverter(ZERO)); - register(Integer.TYPE, throwException ? new IntegerConverter() : new IntegerConverter(ZERO)); - register(Long.TYPE, throwException ? new LongConverter() : new LongConverter(ZERO)); - register(Short.TYPE, throwException ? new ShortConverter() : new ShortConverter(ZERO)); - } - - /** - * Register the converters for standard types. - *

- * This method registers the following converters: - *
    - *
  • {@code BigDecimal.class} - {@link BigDecimalConverter}
  • - *
  • {@code BigInteger.class} - {@link BigIntegerConverter}
  • - *
  • {@code Boolean.class} - {@link BooleanConverter}
  • - *
  • {@code Byte.class} - {@link ByteConverter}
  • - *
  • {@code Character.class} - {@link CharacterConverter}
  • - *
  • {@code Double.class} - {@link DoubleConverter}
  • - *
  • {@code Float.class} - {@link FloatConverter}
  • - *
  • {@code Integer.class} - {@link IntegerConverter}
  • - *
  • {@code Long.class} - {@link LongConverter}
  • - *
  • {@code Short.class} - {@link ShortConverter}
  • - *
  • {@code String.class} - {@link StringConverter}
  • - *
- * @param throwException {@code true} if the converters should - * throw an exception when a conversion error occurs, otherwise - * {@code false} if a default value should be used. - * @param defaultNull {@code true}if the standard converters - * (see {@link ConvertUtilsBean#registerStandard(boolean, boolean)}) - * should use a default value of {@code null, otherwise false}. - * N.B. This values is ignored if {@code throwException is true} - */ - private void registerStandard(final boolean throwException, final boolean defaultNull) { - - final Number defaultNumber = defaultNull ? null : ZERO; - final BigDecimal bigDecDeflt = defaultNull ? null : new BigDecimal("0.0"); - final BigInteger bigIntDeflt = defaultNull ? null : new BigInteger("0"); - final Boolean booleanDefault = defaultNull ? null : Boolean.FALSE; - final Character charDefault = defaultNull ? null : SPACE; - final String stringDefault = defaultNull ? null : ""; - - register(BigDecimal.class, throwException ? new BigDecimalConverter() : new BigDecimalConverter(bigDecDeflt)); - register(BigInteger.class, throwException ? new BigIntegerConverter() : new BigIntegerConverter(bigIntDeflt)); - register(Boolean.class, throwException ? new BooleanConverter() : new BooleanConverter(booleanDefault)); - register(Byte.class, throwException ? new ByteConverter() : new ByteConverter(defaultNumber)); - register(Character.class, throwException ? new CharacterConverter() : new CharacterConverter(charDefault)); - register(Double.class, throwException ? new DoubleConverter() : new DoubleConverter(defaultNumber)); - register(Float.class, throwException ? new FloatConverter() : new FloatConverter(defaultNumber)); - register(Integer.class, throwException ? new IntegerConverter() : new IntegerConverter(defaultNumber)); - register(Long.class, throwException ? new LongConverter() : new LongConverter(defaultNumber)); - register(Short.class, throwException ? new ShortConverter() : new ShortConverter(defaultNumber)); - register(String.class, throwException ? new StringConverter() : new StringConverter(stringDefault)); - - } - - /** - * Register the converters for other types. - *

- * This method registers the following converters: - *
    - *
  • {@code Class.class} - {@link ClassConverter}
  • - *
  • {@code Enum.class} - {@link EnumConverter}
  • - *
  • {@code java.util.Date.class} - {@link DateConverter}
  • - *
  • {@code java.util.Calendar.class} - {@link CalendarConverter}
  • - *
  • {@code File.class} - {@link FileConverter}
  • - *
  • {@code Path.class} - {@link PathConverter}
  • - *
  • {@code java.sql.Date.class} - {@link SqlDateConverter}
  • - *
  • {@code java.sql.Time.class} - {@link SqlTimeConverter}
  • - *
  • {@code java.sql.Timestamp.class} - {@link SqlTimestampConverter}
  • - *
  • {@code URL.class} - {@link URLConverter}
  • - *
  • {@code URI.class} - {@link URIConverter}
  • - *
  • {@code UUID.class} - {@link UUIDConverter}
  • - *
  • {@code LocalDate.class} - {@link LocalDateConverter}
  • - *
  • {@code LocalDateTime.class} - {@link LocalDateTimeConverter}
  • - *
  • {@code LocalTime.class} - {@link LocalTimeConverter}
  • - *
  • {@code OffsetDateTime.class} - {@link OffsetDateTimeConverter}
  • - *
  • {@code OffsetTime.class} - {@link OffsetTimeConverter}
  • - *
  • {@code ZonedDateTime.class} - {@link ZonedDateTimeConverter}
  • - *
  • {@code Duration.class} - {@link DurationConverter}
  • - *
  • {@code MonthDay.class} - {@link MonthDayConverter}
  • - *
  • {@code Period.class} - {@link PeriodConverter}
  • - *
  • {@code Year.class} - {@link YearConverter}
  • - *
  • {@code YearMonth.class} - {@link YearMonthConverter}
  • - *
  • {@code ZoneId.class} - {@link ZoneIdConverter}
  • - *
  • {@code ZoneOffset.class} - {@link ZoneOffsetConverter}
  • - *
- * @param throwException {@code true} if the converters should - * throw an exception when a conversion error occurs, otherwise - * {@code false} if a default value should be used. - */ - private void registerOther(final boolean throwException) { - // @formatter:off - register(Class.class, throwException ? new ClassConverter() : new ClassConverter(null)); - register(Enum.class, throwException ? new EnumConverter() : new EnumConverter(null)); - register(java.util.Date.class, throwException ? new DateConverter() : new DateConverter(null)); - register(Calendar.class, throwException ? new CalendarConverter() : new CalendarConverter(null)); - register(File.class, throwException ? new FileConverter() : new FileConverter(null)); - register(Path.class, throwException ? new PathConverter() : new PathConverter(null)); - register(java.sql.Date.class, throwException ? new SqlDateConverter() : new SqlDateConverter(null)); - register(java.sql.Time.class, throwException ? new SqlTimeConverter() : new SqlTimeConverter(null)); - register(Timestamp.class, throwException ? new SqlTimestampConverter() : new SqlTimestampConverter(null)); - register(URL.class, throwException ? new URLConverter() : new URLConverter(null)); - register(URI.class, throwException ? new URIConverter() : new URIConverter(null)); - register(UUID.class, throwException ? new UUIDConverter() : new UUIDConverter(null)); - register(LocalDate.class, throwException ? new LocalDateConverter() : new LocalDateConverter(null)); - register(LocalDateTime.class, throwException ? new LocalDateTimeConverter() : new LocalDateTimeConverter(null)); - register(LocalTime.class, throwException ? new LocalTimeConverter() : new LocalTimeConverter(null)); - register(OffsetDateTime.class, throwException ? new OffsetDateTimeConverter() : new OffsetDateTimeConverter(null)); - register(OffsetTime.class, throwException ? new OffsetTimeConverter() : new OffsetTimeConverter(null)); - register(ZonedDateTime.class, throwException ? new ZonedDateTimeConverter() : new ZonedDateTimeConverter(null)); - register(Duration.class, throwException ? new DurationConverter() : new DurationConverter(null)); - register(MonthDay.class, throwException ? new MonthDayConverter() : new MonthDayConverter(null)); - register(Period.class, throwException ? new PeriodConverter() : new PeriodConverter(null)); - register(Year.class, throwException ? new YearConverter() : new YearConverter(null)); - register(YearMonth.class, throwException ? new YearMonthConverter() : new YearMonthConverter(null)); - register(ZoneId.class, throwException ? new ZoneIdConverter() : new ZoneIdConverter(null)); - register(ZoneOffset.class, throwException ? new ZoneOffsetConverter() : new ZoneOffsetConverter(null)); - // @formatter:on - } - - /** - * Register array converters. - * - * @param throwException {@code true} if the converters should - * throw an exception when a conversion error occurs, otherwise - * {@code false} if a default value should be used. - * @param defaultArraySize The size of the default array value for array converters - * (N.B. This values is ignored if {@code throwException is true}). - * Specifying a value less than zero causes a null value to be used for - * the default. - */ - private void registerArrays(final boolean throwException, final int defaultArraySize) { - // @formatter:off - - // Primitives - registerArrayConverter(Boolean.TYPE, new BooleanConverter(), throwException, defaultArraySize); - registerArrayConverter(Byte.TYPE, new ByteConverter(), throwException, defaultArraySize); - registerArrayConverter(Character.TYPE, new CharacterConverter(), throwException, defaultArraySize); - registerArrayConverter(Double.TYPE, new DoubleConverter(), throwException, defaultArraySize); - registerArrayConverter(Float.TYPE, new FloatConverter(), throwException, defaultArraySize); - registerArrayConverter(Integer.TYPE, new IntegerConverter(), throwException, defaultArraySize); - registerArrayConverter(Long.TYPE, new LongConverter(), throwException, defaultArraySize); - registerArrayConverter(Short.TYPE, new ShortConverter(), throwException, defaultArraySize); - - // Standard - registerArrayConverter(BigDecimal.class, new BigDecimalConverter(), throwException, defaultArraySize); - registerArrayConverter(BigInteger.class, new BigIntegerConverter(), throwException, defaultArraySize); - registerArrayConverter(Boolean.class, new BooleanConverter(), throwException, defaultArraySize); - registerArrayConverter(Byte.class, new ByteConverter(), throwException, defaultArraySize); - registerArrayConverter(Character.class, new CharacterConverter(), throwException, defaultArraySize); - registerArrayConverter(Double.class, new DoubleConverter(), throwException, defaultArraySize); - registerArrayConverter(Float.class, new FloatConverter(), throwException, defaultArraySize); - registerArrayConverter(Integer.class, new IntegerConverter(), throwException, defaultArraySize); - registerArrayConverter(Long.class, new LongConverter(), throwException, defaultArraySize); - registerArrayConverter(Short.class, new ShortConverter(), throwException, defaultArraySize); - registerArrayConverter(String.class, new StringConverter(), throwException, defaultArraySize); - - // Other - registerArrayConverter(Class.class, new ClassConverter(), throwException, defaultArraySize); - registerArrayConverter(Enum.class, new EnumConverter(), throwException, defaultArraySize); - registerArrayConverter(java.util.Date.class, new DateConverter(), throwException, defaultArraySize); - registerArrayConverter(Calendar.class, new DateConverter(), throwException, defaultArraySize); - registerArrayConverter(File.class, new FileConverter(), throwException, defaultArraySize); - registerArrayConverter(Path.class, new PathConverter(), throwException, defaultArraySize); - registerArrayConverter(java.sql.Date.class, new SqlDateConverter(), throwException, defaultArraySize); - registerArrayConverter(java.sql.Time.class, new SqlTimeConverter(), throwException, defaultArraySize); - registerArrayConverter(Timestamp.class, new SqlTimestampConverter(), throwException, defaultArraySize); - registerArrayConverter(URL.class, new URLConverter(), throwException, defaultArraySize); - registerArrayConverter(URI.class, new URIConverter(), throwException, defaultArraySize); - registerArrayConverter(UUID.class, new UUIDConverter(), throwException, defaultArraySize); - registerArrayConverter(LocalDate.class, new LocalDateConverter(), throwException, defaultArraySize); - registerArrayConverter(LocalDateTime.class, new LocalDateTimeConverter(), throwException, defaultArraySize); - registerArrayConverter(LocalTime.class, new LocalTimeConverter(), throwException, defaultArraySize); - registerArrayConverter(OffsetDateTime.class, new OffsetDateTimeConverter(),throwException, defaultArraySize); - registerArrayConverter(OffsetTime.class, new OffsetTimeConverter(), throwException, defaultArraySize); - registerArrayConverter(ZonedDateTime.class, new ZonedDateTimeConverter(), throwException, defaultArraySize); - registerArrayConverter(Duration.class, new DurationConverter(), throwException, defaultArraySize); - registerArrayConverter(MonthDay.class, new MonthDayConverter(), throwException, defaultArraySize); - registerArrayConverter(Period.class, new PeriodConverter(), throwException, defaultArraySize); - registerArrayConverter(Year.class, new YearConverter(), throwException, defaultArraySize); - registerArrayConverter(YearMonth.class, new YearMonthConverter(), throwException, defaultArraySize); - registerArrayConverter(ZoneId.class, new ZoneIdConverter(), throwException, defaultArraySize); - registerArrayConverter(ZoneOffset.class, new ZoneOffsetConverter(), throwException, defaultArraySize); - // @formatter:on - } - - /** - * Register a new ArrayConverter with the specified element delegate converter - * that returns a default array of the specified size in the event of conversion errors. - * - * @param componentType The component type of the array - * @param componentConverter The converter to delegate to for the array elements - * @param throwException Whether a conversion exception should be thrown or a default - * value used in the event of a conversion error - * @param defaultArraySize The size of the default array - */ - private void registerArrayConverter(final Class componentType, final Converter componentConverter, - final boolean throwException, final int defaultArraySize) { - final Class arrayType = Array.newInstance(componentType, 0).getClass(); - Converter arrayConverter = null; - if (throwException) { - arrayConverter = new ArrayConverter(arrayType, componentConverter); - } else { - arrayConverter = new ArrayConverter(arrayType, componentConverter, defaultArraySize); - } - register(arrayType, arrayConverter); - } - - /** strictly for convenience since it has same parameter order as Map.put */ - private void register(final Class clazz, final Converter converter) { - register(new ConverterFacade(converter), clazz); - } - - /** - * Remove any registered {@link Converter} for the specified destination - * {@code Class}. - * - * @param clazz Class for which to remove a registered Converter - */ - public void deregister(final Class clazz) { - - converters.remove(clazz); - - } - - /** - * Look up and return any registered {@link Converter} for the specified - * destination class; if there is no registered Converter, return - * {@code null}. - * - * @param clazz Class for which to return a registered Converter - * @return The registered {@link Converter} or {@code null} if not found - */ - public Converter lookup(final Class clazz) { - - return converters.get(clazz); - - } - - /** - * Look up and return any registered {@link Converter} for the specified - * source and destination class; if there is no registered Converter, - * return {@code null}. - * - * @param sourceType Class of the value being converted - * @param targetType Class of the value to be converted to - * @return The registered {@link Converter} or {@code null} if not found - */ - public Converter lookup(final Class sourceType, final Class targetType) { - - if (targetType == null) { - throw new IllegalArgumentException("Target type is missing"); - } - if (sourceType == null) { - return lookup(targetType); - } - - Converter converter = null; - // Convert --> String - if (targetType == String.class) { - converter = lookup(sourceType); - if (converter == null && (sourceType.isArray() || - Collection.class.isAssignableFrom(sourceType))) { - converter = lookup(String[].class); - } - if (converter == null) { - converter = lookup(String.class); - } - return converter; - } - - // Convert --> String array - if (targetType == String[].class) { - if (sourceType.isArray() || Collection.class.isAssignableFrom(sourceType)) { - converter = lookup(sourceType); - } - if (converter == null) { - converter = lookup(String[].class); - } - return converter; - } - - return lookup(targetType); - - } - - /** - * Register a custom {@link Converter} for the specified destination - * {@code Class}, replacing any previously registered Converter. - * - * @param converter Converter to be registered - * @param clazz Destination class for conversions performed by this - * Converter - */ - public void register(final Converter converter, final Class clazz) { - - converters.put(clazz, converter); - - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java deleted file mode 100644 index f06958e19..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertUtilsBean2.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.beanutils2; - -/** - * {@link ConvertUtilsBean} implementation that delegates {@code convert()} - * methods to the new {@link ConvertUtilsBean#convert(Object, Class)} method. - * - *

- * To configure this implementation for the current context ClassLoader invoke - * {@code BeanUtilsBean.setInstance(new BeanUtilsBean2());} - *

- * - * @see BeanUtilsBean2 - * @since 1.8.0 - */ -public class ConvertUtilsBean2 extends ConvertUtilsBean { - - /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. - * - * @param value Value to be converted (may be null) - * @return The converted String value or null if value is null - * - * @see ConvertUtilsBean#convert(String[], Class) - */ - @Override - public String convert(final Object value) { - return (String)convert(value, String.class); - } - - /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. - * - * @param value Value to be converted (may be null) - * @param clazz Java class to be converted to (must not be null) - * @return The converted value or null if value is null - * - * @see ConvertUtilsBean#convert(String[], Class) - */ - @Override - public Object convert(final String value, final Class clazz) { - return convert((Object)value, clazz); - } - - /** - * Delegates to the new {@link ConvertUtilsBean#convert(Object, Class)} - * method. - * - * @param value Array of values to be converted - * @param clazz Java array or element class to be converted to (must not be null) - * @return The converted value - * - * @see ConvertUtilsBean#convert(String[], Class) - */ - @Override - public Object convert(final String[] value, final Class clazz) { - return convert((Object)value, clazz); - } - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/Converter.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/Converter.java deleted file mode 100644 index 34e9ef083..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/Converter.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.beanutils2; - -/** - *

General purpose data type converter that can be registered and used - * within the BeanUtils package to manage the conversion of objects from - * one type to another.

- * - *

Converter subclasses bundled with the BeanUtils library are required - * to be thread-safe, as users of the library may call conversion methods - * from more than one thread simultaneously.

- * - *

Custom converter subclasses created by users of the library can be - * non-thread-safe if the application using them is single-threaded. However - * it is recommended that they be written in a thread-safe manner anyway.

- * - * @since 1.3 - */ -public interface Converter { - - /** - * Convert the specified input object into an output object of the - * specified type. - * - * @param the desired result type - * @param type Data type to which this value should be converted - * @param value The input value to be converted - * @return The converted value - * - * @throws ConversionException if conversion cannot be performed - * successfully - */ - T convert(Class type, Object value); - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertingWrapDynaBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertingWrapDynaBean.java deleted file mode 100644 index 588bf5d9f..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/ConvertingWrapDynaBean.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.beanutils2; - -import java.lang.reflect.InvocationTargetException; - -/** - *

Implementation of {@code DynaBean} that wraps a standard JavaBean - * instance, so that DynaBean APIs can be used to access its properties, - * though this implementation allows type conversion to occur when properties are set. - * This means that (say) Strings can be passed in as values in setter methods and - * this DynaBean will convert them to the correct primitive data types.

- * - *

IMPLEMENTATION NOTE - This implementation does not - * support the {@code contains() and remove()} methods.

- * - */ - -public class ConvertingWrapDynaBean extends WrapDynaBean { - - private static final long serialVersionUID = 1L; - - /** - * Construct a new {@code DynaBean} associated with the specified - * JavaBean instance. - * - * @param instance JavaBean instance to be wrapped - */ - public ConvertingWrapDynaBean(final Object instance) { - - super(instance); - - } - - /** - * Set the value of the property with the specified name - * performing any type conversions if necessary. So this method - * can accept String values for primitive numeric data types for example. - * - * @param name Name of the property whose value is to be set - * @param value Value to which this property is to be set - * - * @throws IllegalArgumentException if there are any problems - * copying the property. - */ - @Override - public void set(final String name, final Object value) { - - try { - BeanUtils.copyProperty(instance, name, value); - } catch (final InvocationTargetException ite) { - final Throwable cause = ite.getTargetException(); - throw new IllegalArgumentException - ("Error setting property '" + name + - "' nested exception - " + cause); - } catch (final Throwable t) { - final IllegalArgumentException iae = new IllegalArgumentException - ("Error setting property '" + name + - "', exception - " + t); - BeanUtils.initCause(iae, t); - throw iae; - } - - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultBeanIntrospector.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultBeanIntrospector.java deleted file mode 100644 index 8483f9fde..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultBeanIntrospector.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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.beanutils2; - -import java.beans.BeanInfo; -import java.beans.IndexedPropertyDescriptor; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - *

- * The default {@link BeanIntrospector} implementation. - *

- *

- * This class implements a default bean introspection algorithm based on the JDK - * classes in the {@code java.beans} package. It discovers properties - * conforming to the Java Beans specification. - *

- *

- * This class is a singleton. The single instance can be obtained using the - * {@code INSTANCE} field. It does not define any state and thus can be - * shared by arbitrary clients. {@link PropertyUtils} per default uses this - * instance as its only {@code BeanIntrospector} object. - *

- * - * @since 1.9 - */ -public class DefaultBeanIntrospector implements BeanIntrospector { - /** The singleton instance of this class. */ - public static final BeanIntrospector INSTANCE = new DefaultBeanIntrospector(); - - /** Constant for argument types of a method that expects no arguments. */ - private static final Class[] EMPTY_CLASS_PARAMETERS = new Class[0]; - - /** Constant for arguments types of a method that expects a list argument. */ - private static final Class[] LIST_CLASS_PARAMETER = new Class[] { java.util.List.class }; - - /** Log instance */ - private final Log log = LogFactory.getLog(getClass()); - - /** - * Private constructor so that no instances can be created. - */ - private DefaultBeanIntrospector() { - } - - /** - * Performs introspection of a specific Java class. This implementation uses - * the {@code java.beans.Introspector.getBeanInfo()} method to obtain - * all property descriptors for the current class and adds them to the - * passed in introspection context. - * - * @param icontext the introspection context - */ - @Override - public void introspect(final IntrospectionContext icontext) { - BeanInfo beanInfo = null; - try { - beanInfo = Introspector.getBeanInfo(icontext.getTargetClass()); - } catch (final IntrospectionException e) { - // no descriptors are added to the context - log.error( - "Error when inspecting class " + icontext.getTargetClass(), - e); - return; - } - - PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); - if (descriptors == null) { - descriptors = new PropertyDescriptor[0]; - } - - handleIndexedPropertyDescriptors(icontext.getTargetClass(), - descriptors); - icontext.addPropertyDescriptors(descriptors); - } - - /** - * This method fixes an issue where IndexedPropertyDescriptor behaves - * differently in different versions of the JDK for 'indexed' properties - * which use java.util.List (rather than an array). It implements a - * workaround for Bug 28358. If you have a Bean with the following - * getters/setters for an indexed property: - * - *
-     * public List getFoo()
-     * public Object getFoo(int index)
-     * public void setFoo(List foo)
-     * public void setFoo(int index, Object foo)
-     * 
- * - * then the IndexedPropertyDescriptor's getReadMethod() and getWriteMethod() - * behave as follows: - *
    - *
  • JDK 1.3.1_04: returns valid Method objects from these methods.
  • - *
  • JDK 1.4.2_05: returns null from these methods.
  • - *
- * - * @param beanClass the current class to be inspected - * @param descriptors the array with property descriptors - */ - private void handleIndexedPropertyDescriptors(final Class beanClass, - final PropertyDescriptor[] descriptors) { - for (final PropertyDescriptor pd : descriptors) { - if (pd instanceof IndexedPropertyDescriptor) { - final IndexedPropertyDescriptor descriptor = (IndexedPropertyDescriptor) pd; - final String propName = descriptor.getName().substring(0, 1) - .toUpperCase() - + descriptor.getName().substring(1); - - if (descriptor.getReadMethod() == null) { - final String methodName = descriptor.getIndexedReadMethod() != null ? descriptor - .getIndexedReadMethod().getName() : "get" - + propName; - final Method readMethod = MethodUtils - .getMatchingAccessibleMethod(beanClass, methodName, - EMPTY_CLASS_PARAMETERS); - if (readMethod != null) { - try { - descriptor.setReadMethod(readMethod); - } catch (final Exception e) { - log.error( - "Error setting indexed property read method", - e); - } - } - } - if (descriptor.getWriteMethod() == null) { - final String methodName = descriptor.getIndexedWriteMethod() != null ? descriptor - .getIndexedWriteMethod().getName() : "set" - + propName; - Method writeMethod = MethodUtils - .getMatchingAccessibleMethod(beanClass, methodName, - LIST_CLASS_PARAMETER); - if (writeMethod == null) { - for (final Method m : beanClass.getMethods()) { - if (m.getName().equals(methodName)) { - final Class[] parameterTypes = m.getParameterTypes(); - if (parameterTypes.length == 1 - && List.class - .isAssignableFrom(parameterTypes[0])) { - writeMethod = m; - break; - } - } - } - } - if (writeMethod != null) { - try { - descriptor.setWriteMethod(writeMethod); - } catch (final Exception e) { - log.error( - "Error setting indexed property write method", - e); - } - } - } - } - } - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultIntrospectionContext.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultIntrospectionContext.java deleted file mode 100644 index 9b56567ee..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DefaultIntrospectionContext.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.beanutils2; - -import java.beans.PropertyDescriptor; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -/** - *

- * An implementation of the {@code IntrospectionContext} interface used by - * {@link PropertyUtilsBean} when doing introspection of a bean class. - *

- *

- * This class implements the methods required by the - * {@code IntrospectionContext} interface in a straight-forward manner - * based on a map. It is used internally only. It is not thread-safe. - *

- * - * @since 1.9 - */ -class DefaultIntrospectionContext implements IntrospectionContext { - /** Constant for an empty array of property descriptors. */ - private static final PropertyDescriptor[] EMPTY_DESCRIPTORS = new PropertyDescriptor[0]; - - /** The current class for introspection. */ - private final Class currentClass; - - /** A map for storing the already added property descriptors. */ - private final Map descriptors; - - /** - * - * Creates a new instance of {@code DefaultIntrospectionContext} and sets - * the current class for introspection. - * - * @param cls the current class - */ - public DefaultIntrospectionContext(final Class cls) { - currentClass = cls; - descriptors = new HashMap<>(); - } - - @Override - public Class getTargetClass() { - return currentClass; - } - - @Override - public void addPropertyDescriptor(final PropertyDescriptor desc) { - if (desc == null) { - throw new IllegalArgumentException( - "Property descriptor must not be null!"); - } - descriptors.put(desc.getName(), desc); - } - - @Override - public void addPropertyDescriptors(final PropertyDescriptor[] descs) { - if (descs == null) { - throw new IllegalArgumentException( - "Array with descriptors must not be null!"); - } - - for (final PropertyDescriptor desc : descs) { - addPropertyDescriptor(desc); - } - } - - @Override - public boolean hasProperty(final String name) { - return descriptors.containsKey(name); - } - - @Override - public PropertyDescriptor getPropertyDescriptor(final String name) { - return descriptors.get(name); - } - - @Override - public void removePropertyDescriptor(final String name) { - descriptors.remove(name); - } - - @Override - public Set propertyNames() { - return descriptors.keySet(); - } - - /** - * Returns an array with all descriptors added to this context. This method - * is used to obtain the results of introspection. - * - * @return an array with all known property descriptors - */ - public PropertyDescriptor[] getPropertyDescriptors() { - return descriptors.values().toArray(EMPTY_DESCRIPTORS); - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBean.java deleted file mode 100644 index c7ec3b498..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBean.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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.beanutils2; - -/** - *

A DynaBean is a Java object that supports properties - * whose names and data types, as well as values, may be dynamically modified. - * To the maximum degree feasible, other components of the BeanUtils package - * will recognize such beans and treat them as standard JavaBeans for the - * purpose of retrieving and setting property values.

- * - */ - -public interface DynaBean { - - /** - * Does the specified mapped property contain a value for the specified - * key value? - * - * @param name Name of the property to check - * @param key Name of the key to check - * @return {@code true} if the mapped property contains a value for - * the specified key, otherwise {@code false} - * - * @throws IllegalArgumentException if there is no property - * of the specified name - */ - boolean contains(String name, String key); - - /** - * Return the value of a simple property with the specified name. - * - * @param name Name of the property whose value is to be retrieved - * @return The property's value - * - * @throws IllegalArgumentException if there is no property - * of the specified name - */ - Object get(String name); - - /** - * Return the value of an indexed property with the specified name. - * - * @param name Name of the property whose value is to be retrieved - * @param index Index of the value to be retrieved - * @return The indexed property's value - * - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws IllegalArgumentException if the specified property - * exists, but is not indexed - * @throws IndexOutOfBoundsException if the specified index - * is outside the range of the underlying property - * @throws NullPointerException if no array or List has been - * initialized for this property - */ - Object get(String name, int index); - - /** - * Return the value of a mapped property with the specified name, - * or {@code null} if there is no value for the specified key. - * - * @param name Name of the property whose value is to be retrieved - * @param key Key of the value to be retrieved - * @return The mapped property's value - * - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws IllegalArgumentException if the specified property - * exists, but is not mapped - */ - Object get(String name, String key); - - /** - * Return the {@code DynaClass} instance that describes the set of - * properties available for this DynaBean. - * - * @return The associated DynaClass - */ - DynaClass getDynaClass(); - - /** - * Remove any existing value for the specified key on the - * specified mapped property. - * - * @param name Name of the property for which a value is to - * be removed - * @param key Key of the value to be removed - * - * @throws IllegalArgumentException if there is no property - * of the specified name - */ - void remove(String name, String key); - - /** - * Set the value of a simple property with the specified name. - * - * @param name Name of the property whose value is to be set - * @param value Value to which this property is to be set - * - * @throws ConversionException if the specified value cannot be - * converted to the type required for this property - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws NullPointerException if an attempt is made to set a - * primitive property to null - */ - void set(String name, Object value); - - /** - * Set the value of an indexed property with the specified name. - * - * @param name Name of the property whose value is to be set - * @param index Index of the property to be set - * @param value Value to which this property is to be set - * - * @throws ConversionException if the specified value cannot be - * converted to the type required for this property - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws IllegalArgumentException if the specified property - * exists, but is not indexed - * @throws IndexOutOfBoundsException if the specified index - * is outside the range of the underlying property - */ - void set(String name, int index, Object value); - - /** - * Set the value of a mapped property with the specified name. - * - * @param name Name of the property whose value is to be set - * @param key Key of the property to be set - * @param value Value to which this property is to be set - * - * @throws ConversionException if the specified value cannot be - * converted to the type required for this property - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws IllegalArgumentException if the specified property - * exists, but is not mapped - */ - void set(String name, String key, Object value); - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBeanPropertyMapDecorator.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBeanPropertyMapDecorator.java deleted file mode 100644 index 63c2e7606..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaBeanPropertyMapDecorator.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.beanutils2; - -/** - *

Decorates a {@link DynaBean} to provide {@code Map} behavior.

- * - *

The motivation for this implementation is to provide access to {@link DynaBean} - * properties in technologies that are unaware of BeanUtils and {@link DynaBean}s - - * such as the expression languages of JSTL and JSF.

- * - *

This can be achieved either by wrapping the {@link DynaBean} prior to - * providing it to the technology to process or by providing a {@code Map} - * accessor method on the DynaBean implementation:

- *

- *         public Map<String, Object> getMap() {
- *             return new DynaBeanPropertyMapDecorator(this);
- *         }
- * - *

This, for example, could be used in JSTL in the following way to access - * a DynaBean's {@code fooProperty}:

- *
  • {@code ${myDynaBean.map.fooProperty}}
- * - *

Usage

- * - *

To decorate a {@link DynaBean} simply instantiate this class with the - * target {@link DynaBean}:

- * - *
  • {@code Map<String, Object> fooMap = new DynaBeanPropertyMapDecorator(fooDynaBean);}
- * - *

The above example creates a read only {@code Map}. - * To create a {@code Map} which can be modified, construct a - * {@code DynaBeanPropertyMapDecorator} with the read only - * attribute set to {@code false}:

- * - *
  • Map<String, Object> fooMap = - * new DynaBeanPropertyMapDecorator(fooDynaBean, false);
- * - *

Limitations

- *

In this implementation the {@code entrySet(), keySet()} - * and {@code values()} methods create an unmodifiable - * {@code Set and it does not support the Map's clear()} - * and {@code remove()} operations.

- * - * @since BeanUtils 1.9.0 - */ -public class DynaBeanPropertyMapDecorator extends BaseDynaBeanMapDecorator { - /** - * Construct a Map for the specified {@link DynaBean}. - * - * @param dynaBean The dyna bean being decorated - * @param readOnly {@code true} if the Map is read only - * otherwise {@code false} - * @throws IllegalArgumentException if the {@link DynaBean} is null. - */ - public DynaBeanPropertyMapDecorator(final DynaBean dynaBean, final boolean readOnly) { - super(dynaBean, readOnly); - } - - /** - * Constructs a read only Map for the specified - * {@link DynaBean}. - * - * @param dynaBean The dyna bean being decorated - * @throws IllegalArgumentException if the {@link DynaBean} is null. - */ - public DynaBeanPropertyMapDecorator(final DynaBean dynaBean) { - super(dynaBean); - } - - @Override - protected String convertKey(final String propertyName) { - return propertyName; - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaClass.java deleted file mode 100644 index 41336ccd9..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaClass.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.beanutils2; - -/** - *

A DynaClass is a simulation of the functionality of - * {@code java.lang.Class} for classes implementing the - * {@code DynaBean} interface. DynaBean instances that share the same - * DynaClass all have the same set of available properties, along with any - * associated data types, read-only states, and write-only states.

- * - */ - -public interface DynaClass { - - /** - * Returns the name of this DynaClass (analogous to the - * {@code getName()} method of {@code java.lang.Class}, which - * allows the same {@code DynaClass} implementation class to support - * different dynamic classes, with different sets of properties. - * - * @return the name of the DynaClass - */ - String getName(); - - /** - * Returns a property descriptor for the specified property, if it exists; - * otherwise, return {@code null}. - * - * @param name Name of the dynamic property for which a descriptor - * is requested - * @return The descriptor for the specified property - * - * @throws IllegalArgumentException if no property name is specified - */ - DynaProperty getDynaProperty(String name); - - /** - *

Returns an array of {@code PropertyDescriptor} for the properties - * currently defined in this DynaClass. If no properties are defined, a - * zero-length array will be returned.

- * - *

FIXME - Should we really be implementing - * {@code getBeanInfo()} instead, which returns property descriptors - * and a bunch of other stuff?

- * - * @return the set of properties for this DynaClass - */ - DynaProperty[] getDynaProperties(); - - /** - * Instantiates and return a new DynaBean instance, associated - * with this DynaClass. - * - * @return A new {@code DynaBean} instance - * - * @throws IllegalAccessException if the Class or the appropriate - * constructor is not accessible - * @throws InstantiationException if this Class represents an abstract - * class, an array class, a primitive type, or void; or if instantiation - * fails for some other reason - */ - DynaBean newInstance() - throws IllegalAccessException, InstantiationException; - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaProperty.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaProperty.java deleted file mode 100644 index 2519e00dd..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/DynaProperty.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * 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.beanutils2; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.io.StreamCorruptedException; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - *

The metadata describing an individual property of a DynaBean.

- * - *

The meta contains an optional content type property ({@link #getContentType}) - * for use by mapped and iterated properties. - * A mapped or iterated property may choose to indicate the type it expects. - * The DynaBean implementation may choose to enforce this type on its entries. - * Alternatively, an implementation may choose to ignore this property. - * All keys for maps must be of type String so no meta data is needed for map keys.

- * - */ - -public class DynaProperty implements Serializable { - - - - private static final long serialVersionUID = -3084907613499830175L; - /* - * There are issues with serializing primitive class types on certain JVM versions - * (including java 1.3). - * This class uses a custom serialization implementation that writes an integer - * for these primitive class. - * This list of constants are the ones used in serialization. - * If these values are changed, then older versions will no longer be read correctly - */ - private static final int BOOLEAN_TYPE = 1; - private static final int BYTE_TYPE = 2; - private static final int CHAR_TYPE = 3; - private static final int DOUBLE_TYPE = 4; - private static final int FLOAT_TYPE = 5; - private static final int INT_TYPE = 6; - private static final int LONG_TYPE = 7; - private static final int SHORT_TYPE = 8; - - - - /** - * Construct a property that accepts any data type. - * - * @param name Name of the property being described - */ - public DynaProperty(final String name) { - - this(name, Object.class); - - } - - /** - * Construct a property of the specified data type. - * - * @param name Name of the property being described - * @param type Java class representing the property data type - */ - public DynaProperty(final String name, final Class type) { - - super(); - this.name = name; - this.type = type; - if (type != null && type.isArray()) { - this.contentType = type.getComponentType(); - } - - } - - /** - * Construct an indexed or mapped {@code DynaProperty} that supports (pseudo)-introspection - * of the content type. - * - * @param name Name of the property being described - * @param type Java class representing the property data type - * @param contentType Class that all indexed or mapped elements are instances of - */ - public DynaProperty(final String name, final Class type, final Class contentType) { - - super(); - this.name = name; - this.type = type; - this.contentType = contentType; - - } - - - - /** Property name */ - protected String name = null; - /** - * Get the name of this property. - * @return the name of the property - */ - public String getName() { - return this.name; - } - - /** Property type */ - protected transient Class type = null; - /** - *

Gets the Java class representing the data type of the underlying property - * values.

- * - *

There are issues with serializing primitive class types on certain JVM versions - * (including java 1.3). - * Therefore, this field must not be serialized using the standard methods.

- * - *

Please leave this field as {@code transient}

- * - * @return the property type - */ - public Class getType() { - return this.type; - } - - /** The (optional) type of content elements for indexed {@code DynaProperty} */ - protected transient Class contentType; - /** - * Gets the (optional) type of the indexed content for {@code DynaProperty}'s - * that support this feature. - * - *

There are issues with serializing primitive class types on certain JVM versions - * (including java 1.3). - * Therefore, this field must not be serialized using the standard methods.

- * - * @return the Class for the content type if this is an indexed {@code DynaProperty} - * and this feature is supported. Otherwise null. - */ - public Class getContentType() { - return contentType; - } - - - - /** - * Does this property represent an indexed value (ie an array or List)? - * - * @return {@code true} if the property is indexed (i.e. is a List or - * array), otherwise {@code false} - */ - public boolean isIndexed() { - - if (type == null) { - return false; - } else if (type.isArray() || List.class.isAssignableFrom(type)) { - return true; - } else { - return false; - } - - } - - /** - * Does this property represent a mapped value (ie a Map)? - * - * @return {@code true} if the property is a Map - * otherwise {@code false} - */ - public boolean isMapped() { - - if (type == null) { - return false; - } - return Map.class.isAssignableFrom(type); - - } - - /** - * Checks this instance against the specified Object for equality. Overrides the - * default reference test for equality provided by {@link java.lang.Object#equals(Object)} - * @param obj The object to compare to - * @return {@code true} if object is a dyna property with the same name - * type and content type, otherwise {@code false} - * @since 1.8.0 - */ - @Override - public boolean equals(final Object obj) { - - boolean result = false; - - result = obj == this; - - if (!result && obj instanceof DynaProperty) { - final DynaProperty that = (DynaProperty) obj; - result = - (Objects.equals(this.name, that.name)) && - (Objects.equals(this.type, that.type)) && - (Objects.equals(this.contentType, that.contentType)); - } - - return result; - } - - /** - * @return the hashcode for this dyna property - * @see java.lang.Object#hashCode - * @since 1.8.0 - */ - @Override - public int hashCode() { - - int result = 1; - - result = result * 31 + (name == null ? 0 : name.hashCode()); - result = result * 31 + (type == null ? 0 : type.hashCode()); - result = result * 31 + (contentType == null ? 0 : contentType.hashCode()); - - return result; - } - - /** - * Return a String representation of this Object. - * @return a String representation of the dyna property - */ - @Override - public String toString() { - - final StringBuilder sb = new StringBuilder("DynaProperty[name="); - sb.append(this.name); - sb.append(",type="); - sb.append(this.type); - if (isMapped() || isIndexed()) { - sb.append(" <").append(this.contentType).append(">"); - } - sb.append("]"); - return sb.toString(); - - } - - - - /** - * Writes this object safely. - * There are issues with serializing primitive class types on certain JVM versions - * (including java 1.3). - * This method provides a workaround. - * - * @param out {@link ObjectOutputStream} to write object to - * @throws IOException if the object can't be written - */ - private void writeObject(final ObjectOutputStream out) throws IOException { - - writeAnyClass(this.type,out); - - if (isMapped() || isIndexed()) { - writeAnyClass(this.contentType,out); - } - - // write out other values - out.defaultWriteObject(); - } - - /** - * Write a class using safe encoding to workaround java 1.3 serialization bug. - */ - private void writeAnyClass(final Class clazz, final ObjectOutputStream out) throws IOException { - // safely write out any class - int primitiveType = 0; - if (Boolean.TYPE.equals(clazz)) { - primitiveType = BOOLEAN_TYPE; - } else if (Byte.TYPE.equals(clazz)) { - primitiveType = BYTE_TYPE; - } else if (Character.TYPE.equals(clazz)) { - primitiveType = CHAR_TYPE; - } else if (Double.TYPE.equals(clazz)) { - primitiveType = DOUBLE_TYPE; - } else if (Float.TYPE.equals(clazz)) { - primitiveType = FLOAT_TYPE; - } else if (Integer.TYPE.equals(clazz)) { - primitiveType = INT_TYPE; - } else if (Long.TYPE.equals(clazz)) { - primitiveType = LONG_TYPE; - } else if (Short.TYPE.equals(clazz)) { - primitiveType = SHORT_TYPE; - } - - if (primitiveType == 0) { - // then it's not a primitive type - out.writeBoolean(false); - out.writeObject(clazz); - } else { - // we'll write out a constant instead - out.writeBoolean(true); - out.writeInt(primitiveType); - } - } - - /** - * Reads field values for this object safely. - * There are issues with serializing primitive class types on certain JVM versions - * (including java 1.3). - * This method provides a workaround. - * - * @param in {@link ObjectInputStream} to read object from - * @throws StreamCorruptedException when the stream data values are outside expected range - * @throws IOException if the input stream can't be read - * @throws ClassNotFoundException When trying to read an object of class that is not on the classpath - */ - private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { - - this.type = readAnyClass(in); - - if (isMapped() || isIndexed()) { - this.contentType = readAnyClass(in); - } - - // read other values - in.defaultReadObject(); - } - - /** - * Reads a class using safe encoding to workaround java 1.3 serialization bug. - */ - private Class readAnyClass(final ObjectInputStream in) throws IOException, ClassNotFoundException { - // read back type class safely - if (in.readBoolean()) { - // it's a type constant - switch (in.readInt()) { - - case BOOLEAN_TYPE: return Boolean.TYPE; - case BYTE_TYPE: return Byte.TYPE; - case CHAR_TYPE: return Character.TYPE; - case DOUBLE_TYPE: return Double.TYPE; - case FLOAT_TYPE: return Float.TYPE; - case INT_TYPE: return Integer.TYPE; - case LONG_TYPE: return Long.TYPE; - case SHORT_TYPE: return Short.TYPE; - default: - // something's gone wrong - throw new StreamCorruptedException( - "Invalid primitive type. " - + "Check version of beanutils used to serialize is compatible."); - - } - - } - // it's another class - return (Class) in.readObject(); - } -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/FluentPropertyBeanIntrospector.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/FluentPropertyBeanIntrospector.java deleted file mode 100644 index 6bfa2bef5..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/FluentPropertyBeanIntrospector.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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.beanutils2; - -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.reflect.Method; -import java.util.Locale; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - *

- * An implementation of the {@code BeanIntrospector} interface which can - * detect write methods for properties used in fluent API scenario. - *

- *

- * A fluent API allows setting multiple properties using a single - * statement by supporting so-called method chaining: Methods for - * setting a property value do not return void, but an object which can - * be called for setting another property. An example of such a fluent API could - * look as follows: - *

- *
- * public class FooBuilder {
- *     public FooBuilder setFooProperty1(String value) {
- *        ...
- *        return this;
- *    }
- *
- *     public FooBuilder setFooProperty2(int value) {
- *        ...
- *        return this;
- *    }
- * }
- * 
- * - *

Per default, {@code PropertyUtils} does not detect methods like this - * because, having a non-void return type, they violate the Java Beans - * specification. - *

- *

- * This class is more tolerant with regards to the return type of a set method. - * It basically iterates over all methods of a class and filters them for a - * configurable prefix (the default prefix is {@code set}). It then - * generates corresponding {@code PropertyDescriptor} objects for the - * methods found which use these methods as write methods. - *

- *

- * An instance of this class is intended to collaborate with a - * {@link DefaultBeanIntrospector} object. So best results are achieved by - * adding this instance as custom {@code BeanIntrospector} after the - * {@code DefaultBeanIntrospector} object. Then default introspection finds - * read-only properties because it does not detect the write methods with a - * non-void return type. {@code FluentPropertyBeanIntrospector} - * completes the descriptors for these properties by setting the correct write - * method. - *

- * - * @since 1.9 - */ -public class FluentPropertyBeanIntrospector implements BeanIntrospector { - /** The default prefix for write methods. */ - public static final String DEFAULT_WRITE_METHOD_PREFIX = "set"; - - /** The logger. */ - private final Log log = LogFactory.getLog(getClass()); - - /** The prefix of write methods to search for. */ - private final String writeMethodPrefix; - - /** - * - * Creates a new instance of {@code FluentPropertyBeanIntrospector} and - * initializes it with the prefix for write methods used by the classes to - * be inspected. - * - * @param writePrefix the prefix for write methods (must not be null) - * @throws IllegalArgumentException if the prefix is null - */ - public FluentPropertyBeanIntrospector(final String writePrefix) { - if (writePrefix == null) { - throw new IllegalArgumentException( - "Prefix for write methods must not be null!"); - } - writeMethodPrefix = writePrefix; - } - - /** - * - * Creates a new instance of {@code FluentPropertyBeanIntrospector} and - * sets the default prefix for write methods. - */ - public FluentPropertyBeanIntrospector() { - this(DEFAULT_WRITE_METHOD_PREFIX); - } - - /** - * Returns the prefix for write methods this instance scans for. - * - * @return the prefix for write methods - */ - public String getWriteMethodPrefix() { - return writeMethodPrefix; - } - - /** - * Performs introspection. This method scans the current class's methods for - * property write methods which have not been discovered by default - * introspection. - * - * @param icontext the introspection context - * @throws IntrospectionException if an error occurs - */ - @Override - public void introspect(final IntrospectionContext icontext) - throws IntrospectionException { - for (final Method m : icontext.getTargetClass().getMethods()) { - if (m.getName().startsWith(getWriteMethodPrefix())) { - final String propertyName = propertyName(m); - final PropertyDescriptor pd = icontext - .getPropertyDescriptor(propertyName); - try { - if (pd == null) { - icontext.addPropertyDescriptor(createFluentPropertyDescritor( - m, propertyName)); - } else if (pd.getWriteMethod() == null) { - pd.setWriteMethod(m); - } - } catch (final IntrospectionException e) { - log.debug("Error when creating PropertyDescriptor for " + m - + "! Ignoring this property."); - log.debug("Exception is:", e); - } - } - } - } - - /** - * Derives the name of a property from the given set method. - * - * @param m the method - * @return the corresponding property name - */ - private String propertyName(final Method m) { - final String methodName = m.getName().substring( - getWriteMethodPrefix().length()); - return methodName.length() > 1 ? Introspector.decapitalize(methodName) : methodName - .toLowerCase(Locale.ENGLISH); - } - - /** - * Creates a property descriptor for a fluent API property. - * - * @param m the set method for the fluent API property - * @param propertyName the name of the corresponding property - * @return the descriptor - * @throws IntrospectionException if an error occurs - */ - private PropertyDescriptor createFluentPropertyDescritor(final Method m, - final String propertyName) throws IntrospectionException { - return new PropertyDescriptor(propertyName(m), null, m); - } -} \ No newline at end of file diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/IntrospectionContext.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/IntrospectionContext.java deleted file mode 100644 index 858dd52a3..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/IntrospectionContext.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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.beanutils2; - -import java.beans.PropertyDescriptor; -import java.util.Set; - -/** - *

- * A context interface used during introspection for querying and setting - * property descriptors. - *

- *

- * An implementation of this interface is passed to {@link BeanIntrospector} - * objects during processing of a bean class. It allows the - * {@code BeanIntrospector} to deliver descriptors for properties it has - * detected. It is also possible to find out which properties have already been - * found by another {@code BeanIntrospector}; this allows multiple - * {@code BeanIntrospector} instances to collaborate. - *

- * - * @since 1.9 - */ -public interface IntrospectionContext { - /** - * Returns the class that is subject of introspection. - * - * @return the current class - */ - Class getTargetClass(); - - /** - * Adds the given property descriptor to this context. This method is called - * by a {@code BeanIntrospector} during introspection for each detected - * property. If this context already contains a descriptor for the affected - * property, it is overridden. - * - * @param desc the property descriptor - */ - void addPropertyDescriptor(PropertyDescriptor desc); - - /** - * Adds an array of property descriptors to this context. Using this method - * multiple descriptors can be added at once. - * - * @param descriptors the array of descriptors to be added - */ - void addPropertyDescriptors(PropertyDescriptor[] descriptors); - - /** - * Tests whether a descriptor for the property with the given name is - * already contained in this context. This method can be used for instance - * to prevent that an already existing property descriptor is overridden. - * - * @param name the name of the property in question - * @return true if a descriptor for this property has already been - * added, false otherwise - */ - boolean hasProperty(String name); - - /** - * Returns the descriptor for the property with the given name or - * null if this property is unknown. - * - * @param name the name of the property in question - * @return the descriptor for this property or null if this property - * is unknown - */ - PropertyDescriptor getPropertyDescriptor(String name); - - /** - * Removes the descriptor for the property with the given name. - * - * @param name the name of the affected property - */ - void removePropertyDescriptor(String name); - - /** - * Returns a set with the names of all properties known to this context. - * - * @return a set with the known property names - */ - Set propertyNames(); -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/JDBCDynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/JDBCDynaClass.java deleted file mode 100644 index b3583cfd3..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/JDBCDynaClass.java +++ /dev/null @@ -1,313 +0,0 @@ -/* - * 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.beanutils2; - -import java.io.Serializable; -import java.sql.Date; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - *

Provides common logic for JDBC implementations of {@link DynaClass}.

- * - */ - -abstract class JDBCDynaClass implements DynaClass, Serializable { - - private static final long serialVersionUID = 1L; - - - - /** - *

Flag defining whether column names should be lower cased when - * converted to property names.

- */ - protected boolean lowerCase = true; - - /** - *

Flag defining whether column names or labels should be used. - */ - private boolean useColumnLabel; - - /** - *

The set of dynamic properties that are part of this - * {@link DynaClass}.

- */ - protected DynaProperty[] properties = null; - - /** - *

The set of dynamic properties that are part of this - * {@link DynaClass}, keyed by the property name. Individual descriptor - * instances will be the same instances as those in the - * {@code properties} list.

- */ - protected Map propertiesMap = new HashMap<>(); - - /** - * Cross Reference for column name --> dyna property name - * (needed when lowerCase option is true) - */ - private Map columnNameXref; - - - - /** - *

Return the name of this DynaClass (analogous to the - * {@code getName() method of java.lang.Class}, which - * allows the same {@code DynaClass} implementation class to support - * different dynamic classes, with different sets of properties.

- */ - @Override - public String getName() { - - return this.getClass().getName(); - - } - - /** - *

Return a property descriptor for the specified property, if it - * exists; otherwise, return {@code null}.

- * - * @param name Name of the dynamic property for which a descriptor - * is requested - * - * @throws IllegalArgumentException if no property name is specified - */ - @Override - public DynaProperty getDynaProperty(final String name) { - - if (name == null) { - throw new IllegalArgumentException("No property name specified"); - } - return propertiesMap.get(name); - - } - - /** - *

Return an array of {@code PropertyDescriptor} for the properties - * currently defined in this DynaClass. If no properties are defined, a - * zero-length array will be returned.

- */ - @Override - public DynaProperty[] getDynaProperties() { - - return properties; - - } - - /** - *

Instantiate and return a new DynaBean instance, associated - * with this DynaClass. NOTE - This operation is not - * supported, and throws an exception.

- * - * @throws IllegalAccessException if the Class or the appropriate - * constructor is not accessible - * @throws InstantiationException if this Class represents an abstract - * class, an array class, a primitive type, or void; or if instantiation - * fails for some other reason - */ - @Override - public DynaBean newInstance() - throws IllegalAccessException, InstantiationException { - - throw new UnsupportedOperationException("newInstance() not supported"); - - } - - /** - * Set whether the column label or name should be used for the property name. - * - * @param useColumnLabel true if the column label should be used, otherwise false - */ - public void setUseColumnLabel(final boolean useColumnLabel) { - this.useColumnLabel = useColumnLabel; - } - - /** - *

Loads and returns the {@code Class} of the given name. - * By default, a load from the thread context class loader is attempted. - * If there is no such class loader, the class loader used to load this - * class will be utilized.

- * - * @param className The name of the class to load - * @return The loaded class - * @throws SQLException if an exception was thrown trying to load - * the specified class - */ - protected Class loadClass(final String className) throws SQLException { - - try { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = this.getClass().getClassLoader(); - } - // use Class.forName() - see BEANUTILS-327 - return Class.forName(className, false, cl); - } catch (final Exception e) { - throw new SQLException( - "Cannot load column class '" + className + "': " + e); - } - - } - - /** - *

Factory method to create a new DynaProperty for the given index - * into the result set metadata.

- * - * @param metadata is the result set metadata - * @param i is the column index in the metadata - * @return the newly created DynaProperty instance - * @throws SQLException If an error occurs accessing the SQL metadata - */ - protected DynaProperty createDynaProperty( - final ResultSetMetaData metadata, - final int i) - throws SQLException { - - String columnName = null; - if (useColumnLabel) { - columnName = metadata.getColumnLabel(i); - } - if (columnName == null || columnName.trim().length() == 0) { - columnName = metadata.getColumnName(i); - } - final String name = lowerCase ? columnName.toLowerCase() : columnName; - if (!name.equals(columnName)) { - if (columnNameXref == null) { - columnNameXref = new HashMap<>(); - } - columnNameXref.put(name, columnName); - } - String className = null; - try { - final int sqlType = metadata.getColumnType(i); - switch (sqlType) { - case java.sql.Types.DATE: - return new DynaProperty(name, java.sql.Date.class); - case java.sql.Types.TIMESTAMP: - return new DynaProperty(name, java.sql.Timestamp.class); - case java.sql.Types.TIME: - return new DynaProperty(name, java.sql.Time.class); - default: - className = metadata.getColumnClassName(i); - } - } catch (final SQLException e) { - // this is a patch for HsqlDb to ignore exceptions - // thrown by its metadata implementation - } - - // Default to Object type if no class name could be retrieved - // from the metadata - Class clazz = Object.class; - if (className != null) { - clazz = loadClass(className); - } - return new DynaProperty(name, clazz); - - } - - /** - *

Introspect the metadata associated with our result set, and populate - * the {@code properties and propertiesMap} instance - * variables.

- * - * @param resultSet The {@code resultSet} whose metadata is to - * be introspected - * - * @throws SQLException if an error is encountered processing the - * result set metadata - */ - protected void introspect(final ResultSet resultSet) throws SQLException { - - // Accumulate an ordered list of DynaProperties - final List list = new ArrayList<>(); - final ResultSetMetaData metadata = resultSet.getMetaData(); - final int n = metadata.getColumnCount(); - for (int i = 1; i <= n; i++) { // JDBC is one-relative! - final DynaProperty dynaProperty = createDynaProperty(metadata, i); - if (dynaProperty != null) { - list.add(dynaProperty); - } - } - - // Convert this list into the internal data structures we need - properties = - list.toArray(new DynaProperty[list.size()]); - for (final DynaProperty property : properties) { - propertiesMap.put(property.getName(), property); - } - - } - - /** - * Get a column value from a {@link ResultSet} for the specified name. - * - * @param resultSet The result set - * @param name The property name - * @return The value - * @throws SQLException if an error occurs - */ - protected Object getObject(final ResultSet resultSet, final String name) throws SQLException { - - final DynaProperty property = getDynaProperty(name); - if (property == null) { - throw new IllegalArgumentException("Invalid name '" + name + "'"); - } - final String columnName = getColumnName(name); - final Class type = property.getType(); - - // java.sql.Date - if (type.equals(Date.class)) { - return resultSet.getDate(columnName); - } - - // java.sql.Timestamp - if (type.equals(Timestamp.class)) { - return resultSet.getTimestamp(columnName); - } - - // java.sql.Time - if (type.equals(Time.class)) { - return resultSet.getTime(columnName); - } - - return resultSet.getObject(columnName); - } - - /** - * Get the table column name for the specified property name. - * - * @param name The property name - * @return The column name (which can be different if the lowerCase - * option is used). - */ - protected String getColumnName(final String name) { - if (columnNameXref != null && columnNameXref.containsKey(name)) { - return columnNameXref.get(name); - } - return name; - } - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java deleted file mode 100644 index 878968559..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaBean.java +++ /dev/null @@ -1,955 +0,0 @@ -/* - * 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.beanutils2; - -import java.io.Serializable; -import java.lang.reflect.Array; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - *

DynaBean which automatically adds properties to the {@code DynaClass} - * and provides Lazy List and Lazy Map features.

- * - *

DynaBeans deal with three types of properties - simple, indexed and mapped and - * have the following {@code get() and set()} methods for - * each of these types:

- *
    - *
  • Simple property methods - {@code get(name)} and - * {@code set(name, value)}
  • - *
  • Indexed property methods - {@code get(name, index)} and - * {@code set(name, index, value)}
  • - *
  • Mapped property methods - {@code get(name, key)} and - * {@code set(name, key, value)}
  • - *
- * - *

Getting Property Values

- *

Calling any of the {@code get()} methods, for a property which - * doesn't exist, returns {@code null} in this implementation.

- * - *

Setting Simple Properties

- *

The {@code LazyDynaBean will automatically add a property to the DynaClass} - * if it doesn't exist when the {@code set(name, value)} method is called.

- * - *

- *         DynaBean myBean = new LazyDynaBean();
- *         myBean.set("myProperty", "myValue");
- *     
- * - *

Setting Indexed Properties

- *

If the property doesn't exist, the {@code LazyDynaBean} will automatically add - * a property with an {@code ArrayList type to the DynaClass} when - * the {@code set(name, index, value)} method is called. - * It will also instantiate a new {@code ArrayList} and automatically grow - * the {@code List} so that it is big enough to accommodate the index being set. - * {@code ArrayList} is the default indexed property that LazyDynaBean uses but - * this can be easily changed by overriding the {@code defaultIndexedProperty(name)} - * method.

- * - *

- *         DynaBean myBean = new LazyDynaBean();
- *         myBean.set("myIndexedProperty", 0, "myValue1");
- *         myBean.set("myIndexedProperty", 1, "myValue2");
- *     
- * - *

If the indexed property does exist in the {@code DynaClass} but is set to - * {@code null in the LazyDynaBean}, then it will instantiate a - * new {@code List or Array} as specified by the property's type - * in the {@code DynaClass and automatically grow the List} - * or {@code Array} so that it is big enough to accommodate the index being set.

- * - *

- *         DynaBean myBean = new LazyDynaBean();
- *         MutableDynaClass myClass = (MutableDynaClass)myBean.getDynaClass();
- *         myClass.add("myIndexedProperty", int[].class);
- *         myBean.set("myIndexedProperty", 0, new Integer(10));
- *         myBean.set("myIndexedProperty", 1, new Integer(20));
- *     
- * - *

Setting Mapped Properties

- *

If the property doesn't exist, the {@code LazyDynaBean} will automatically add - * a property with a {@code HashMap type to the DynaClass} and - * instantiate a new {@code HashMap} in the DynaBean when the - * {@code set(name, key, value) method is called. HashMap} is the default - * mapped property that LazyDynaBean uses but this can be easily changed by overriding - * the {@code defaultMappedProperty(name)} method.

- * - *

- *         DynaBean myBean = new LazyDynaBean();
- *         myBean.set("myMappedProperty", "myKey", "myValue");
- *     
- * - *

If the mapped property does exist in the {@code DynaClass} but is set to - * {@code null in the LazyDynaBean}, then it will instantiate a - * new {@code Map as specified by the property's type in the DynaClass}.

- * - *

- *         DynaBean myBean = new LazyDynaBean();
- *         MutableDynaClass myClass = (MutableDynaClass)myBean.getDynaClass();
- *         myClass.add("myMappedProperty", TreeMap.class);
- *         myBean.set("myMappedProperty", "myKey", "myValue");
- *     
- * - *

Restricted DynaClass

- *

{@code MutableDynaClass have a facility to restrict the DynaClass} - * so that its properties cannot be modified. If the {@code MutableDynaClass} is - * restricted then calling any of the {@code set()} methods for a property which - * doesn't exist will result in a {@code IllegalArgumentException} being thrown.

- * - * @see LazyDynaClass - */ -public class LazyDynaBean implements DynaBean, Serializable { - - private static final long serialVersionUID = 1L; - - /** - * Commons Logging - */ - private transient Log logger = LogFactory.getLog(LazyDynaBean.class); - - /** BigInteger Zero */ - protected static final BigInteger BigInteger_ZERO = new BigInteger("0"); - /** BigDecimal Zero */ - protected static final BigDecimal BigDecimal_ZERO = new BigDecimal("0"); - /** Character Space */ - protected static final Character Character_SPACE = Character.valueOf(' '); - /** Byte Zero */ - protected static final Byte Byte_ZERO = Byte.valueOf((byte)0); - /** Short Zero */ - protected static final Short Short_ZERO = Short.valueOf((short)0); - /** Integer Zero */ - protected static final Integer Integer_ZERO = Integer.valueOf(0); - /** Long Zero */ - protected static final Long Long_ZERO = Long.valueOf(0); - /** Float Zero */ - protected static final Float Float_ZERO = Float.valueOf((byte)0); - /** Double Zero */ - protected static final Double Double_ZERO = Double.valueOf((byte)0); - - /** - * The {@code MutableDynaClass} "base class" that this DynaBean - * is associated with. - */ - protected Map values; - - /** Map decorator for this DynaBean */ - private transient Map mapDecorator; - - /** - * The {@code MutableDynaClass} "base class" that this DynaBean - * is associated with. - */ - protected MutableDynaClass dynaClass; - - - - /** - * Construct a new {@code LazyDynaBean with a LazyDynaClass} instance. - */ - public LazyDynaBean() { - this(new LazyDynaClass()); - } - - /** - * Construct a new {@code LazyDynaBean with a LazyDynaClass} instance. - * - * @param name Name of this DynaBean class - */ - public LazyDynaBean(final String name) { - this(new LazyDynaClass(name)); - } - - /** - * Construct a new {@code DynaBean} associated with the specified - * {@code DynaClass instance - if its not a MutableDynaClass} - * then a new {@code LazyDynaClass} is created and the properties copied. - * - * @param dynaClass The DynaClass we are associated with - */ - public LazyDynaBean(final DynaClass dynaClass) { - - values = newMap(); - - if (dynaClass instanceof MutableDynaClass) { - this.dynaClass = (MutableDynaClass)dynaClass; - } else { - this.dynaClass = new LazyDynaClass(dynaClass.getName(), dynaClass.getDynaProperties()); - } - - } - - - - /** - *

- * Return a Map representation of this DynaBean. - *

- * This, for example, could be used in JSTL in the following way to access - * a DynaBean's {@code fooProperty}: - *
  • {@code ${myDynaBean.map.fooProperty}}
- * - * @return a Map representation of this DynaBean - */ - public Map getMap() { - // cache the Map - if (mapDecorator == null) { - mapDecorator = new DynaBeanPropertyMapDecorator(this); - } - return mapDecorator; - } - - /** - *

Return the size of an indexed or mapped property.

- * - * @param name Name of the property - * @return The indexed or mapped property size - * @throws IllegalArgumentException if no property name is specified - */ - public int size(final String name) { - - if (name == null) { - throw new IllegalArgumentException("No property name specified"); - } - - final Object value = values.get(name); - if (value == null) { - return 0; - } - - if (value instanceof Map) { - return ((Map)value).size(); - } - - if (value instanceof List) { - return ((List)value).size(); - } - - if (value.getClass().isArray()) { - return Array.getLength(value); - } - - return 0; - - } - - - - /** - * Does the specified mapped property contain a value for the specified - * key value? - * - * @param name Name of the property to check - * @param key Name of the key to check - * @return {@code true} if the mapped property contains a value for - * the specified key, otherwise {@code false} - * - * @throws IllegalArgumentException if no property name is specified - */ - @Override - public boolean contains(final String name, final String key) { - - if (name == null) { - throw new IllegalArgumentException("No property name specified"); - } - - final Object value = values.get(name); - if (value == null) { - return false; - } - - if (value instanceof Map) { - return ((Map) value).containsKey(key); - } - - return false; - - } - - /** - *

Return the value of a simple property with the specified name.

- * - *

N.B. Returns {@code null} if there is no property - * of the specified name.

- * - * @param name Name of the property whose value is to be retrieved. - * @return The property's value - * @throws IllegalArgumentException if no property name is specified - */ - @Override - public Object get(final String name) { - - if (name == null) { - throw new IllegalArgumentException("No property name specified"); - } - - // Value found - Object value = values.get(name); - if (value != null) { - return value; - } - - // Property doesn't exist - if (!isDynaProperty(name)) { - return null; - } - - // Property doesn't exist - value = createProperty(name, dynaClass.getDynaProperty(name).getType()); - - if (value != null) { - set(name, value); - } - - return value; - - } - - /** - *

Return the value of an indexed property with the specified name.

- * - *

N.B. Returns {@code null} if there is no 'indexed' - * property of the specified name.

- * - * @param name Name of the property whose value is to be retrieved - * @param index Index of the value to be retrieved - * @return The indexed property's value - * - * @throws IllegalArgumentException if the specified property - * exists, but is not indexed - * @throws IndexOutOfBoundsException if the specified index - * is outside the range of the underlying property - */ - @Override - public Object get(final String name, final int index) { - - // If its not a property, then create default indexed property - if (!isDynaProperty(name)) { - set(name, defaultIndexedProperty(name)); - } - - // Get the indexed property - Object indexedProperty = get(name); - - // Check that the property is indexed - if (!dynaClass.getDynaProperty(name).isIndexed()) { - throw new IllegalArgumentException - ("Non-indexed property for '" + name + "[" + index + "]' " - + dynaClass.getDynaProperty(name).getName()); - } - - // Grow indexed property to appropriate size - indexedProperty = growIndexedProperty(name, indexedProperty, index); - - // Return the indexed value - if (indexedProperty.getClass().isArray()) { - return Array.get(indexedProperty, index); - } else if (indexedProperty instanceof List) { - return ((List)indexedProperty).get(index); - } else { - throw new IllegalArgumentException - ("Non-indexed property for '" + name + "[" + index + "]' " - + indexedProperty.getClass().getName()); - } - - } - - /** - *

Return the value of a mapped property with the specified name.

- * - *

N.B. Returns {@code null} if there is no 'mapped' - * property of the specified name.

- * - * @param name Name of the property whose value is to be retrieved - * @param key Key of the value to be retrieved - * @return The mapped property's value - * - * @throws IllegalArgumentException if the specified property - * exists, but is not mapped - */ - @Override - public Object get(final String name, final String key) { - - // If its not a property, then create default mapped property - if (!isDynaProperty(name)) { - set(name, defaultMappedProperty(name)); - } - - // Get the mapped property - final Object mappedProperty = get(name); - - // Check that the property is mapped - if (!dynaClass.getDynaProperty(name).isMapped()) { - throw new IllegalArgumentException - ("Non-mapped property for '" + name + "(" + key + ")' " - + dynaClass.getDynaProperty(name).getType().getName()); - } - - // Get the value from the Map - if (mappedProperty instanceof Map) { - return ((Map) mappedProperty).get(key); - } - throw new IllegalArgumentException - ("Non-mapped property for '" + name + "(" + key + ")'" - + mappedProperty.getClass().getName()); - - } - - /** - * Return the {@code DynaClass} instance that describes the set of - * properties available for this DynaBean. - * - * @return The associated DynaClass - */ - @Override - public DynaClass getDynaClass() { - return dynaClass; - } - - /** - * Remove any existing value for the specified key on the - * specified mapped property. - * - * @param name Name of the property for which a value is to - * be removed - * @param key Key of the value to be removed - * - * @throws IllegalArgumentException if there is no property - * of the specified name - */ - @Override - public void remove(final String name, final String key) { - - if (name == null) { - throw new IllegalArgumentException("No property name specified"); - } - - final Object value = values.get(name); - if (value == null) { - return; - } - - if (value instanceof Map) { - ((Map) value).remove(key); - } else { - throw new IllegalArgumentException - ("Non-mapped property for '" + name + "(" + key + ")'" - + value.getClass().getName()); - } - - } - - /** - * Set the value of a simple property with the specified name. - * - * @param name Name of the property whose value is to be set - * @param value Value to which this property is to be set - * - * @throws IllegalArgumentException if this is not an existing property - * name for our DynaClass and the MutableDynaClass is restricted - * @throws ConversionException if the specified value cannot be - * converted to the type required for this property - * @throws NullPointerException if an attempt is made to set a - * primitive property to null - */ - @Override - public void set(final String name, final Object value) { - - // If the property doesn't exist, then add it - if (!isDynaProperty(name)) { - - if (dynaClass.isRestricted()) { - throw new IllegalArgumentException - ("Invalid property name '" + name + "' (DynaClass is restricted)"); - } - if (value == null) { - dynaClass.add(name); - } else { - dynaClass.add(name, value.getClass()); - } - - } - - final DynaProperty descriptor = dynaClass.getDynaProperty(name); - - if (value == null) { - if (descriptor.getType().isPrimitive()) { - throw new NullPointerException - ("Primitive value for '" + name + "'"); - } - } else if (!isAssignable(descriptor.getType(), value.getClass())) { - throw new ConversionException - ("Cannot assign value of type '" + - value.getClass().getName() + - "' to property '" + name + "' of type '" + - descriptor.getType().getName() + "'"); - } - - // Set the property's value - values.put(name, value); - - } - - /** - * Set the value of an indexed property with the specified name. - * - * @param name Name of the property whose value is to be set - * @param index Index of the property to be set - * @param value Value to which this property is to be set - * - * @throws ConversionException if the specified value cannot be - * converted to the type required for this property - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws IllegalArgumentException if the specified property - * exists, but is not indexed - * @throws IndexOutOfBoundsException if the specified index - * is outside the range of the underlying property - */ - @Override - public void set(final String name, final int index, final Object value) { - - // If its not a property, then create default indexed property - if (!isDynaProperty(name)) { - set(name, defaultIndexedProperty(name)); - } - - // Get the indexed property - Object indexedProperty = get(name); - - // Check that the property is indexed - if (!dynaClass.getDynaProperty(name).isIndexed()) { - throw new IllegalArgumentException - ("Non-indexed property for '" + name + "[" + index + "]'" - + dynaClass.getDynaProperty(name).getType().getName()); - } - - // Grow indexed property to appropriate size - indexedProperty = growIndexedProperty(name, indexedProperty, index); - - // Set the value in an array - if (indexedProperty.getClass().isArray()) { - Array.set(indexedProperty, index, value); - } else if (indexedProperty instanceof List) { - @SuppressWarnings("unchecked") - final - // Indexed properties are stored in a List - List values = (List) indexedProperty; - values.set(index, value); - } else { - throw new IllegalArgumentException - ("Non-indexed property for '" + name + "[" + index + "]' " - + indexedProperty.getClass().getName()); - } - - } - - /** - * Set the value of a mapped property with the specified name. - * - * @param name Name of the property whose value is to be set - * @param key Key of the property to be set - * @param value Value to which this property is to be set - * - * @throws ConversionException if the specified value cannot be - * converted to the type required for this property - * @throws IllegalArgumentException if there is no property - * of the specified name - * @throws IllegalArgumentException if the specified property - * exists, but is not mapped - */ - @Override - public void set(final String name, final String key, final Object value) { - - // If the 'mapped' property doesn't exist, then add it - if (!isDynaProperty(name)) { - set(name, defaultMappedProperty(name)); - } - - // Get the mapped property - final Object mappedProperty = get(name); - - // Check that the property is mapped - if (!dynaClass.getDynaProperty(name).isMapped()) { - throw new IllegalArgumentException - ("Non-mapped property for '" + name + "(" + key + ")'" - + dynaClass.getDynaProperty(name).getType().getName()); - } - - // Set the value in the Map - @SuppressWarnings("unchecked") - final - // mapped properties are stored in a Map - Map valuesMap = (Map) mappedProperty; - valuesMap.put(key, value); - - } - - - - /** - * Grow the size of an indexed property - * @param name The name of the property - * @param indexedProperty The current property value - * @param index The indexed value to grow the property to (i.e. one less than - * the required size) - * @return The new property value (grown to the appropriate size) - */ - protected Object growIndexedProperty(final String name, Object indexedProperty, final int index) { - - // Grow a List to the appropriate size - if (indexedProperty instanceof List) { - - @SuppressWarnings("unchecked") - final - // Indexed properties are stored as List - List list = (List)indexedProperty; - while (index >= list.size()) { - final Class contentType = getDynaClass().getDynaProperty(name).getContentType(); - Object value = null; - if (contentType != null) { - value = createProperty(name+"["+list.size()+"]", contentType); - } - list.add(value); - } - - } - - // Grow an Array to the appropriate size - if (indexedProperty.getClass().isArray()) { - - final int length = Array.getLength(indexedProperty); - if (index >= length) { - final Class componentType = indexedProperty.getClass().getComponentType(); - final Object newArray = Array.newInstance(componentType, index + 1); - System.arraycopy(indexedProperty, 0, newArray, 0, length); - indexedProperty = newArray; - set(name, indexedProperty); - final int newLength = Array.getLength(indexedProperty); - for (int i = length; i < newLength; i++) { - Array.set(indexedProperty, i, createProperty(name+"["+i+"]", componentType)); - } - } - } - - return indexedProperty; - - } - - /** - * Create a new Instance of a Property - * @param name The name of the property - * @param type The class of the property - * @return The new value - */ - protected Object createProperty(final String name, final Class type) { - if (type == null) { - return null; - } - - // Create Lists, arrays or DynaBeans - if (type.isArray() || List.class.isAssignableFrom(type)) { - return createIndexedProperty(name, type); - } - - if (Map.class.isAssignableFrom(type)) { - return createMappedProperty(name, type); - } - - if (DynaBean.class.isAssignableFrom(type)) { - return createDynaBeanProperty(name, type); - } - - if (type.isPrimitive()) { - return createPrimitiveProperty(name, type); - } - - if (Number.class.isAssignableFrom(type)) { - return createNumberProperty(name, type); - } - - return createOtherProperty(name, type); - - } - - /** - * Create a new Instance of an 'Indexed' Property - * @param name The name of the property - * @param type The class of the property - * @return The new value - */ - protected Object createIndexedProperty(final String name, final Class type) { - - // Create the indexed object - Object indexedProperty = null; - - if (type == null) { - - indexedProperty = defaultIndexedProperty(name); - - } else if (type.isArray()) { - - indexedProperty = Array.newInstance(type.getComponentType(), 0); - - } else if (List.class.isAssignableFrom(type)) { - if (type.isInterface()) { - indexedProperty = defaultIndexedProperty(name); - } else { - try { - indexedProperty = type.newInstance(); - } - catch (final Exception ex) { - throw new IllegalArgumentException - ("Error instantiating indexed property of type '" + - type.getName() + "' for '" + name + "' " + ex); - } - } - } else { - - throw new IllegalArgumentException - ("Non-indexed property of type '" + type.getName() + "' for '" + name + "'"); - } - - return indexedProperty; - - } - - /** - * Create a new Instance of a 'Mapped' Property - * @param name The name of the property - * @param type The class of the property - * @return The new value - */ - protected Object createMappedProperty(final String name, final Class type) { - - // Create the mapped object - Object mappedProperty = null; - - if ((type == null) || type.isInterface()) { - - mappedProperty = defaultMappedProperty(name); - - } else if (Map.class.isAssignableFrom(type)) { - try { - mappedProperty = type.newInstance(); - } - catch (final Exception ex) { - throw new IllegalArgumentException - ("Error instantiating mapped property of type '" + - type.getName() + "' for '" + name + "' " + ex); - } - } else { - - throw new IllegalArgumentException - ("Non-mapped property of type '" + type.getName() + "' for '" + name + "'"); - } - - return mappedProperty; - - } - - /** - * Create a new Instance of a 'DynaBean' Property. - * @param name The name of the property - * @param type The class of the property - * @return The new value - */ - protected Object createDynaBeanProperty(final String name, final Class type) { - try { - return type.newInstance(); - } - catch (final Exception ex) { - if (logger().isWarnEnabled()) { - logger().warn("Error instantiating DynaBean property of type '" + - type.getName() + "' for '" + name + "' " + ex); - } - return null; - } - } - - /** - * Create a new Instance of a 'Primitive' Property. - * @param name The name of the property - * @param type The class of the property - * @return The new value - */ - protected Object createPrimitiveProperty(final String name, final Class type) { - - if (type == Boolean.TYPE) { - return Boolean.FALSE; - } else if (type == Integer.TYPE) { - return Integer_ZERO; - } else if (type == Long.TYPE) { - return Long_ZERO; - } else if (type == Double.TYPE) { - return Double_ZERO; - } else if (type == Float.TYPE) { - return Float_ZERO; - } else if (type == Byte.TYPE) { - return Byte_ZERO; - } else if (type == Short.TYPE) { - return Short_ZERO; - } else if (type == Character.TYPE) { - return Character_SPACE; - } else { - return null; - } - - } - - /** - * Create a new Instance of a {@code java.lang.Number} Property. - * @param name The name of the property - * @param type The class of the property - * @return The new value - */ - protected Object createNumberProperty(final String name, final Class type) { - - return null; - - } - - /** - * Create a new Instance of other Property types - * @param name The name of the property - * @param type The class of the property - * @return The new value - */ - protected Object createOtherProperty(final String name, final Class type) { - - if (type == Object.class || - type == String.class || - type == Boolean.class || - type == Character.class || - Date.class.isAssignableFrom(type)) { - - return null; - - } - - try { - return type.newInstance(); - } - catch (final Exception ex) { - if (logger().isWarnEnabled()) { - logger().warn("Error instantiating property of type '" + type.getName() + "' for '" + name + "' " + ex); - } - return null; - } - } - - /** - *

Creates a new {@code ArrayList} for an 'indexed' property - * which doesn't exist.

- * - *

This method should be overridden if an alternative {@code List} - * or {@code Array} implementation is required for 'indexed' properties.

- * - * @param name Name of the 'indexed property. - * @return The default value for an indexed property (java.util.ArrayList) - */ - protected Object defaultIndexedProperty(final String name) { - return new ArrayList<>(); - } - - /** - *

Creates a new {@code HashMap} for a 'mapped' property - * which doesn't exist.

- * - *

This method can be overridden if an alternative {@code Map} - * implementation is required for 'mapped' properties.

- * - * @param name Name of the 'mapped property. - * @return The default value for a mapped property (java.util.HashMap) - */ - protected Map defaultMappedProperty(final String name) { - return new HashMap<>(); - } - - /** - * Indicates if there is a property with the specified name. - * @param name The name of the property to check - * @return {@code true} if there is a property of the - * specified name, otherwise {@code false} - */ - protected boolean isDynaProperty(final String name) { - - if (name == null) { - throw new IllegalArgumentException("No property name specified"); - } - - // Handle LazyDynaClasses - if (dynaClass instanceof LazyDynaClass) { - return ((LazyDynaClass)dynaClass).isDynaProperty(name); - } - - // Handle other MutableDynaClass - return dynaClass.getDynaProperty(name) != null; - - } - - /** - * Is an object of the source class assignable to the destination class? - * - * @param dest Destination class - * @param source Source class - * @return {@code true} if the source class is assignable to the - * destination class, otherwise {@code false} - */ - protected boolean isAssignable(final Class dest, final Class source) { - - if (dest.isAssignableFrom(source) || - dest == Boolean.TYPE && source == Boolean.class || - dest == Byte.TYPE && source == Byte.class || - dest == Character.TYPE && source == Character.class || - dest == Double.TYPE && source == Double.class || - dest == Float.TYPE && source == Float.class || - dest == Integer.TYPE && source == Integer.class || - dest == Long.TYPE && source == Long.class || - dest == Short.TYPE && source == Short.class) { - return true; - } - return false; - - } - - /** - *

Creates a new instance of the {@code Map}.

- * @return a new Map instance - */ - protected Map newMap() { - return new HashMap<>(); - } - - /** - *

Returns the {@code Log}. - */ - private Log logger() { - if (logger == null) { - logger = LogFactory.getLog(LazyDynaBean.class); - } - return logger; - } - -} diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaClass.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaClass.java deleted file mode 100644 index 9c29af5e7..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaClass.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * 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.beanutils2; - -/** - *

DynaClass which implements the {@code MutableDynaClass} interface.

- * - *

A {@code MutableDynaClass is a specialized extension to DynaClass} - * that allows properties to be added or removed dynamically.

- * - *

This implementation has one slightly unusual default behavior - calling - * the {@code getDynaProperty(name)} method for a property which doesn't - * exist returns a {@code DynaProperty rather than null}. The - * reason for this is that {@code BeanUtils} calls this method to check if - * a property exists before trying to set the value. This would defeat the object - * of the {@code LazyDynaBean} which automatically adds missing properties - * when any of its {@code set()} methods are called. For this reason the - * {@code isDynaProperty(name)} method has been added to this implementation - * in order to determine if a property actually exists. If the more normal - * behavior of returning {@code null} is required, then this can be achieved - * by calling the {@code setReturnNull(true)}.

- * - *

The {@code add(name, type, readable, writable)} method is not implemented - * and always throws an {@code UnsupportedOperationException}. I believe - * this attributes need to be added to the {@code DynaProperty} class - * in order to control read/write facilities.

- * - * @see LazyDynaBean - */ -public class LazyDynaClass extends BasicDynaClass implements MutableDynaClass { - - private static final long serialVersionUID = 1L; - - /** - * Controls whether changes to this DynaClass's properties are allowed. - */ - protected boolean restricted; - - /** - *

Controls whether the {@code getDynaProperty()} method returns - * null if a property doesn't exist - or creates a new one.

- * - *

Default is {@code false}. - */ - protected boolean returnNull = false; - - /** - * Construct a new LazyDynaClass with default parameters. - */ - public LazyDynaClass() { - this(null, (DynaProperty[])null); - } - - /** - * Construct a new LazyDynaClass with the specified name. - * - * @param name Name of this DynaBean class - */ - public LazyDynaClass(final String name) { - this(name, (DynaProperty[])null); - } - - /** - * Construct a new LazyDynaClass with the specified name and DynaBean class. - * - * @param name Name of this DynaBean class - * @param dynaBeanClass The implementation class for new instances - */ - public LazyDynaClass(final String name, final Class dynaBeanClass) { - this(name, dynaBeanClass, null); - } - - /** - * Construct a new LazyDynaClass with the specified name and properties. - * - * @param name Name of this DynaBean class - * @param properties Property descriptors for the supported properties - */ - public LazyDynaClass(final String name, final DynaProperty[] properties) { - this(name, LazyDynaBean.class, properties); - } - - /** - * Construct a new LazyDynaClass with the specified name, DynaBean class and properties. - * - * @param name Name of this DynaBean class - * @param dynaBeanClass The implementation class for new instances - * @param properties Property descriptors for the supported properties - */ - public LazyDynaClass(final String name, final Class dynaBeanClass, final DynaProperty[] properties) { - super(name, dynaBeanClass, properties); - } - - /** - *

Is this DynaClass currently restricted.

- *

If restricted, no changes to the existing registration of - * property names, data types, readability, or writeability are allowed.

- * @return {@code true} if this {@link MutableDynaClass} cannot be changed - * otherwise {@code false} - */ - @Override - public boolean isRestricted() { - return restricted; - } - - /** - *

Set whether this DynaClass is currently restricted.

- *

If restricted, no changes to the existing registration of - * property names, data types, readability, or writeability are allowed.

- * @param restricted {@code true} if this {@link MutableDynaClass} cannot - * be changed otherwise {@code false} - */ - @Override - public void setRestricted(final boolean restricted) { - this.restricted = restricted; - } - - /** - * Should this DynaClass return a {@code null} from - * the {@code getDynaProperty(name)} method if the property - * doesn't exist. - * - * @return {@code true
if a null} {@link DynaProperty} - * should be returned if the property doesn't exist, otherwise - * {@code false} if a new {@link DynaProperty} should be created. - */ - public boolean isReturnNull() { - return returnNull; - } - - /** - * Set whether this DynaClass should return a {@code null} from - * the {@code getDynaProperty(name)} method if the property - * doesn't exist. - * @param returnNull {@code true if a null} {@link DynaProperty} - * should be returned if the property doesn't exist, otherwise - * {@code false} if a new {@link DynaProperty} should be created. - */ - public void setReturnNull(final boolean returnNull) { - this.returnNull = returnNull; - } - - /** - * Add a new dynamic property with no restrictions on data type, - * readability, or writeability. - * - * @param name Name of the new dynamic property - * - * @throws IllegalArgumentException if name is null - * @throws IllegalStateException if this DynaClass is currently - * restricted, so no new properties can be added - */ - @Override - public void add(final String name) { - add(new DynaProperty(name)); - } - - /** - * Add a new dynamic property with the specified data type, but with - * no restrictions on readability or writeability. - * - * @param name Name of the new dynamic property - * @param type Data type of the new dynamic property (null for no - * restrictions) - * - * @throws IllegalArgumentException if name is null - * @throws IllegalStateException if this DynaClass is currently - * restricted, so no new properties can be added - */ - @Override - public void add(final String name, final Class type) { - if (type == null) { - add(name); - } else { - add(new DynaProperty(name, type)); - } - } - - /** - *

Add a new dynamic property with the specified data type, readability, - * and writeability.

- * - *

N.B.Support for readable/writeable properties has not been implemented - * and this method always throws a {@code UnsupportedOperationException}.

- * - *

I'm not sure the intention of the original authors for this method, but it seems to - * me that readable/writable should be attributes of the {@code DynaProperty} class - * (which they are not) and is the reason this method has not been implemented.

- * - * @param name Name of the new dynamic property - * @param type Data type of the new dynamic property (null for no - * restrictions) - * @param readable Set to {@code true} if this property value - * should be readable - * @param writeable Set to {@code true} if this property value - * should be writeable - * - * @throws UnsupportedOperationException anytime this method is called - */ - @Override - public void add(final String name, final Class type, final boolean readable, final boolean writeable) { - throw new java.lang.UnsupportedOperationException("readable/writable properties not supported"); - } - - /** - * Add a new dynamic property. - * - * @param property Property the new dynamic property to add. - * - * @throws IllegalArgumentException if name is null - * @throws IllegalStateException if this DynaClass is currently - * restricted, so no new properties can be added - */ - protected void add(final DynaProperty property) { - - if (property.getName() == null) { - throw new IllegalArgumentException("Property name is missing."); - } - - if (isRestricted()) { - throw new IllegalStateException("DynaClass is currently restricted. No new properties can be added."); - } - - // Check if property already exists - if (propertiesMap.get(property.getName()) != null) { - return; - } - - // Create a new property array with the specified property - final DynaProperty[] oldProperties = getDynaProperties(); - final DynaProperty[] newProperties = new DynaProperty[oldProperties.length+1]; - System.arraycopy(oldProperties, 0, newProperties, 0, oldProperties.length); - newProperties[oldProperties.length] = property; - - // Update the properties - setProperties(newProperties); - - } - - /** - * Remove the specified dynamic property, and any associated data type, - * readability, and writeability, from this dynamic class. - * NOTE - This does NOT cause any - * corresponding property values to be removed from DynaBean instances - * associated with this DynaClass. - * - * @param name Name of the dynamic property to remove - * - * @throws IllegalArgumentException if name is null - * @throws IllegalStateException if this DynaClass is currently - * restricted, so no properties can be removed - */ - @Override - public void remove(final String name) { - - if (name == null) { - throw new IllegalArgumentException("Property name is missing."); - } - - if (isRestricted()) { - throw new IllegalStateException("DynaClass is currently restricted. No properties can be removed."); - } - - // Ignore if property doesn't exist - if (propertiesMap.get(name) == null) { - return; - } - - // Create a new property array of without the specified property - final DynaProperty[] oldProperties = getDynaProperties(); - final DynaProperty[] newProperties = new DynaProperty[oldProperties.length-1]; - int j = 0; - for (DynaProperty oldProperty : oldProperties) { - if (!name.equals(oldProperty.getName())) { - newProperties[j] = oldProperty; - j++; - } - } - - // Update the properties - setProperties(newProperties); - - } - - /** - *

Return a property descriptor for the specified property.

- * - *

If the property is not found and the {@code returnNull} indicator is - * {@code true, this method always returns null}.

- * - *

If the property is not found and the {@code returnNull} indicator is - * {@code false} a new property descriptor is created and returned (although - * its not actually added to the DynaClass's properties). This is the default - * behavior.

- * - *

The reason for not returning a {@code null} property descriptor is that - * {@code BeanUtils} uses this method to check if a property exists - * before trying to set it - since these Lazy implementations automatically - * add any new properties when they are set, returning {@code null} from - * this method would defeat their purpose.

- * - * @param name Name of the dynamic property for which a descriptor - * is requested - * @return The dyna property for the specified name - * - * @throws IllegalArgumentException if no property name is specified - */ - @Override - public DynaProperty getDynaProperty(final String name) { - - if (name == null) { - throw new IllegalArgumentException("Property name is missing."); - } - - DynaProperty dynaProperty = propertiesMap.get(name); - - // If it doesn't exist and returnNull is false - // create a new DynaProperty - if (dynaProperty == null && !isReturnNull() && !isRestricted()) { - dynaProperty = new DynaProperty(name); - } - - return dynaProperty; - - } - - /** - *

Indicate whether a property actually exists.

- * - *

N.B. Using {@code getDynaProperty(name) == null} - * doesn't work in this implementation because that method might - * return a DynaProperty if it doesn't exist (depending on the - * {@code returnNull} indicator).

- * - * @param name The name of the property to check - * @return {@code true} if there is a property of the - * specified name, otherwise {@code false} - * @throws IllegalArgumentException if no property name is specified - */ - public boolean isDynaProperty(final String name) { - - if (name == null) { - throw new IllegalArgumentException("Property name is missing."); - } - - return propertiesMap.get(name) != null; - - } - -} \ No newline at end of file diff --git a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaList.java b/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaList.java deleted file mode 100644 index 7409ce4b4..000000000 --- a/safety/Java/commons-beanutils/src/src/main/java/org/apache/commons/beanutils2/LazyDynaList.java +++ /dev/null @@ -1,714 +0,0 @@ -/* - * 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.beanutils2; - -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; - -/** - *

Lazy DynaBean List.

- * - *

There are two main purposes for this class:

- *
    - *
  • To provide Lazy List behavior - automatically - * growing and populating the {@code List} - * with either {@code DynaBean, java.util.Map} - * or POJO Beans.
  • - *
  • To provide a straight forward way of putting a Collection - * or Array into the lazy list and a straight forward - * way to get it out again at the end.
  • - *
- * - *

All elements added to the List are stored as {@code DynaBean}'s:

- *
    - *
  • {@code java.util.Map elements are "wrapped" in a LazyDynaMap}.
  • - *
  • POJO Bean elements are "wrapped" in a {@code WrapDynaBean}.
  • - *
  • {@code DynaBean}'s are stored un-changed.
  • - *
- * - *

{@code toArray()}

- *

The {@code toArray()} method returns an array of the - * elements of the appropriate type. If the {@code LazyDynaList} - * is populated with {@code java.util.Map} objects a - * {@code Map[]} array is returned. - * If the list is populated with POJO Beans an appropriate - * array of the POJO Beans is returned. Otherwise a {@code DynaBean[]} - * array is returned. - *

- * - *

{@code toDynaBeanArray()}

- *

The {@code toDynaBeanArray()} method returns a - * {@code DynaBean[]} array of the elements in the List. - *

- * - *

N.B.All the elements in the List must be the - * same type. If the {@code DynaClass or Class} - * of the {@code LazyDynaList}'s elements is - * not specified, then it will be automatically set to the type - * of the first element populated. - *

- * - *

Example 1

- *

If you have an array of {@code java.util.Map[]} - you can put that into - * a {@code LazyDynaList}.

- * - *

- *    TreeMap[] myArray = .... // your Map[]
- *    List lazyList = new LazyDynaList(myArray);
- * 
- * - *

New elements of the appropriate Map type are - * automatically populated:

- * - *

- *    // get(index) automatically grows the list
- *    DynaBean newElement = (DynaBean)lazyList.get(lazyList.size());
- *    newElement.put("someProperty", "someValue");
- * 
- * - *

Once you've finished you can get back an Array of the - * elements of the appropriate type:

- * - *

- *    // Retrieve the array from the list
- *    TreeMap[] myArray = (TreeMap[])lazyList.toArray());
- * 
- * - * - *

Example 2

- *

Alternatively you can create an empty List and - * specify the Class for List's elements. The LazyDynaList - * uses the Class to automatically populate elements:

- * - *

- *    // e.g. For Maps
- *    List lazyList = new LazyDynaList(TreeMap.class);
- *
- *    // e.g. For POJO Beans
- *    List lazyList = new LazyDynaList(MyPojo.class);
- *
- *    // e.g. For DynaBeans
- *    List lazyList = new LazyDynaList(MyDynaBean.class);
- * 
- * - *

Example 3

- *

Alternatively you can create an empty List and specify the - * DynaClass for List's elements. The LazyDynaList uses - * the DynaClass to automatically populate elements:

- * - *

- *    // e.g. For Maps
- *    DynaClass dynaClass = new LazyDynaMap(new HashMap());
- *    List lazyList = new LazyDynaList(dynaClass);
- *
- *    // e.g. For POJO Beans
- *    DynaClass dynaClass = (new WrapDynaBean(myPojo)).getDynaClass();
- *    List lazyList = new LazyDynaList(dynaClass);
- *
- *    // e.g. For DynaBeans
- *    DynaClass dynaClass = new BasicDynaClass(properties);
- *    List lazyList = new LazyDynaList(dynaClass);
- * 
- * - *

N.B. You may wonder why control the type - * using a {@code DynaClass rather than the Class} - * as in the previous example - the reason is that some {@code DynaBean} - * implementations don't have a default empty constructor and - * therefore need to be instantiated using the {@code DynaClass.newInstance()} - * method.

- * - *

Example 4

- *

A slight variation - set the element type using either - * the {@code setElementType(Class)} method or the - * {@code setElementDynaClass(DynaClass)} method - then populate - * with the normal {@code java.util.List} methods(i.e. - * {@code add(), addAll() or set()}).

- * - *

- *    // Create a new LazyDynaList (100 element capacity)
- *    LazyDynaList lazyList = new LazyDynaList(100);
- *
- *    // Either Set the element type...
- *    lazyList.setElementType(TreeMap.class);
- *
- *    // ...or the element DynaClass...
- *    lazyList.setElementDynaClass(new MyCustomDynaClass());
- *
- *    // Populate from a collection
- *    lazyList.addAll(myCollection);
- *
- * 
- * - * @since 1.8.0 - */ -public class LazyDynaList extends ArrayList { - - private static final long serialVersionUID = 1L; - - /** - * The DynaClass of the List's elements. - */ - private DynaClass elementDynaClass; - - /** - * The WrapDynaClass if the List's contains - * POJO Bean elements. - * - * N.B. WrapDynaClass isn't serializable, which - * is why its stored separately in a - * transient instance variable. - */ - private transient WrapDynaClass wrapDynaClass; - - /** - * The type of the List's elements. - */ - private Class elementType; - - /** - * The DynaBean type of the List's elements. - */ - private Class elementDynaBeanType; - - - - /** - * Default Constructor. - */ - public LazyDynaList() { - super(); - } - - /** - * Construct a LazyDynaList with the - * specified capacity. - * - * @param capacity The initial capacity of the list. - */ - public LazyDynaList(final int capacity) { - super(capacity); - - } - - /** - * Construct a LazyDynaList with a - * specified DynaClass for its elements. - * - * @param elementDynaClass The DynaClass of the List's elements. - */ - public LazyDynaList(final DynaClass elementDynaClass) { - super(); - setElementDynaClass(elementDynaClass); - } - - /** - * Construct a LazyDynaList with a - * specified type for its elements. - * - * @param elementType The Type of the List's elements. - */ - public LazyDynaList(final Class elementType) { - super(); - setElementType(elementType); - } - - /** - * Construct a LazyDynaList populated with the - * elements of a Collection. - * - * @param collection The Collection to populate the List from. - */ - public LazyDynaList(final Collection collection) { - super(collection.size()); - addAll(collection); - } - - /** - * Construct a LazyDynaList populated with the - * elements of an Array. - * - * @param array The Array to populate the List from. - */ - public LazyDynaList(final Object[] array) { - super(array.length); - this.addAll(Arrays.asList(array)); - } - - - - /** - *

Insert an element at the specified index position.

- * - *

If the index position is greater than the current - * size of the List, then the List is automatically - * grown to the appropriate size.

- * - * @param index The index position to insert the new element. - * @param element The new element to add. - */ - @Override - public void add(final int index, final Object element) { - - final DynaBean dynaBean = transform(element); - - growList(index); - - super.add(index, dynaBean); - - } - - /** - *

Add an element to the List.

- * - * @param element The new element to add. - * @return true. - */ - @Override - public boolean add(final Object element) { - - final DynaBean dynaBean = transform(element); - - return super.add(dynaBean); - - } - - /** - *

Add all the elements from a Collection to the list. - * - * @param collection The Collection of new elements. - * @return true if elements were added. - */ - @Override - public boolean addAll(final Collection collection) { - - if (collection == null || collection.size() == 0) { - return false; - } - - ensureCapacity(size() + collection.size()); - - for (final Object e : collection) { - add(e); - } - - return true; - - } - - /** - *

Insert all the elements from a Collection into the - * list at a specified position. - * - *

If the index position is greater than the current - * size of the List, then the List is automatically - * grown to the appropriate size.

- * - * @param collection The Collection of new elements. - * @param index The index position to insert the new elements at. - * @return true if elements were added. - */ - @Override - public boolean addAll(final int index, final Collection collection) { - - if (collection == null || collection.size() == 0) { - return false; - } - - ensureCapacity((Math.max(index, size())) + collection.size()); - - // Call "transform" with first element, before - // List is "grown" to ensure the correct DynaClass - // is set. - if (size() == 0) { - transform(collection.iterator().next()); - } - - growList(index); - - int currentIndex = index; - for (final Object e : collection) { - add(currentIndex++, e); - } - - return true; - - } - - /** - *

Return the element at the specified position.

- * - *

If the position requested is greater than the current - * size of the List, then the List is automatically - * grown (and populated) to the appropriate size.

- * - * @param index The index position to insert the new elements at. - * @return The element at the specified position. - */ - @Override - public Object get(final int index) { - - growList(index + 1); - - return super.get(index); - - } - - /** - *

Set the element at the specified position.

- * - *

If the position requested is greater than the current - * size of the List, then the List is automatically - * grown (and populated) to the appropriate size.

- * - * @param index The index position to insert the new element at. - * @param element The new element. - * @return The new element. - */ - @Override - public Object set(final int index, final Object element) { - - final DynaBean dynaBean = transform(element); - - growList(index + 1); - - return super.set(index, dynaBean); - - } - - /** - *

Converts the List to an Array.

- * - *

The type of Array created depends on the contents - * of the List:

- *
    - *
  • If the List contains only LazyDynaMap type elements - * then a java.util.Map[] array will be created.
  • - *
  • If the List contains only elements which are - * "wrapped" DynaBeans then an Object[] of the most - * suitable type will be created.
  • - *
  • ...otherwise a DynaBean[] will be created.
  • - *
- * - * @return An Array of the elements in this List. - */ - @Override - public Object[] toArray() { - - if (size() == 0 && elementType == null) { - return new LazyDynaBean[0]; - } - - final Object[] array = (Object[])Array.newInstance(elementType, size()); - for (int i = 0; i < size(); i++) { - if (Map.class.isAssignableFrom(elementType)) { - array[i] = ((LazyDynaMap)get(i)).getMap(); - } else if (DynaBean.class.isAssignableFrom(elementType)) { - array[i] = get(i); - } else { - array[i] = ((WrapDynaBean)get(i)).getInstance(); - } - } - return array; - - } - - /** - *

Converts the List to an Array of the specified type.

- * - * @param The type of the array elements - * @param model The model for the type of array to return - * @return An Array of the elements in this List. - */ - @Override - public T[] toArray(final T[] model) { - - final Class arrayType = model.getClass().getComponentType(); - if (DynaBean.class.isAssignableFrom(arrayType) - || size() == 0 && elementType == null) { - return super.toArray(model); - } - - if (arrayType.isAssignableFrom(elementType)) { - T[] array; - if (model.length >= size()) { - array = model; - } else { - @SuppressWarnings("unchecked") - final - // This is safe because we know the element type - T[] tempArray = (T[]) Array.newInstance(arrayType, size()); - array = tempArray; - } - - for (int i = 0; i < size(); i++) { - Object elem; - if (Map.class.isAssignableFrom(elementType)) { - elem = ((LazyDynaMap) get(i)).getMap(); - } else if (DynaBean.class.isAssignableFrom(elementType)) { - elem = get(i); - } else { - elem = ((WrapDynaBean) get(i)).getInstance(); - } - Array.set(array, i, elem); - } - return array; - } - - throw new IllegalArgumentException("Invalid array type: " - + arrayType.getName() + " - not compatible with '" - + elementType.getName()); - - } - - - - /** - *

Converts the List to an DynaBean Array.

- * - * @return A DynaBean[] of the elements in this List. - */ - public DynaBean[] toDynaBeanArray() { - - if (size() == 0 && elementDynaBeanType == null) { - return new LazyDynaBean[0]; - } - - final DynaBean[] array = (DynaBean[])Array.newInstance(elementDynaBeanType, size()); - for (int i = 0; i < size(); i++) { - array[i] = (DynaBean)get(i); - } - return array; - - } - - /** - *

Set the element Type and DynaClass.

- * - * @param elementType The type of the elements. - * @throws IllegalArgumentException if the List already - * contains elements or the DynaClass is null. - */ - public void setElementType(final Class elementType) { - - if (elementType == null) { - throw new IllegalArgumentException("Element Type is missing"); - } - - final boolean changeType = this.elementType != null && !this.elementType.equals(elementType); - if (changeType && size() > 0) { - throw new IllegalStateException("Element Type cannot be reset"); - } - - this.elementType = elementType; - - // Create a new object of the specified type - Object object = null; - try { - object = elementType.newInstance(); - } catch (final Exception e) { - throw new IllegalArgumentException("Error creating type: " - + elementType.getName() + " - " + e); - } - - // Create a DynaBean - DynaBean dynaBean = null; - if (Map.class.isAssignableFrom(elementType)) { - dynaBean = createDynaBeanForMapProperty(object); - this.elementDynaClass = dynaBean.getDynaClass(); - } else if (DynaBean.class.isAssignableFrom(elementType)) { - dynaBean = (DynaBean)object; - this.elementDynaClass = dynaBean.getDynaClass(); - } else { - dynaBean = new WrapDynaBean(object); - this.wrapDynaClass = (WrapDynaClass)dynaBean.getDynaClass(); - } - - this.elementDynaBeanType = dynaBean.getClass(); - - // Re-calculate the type - if (WrapDynaBean.class.isAssignableFrom(elementDynaBeanType )) { - this.elementType = ((WrapDynaBean)dynaBean).getInstance().getClass(); - } else if (LazyDynaMap.class.isAssignableFrom(elementDynaBeanType )) { - this.elementType = ((LazyDynaMap)dynaBean).getMap().getClass(); - } - - } - - /** - *

Set the element Type and DynaClass.

- * - * @param elementDynaClass The DynaClass of the elements. - * @throws IllegalArgumentException if the List already - * contains elements or the DynaClass is null. - */ - public void setElementDynaClass(final DynaClass elementDynaClass) { - - if (elementDynaClass == null) { - throw new IllegalArgumentException("Element DynaClass is missing"); - } - - if (size() > 0) { - throw new IllegalStateException("Element DynaClass cannot be reset"); - } - - // Try to create a new instance of the DynaBean - try { - final DynaBean dynaBean = elementDynaClass.newInstance(); - this.elementDynaBeanType = dynaBean.getClass(); - if (WrapDynaBean.class.isAssignableFrom(elementDynaBeanType)) { - this.elementType = ((WrapDynaBean)dynaBean).getInstance().getClass(); - this.wrapDynaClass = (WrapDynaClass)elementDynaClass; - } else if (LazyDynaMap.class.isAssignableFrom(elementDynaBeanType)) { - this.elementType = ((LazyDynaMap)dynaBean).getMap().getClass(); - this.elementDynaClass = elementDynaClass; - } else { - this.elementType = dynaBean.getClass(); - this.elementDynaClass = elementDynaClass; - } - } catch (final Exception e) { - throw new IllegalArgumentException( - "Error creating DynaBean from " + - elementDynaClass.getClass().getName() + " - " + e); - } - - } - - - - /** - *

Automatically grown the List - * to the appropriate size, populating with - * DynaBeans.

- * - * @param requiredSize the required size of the List. - */ - private void growList(final int requiredSize) { - - if (requiredSize < size()) { - return; - } - - ensureCapacity(requiredSize + 1); - - for (int i = size(); i < requiredSize; i++) { - final DynaBean dynaBean = transform(null); - super.add(dynaBean); - } - - } - - /** - *

Transform the element into a DynaBean:

- * - *