Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, Red Hat Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.as.ejb3.component.entity;
 
 
 
 import  org.jboss.invocation.ImmediateInterceptorFactory;
 import  org.jboss.invocation.InterceptorFactory;
 import  org.jboss.invocation.Interceptors;
 import  org.jboss.invocation.proxy.MethodIdentifier;
 
 import static org.jboss.as.ejb3.EjbMessages.MESSAGES;

configurator that sets up interceptors for an EJB's object view

Author(s):
Stuart Douglas
 
 public class EntityBeanObjectViewConfigurator implements ViewConfigurator {
 
     @Override
     public void configure(final DeploymentPhaseContext contextfinal ComponentConfiguration componentConfigurationfinal ViewDescription descriptionfinal ViewConfiguration configurationthrows DeploymentUnitProcessingException {
 
 
         for (final Method method : configuration.getProxyFactory().getCachedMethods()) {
 
             if (method.getName().equals("getPrimaryKey") && method.getParameterTypes().length == 0) {
                 configuration.addViewInterceptor(method...);
             } else if (method.getName().equals("remove") && method.getParameterTypes().length == 0) {
                 Method remove = resolveRemoveMethod(componentConfiguration.getComponentClass(), indexcomponentConfiguration.getComponentName());
                 configuration.addViewInterceptor(methodgetEjbRemoveInterceptorFactory(remove), ..);
             } else if (method.getName().equals("isIdentical") && method.getParameterTypes().length == 1 &&
                     (method.getParameterTypes()[0] == EJBLocalObject.class || method.getParameterTypes()[0] == EJBObject.class)) {
             } else if (method.getName().equals("getEJBLocalHome") && method.getParameterTypes().length == 0) {
                 final EntityGetHomeInterceptorFactory factory = new EntityGetHomeInterceptorFactory();
                 configuration.addViewInterceptor(methodfactory..);
                 final EntityBeanComponentDescription entityBeanComponentDescription = (EntityBeanComponentDescriptioncomponentConfiguration.getComponentDescription();
                 componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
                     @Override
                     public void configureDependency(final ServiceBuilder<?> serviceBuilderfinal ComponentStartService servicethrows DeploymentUnitProcessingException {
                         serviceBuilder.addDependency(entityBeanComponentDescription.getEjbLocalHomeView().getServiceName(), ComponentView.classfactory.getViewToCreate());
                     }
                 });
 
             } else if (method.getName().equals("getEJBHome") && method.getParameterTypes().length == 0) {
                final EntityGetHomeInterceptorFactory factory = new EntityGetHomeInterceptorFactory();
                configuration.addViewInterceptor(methodfactory..);
                final EntityBeanComponentDescription entityBeanComponentDescription = (EntityBeanComponentDescriptioncomponentConfiguration.getComponentDescription();
                componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
                    @Override
                    public void configureDependency(final ServiceBuilder<?> serviceBuilderfinal ComponentStartService servicethrows DeploymentUnitProcessingException {
                        serviceBuilder.addDependency(entityBeanComponentDescription.getEjbHomeView().getServiceName(), ComponentView.classfactory.getViewToCreate());
                    }
                });
            } else if (method.getName().equals("getHandle") && method.getParameterTypes().length == 0) {
                //ignore, handled client side
            }  else if ((method.getName().equals("hashCode") && method.getParameterTypes().length == 0) || method.getName().equals("equals") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Object.class) {
            } else {
                final Method componentMethod = ClassReflectionIndexUtil.findMethod(indexcomponentConfiguration.getComponentClass(), MethodIdentifier.getIdentifierForMethod(method));
                if (componentMethod == null) {
                    handleNonBeanMethod(componentConfigurationconfigurationindexmethod);
                } else {
                    if(!Modifier.isPublic(componentMethod.getModifiers())) {
                        throw ..ejbBusinessMethodMustBePublic(componentMethod);
                    }
                    configuration.addViewInterceptor(methodnew ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)), ..);
                }
            }
        }
        configuration.addClientPostConstructInterceptor(Interceptors.getTerminalInterceptorFactory(), ..);
        configuration.addClientPreDestroyInterceptor(Interceptors.getTerminalInterceptorFactory(), ..);
    }

    
Handle method found on the view that is not implemented by the entity bean impl. By default it will do nothing with it.

Parameters:
componentConfiguration
configuration
index
method
    protected void handleNonBeanMethod(final ComponentConfiguration componentConfigurationfinal ViewConfiguration configurationfinal DeploymentReflectionIndex indexfinal Method methodthrows DeploymentUnitProcessingException {
        if(method.getDeclaringClass() != Object.class && method.getDeclaringClass() != WriteReplaceInterface.class) {
            throw ..couldNotFindViewMethodOnEjb(methodconfiguration.getViewClass().getName(), componentConfiguration.getComponentName());
        }
    }
    protected InterceptorFactory getEjbCreateInterceptorFactory() {
    }
    protected InterceptorFactory getEjbRemoveInterceptorFactory(final Method remove) {
        //for BMP beans we just invoke the ejb remove method as normal, and allow the ejb remove
        //method to handle the actual removal
        return new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(remove));
    }
    private Method resolveRemoveMethod(final Class<?> componentClassfinal DeploymentReflectionIndex indexfinal String ejbNamethrows DeploymentUnitProcessingException {
        Class<?> clazz = componentClass;
        while (clazz != Object.class) {
            final ClassReflectionIndex<?> classIndex = index.getClassIndex(clazz);
            Method ret = classIndex.getMethod(."ejbRemove");
            if (ret != null) {
                return ret;
            }
            clazz = clazz.getSuperclass();
        }
        throw .failToResolveEjbRemoveForInterface(ejbName);
    }
New to GrepCode? Check out our FAQ X