Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2012, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * 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.jboss.weld.injection.producer;
 
 import java.util.Set;
 
 
javax.enterprise.inject.spi.Producer implementation for producer methods.

Author(s):
Jozef Hartinger
 
 public abstract class ProducerMethodProducer<X, T> extends AbstractMemberProducer<X, T> {
 
     private static final String PRODUCER_ANNOTATION = "@Produces";
     // The underlying method
     private final MethodInjectionPoint<T, ? super X> method;
 
     public ProducerMethodProducer(EnhancedAnnotatedMethod<T, ? super X> enhancedAnnotatedMethodDisposalMethod<?, ?> disposalMethod) {
         super(enhancedAnnotatedMethoddisposalMethod);
         this. = InjectionPointFactory.instance().createMethodInjectionPoint(enhancedAnnotatedMethodgetBean(), enhancedAnnotatedMethod.getDeclaringType().getJavaClass(), falsegetBeanManager());
         checkProducerMethod(enhancedAnnotatedMethod);
         checkDelegateInjectionPoints();
     }

    
Validates the producer method
 
     protected void checkProducerMethod(EnhancedAnnotatedMethod<T, ? super X> method) {
         if (method.getEnhancedParameters(Observes.class).size() > 0) {
             throw ..inconsistentAnnotationsOnMethod("@Observes"this.);
         } else if (method.getEnhancedParameters(Disposes.class).size() > 0) {
             throw ..inconsistentAnnotationsOnMethod("@Disposes"this.);
         } else if (getDeclaringBean() instanceof SessionBean<?>) {
             boolean methodDeclaredOnTypes = false;
             // TODO use annotated item?
             for (Type type : getDeclaringBean().getTypes()) {
                 // TODO: deal with parameterized types!
                 if (type instanceof Class<?>) {
                     try {
                         AccessController.doPrivileged(new GetMethodAction((Class<?>) typemethod.getName(), method.getParameterTypesAsArray()));
                         methodDeclaredOnTypes = true;
                         break;
                     } catch (PrivilegedActionException ignored) {
                     }
                 }
             }
             if (!methodDeclaredOnTypes) {
                 throw ..methodNotBusinessMethod(thisgetDeclaringBean());
             }
         }
     }
 
     @Override
     public Set<InjectionPointgetInjectionPoints() {
         return .getInjectionPoints();
     }
 
     @Override
     protected T produce(Object receiverCreationalContext<T> ctx) {
         if (receiver != null) {
             return .invokeOnInstance(receivergetBeanManager(), ctxCreationException.class);
         } else {
             return .invoke(nullgetBeanManager(), ctxCreationException.class);
         }
    }
    @Override
    public AnnotatedMember<? super X> getAnnotated() {
        return .getAnnotated();
    }
    }
    }
New to GrepCode? Check out our FAQ X