private void doConfigure(final DeploymentPhaseContext context, final EJBComponentDescription ejbComponentDescription, final ViewConfiguration viewConfiguration) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = context.getDeploymentUnit(); final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION); final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); final List<Method> viewMethods = viewConfiguration.getProxyFactory().getCachedMethods(); for (final Method method : viewMethods) { final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(method.getReturnType(), method.getName(), method.getParameterTypes()); final List<InterceptorFactory> aroundInvokesApplicableForMethod = new ArrayList<InterceptorFactory>(); final List<InterceptorFactory> aroundTimeoutsApplicableForMethod = new ArrayList<InterceptorFactory>();
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException { // Create method indexes final DeploymentReflectionIndex reflectionIndex = context.getDeploymentUnit().getAttachment(REFLECTION_INDEX); final List<Method> methods = configuration.getProxyFactory().getCachedMethods(); for (final Method method : methods) { MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method); Method componentMethod = ClassReflectionIndexUtil.findMethod(reflectionIndex, componentConfiguration.getComponentClass(), methodIdentifier); if (componentMethod == null && method.getDeclaringClass().isInterface() && (method.getModifiers() & (ABSTRACT | PUBLIC | STATIC)) == PUBLIC) { // no component method and the interface method is defaulted, so we really do want to invoke on the interface method componentMethod = method; } if (componentMethod != null) { if ((BRIDGE & componentMethod.getModifiers()) != 0) { Method other = findRealMethodForBridgeMethod(componentMethod, componentConfiguration, reflectionIndex, methodIdentifier); //try and find the non-bridge method to delegate to if(other != null) { componentMethod = other; } } configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)), InterceptorOrder.View.COMPONENT_DISPATCHER); configuration.addClientInterceptor(method, CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER); configuration.getViewToComponentMethodMap().put(method, componentMethod); } } configuration.addClientPostConstructInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR); configuration.addClientPreDestroyInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR); }
protected boolean createPermissions(final EjbJaccConfig ejbJaccConfig, final EJBComponentDescription description, final EJBViewConfiguration ejbViewConfiguration, final Method viewMethod, final DeploymentReflectionIndex index, final ApplicableMethodInformation<EJBMethodSecurityAttribute> permissions) { MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(viewMethod); EJBMethodSecurityAttribute ejbMethodSecurityMetaData = permissions.getViewAttribute(ejbViewConfiguration.getMethodIntf(), viewMethod); final Method classMethod = ClassReflectionIndexUtil.findMethod(index, ejbViewConfiguration.getComponentConfiguration().getComponentClass(), viewMethod); if (ejbMethodSecurityMetaData == null) { if (classMethod != null) { methodIdentifier = MethodIdentifier.getIdentifierForMethod(classMethod); final EJBMethodPermission permission = new EJBMethodPermission(description.getEJBName(), methodIdentifier.getName(), interfaceType.name(), methodIdentifier.getParameterTypes());
private EJBBusinessMethod getEJBBusinessMethod(final MethodIdentifier method) { final ClassLoader classLoader = this.getComponentClass().getClassLoader(); final String methodName = method.getName(); final String[] types = method.getParameterTypes(); if (types == null || types.length == 0) { return new EJBBusinessMethod(methodName); } Class<?>[] paramTypes = new Class<?>[types.length]; int i = 0; for (String type : types) { try { paramTypes[i++] = PrimitiveClassLoaderUtil.loadClass(type, classLoader); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } return new EJBBusinessMethod(methodName, paramTypes); }
@Override public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException { final StatefulComponentDescription statefulComponentDescription = (StatefulComponentDescription) componentConfiguration.getComponentDescription(); final Collection<StatefulRemoveMethod> removeMethods = statefulComponentDescription.getRemoveMethods(); if (removeMethods.isEmpty()) { return; } for (final Method viewMethod : configuration.getProxyFactory().getCachedMethods()) { final MethodIdentifier viewMethodIdentifier = MethodIdentifier.getIdentifierForMethod(viewMethod); for (final StatefulRemoveMethod removeMethod : removeMethods) { if (removeMethod.methodIdentifier.equals(viewMethodIdentifier)) { //we do not want to add this if it is the Ejb(Local)Object.remove() method, as that is handed elsewhere final boolean object = EJBObject.class.isAssignableFrom(configuration.getViewClass()) || EJBLocalObject.class.isAssignableFrom(configuration.getViewClass()); if (!object || !viewMethodIdentifier.getName().equals("remove") || viewMethodIdentifier.getParameterTypes().length != 0) { configuration.addViewInterceptor(viewMethod, new ImmediateInterceptorFactory(new StatefulRemoveInterceptor(removeMethod.retainIfException)), InterceptorOrder.View.SESSION_REMOVE_INTERCEPTOR); } break; } } } } });
@Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA); final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); final DeploymentReflectionIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX); } else if(ejbNameRegexService.isEjbNameRegexAllowed()) { Pattern pattern = Pattern.compile(binding.getEjbName()); for (final ComponentDescription componentDescription : eeModuleDescription.getComponentDescriptions()) { if(componentDescription instanceof EJBComponentDescription) { String ejbName = ((EJBComponentDescription) componentDescription).getEJBName(); for (final ComponentDescription componentDescription : eeModuleDescription.getComponentDescriptions()) { final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName(), methodData.getMethodParams().size()); for (final Method method : methods) { boolean match = true; final List<InterceptorBindingMetaData> methodBindings = entry.getValue(); boolean totalOrder = methodLevelAbsoluteOrder.containsKey(method); final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = context.getDeploymentUnit(); final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(REFLECTION_INDEX); final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE); final ClassReflectionIndex componentClassIndex = deploymentReflectionIndex.getClassIndex(configuration.getComponentClass()); final Constructor<?> constructor = componentClassIndex.getConstructor(EMPTY_CLASS_ARRAY); if (constructor == null) { throw EeLogger.ROOT_LOGGER.defaultConstructorNotFound(configuration.getComponentClass()); final InterceptorEnvironment interceptorEnvironment = moduleDescription.getInterceptorEnvironment().get(interceptorClassName); if (interceptorEnvironment != null) { final Constructor<?> constructor = interceptorIndex.getConstructor(EMPTY_CLASS_ARRAY); if (constructor == null) { throw EeLogger.ROOT_LOGGER.defaultConstructorNotFoundOnComponent(interceptorClassName, configuration.getComponentClass()); final MethodIdentifier identifier = MethodIdentifier.getIdentifier(method.getReturnType(), method.getName(), method.getParameterTypes());
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(); String methodName = aroundInvoke.getMethodName(); MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(Object.class, methodName, InvocationContext.class); builder.setAroundInvoke(methodIdentifier); if (aroundInvoke.getClassName() == null || aroundInvoke.getClassName().isEmpty()) { eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build()); } else { eeModuleDescription.addInterceptorMethodOverride(aroundInvoke.getClassName(), builder.build()); final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(); String methodName = aroundTimeout.getMethodName(); MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(Object.class, methodName, InvocationContext.class); builder.setAroundTimeout(methodIdentifier); if (aroundTimeout.getClassName() == null || aroundTimeout.getClassName().isEmpty()) { eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build()); final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(); String methodName = postConstruct.getMethodName(); MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class); builder.setPostConstruct(methodIdentifier); if (postConstruct.getClassName() == null || postConstruct.getClassName().isEmpty()) { final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(); String methodName = preDestroy.getMethodName(); MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class); builder.setPreDestroy(methodIdentifier); if (preDestroy.getClassName() == null || preDestroy.getClassName().isEmpty()) { final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX); for(final Method method : methods) { final Boolean retainIfException = removeMethod.getRetainIfException(); final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method); if(retainIfException == null) { for(final Method method : methods) { final Boolean retainIfException = removeMethod.getRetainIfException(); final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method); if(retainIfException == null) {
final Method method = classIndex.getMethod(entry.getKey()); if (method != null) { for (Method method : (Iterable<Method>)classIndex.getMethods()) { methodIdentifiers.add(MethodIdentifier.getIdentifierForMethod(method));
private void processAroundInvoke(final EEModuleDescription eeModuleDescription, final AnnotationTarget target) throws DeploymentUnitProcessingException { if (!(target instanceof MethodInfo)) { throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(AROUND_INVOKE_ANNOTATION_NAME); } final MethodInfo methodInfo = MethodInfo.class.cast(target); final ClassInfo classInfo = methodInfo.declaringClass(); final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString()); final List<AnnotationInstance> classAroundInvokes = classInfo.annotations().get(AROUND_INVOKE_ANNOTATION_NAME); if(classAroundInvokes.size() > 1) { throw EeLogger.ROOT_LOGGER.aroundInvokeAnnotationUsedTooManyTimes(classInfo.name(), classAroundInvokes.size()); } validateArgumentType(classInfo, methodInfo); InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription()); builder.setAroundInvoke(MethodIdentifier.getIdentifier(Object.class, methodInfo.name(), InvocationContext.class)); classDescription.setInterceptorClassDescription(builder.build()); }
@Override public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException { final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription(); for (final Method method : configuration.getProxyFactory().getCachedMethods()) { //we need the component method to get the correct declaring class final Method componentMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, componentClass, method); if (componentMethod != null) { if (componentDescription.getAsynchronousClasses().contains(componentMethod.getDeclaringClass().getName())) { addAsyncInterceptor(configuration, method, isSecurityDomainKnown); configuration.addAsyncMethod(method); } else { MethodIdentifier id = MethodIdentifier.getIdentifierForMethod(method); if (componentDescription.getAsynchronousMethods().contains(id)) { addAsyncInterceptor(configuration, method, isSecurityDomainKnown); configuration.addAsyncMethod(method); } } } } } });
private void setProperty(final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> dataSourceClass, final Map<String, String> properties, final String name, final Object value) { // Ignore defaulted values if (value == null || "".equals(value)) return; if (value instanceof Integer && ((Integer) value).intValue() == -1) return; StringBuilder builder = new StringBuilder("set").append(name); builder.setCharAt(3, Character.toUpperCase(name.charAt(0))); final String methodName = builder.toString(); final Class<?> paramType = value.getClass(); MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, paramType); Method setterMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, dataSourceClass, methodIdentifier); if (setterMethod != null) { properties.put(name, value.toString()); } else if (paramType == Integer.class) { //if this is an Integer also look for int setters (WFLY-1364) methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, int.class); setterMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, dataSourceClass, methodIdentifier); if (setterMethod != null) { properties.put(name, value.toString()); } } else if (paramType == Boolean.class) { methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, boolean.class); setterMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, dataSourceClass, methodIdentifier); if (setterMethod != null) { properties.put(name, value.toString()); } } }
private void addDefaultMethods(final Class<?> componentClass, Set<MethodIdentifier> foundMethods, Map<Class<?>, Set<Method>> defaultMethodsByInterface, Class<?>[] interfaces) { for (Class<?> i : interfaces) { if (! defaultMethodsByInterface.containsKey(i)) { Set<Method> set = methodSet(); defaultMethodsByInterface.put(i, set); final ClassReflectionIndex interfaceIndex = deploymentReflectionIndex.getClassIndex(i); for (Method method : interfaceIndex.getMethods()) { final MethodIdentifier identifier = MethodIdentifier.getIdentifierForMethod(method); if ((method.getModifiers() & (STATIC | PUBLIC | ABSTRACT)) == PUBLIC && ! classContains(componentClass, identifier) && foundMethods.add(identifier)) { set.add(method); } } } addDefaultMethods(componentClass, foundMethods, defaultMethodsByInterface, i.getInterfaces()); } }
/** * Finds and returns a method corresponding to the passed <code>method</code>, which may be declared in the super class * of the passed <code>classReflectionIndex</code>. * <p/> * <p/> * Throws {@link org.jboss.as.server.deployment.DeploymentUnitProcessingException} if no such method is found. * * @param deploymentReflectionIndex The deployment reflection index * @param clazz The class * @param method The method being searched for * @return * @throws org.jboss.as.server.deployment.DeploymentUnitProcessingException * If no such method is found */ public static Method findRequiredMethod(final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> clazz, final Method method) throws DeploymentUnitProcessingException { Assert.checkNotNullParam("method", method); final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method); return findRequiredMethod(deploymentReflectionIndex, clazz, methodIdentifier); }
/** * Get a method declared on this object. * * @param methodIdentifier the method identifier * @return the method, or {@code null} if no method of that description exists */ public Method getMethod(MethodIdentifier methodIdentifier) { final Map<ParamNameList, Map<String, Method>> nameMap = methodsByTypeName.get(methodIdentifier.getName()); if (nameMap == null) { return null; } final Map<String, Method> paramsMap = nameMap.get(createParamNameList(methodIdentifier.getParameterTypes())); if (paramsMap == null) { return null; } return paramsMap.get(methodIdentifier.getReturnType()); }
final MethodIdentifier ejbRemoveIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbRemove"); final MethodIdentifier ejbActivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbActivate"); final MethodIdentifier ejbPassivateIdentifier = MethodIdentifier.getIdentifier(void.class, "ejbPassivate"); final Method method = index.getMethod(ejbActivateIdentifier); if(method != null) { final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(); final Method method = index.getMethod(ejbPassivateIdentifier); if(method != null) { final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(); final Method method = index.getMethod(ejbRemoveIdentifier); if(method != null) { final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
public Set<MethodIdentifier> getTimerMethods() { final Set<MethodIdentifier> methods = new HashSet<MethodIdentifier>(); if (timeoutMethod != null) { methods.add(MethodIdentifier.getIdentifierForMethod(timeoutMethod)); } for (Method method : scheduleMethods.keySet()) { methods.add(MethodIdentifier.getIdentifierForMethod(method)); } return methods; }
MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName); builder.setPostConstruct(methodIdentifier); eeModuleDescription.addInterceptorMethodOverride(className, builder.build()); MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName); builder.setPreDestroy(methodIdentifier); eeModuleDescription.addInterceptorMethodOverride(className, builder.build());
private void processTransactionAttributeAnnotation(final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, MethodIntf methodIntf, final EJBComponentDescription componentConfiguration) { final RuntimeAnnotationInformation<TransactionAttributeType> data = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, TransactionAttribute.class); for (Map.Entry<String, List<TransactionAttributeType>> entry : data.getClassAnnotations().entrySet()) { if (!entry.getValue().isEmpty()) { //we can't specify both methodIntf and class name final String className = methodIntf == null ? entry.getKey() : null; componentConfiguration.getTransactionAttributes().setAttribute(methodIntf, className, entry.getValue().get(0)); } } for (Map.Entry<Method, List<TransactionAttributeType>> entry : data.getMethodAnnotations().entrySet()) { if (!entry.getValue().isEmpty()) { final MethodIdentifier method = MethodIdentifier.getIdentifierForMethod(entry.getKey()); componentConfiguration.getTransactionAttributes().setAttribute(methodIntf, entry.getValue().get(0), entry.getKey().getDeclaringClass().getName(), method.getName(), method.getParameterTypes()); } } }