
org.omnifaces.services.util.AnnotatedMethodWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of omniservices Show documentation
Show all versions of omniservices Show documentation
Utility library that provides EJB3-like features for CDI beans
The newest version!
/*
* Copyright 2021 OmniFaces
*
* 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
*
* 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.omnifaces.services.util;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import jakarta.enterprise.inject.spi.AnnotatedMethod;
import jakarta.enterprise.inject.spi.AnnotatedParameter;
import jakarta.enterprise.inject.spi.AnnotatedType;
public class AnnotatedMethodWrapper implements AnnotatedMethod {
private AnnotatedMethod wrappedAnnotatedMethod;
private Set annotations;
public AnnotatedMethodWrapper(AnnotatedMethod wrappedAnnotatedMethod) {
this.wrappedAnnotatedMethod = wrappedAnnotatedMethod;
annotations = new HashSet<>(wrappedAnnotatedMethod.getAnnotations());
}
@Override
public List> getParameters() {
return wrappedAnnotatedMethod.getParameters();
}
@Override
public AnnotatedType getDeclaringType() {
return wrappedAnnotatedMethod.getDeclaringType();
}
@Override
public boolean isStatic() {
return wrappedAnnotatedMethod.isStatic();
}
@Override
public T getAnnotation(Class annotationType) {
for (Annotation annotation : annotations) {
if (annotationType.isInstance(annotation)) {
return annotationType.cast(annotation);
}
}
return null;
}
@Override
public Set getAnnotations() {
return Collections.unmodifiableSet(annotations);
}
@Override
public Type getBaseType() {
return wrappedAnnotatedMethod.getBaseType();
}
@Override
public Set getTypeClosure() {
return wrappedAnnotatedMethod.getTypeClosure();
}
@Override
public boolean isAnnotationPresent(Class extends Annotation> annotationType) {
for (Annotation annotation : annotations) {
if (annotationType.isInstance(annotation)) {
return true;
}
}
return false;
}
@Override
public Method getJavaMember() {
return wrappedAnnotatedMethod.getJavaMember();
}
public void addAnnotation(Annotation annotation) {
annotations.add(annotation);
}
public void removeAnnotation(Annotation annotation) {
annotations.remove(annotation);
}
public void removeAnnotation(Class extends Annotation> annotationType) {
Annotation annotation = getAnnotation(annotationType);
if (annotation != null ) {
removeAnnotation(annotation);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy