package com.fasterxml.jackson.databind.util;
import java.util.Collections;
import java.util.Iterator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.type.TypeFactory;
public class SimpleBeanPropertyDefinition
extends BeanPropertyDefinition
{
protected final AnnotationIntrospector _annotationIntrospector;
protected final AnnotatedMember _member;
protected final PropertyMetadata _metadata;
protected final PropertyName _fullName;
protected final JsonInclude.Value _inclusion;
protected SimpleBeanPropertyDefinition(AnnotationIntrospector intr,
AnnotatedMember member, PropertyName fullName, PropertyMetadata metadata,
JsonInclude.Value inclusion)
{
_annotationIntrospector = intr;
_member = member;
_fullName = fullName;
_metadata = (metadata == null) ? PropertyMetadata.STD_OPTIONAL: metadata;
_inclusion = inclusion;
}
public static SimpleBeanPropertyDefinition construct(MapperConfig<?> config,
AnnotatedMember member)
{
return new SimpleBeanPropertyDefinition(config.getAnnotationIntrospector(),
member, PropertyName.construct(member.getName()), null, EMPTY_INCLUDE);
}
public static SimpleBeanPropertyDefinition construct(MapperConfig<?> config,
AnnotatedMember member, PropertyName name) {
return construct(config, member, name, null, EMPTY_INCLUDE);
}
public static SimpleBeanPropertyDefinition construct(MapperConfig<?> config,
AnnotatedMember member, PropertyName name, PropertyMetadata metadata,
JsonInclude.Include inclusion)
{
JsonInclude.Value inclValue
= ((inclusion == null) || (inclusion == JsonInclude.Include.USE_DEFAULTS))
? EMPTY_INCLUDE : JsonInclude.Value.construct(inclusion, null);
return new SimpleBeanPropertyDefinition(config.getAnnotationIntrospector(),
member, name, metadata, inclValue);
}
public static SimpleBeanPropertyDefinition construct(MapperConfig<?> config,
AnnotatedMember member, PropertyName name, PropertyMetadata metadata,
JsonInclude.Value inclusion) {
return new SimpleBeanPropertyDefinition(config.getAnnotationIntrospector(),
member, name, metadata, inclusion);
}
@Override
public BeanPropertyDefinition withSimpleName(String newName) {
if (_fullName.hasSimpleName(newName) && !_fullName.hasNamespace()) {
return this;
}
return new SimpleBeanPropertyDefinition(_annotationIntrospector,
_member, new PropertyName(newName), _metadata, _inclusion);
}
@Override
public BeanPropertyDefinition withName(PropertyName newName) {
if (_fullName.equals(newName)) {
return this;
}
return new SimpleBeanPropertyDefinition(_annotationIntrospector,
_member, newName, _metadata, _inclusion);
}
public BeanPropertyDefinition withMetadata(PropertyMetadata metadata) {
if (metadata.equals(_metadata)) {
return this;
}
return new SimpleBeanPropertyDefinition(_annotationIntrospector,
_member, _fullName, metadata, _inclusion);
}
public BeanPropertyDefinition withInclusion(JsonInclude.Value inclusion) {
if (_inclusion == inclusion) {
return this;
}
return new SimpleBeanPropertyDefinition(_annotationIntrospector,
_member, _fullName, _metadata, inclusion);
}
@Override
public String getName() { return _fullName.getSimpleName(); }
@Override
public PropertyName getFullName() { return _fullName; }
@Override
public boolean hasName(PropertyName name) {
return _fullName.equals(name);
}
@Override
public String getInternalName() { return getName(); }
@Override
public PropertyName getWrapperName() {
if ((_annotationIntrospector == null) || (_member == null)) {
return null;
}
return _annotationIntrospector.findWrapperName(_member);
}
@Override public boolean isExplicitlyIncluded() { return false; }
@Override public boolean isExplicitlyNamed() { return false; }
@Override
public PropertyMetadata getMetadata() {
return _metadata;
}
@Override
public JavaType getPrimaryType() {
if (_member == null) {
return TypeFactory.unknownType();
}
return _member.getType();
}
@Override
public Class<?> getRawPrimaryType() {
if (_member == null) {
return Object.class;
}
return _member.getRawType();
}
@Override
public JsonInclude.Value findInclusion() {
return _inclusion;
}
@Override
public boolean hasGetter() { return (getGetter() != null); }
@Override
public boolean hasSetter() { return (getSetter() != null); }
@Override
public boolean hasField() { return (_member instanceof AnnotatedField); }
@Override
public boolean hasConstructorParameter() { return (_member instanceof AnnotatedParameter); }
@Override
public AnnotatedMethod getGetter() {
if ((_member instanceof AnnotatedMethod)
&& ((AnnotatedMethod) _member).getParameterCount() == 0) {
return (AnnotatedMethod) _member;
}
return null;
}
@Override
public AnnotatedMethod getSetter() {
if ((_member instanceof AnnotatedMethod)
&& ((AnnotatedMethod) _member).getParameterCount() == 1) {
return (AnnotatedMethod) _member;
}
return null;
}
@Override
public AnnotatedField getField() {
return (_member instanceof AnnotatedField) ? (AnnotatedField) _member : null;
}
@Override
public AnnotatedParameter getConstructorParameter() {
return (_member instanceof AnnotatedParameter) ? (AnnotatedParameter) _member : null;
}
@Override
public Iterator<AnnotatedParameter> getConstructorParameters() {
AnnotatedParameter param = getConstructorParameter();
if (param == null) {
return ClassUtil.emptyIterator();
}
return Collections.singleton(param).iterator();
}
@Override
public AnnotatedMember getPrimaryMember() { return _member; }
}