1 8 package org.codehaus.aspectwerkz.aspect; 9 10 import java.lang.reflect.Constructor ; 11 12 import org.codehaus.aspectwerkz.exception.DefinitionException; 13 import org.codehaus.aspectwerkz.DeploymentModel; 14 15 20 public abstract class AbstractMixinFactory implements MixinFactory { 21 22 protected final Class m_mixinClass; 23 protected final DeploymentModel m_deploymentModel; 24 protected Constructor m_defaultConstructor; 25 protected Constructor m_perClassConstructor; 26 protected Constructor m_perInstanceConstructor; 27 28 34 public AbstractMixinFactory(final Class mixinClass, final DeploymentModel deploymentModel) { 35 m_mixinClass = mixinClass; 36 m_deploymentModel = deploymentModel; 37 try { 38 if (m_deploymentModel.equals(DeploymentModel.PER_CLASS)) { 39 m_perClassConstructor = m_mixinClass.getConstructor(new Class []{Class .class}); 40 } else if (m_deploymentModel.equals(DeploymentModel.PER_INSTANCE)) { 41 m_perInstanceConstructor = m_mixinClass.getConstructor(new Class []{Object .class}); 42 } else if (m_deploymentModel.equals(DeploymentModel.PER_JVM)) { 43 m_defaultConstructor = m_mixinClass.getConstructor(new Class []{}); 44 } else { 45 throw new DefinitionException( 46 "deployment model for [" + m_mixinClass.getName() + "] is not supported [" + 47 m_deploymentModel + "]" 48 ); 49 } 50 } catch (NoSuchMethodException e1) { 51 try { 52 m_defaultConstructor = m_mixinClass.getConstructor(new Class []{}); 53 } catch (NoSuchMethodException e2) { 54 throw new DefinitionException( 55 "mixin [" + m_mixinClass.getName() + 56 "] does not have a constructor that matches with its deployment model or a non-argument default constructor" 57 ); 58 } 59 } 60 } 61 62 67 public abstract Object mixinOf(); 68 69 75 public abstract Object mixinOf(Class klass); 76 77 83 public abstract Object mixinOf(Object instance); 84 } | Popular Tags |