1 22 package org.jboss.aop.microcontainer.integration; 23 24 import org.jboss.joinpoint.plugins.BasicConstructorJoinPoint; 25 import org.jboss.joinpoint.plugins.BasicJoinpointFactory; 26 import org.jboss.joinpoint.spi.ConstructorJoinpoint; 27 import org.jboss.joinpoint.spi.JoinpointException; 28 import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory; 29 import org.jboss.reflect.spi.ClassInfo; 30 import org.jboss.reflect.spi.ConstructorInfo; 31 import org.jboss.reflect.spi.TypeInfoFactory; 32 import org.jboss.repository.spi.MetaDataContext; 33 34 43 public class AOPJoinpointFactory extends BasicJoinpointFactory 44 { 45 46 static volatile ConstructorInfo ctorInfo; 47 48 53 public AOPJoinpointFactory(ClassInfo classInfo, MetaDataContext metaDataContext) 54 { 55 super(classInfo, metaDataContext); 56 } 57 58 public ConstructorJoinpoint getConstructorJoinpoint(ConstructorInfo constructorInfo) throws JoinpointException 59 { 60 ConstructorInfo info = getAOPJoinpointConstructorInfo(constructorInfo); 61 62 if (info != null) 63 { 64 return createAOPConstructorJoinpoint(info, constructorInfo); 65 } 66 else 67 { 68 return super.getConstructorJoinpoint(constructorInfo); 69 } 70 } 71 72 private synchronized ConstructorInfo getAOPJoinpointConstructorInfo(ConstructorInfo currentConstructorInfo) throws JoinpointException 73 { 74 if (ctorInfo != null) 75 { 76 return ctorInfo; 77 } 78 79 Class clazz = AOPDeployedChecker.getClassIfExists( 80 classInfo.getType().getClassLoader(), 81 "org.jboss.aop.microcontainer.integration.AOPConstructorJoinpoint"); 82 83 if (clazz == null) 84 { 85 return null; 86 } 87 88 TypeInfoFactory factory = new IntrospectionTypeInfoFactory(); 89 ClassInfo info = (ClassInfo)factory.getTypeInfo(clazz); 90 ConstructorInfo[] ctors = info.getDeclaredConstructors(); 91 for (int i = 0 ; i < ctors.length ; i++) 92 { 93 if (ctors[i].getParameterTypes().length == 2) 94 { 95 if (ctors[i].getParameterTypes()[0].getName().equals(ConstructorInfo.class.getName()) == false) 96 { 97 continue; 98 } 99 100 if (ctors[i].getParameterTypes()[1].getName().equals(MetaDataContext.class.getName()) == false) 101 { 102 continue; 103 } 104 ctorInfo = ctors[i]; 105 break; 106 } 107 } 108 109 if (ctorInfo == null) 110 { 111 throw new JoinpointException("No constructor found with the reqiured signature AOPConstructorJoinpoint(ConstructorInfo, MetadataContext)"); 112 } 113 return ctorInfo; 114 } 115 116 private ConstructorJoinpoint createAOPConstructorJoinpoint(ConstructorInfo info, ConstructorInfo aopCtorInfo) throws JoinpointException 117 { 118 ConstructorJoinpoint jp = new BasicConstructorJoinPoint(info); 119 jp.setArguments(new Object [] {aopCtorInfo, metaDataContext}); 120 try 121 { 122 return (ConstructorJoinpoint)jp.dispatch(); 123 } 124 catch (Throwable e) 125 { 126 throw new JoinpointException("Error calling AOPConstructorJoinpoint constructor", e); 127 } 128 129 } 130 } 131 | Popular Tags |