com.maxifier.mxcache.provider.AnnotationProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mxcache-runtime Show documentation
Show all versions of mxcache-runtime Show documentation
Constains all classes necessary for launching a MxCache-instrumentated application
/*
* Copyright (c) 2008-2014 Maxifier Ltd. All Rights Reserved.
*/
package com.maxifier.mxcache.provider;
import javax.annotation.Nonnull;
import java.lang.annotation.Annotation;
/**
* AnnotationProperty are like StrategyProperty but they allow to use custom annotation to override the value of
* property.
* In most cases you should not extend this class directly, use
* {@link com.maxifier.mxcache.provider.ReflectiveAnnotationProperty} instead.
*
* @see ReflectiveAnnotationProperty
*
* @author Alexander Kochurov ([email protected])
*/
public abstract class AnnotationProperty extends StrategyProperty {
private final Class annotationType;
protected AnnotationProperty(String name, Class type, Class annotationType, T defaultValue) {
super(name, type, defaultValue);
if (!Annotation.class.isAssignableFrom(annotationType)) {
throw new IllegalArgumentException(annotationType + " is not annotation type");
}
this.annotationType = annotationType;
}
protected AnnotationProperty(String name, Class type, Class annotationType) {
this(name, type, annotationType, null);
}
/**
* Gets the value from annotation. Implement this method for your custom annotations.
* @param annotation your custom annotation.
* @return the value of property; null means that MxCache should lookup the value in xml configuration
*/
public abstract T getFromAnnotation(@Nonnull A annotation);
public Class getAnnotationType() {
return annotationType;
}
}