[jboss-cvs] JBossAS SVN: r68938 - in projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors: metadata and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 14 04:46:25 EST 2008


Author: wolfc
Date: 2008-01-14 04:46:25 -0500 (Mon, 14 Jan 2008)
New Revision: 68938

Added:
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/BeanInterceptorMetaDataBridge.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/EnvironmentInterceptorMetaDataBridge.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorComponentMetaDataLoaderFactory.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorMetaDataBridge.java
Log:
Integration with meta data bridge

Copied: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/BeanInterceptorMetaDataBridge.java (from rev 68904, projects/ejb3/trunk/metadata/src/test/java/org/jboss/ejb3/test/metadata/interceptor/BeanInterceptorMetaDataBridge.java)
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/BeanInterceptorMetaDataBridge.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/BeanInterceptorMetaDataBridge.java	2008-01-14 09:46:25 UTC (rev 68938)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.interceptors.metadata;
+
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptors;
+
+import org.jboss.ejb3.annotation.impl.InterceptorsImpl;
+import org.jboss.ejb3.metadata.MetaDataBridge;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMessageDrivenBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.AroundInvokesMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorBindingMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorBindingsMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorClassesMetaData;
+import org.jboss.metadata.ejb.spec.MethodParametersMetaData;
+import org.jboss.metadata.ejb.spec.NamedMethodMetaData;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class BeanInterceptorMetaDataBridge extends EnvironmentInterceptorMetaDataBridge<JBossEnterpriseBeanMetaData> implements MetaDataBridge<JBossEnterpriseBeanMetaData>
+{
+   private static final Logger log = Logger.getLogger(BeanInterceptorMetaDataBridge.class);
+
+   private static boolean add(InterceptorsImpl interceptors, ClassLoader classLoader, InterceptorBindingMetaData binding)
+   {
+      InterceptorClassesMetaData interceptorClassesMetaData;
+      if(binding.isTotalOrdering())
+      {
+         interceptorClassesMetaData = binding.getInterceptorOrder();
+      }
+      else
+      {
+         interceptorClassesMetaData = binding.getInterceptorClasses();
+      }
+      for(String interceptorClassName : interceptorClassesMetaData)
+      {
+         interceptors.addValue(loadClass(classLoader, interceptorClassName));
+      }
+      return true;
+   }
+   
+   private static Class<?> loadClass(ClassLoader classLoader, String name)
+   {
+      try
+      {
+         return classLoader.loadClass(name);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   @Override
+   public <A extends Annotation> A retrieveAnnotation(Class<A> annotationClass, JBossEnterpriseBeanMetaData beanMetaData, ClassLoader classLoader)
+   {
+      if(annotationClass == Interceptors.class)
+      {
+         InterceptorBindingsMetaData bindings = beanMetaData.getEjbJarMetaData().getAssemblyDescriptor().getInterceptorBindings();
+         if(bindings != null)
+         {
+            for(InterceptorBindingMetaData binding : bindings)
+            {
+               // For the method component
+               if(binding.getMethod() != null)
+                  continue;
+               
+               String ejbName = beanMetaData.getEjbName();
+               String bindingEjbName = binding.getEjbName();
+               if(bindingEjbName.equals("*") || bindingEjbName.equals(ejbName))
+               {
+                  //List<Class<?>> interceptorClasses = new ArrayList<Class<?>>();
+                  InterceptorsImpl interceptors = new InterceptorsImpl();
+                  add(interceptors, classLoader, binding);
+                  return annotationClass.cast(interceptors);
+               }
+            }
+         }
+      }
+      return super.retrieveAnnotation(annotationClass, beanMetaData, classLoader);
+   }
+
+   @Override
+   public <A extends Annotation> A retrieveAnnotation(Class<A> annotationClass, JBossEnterpriseBeanMetaData beanMetaData, ClassLoader classLoader, String methodName, String... parameterNames)
+   {
+      if(annotationClass == AroundInvoke.class)
+      {
+         AroundInvokesMetaData aroundInvokes = null;
+//         if(beanMetaData instanceof JBossGenericBeanMetaData)
+//            aroundInvokes = ((JBossGenericBeanMetaData) beanMetaData).getAroundInvokes();
+         if(beanMetaData instanceof JBossMessageDrivenBeanMetaData)
+            aroundInvokes = ((JBossMessageDrivenBeanMetaData) beanMetaData).getAroundInvokes();
+         else if(beanMetaData instanceof JBossSessionBeanMetaData)
+            aroundInvokes = ((JBossSessionBeanMetaData) beanMetaData).getAroundInvokes();
+         if(aroundInvokes != null)
+         {
+            Annotation annotation = getAroundInvokeAnnotation(aroundInvokes, methodName);
+            if(annotation != null)
+               return annotationClass.cast(annotation);
+         }
+      }
+      else if(annotationClass == Interceptors.class)
+      {
+         InterceptorBindingsMetaData bindings = beanMetaData.getEjbJarMetaData().getAssemblyDescriptor().getInterceptorBindings();
+         if(bindings != null)
+         {
+            InterceptorsImpl interceptors = new InterceptorsImpl();
+            for(InterceptorBindingMetaData binding : bindings)
+            {
+               // For the bean
+               if(binding.getMethod() == null)
+                  continue;
+               
+               NamedMethodMetaData method = binding.getMethod();
+               
+               // TODO: this is weird, it should have been caught earlier (invalid xml)
+               if(method.getMethodName() == null)
+                  continue;
+               
+               if(method.getMethodName().equals(methodName))
+               {
+                  MethodParametersMetaData methodParams = method.getMethodParams();
+                  if(methodParams == null)
+                     add(interceptors, classLoader, binding);
+                  else
+                  {
+                     if(Arrays.equals(methodParams.toArray(), parameterNames))
+                        add(interceptors, classLoader, binding);
+                  }
+               }
+            }
+            if(interceptors.value().length > 0)
+               return annotationClass.cast(interceptors);
+         }
+      }
+      return super.retrieveAnnotation(annotationClass, beanMetaData, classLoader, methodName, parameterNames);
+   }
+}

Copied: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/EnvironmentInterceptorMetaDataBridge.java (from rev 68904, projects/ejb3/trunk/metadata/src/test/java/org/jboss/ejb3/test/metadata/interceptor/EnvironmentInterceptorMetaDataBridge.java)
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/EnvironmentInterceptorMetaDataBridge.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/EnvironmentInterceptorMetaDataBridge.java	2008-01-14 09:46:25 UTC (rev 68938)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.interceptors.metadata;
+
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+
+import org.jboss.ejb3.annotation.impl.AroundInvokeImpl;
+import org.jboss.ejb3.annotation.impl.PostConstructImpl;
+import org.jboss.ejb3.annotation.impl.PreDestroyImpl;
+import org.jboss.ejb3.metadata.MetaDataBridge;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.spec.AroundInvokesMetaData;
+import org.jboss.metadata.javaee.spec.Environment;
+import org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData;
+
+/**
+ * Does only interceptor stuff.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class EnvironmentInterceptorMetaDataBridge<M extends Environment> implements MetaDataBridge<M>
+{
+   private static final Logger log = Logger.getLogger(EnvironmentInterceptorMetaDataBridge.class);
+
+   protected <T extends Annotation> T createAnnotationImpl(Class<T> annotationImplType)
+   {
+      try
+      {
+         return annotationImplType.newInstance();
+      }
+      catch (InstantiationException e)
+      {
+         throw new RuntimeException(e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   protected AroundInvoke getAroundInvokeAnnotation(AroundInvokesMetaData callbacks, String methodName)
+   {
+      if(callbacks == null || callbacks.isEmpty())
+         return null;
+      
+      assert callbacks.size() == 1;
+      String callbackMethodName = callbacks.get(0).getMethodName();
+      if(methodName.equals(callbackMethodName))
+         return new AroundInvokeImpl();
+      return null;
+   }
+   
+   private <T extends Annotation> T getLifeCycleAnnotation(LifecycleCallbacksMetaData callbacks, Class<T> annotationImplType, String methodName)
+   {
+      if(callbacks == null || callbacks.isEmpty())
+         return null;
+      
+      assert callbacks.size() == 1;
+      // TODO: callbacks[0].className
+      String callbackMethodName = callbacks.get(0).getMethodName();
+      if(methodName.equals(callbackMethodName))
+         return createAnnotationImpl(annotationImplType);
+      return null;
+   }
+   
+   public <A extends Annotation> A retrieveAnnotation(Class<A> annotationClass, M metaData, ClassLoader classLoader)
+   {
+      return null;
+   }
+
+   public <A extends Annotation> A retrieveAnnotation(Class<A> annotationClass, M metaData, ClassLoader classLoader, String methodName, String... parameterNames)
+   {
+      if(log.isTraceEnabled()) log.trace("retrieve annotation " + annotationClass + " on " + metaData + " for " + methodName + " " + Arrays.toString(parameterNames));
+      if(annotationClass == PostConstruct.class)
+      {
+         PostConstruct lifeCycleAnnotation = getLifeCycleAnnotation(metaData.getPostConstructs(), PostConstructImpl.class, methodName);
+         if(lifeCycleAnnotation != null)
+            return annotationClass.cast(lifeCycleAnnotation);
+      }
+      else if(annotationClass == PreDestroy.class)
+      {
+         PreDestroy lifeCycleAnnotation = getLifeCycleAnnotation(metaData.getPreDestroys(), PreDestroyImpl.class, methodName);
+         if(lifeCycleAnnotation != null)
+            return annotationClass.cast(lifeCycleAnnotation);
+      }
+      return null;
+   }
+}

Copied: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorComponentMetaDataLoaderFactory.java (from rev 68904, projects/ejb3/trunk/metadata/src/test/java/org/jboss/ejb3/test/metadata/interceptor/InterceptorComponentMetaDataLoaderFactory.java)
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorComponentMetaDataLoaderFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorComponentMetaDataLoaderFactory.java	2008-01-14 09:46:25 UTC (rev 68938)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.interceptors.metadata;
+
+import java.util.List;
+
+import org.jboss.ejb3.metadata.ComponentMetaDataLoaderFactory;
+import org.jboss.ejb3.metadata.MetaDataBridge;
+import org.jboss.ejb3.metadata.plugins.loader.BridgedMetaDataLoader;
+import org.jboss.ejb3.metadata.spi.signature.ClassSignature;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorsMetaData;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.metadata.spi.signature.Signature;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorComponentMetaDataLoaderFactory implements ComponentMetaDataLoaderFactory<JBossEnterpriseBeanMetaData>
+{
+   private static final Logger log = Logger.getLogger(InterceptorComponentMetaDataLoaderFactory.class);
+
+   private List<MetaDataBridge<InterceptorMetaData>> defaultBridges;
+   
+   public InterceptorComponentMetaDataLoaderFactory(List<MetaDataBridge<InterceptorMetaData>> defaultBridges)
+   {
+      assert defaultBridges != null : "defaultBridges is null";
+      assert !defaultBridges.isEmpty() : "defaultBridges is empty"; // equally stupid
+      this.defaultBridges = defaultBridges;
+   }
+   
+   public MetaDataRetrieval createComponentMetaDataRetrieval(JBossEnterpriseBeanMetaData beanMetaData, Signature signature, ScopeKey key, ClassLoader classLoader)
+   {
+      if(signature instanceof ClassSignature)
+      {
+         InterceptorMetaData interceptorMetaData = findInterceptor(beanMetaData, signature.getName());
+         if(interceptorMetaData != null)
+            return new BridgedMetaDataLoader<InterceptorMetaData>(key, interceptorMetaData, classLoader, defaultBridges);
+      }
+      return null;
+   }
+
+   private InterceptorMetaData findInterceptor(JBossEnterpriseBeanMetaData beanMetaData, String name)
+   {
+      InterceptorsMetaData interceptors = beanMetaData.getEjbJarMetaData().getInterceptors();
+      for(InterceptorMetaData interceptorMetaData : interceptors)
+      {
+         if(interceptorMetaData.getInterceptorClass().equals(name))
+            return interceptorMetaData;
+      }
+      return null;
+   }
+   
+}

Copied: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorMetaDataBridge.java (from rev 68904, projects/ejb3/trunk/metadata/src/test/java/org/jboss/ejb3/test/metadata/interceptor/InterceptorMetaDataBridge.java)
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorMetaDataBridge.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/metadata/InterceptorMetaDataBridge.java	2008-01-14 09:46:25 UTC (rev 68938)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.interceptors.metadata;
+
+import java.lang.annotation.Annotation;
+
+import javax.interceptor.AroundInvoke;
+
+import org.jboss.ejb3.metadata.MetaDataBridge;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.spec.InterceptorMetaData;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorMetaDataBridge extends EnvironmentInterceptorMetaDataBridge<InterceptorMetaData> implements MetaDataBridge<InterceptorMetaData>
+{
+   private static final Logger log = Logger.getLogger(InterceptorMetaDataBridge.class);
+
+   @Override
+   public <A extends Annotation> A retrieveAnnotation(Class<A> annotationClass, InterceptorMetaData metaData, ClassLoader classLoader)
+   {
+      return super.retrieveAnnotation(annotationClass, metaData, classLoader);
+   }
+
+   @Override
+   public <A extends Annotation> A retrieveAnnotation(Class<A> annotationClass, InterceptorMetaData interceptorMetaData, ClassLoader classLoader, String methodName, String... parameterNames)
+   {
+      if(annotationClass == AroundInvoke.class)
+      {
+         Annotation annotation = getAroundInvokeAnnotation(interceptorMetaData.getAroundInvokes(), methodName);
+         if(annotation != null)
+            return annotationClass.cast(annotation);
+      }
+      return super.retrieveAnnotation(annotationClass, interceptorMetaData, classLoader, methodName, parameterNames);
+   }
+}




More information about the jboss-cvs-commits mailing list