
org.apache.commons.beanutils2.WrapDynaClass Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-beanutils2 Show documentation
Show all versions of commons-beanutils2 Show documentation
Apache Commons BeanUtils provides an easy-to-use but flexible wrapper around reflection and introspection.
The newest version!
/*
* 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
*
* https://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.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.WeakHashMap;
/**
* Implements {@link DynaClass} to wrap standard JavaBean instances.
*
* This class should not usually need to be used directly to create new {@link WrapDynaBean} instances - it's usually better to call the {@link WrapDynaBean}
* constructor. For example:
*
*
*
* Object javaBean = ...;
* DynaBean wrapper = new WrapDynaBean(javaBean);
*
*/
public class WrapDynaClass implements DynaClass {
/**
* A class representing the combined key for the cache of {@code WrapDynaClass} instances. A single key consists of a bean class and an instance of
* {@code PropertyUtilsBean}. Instances are immutable.
*/
private static final class CacheKey {
/** The bean class. */
private final Class> beanClass;
/** The instance of PropertyUtilsBean. */
private final PropertyUtilsBean propUtils;
/**
* Creates a new instance of {@code CacheKey}.
*
* @param beanCls the bean class
* @param pu the instance of {@code PropertyUtilsBean}
*/
public CacheKey(final Class> beanCls, final PropertyUtilsBean pu) {
beanClass = beanCls;
propUtils = pu;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof CacheKey)) {
return false;
}
final CacheKey c = (CacheKey) obj;
return beanClass.equals(c.beanClass) && propUtils.equals(c.propUtils);
}
@Override
public int hashCode() {
final int factor = 31;
int result = 17;
result = factor * beanClass.hashCode() + result;
result = factor * propUtils.hashCode() + result;
return result;
}
}
private static final ContextClassLoaderLocal
© 2015 - 2025 Weber Informatics LLC | Privacy Policy