001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.aspectwerkz.aspect.container;
005:
006: import com.tc.aspectwerkz.DeploymentModel;
007: import com.tc.aspectwerkz.transform.inlining.AsmHelper;
008: import com.tc.aspectwerkz.util.ContextClassLoader;
009:
010: /**
011: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
012: */
013: public class AspectFactoryManager {
014:
015: public static String getAspectFactoryClassName(
016: String aspectClassName, String aspectQualifiedName) {
017: return aspectClassName.replace('.', '/')
018: + "$"
019: + aspectQualifiedName.replace('.', '/').replace('/',
020: '_') + "_AWFactory";
021: }
022:
023: // TODO refactor for offline stuff -genjp
024:
025: /**
026: * Ensure that the aspect factory is loaded.
027: *
028: * @param aspectFactoryClassName
029: * @param aspectClassName
030: * @param aspectQualifiedName
031: * @param containerClassName
032: * @param rawParameters
033: * @param loader
034: * @param deploymentModelAsString
035: */
036: public static void loadAspectFactory(String aspectFactoryClassName,
037: String uuid, String aspectClassName,
038: String aspectQualifiedName, String containerClassName,
039: String rawParameters, ClassLoader loader,
040: String deploymentModelAsString) {
041:
042: try {
043: ContextClassLoader.forName(loader, aspectFactoryClassName
044: .replace('/', '.'));
045: } catch (ClassNotFoundException e) {
046: // compile it
047: DeploymentModel deploymentModel = DeploymentModel
048: .getDeploymentModelFor(deploymentModelAsString);
049: AbstractAspectFactoryCompiler compiler;
050:
051: if (DeploymentModel.PER_JVM.equals(deploymentModel)) {
052: compiler = new PerJVMAspectFactoryCompiler(uuid,
053: aspectClassName, aspectQualifiedName,
054: containerClassName, rawParameters, loader);
055: } else if (DeploymentModel.PER_CLASS
056: .equals(deploymentModel)) {
057: compiler = new LazyPerXFactoryCompiler.PerClassAspectFactoryCompiler(
058: uuid, aspectClassName, aspectQualifiedName,
059: containerClassName, rawParameters, loader);
060: } else if (DeploymentModel.PER_INSTANCE
061: .equals(deploymentModel)) {
062: compiler = new PerObjectFactoryCompiler.PerInstanceFactoryCompiler(
063: uuid, aspectClassName, aspectQualifiedName,
064: containerClassName, rawParameters, loader);
065: } else if (DeploymentModel.PER_TARGET
066: .equals(deploymentModel)
067: || DeploymentModel.PER_THIS.equals(deploymentModel)) {
068: compiler = new PerObjectFactoryCompiler(uuid,
069: aspectClassName, aspectQualifiedName,
070: containerClassName, rawParameters, loader);
071: } else if (DeploymentModel.PER_CFLOW
072: .equals(deploymentModel)
073: || DeploymentModel.PER_CFLOWBELOW
074: .equals(deploymentModel)) {
075: compiler = new PerCflowXAspectFactoryCompiler(uuid,
076: aspectClassName, aspectQualifiedName,
077: containerClassName, rawParameters, loader);
078: } else {
079: //FIXME perThread
080: throw new Error(
081: "aspect factory not implemented for deployment model: "
082: + deploymentModel);
083: }
084: Artifact artifact = compiler.compile();
085: Class factory = AsmHelper.defineClass(loader,
086: artifact.bytecode, artifact.className);
087:
088: // System.out.println("factory.getClassLoader() = " + factory.getClassLoader());
089: // try {
090: // Method m = factory.getMethod("aspectOf", new Class[]{});
091: // Object aspect = m.invoke(null, new Object[]{});
092: // System.out.println("aspect = " + aspect);
093: // } catch (NoSuchMethodException e1) {
094: // e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
095: // } catch (IllegalAccessException e1) {
096: // e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
097: // } catch (InvocationTargetException e1) {
098: // e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
099: // }
100: }
101: }
102: }
|