/** * Verify that the return type is void and it's a no-arg method */ private void checkValid(Method m) throws AnnotationProcessorException { if ( !(m.getReturnType().equals(Void.TYPE) && m.getParameterTypes().length == 0) ) { throw new AnnotationProcessorException("Method " + m + "annotated as @BeforeCompletion is not valid"); } }
/** * Verify that the return type is void and it's a no-arg method */ private void checkValid(Method m) throws AnnotationProcessorException { if ( !(m.getReturnType().equals(Void.TYPE) && m.getParameterTypes().length == 0) ) { throw new AnnotationProcessorException("Method " + m + "annotated as @BeforeCompletion is not valid"); } }
/** * Verify that the return type is void and it's a no-arg method */ private void checkValid(Method m) throws AnnotationProcessorException { if ( !(m.getReturnType().equals(Void.TYPE) && m.getParameterTypes().length == 0) ) { throw new AnnotationProcessorException("Method " + m + "annotated as @AfterBegin is not valid"); } }
/** * Verify that the return type is void and it's a no-arg method */ private void checkValid(Method m) throws AnnotationProcessorException { if ( !(m.getReturnType().equals(Void.TYPE) && (m.getParameterTypes().length == 1 && m.getParameterTypes()[0].equals(Boolean.TYPE))) ) { throw new AnnotationProcessorException("Method " + m + "annotated as @AfterCompletion is not valid"); } }
/** * Verify that the return type is void and it's a no-arg method */ private void checkValid(Method m) throws AnnotationProcessorException { if ( !(m.getReturnType().equals(Void.TYPE) && m.getParameterTypes().length == 0) ) { throw new AnnotationProcessorException("Method " + m + "annotated as @AfterBegin is not valid"); } }
/** * Verify that the return type is void and it's a no-arg method */ private void checkValid(Method m) throws AnnotationProcessorException { if ( !(m.getReturnType().equals(Void.TYPE) && (m.getParameterTypes().length == 1 && m.getParameterTypes()[0].equals(Boolean.TYPE))) ) { throw new AnnotationProcessorException("Method " + m + "annotated as @AfterCompletion is not valid"); } }
/** * Check if given method is a valid injection method. * Throw Exception if it is not. * @exception AnnotationProcessorException */ protected void validateInjectionMethod(Method method, AnnotationInfo ainfo) throws AnnotationProcessorException { if (method.getParameterTypes().length!=1){ throw new AnnotationProcessorException( localStrings.getLocalString( "enterprise.deployment.annotation.handlers.invalidinjectionmethod", "Injection on a method requires a JavaBeans setter method type with one parameter "), ainfo); } if (!void.class.equals(method.getReturnType())) { throw new AnnotationProcessorException( localStrings.getLocalString( "enterprise.deployment.annotation.handlers.injectionmethodmustreturnvoid", "Injection on a method requires a void return type"), ainfo); } }
/** * Check if given method is a valid injection method. * Throw Exception if it is not. * @exception AnnotationProcessorException */ protected void validateInjectionMethod(Method method, AnnotationInfo ainfo) throws AnnotationProcessorException { if (method.getParameterTypes().length!=1){ throw new AnnotationProcessorException( localStrings.getLocalString( "enterprise.deployment.annotation.handlers.invalidinjectionmethod", "Injection on a method requires a JavaBeans setter method type with one parameter "), ainfo); } if (!void.class.equals(method.getReturnType())) { throw new AnnotationProcessorException( localStrings.getLocalString( "enterprise.deployment.annotation.handlers.injectionmethodmustreturnvoid", "Injection on a method requires a void return type"), ainfo); } }
protected String getInjectionMethodPropertyName(Method method, AnnotationInfo ainfo) throws AnnotationProcessorException { String methodName = method.getName(); String propertyName = null; if( (methodName.length() > 3) && methodName.startsWith("set") ) { // Derive javabean property name. propertyName = methodName.substring(3, 4).toLowerCase(Locale.US) + methodName.substring(4); } else { throw new AnnotationProcessorException( localStrings.getLocalString( "enterprise.deployment.annotation.handlers.invalidinjectionmethodname", "Injection method name must start with \"set\""), ainfo); } return propertyName; }
protected String getInjectionMethodPropertyName(Method method, AnnotationInfo ainfo) throws AnnotationProcessorException { String methodName = method.getName(); String propertyName = methodName; if( (methodName.length() > 3) && methodName.startsWith("set") ) { // Derive javabean property name. propertyName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4); } else { throw new AnnotationProcessorException( localStrings.getLocalString( "enterprise.deployment.annotation.handlers.invalidinjectionmethodname", "Injection method name must start with \"set\""), ainfo); } return propertyName; }
/** * Designate a method as asynchronous in the deployment descriptor * @param methodIntf null if processed on bean class / superclass. Otherwise, * set to the remote/local client view of the associated interface * @throws AnnotationProcessorException */ private void setAsynchronous(Method m0, EjbDescriptor ejbDesc, String methodIntf) throws AnnotationProcessorException { if( !ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) { throw new AnnotationProcessorException("Invalid asynchronous method " + m0 + "@Asynchronous is only permitted for session beans"); } EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc; MethodDescriptor methodDesc = (methodIntf == null) ? new MethodDescriptor(m0) : new MethodDescriptor(m0, methodIntf); if (logger.isLoggable(Level.FINE)) { logger.fine("Adding asynchronous method " + methodDesc); } // There is no way to "turn off" the asynchronous designation in the // deployment descriptor, so we don't need to do any override checks // here. Just always add any async methods. sessionDesc.addAsynchronousMethod(methodDesc); }
/** * Designate a method as asynchronous in the deployment descriptor * @param methodIntf null if processed on bean class / superclass. Otherwise, * set to the remote/local client view of the associated interface * @throws AnnotationProcessorException */ private void setAsynchronous(Method m0, EjbDescriptor ejbDesc, String methodIntf) throws AnnotationProcessorException { if( !ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) { throw new AnnotationProcessorException("Invalid asynchronous method " + m0 + "@Asynchronous is only permitted for session beans"); } EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc; MethodDescriptor methodDesc = (methodIntf == null) ? new MethodDescriptor(m0) : new MethodDescriptor(m0, methodIntf); if (logger.isLoggable(Level.FINE)) { logger.fine("Adding asynchronous method " + methodDesc); } // There is no way to "turn off" the asynchronous designation in the // deployment descriptor, so we don't need to do any override checks // here. Just always add any async methods. sessionDesc.addAsynchronousMethod(methodDesc); }
private void processForAnnotations(AnnotationInfo element, AccessibleObject o, Map<AccessibleObject, Class[]> methodLevelInterceptors, ManagedBeanDescriptor managedBeanDesc, Class managedBeanClass) throws AnnotationProcessorException { Annotation ann = getMethodAnnotation(o, "javax.interceptor.Interceptors"); if(ann != null) { try { Method valueM = ann.annotationType().getDeclaredMethod("value"); methodLevelInterceptors.put(o, (Class[]) valueM.invoke(ann)); } catch(Exception e) { AnnotationProcessorException ape = new AnnotationProcessorException(e.getMessage(), element); ape.initCause(e); throw ape; } } else { // If the method or constructor excludes // class-level interceptors, explicitly set method-level to an empty list. boolean excludeClassInterceptors = ( getMethodAnnotation(o, "javax.interceptor.ExcludeClassInterceptors") != null ); if( excludeClassInterceptors ) { MethodDescriptor mDesc = getMethodDescriptor(o, managedBeanClass); if (mDesc != null) { managedBeanDesc.setMethodLevelInterceptorChain(mDesc, new LinkedList<InterceptorDescriptor>()); } } } }
protected void log(Level level, AnnotationInfo ainfo, String localizedMessage) throws AnnotationProcessorException { if (Level.SEVERE.equals(level)) { ainfo.getProcessingContext().getErrorHandler().error( new AnnotationProcessorException(localizedMessage, ainfo)); } else if (Level.WARNING.equals(level)) { ainfo.getProcessingContext().getErrorHandler().warning( new AnnotationProcessorException(localizedMessage, ainfo)); } else if (Level.FINE.equals(level)) { ainfo.getProcessingContext().getErrorHandler().fine( new AnnotationProcessorException(localizedMessage, ainfo)); } else if (ainfo != null) { ainfo.getProcessingContext().getProcessor().log( level, ainfo, localizedMessage); } else { logger.log(level, localizedMessage); } }
protected void log(Level level, AnnotationInfo ainfo, String localizedMessage) throws AnnotationProcessorException { if (Level.SEVERE.equals(level)) { ainfo.getProcessingContext().getErrorHandler().error( new AnnotationProcessorException(localizedMessage, ainfo)); } else if (Level.WARNING.equals(level)) { ainfo.getProcessingContext().getErrorHandler().warning( new AnnotationProcessorException(localizedMessage, ainfo)); } else if (Level.FINE.equals(level)) { ainfo.getProcessingContext().getErrorHandler().fine( new AnnotationProcessorException(localizedMessage, ainfo)); } else if (ainfo != null) { ainfo.getProcessingContext().getProcessor().log( level, ainfo, localizedMessage); } else { logger.log(level, localizedMessage); } }
declaringClass = (Class) annElem; } else { throw new AnnotationProcessorException( localStrings.getLocalString( "enterprise.deployment.annotation.handlers.invalidtype",
declaringClass = (Class) annElem; } else { throw new AnnotationProcessorException( localStrings.getLocalString( "enterprise.deployment.annotation.handlers.invalidtype",
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException { ConcurrencyManagement cmAn = (ConcurrencyManagement) ainfo.getAnnotation(); ConcurrencyManagementType cmType = cmAn.value(); for (EjbContext ejbContext : ejbContexts) { EjbDescriptor ejbDesc = ejbContext.getDescriptor(); if (ejbDesc instanceof EjbSessionDescriptor) { EjbSessionDescriptor.ConcurrencyManagementType descCMType; switch(cmType) { case CONTAINER : descCMType = EjbSessionDescriptor.ConcurrencyManagementType.Container; break; case BEAN : descCMType = EjbSessionDescriptor.ConcurrencyManagementType.Bean; break; default : throw new AnnotationProcessorException("Unsupported concurrency management " + "type = " + cmType); } EjbSessionDescriptor sDesc = (EjbSessionDescriptor) ejbDesc; // Set value on descriptor unless it has been set by .xml sDesc.setConcurrencyManagementTypeIfNotSet(descCMType); } } return getDefaultProcessedResult(); }
protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException { ConcurrencyManagement cmAn = (ConcurrencyManagement) ainfo.getAnnotation(); ConcurrencyManagementType cmType = cmAn.value(); for (EjbContext ejbContext : ejbContexts) { EjbDescriptor ejbDesc = ejbContext.getDescriptor(); if (ejbDesc instanceof EjbSessionDescriptor) { EjbSessionDescriptor.ConcurrencyManagementType descCMType; switch(cmType) { case CONTAINER : descCMType = EjbSessionDescriptor.ConcurrencyManagementType.Container; break; case BEAN : descCMType = EjbSessionDescriptor.ConcurrencyManagementType.Bean; break; default : throw new AnnotationProcessorException("Unsupported concurrency management " + "type = " + cmType); } EjbSessionDescriptor sDesc = (EjbSessionDescriptor) ejbDesc; // Set value on descriptor unless it has been set by .xml sDesc.setConcurrencyManagementTypeIfNotSet(descCMType); } } return getDefaultProcessedResult(); }
throw new AnnotationProcessorException("@Lock is only permitted for " + "singleton session beans");