1 4 package com.tc.aspectwerkz.aspect; 5 6 import java.lang.reflect.Constructor ; 7 8 9 import com.tc.aspectwerkz.DeploymentModel; 10 import com.tc.aspectwerkz.exception.DefinitionException; 11 12 17 public abstract class AbstractMixinFactory implements MixinFactory { 18 19 protected final Class m_mixinClass; 20 protected final DeploymentModel m_deploymentModel; 21 protected Constructor m_defaultConstructor; 22 protected Constructor m_perClassConstructor; 23 protected Constructor m_perInstanceConstructor; 24 25 31 public AbstractMixinFactory(final Class mixinClass, final DeploymentModel deploymentModel) { 32 m_mixinClass = mixinClass; 33 m_deploymentModel = deploymentModel; 34 try { 35 if (m_deploymentModel.equals(DeploymentModel.PER_CLASS)) { 36 m_perClassConstructor = m_mixinClass.getConstructor(new Class []{Class .class}); 37 } else if (m_deploymentModel.equals(DeploymentModel.PER_INSTANCE)) { 38 m_perInstanceConstructor = m_mixinClass.getConstructor(new Class []{Object .class}); 39 } else if (m_deploymentModel.equals(DeploymentModel.PER_JVM)) { 40 m_defaultConstructor = m_mixinClass.getConstructor(new Class []{}); 41 } else { 42 throw new DefinitionException( 43 "deployment model for [" + m_mixinClass.getName() + "] is not supported [" + 44 m_deploymentModel + "]" 45 ); 46 } 47 } catch (NoSuchMethodException e1) { 48 try { 49 m_defaultConstructor = m_mixinClass.getConstructor(new Class []{}); 50 } catch (NoSuchMethodException e2) { 51 throw new DefinitionException( 52 "mixin [" + m_mixinClass.getName() + 53 "] does not have a constructor that matches with its deployment model or a non-argument default constructor" 54 ); 55 } 56 } 57 } 58 59 64 public abstract Object mixinOf(); 65 66 72 public abstract Object mixinOf(Class klass); 73 74 80 public abstract Object mixinOf(Object instance); 81 } | Popular Tags |