本文整理汇总了Java中javax.enterprise.inject.spi.AnnotatedType.getMethods方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedType.getMethods方法的具体用法?Java AnnotatedType.getMethods怎么用?Java AnnotatedType.getMethods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.enterprise.inject.spi.AnnotatedType
的用法示例。
在下文中一共展示了AnnotatedType.getMethods方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAnnotatedMember
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <X, A extends AnnotatedMember<? super X>> A getAnnotatedMember(Class<X> javaClass, String memberName,
BeanManager beanManager) {
AnnotatedType<X> type = beanManager.createAnnotatedType(javaClass);
for (AnnotatedField<? super X> field : type.getFields()) {
if (field.getJavaMember().getName().equals(memberName)) {
return (A) field;
}
}
for (AnnotatedMethod<? super X> method : type.getMethods()) {
if (method.getJavaMember().getName().equals(memberName)) {
return (A) method;
}
}
throw new IllegalArgumentException("Member " + memberName + " not found on " + javaClass);
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:17,代码来源:InjectSPITestCase.java
示例2: getReplacement
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
public <T> AnnotatedType<T> getReplacement(AnnotatedType<T> originalType) {
boolean modified = false;
Set<AnnotatedMethod<? super T>> methods = new LinkedHashSet<>();
for (AnnotatedMethod<? super T> originalMethod : originalType.getMethods()) {
AnnotatedMethod<? super T> replacement = getReplacement(originalType, originalMethod);
if (replacement != null) {
methods.add(replacement);
modified = true;
} else {
methods.add(originalMethod);
}
}
if (modified) {
return new AnnotatedTypeWrapper<T>(originalType, methods);
}
return null;
}
示例3: findJobs
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
<T> void findJobs( @Observes @WithAnnotations({Cron.class}) ProcessAnnotatedType<T> pat, BeanManager beanManager )
{
// Ensure we are named otherwise job won't fire as we can't locate it
AnnotatedType<?> type = pat.getAnnotatedType();
Class<?> clazz = type.getJavaClass();
CDIUtils.addTypeAnnotation( pat, Named.class, () -> new NamedImpl( "Schedule_" + (id++) ) );
if( type.isAnnotationPresent( Cron.class ) ) {
if( Job.class.isAssignableFrom( clazz ) ) {
jobClasses.add( clazz );
}
else {
throw new UnsupportedOperationException( "@Cron on type must implement Job" );
}
}
else {
for( AnnotatedMethod<?> meth: type.getMethods() ) {
if( meth.isAnnotationPresent( Cron.class ) ) {
jobClasses.add( clazz );
}
}
}
}
示例4: hasAnnotation
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
static boolean hasAnnotation(AnnotatedType<?> type, Class<? extends Annotation> annotation) {
if (type.isAnnotationPresent(annotation)) {
return true;
}
for (AnnotatedMethod<?> method : type.getMethods()) {
if (method.isAnnotationPresent(annotation)) {
return true;
}
}
for (AnnotatedConstructor<?> constructor : type.getConstructors()) {
if (constructor.isAnnotationPresent(annotation)) {
return true;
}
}
for (AnnotatedField<?> field : type.getFields()) {
if (field.isAnnotationPresent(annotation)) {
return true;
}
}
return false;
}
示例5: alternatives
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
/**
* Activates the alternatives declared with {@code @Beans} globally for the
* application.
* <p/>
* For every types and every methods of every types declared with
* {@link Beans#alternatives()}, the {@code Priority} annotation is added
* so that the corresponding alternatives are selected globally for the
* entire application.
*
* @see Beans
*/
private <T> void alternatives(@Observes @WithAnnotations(Alternative.class) ProcessAnnotatedType<T> pat) {
AnnotatedType<T> type = pat.getAnnotatedType();
if (!Arrays.asList(beans.alternatives()).contains(type.getJavaClass())) {
// Only select globally the alternatives that are declared with @Beans
return;
}
Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
for (AnnotatedMethod<? super T> method : type.getMethods()) {
if (method.isAnnotationPresent(Alternative.class) && !method.isAnnotationPresent(Priority.class)) {
methods.add(new AnnotatedMethodDecorator<>(method, PriorityLiteral.of(APPLICATION)));
}
}
if (type.isAnnotationPresent(Alternative.class) && !type.isAnnotationPresent(Priority.class)) {
pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, PriorityLiteral.of(APPLICATION), methods));
} else if (!methods.isEmpty()) {
pat.setAnnotatedType(new AnnotatedTypeDecorator<>(type, methods));
}
}
示例6: findMethod
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
public static AnnotatedMethod<?> findMethod(final AnnotatedType<?> type, final Method method)
{
AnnotatedMethod<?> annotatedMethod = null;
for (final AnnotatedMethod<?> am : type.getMethods())
{
if (am.getJavaMember().equals(method))
{
annotatedMethod = am;
break;
}
}
if (annotatedMethod == null)
{
throw new IllegalStateException("No annotated method for " + method);
}
return annotatedMethod;
}
示例7: processBean
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
<X> void processBean(@Observes ProcessManagedBean<X> event) {
AnnotatedType<X> annotatedType = event.getAnnotatedBeanClass();
Transactional classTx = annotatedType.getAnnotation(Transactional.class);
for (AnnotatedMethod<? super X> am : annotatedType.getMethods()) {
Transactional methodTx = am.getAnnotation(Transactional.class);
if (classTx != null || methodTx != null) {
Method method = am.getJavaMember();
Transactional attrType = mergeTransactionAttributes(classTx, methodTx);
transactionAttributes.put(method, attrType);
}
}
}
示例8: process
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
public void process(Set<AnnotatedType<?>> discoveredTypes) {
for(AnnotatedType<?> at : discoveredTypes) {
for(AnnotatedMethod<?> am : at.getMethods()) {
boolean hasObserver = am.getParameters().stream().anyMatch(ap -> ap.getAnnotation(ObservesReactor.class) != null);
if(hasObserver) {
AnnotatedParameter<?> observerType = am.getParameters().stream().filter(ap -> ap.isAnnotationPresent(ObservesReactor.class)).findFirst().orElseThrow(() -> new RuntimeException("No observer found"));
Class<?> returnType = null;
Type genericReturnType = am.getJavaMember().getGenericReturnType();
boolean returnsPublisher = false;
if(genericReturnType instanceof ParameterizedType) {
ParameterizedType type = (ParameterizedType)genericReturnType;
if(Publisher.class.isAssignableFrom((Class<?>) type.getRawType())) {
returnsPublisher = true;
returnType = (Class<?>) type.getActualTypeArguments()[0];
} else {
throw new RuntimeException("Method "+am+" should either return a concrete type or an instance of "+Publisher.class.getName());
}
}
else {
returnType = (Class)genericReturnType;
}
Class<?> eventType = observerType.getJavaParameter().getType();
Set<Annotation> annotations = new LinkedHashSet<>(asList(observerType.getJavaParameter().getAnnotations()));
methods.add(new ReactorMethod(at,am,returnType,eventType,annotations,returnsPublisher));
}
}
}
}
示例9: declareAsInterceptorBinding
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
private static <T extends Annotation> void declareAsInterceptorBinding(Class<T> annotation, BeanManager manager, BeforeBeanDiscovery bbd) {
AnnotatedType<T> annotated = manager.createAnnotatedType(annotation);
Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
for (AnnotatedMethod<? super T> method : annotated.getMethods()) {
methods.add(new AnnotatedMethodDecorator<>(method, NON_BINDING));
}
bbd.addInterceptorBinding(new AnnotatedTypeDecorator<>(annotated, INTERCEPTOR_BINDING, methods));
}
示例10: collectFaultToleranceOperations
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
/**
* Observe all enabled managed beans and identify/validate FT operations. This allows us to:
* <ul>
* <li>Skip validation of types which are not recognized as beans (e.g. are vetoed)</li>
* <li>Take the final values of AnnotatedTypes</li>
* <li>Support annotations added via portable extensions</li>
* </ul>
*
* @param event
*/
void collectFaultToleranceOperations(@Observes ProcessManagedBean<?> event) {
AnnotatedType<?> annotatedType = event.getAnnotatedBeanClass();
for (AnnotatedMethod<?> annotatedMethod : annotatedType.getMethods()) {
FaultToleranceOperation operation = FaultToleranceOperation.of(annotatedMethod);
if (operation.isLegitimate() && operation.validate()) {
LOGGER.debugf("Found %s", operation);
faultToleranceOperations.put(annotatedMethod.getJavaMember().toGenericString(), operation);
}
}
}
示例11: AnnotatedTypeDelegate
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
AnnotatedTypeDelegate(AnnotatedType<T> delegate, Set<AnnotatedMethod<? super T>> methods) {
super(delegate);
this.delegate = delegate;
this.methods = new HashSet<>(delegate.getMethods());
this.methods.removeAll(methods);
this.methods.addAll(methods);
}
示例12: addInjectAnnotation
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
/**
* Adds the {@link Inject} annotation to the fields and setters of the annotated type if required.
*
* @param <X>
* the type of the annotated type
* @param annotatedType
* the annotated type whose fields and setters the inject annotation should be added to
* @param builder
* the builder that should be used to add the annotation.
* @see #shouldInjectionAnnotationBeAddedToMember(AnnotatedMember)
*/
public static <X> void addInjectAnnotation(final AnnotatedType<X> annotatedType, AnnotatedTypeBuilder<X> builder) {
for (AnnotatedField<? super X> field : annotatedType.getFields()) {
if (shouldInjectionAnnotationBeAddedToMember(field)) {
builder.addToField(field, AnnotationInstances.INJECT);
}
}
for (AnnotatedMethod<? super X> method : annotatedType.getMethods()) {
if (shouldInjectionAnnotationBeAddedToMember(method)) {
builder.addToMethod(method, AnnotationInstances.INJECT);
}
}
}
示例13: process
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
/**
* @see {@link com.byteslounge.cdi.resolver.bean.ResolverBean#process(AnnotatedType)}
*/
@Override
public void process(AnnotatedType<?> at) {
for (AnnotatedMethod<?> method : at.getMethods()) {
if (method.isAnnotationPresent(typeToSearch)) {
if (method.getJavaMember().getDeclaringClass().equals(defaulResolverClass)) {
resolverMethod = method;
if (logger.isDebugEnabled()) {
logger.debug("Found default " + resolverDescription + "resolver method: "
+ MessageUtils.getMethodDefinition(method));
}
} else {
if (providedResolverMethod != null) {
String errorMessage = "Found multiple provided " + resolverDescription + " resolver methods: "
+ MessageUtils.getMethodDefinition(providedResolverMethod) + ", "
+ MessageUtils.getMethodDefinition(method);
logger.error(errorMessage);
throw new ExtensionInitializationException(errorMessage);
}
providedResolverMethod = method;
if (logger.isDebugEnabled()) {
logger.debug("Found provided " + resolverDescription + "resolver method: "
+ MessageUtils.getMethodDefinition(providedResolverMethod));
}
}
}
}
}
示例14: processBean
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
/**
* Observes {@link ProcessManagedBean} event.
*
* @param event {@link ProcessManagedBean} event.
*/
<X> void processBean(
@Observes ProcessManagedBean<X> event)
{
boolean sessionBean = event instanceof ProcessSessionBean<?>;
AnnotatedType<X> annotatedType = event.getAnnotatedBeanClass();
boolean hasClassInterceptor = annotatedType
.isAnnotationPresent(Transactional.class);
if (hasClassInterceptor && sessionBean)
{
event.addDefinitionError(new RuntimeException(
"@Transactional is forbidden for session bean "
+ event.getBean()));
}
else
{
TransactionAttribute classAttr = annotatedType
.getAnnotation(TransactionAttribute.class);
for (AnnotatedMethod<? super X> am : annotatedType.getMethods())
{
boolean hasMethodInterceptor = am
.isAnnotationPresent(Transactional.class);
if (hasMethodInterceptor && sessionBean)
{
event.addDefinitionError(new RuntimeException(
"@Transactional is forbidden for session bean method "
+ am));
}
else if (hasClassInterceptor || hasMethodInterceptor)
{
TransactionAttribute attr = am
.getAnnotation(TransactionAttribute.class);
Method method = am.getJavaMember();
TransactionAttributeType attrType =
mergeTransactionAttributes(classAttr, attr);
transactionAttributes.put(method, attrType);
}
}
}
}
示例15: declareAsInterceptorBinding
import javax.enterprise.inject.spi.AnnotatedType; //导入方法依赖的package包/类
private static <T extends Annotation> void declareAsInterceptorBinding(Class<T> annotation, BeanManager manager, BeforeBeanDiscovery bbd) {
AnnotatedType<T> annotated = manager.createAnnotatedType(annotation);
Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
for (AnnotatedMethod<? super T> method : annotated.getMethods())
methods.add(new AnnotatedMethodDecorator<>(method, NON_BINDING));
bbd.addInterceptorBinding(new AnnotatedTypeDecorator<>(annotated, INTERCEPTOR_BINDING, methods));
}