Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2011 the original author or authors.
*
* 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.
*/
package org.modelmapper.internal;
import net.jodah.typetools.TypeResolver;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import org.modelmapper.spi.PropertyInfo;
import org.modelmapper.spi.PropertyType;
import org.modelmapper.spi.ValueReader;
/**
* Abstract PropertyInfo implementation that provides {@link #equals(Object)} and
* {@link #hashCode()} operations based on the property name.
*
* @author Jonathan Halterman
*/
abstract class PropertyInfoImpl implements PropertyInfo {
protected final Class initialType;
protected final M member;
protected final Class type;
protected final String name;
private final PropertyType propertyType;
static abstract class AbstractMethodInfo extends PropertyInfoImpl {
private AbstractMethodInfo(Class initialType, Method method, String name) {
super(initialType, method, PropertyType.METHOD, name);
method.setAccessible(true);
}
public T getAnnotation(Class annotationClass) {
return member.getAnnotation(annotationClass);
}
}
static class FieldPropertyInfo extends PropertyInfoImpl implements Accessor, Mutator {
FieldPropertyInfo(Class initialType, Field field, String name) {
super(initialType, field, PropertyType.FIELD, name);
field.setAccessible(true);
}
public T getAnnotation(Class annotationClass) {
return member.getAnnotation(annotationClass);
}
public Type getGenericType() {
return member.getGenericType();
}
public Object getValue(Object subject) {
try {
return member.get(subject);
} catch (Exception e) {
throw new Errors().errorGettingValue(member, e).toMappingException();
}
}
public void setValue(Object subject, Object value) {
try {
member.set(subject, value);
} catch (Exception e) {
throw new Errors().errorSettingValue(member, value, e).toMappingException();
}
}
public TypeInfo getTypeInfo(InheritingConfiguration configuration) {
return TypeInfoRegistry.typeInfoFor(this, configuration);
}
}
static class MethodAccessor extends AbstractMethodInfo implements Accessor {
MethodAccessor(Class initialType, Method method, String name) {
super(initialType, method, name);
}
public Type getGenericType() {
return member.getGenericReturnType();
}
public Object getValue(Object subject) {
try {
return member.invoke(subject);
} catch (IllegalAccessException e) {
new Errors().errorAccessingProperty(this).throwMappingExceptionIfErrorsExist();
return null;
} catch (Exception e) {
throw new Errors().errorGettingValue(member, e).toMappingException();
}
}
public TypeInfo getTypeInfo(InheritingConfiguration configuration) {
return TypeInfoRegistry.typeInfoFor(this, configuration);
}
}
static class MethodMutator extends AbstractMethodInfo implements Mutator {
MethodMutator(Class initialType, Method method, String name) {
super(initialType, method, name);
}
public Type getGenericType() {
return member.getGenericParameterTypes()[0];
}
public void setValue(Object subject, Object value) {
try {
member.invoke(subject, value);
} catch (Exception e) {
throw new Errors().errorSettingValue(member, value, e).toMappingException();
}
}
public TypeInfo getTypeInfo(InheritingConfiguration configuration) {
return TypeInfoRegistry.typeInfoFor(type, configuration);
}
}
static class ValueReaderPropertyInfo extends PropertyInfoImpl implements Accessor {
private ValueReader