01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.aspectwerkz.aspect.container;
05:
06: import com.tc.asm.MethodVisitor;
07: import com.tc.asm.Label;
08:
09: /**
10: * Simplest factory for perJVM aspects
11: *
12: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
13: * @author Jonas Bonér
14: */
15: public class PerJVMAspectFactoryCompiler extends
16: AbstractAspectFactoryCompiler {
17:
18: public PerJVMAspectFactoryCompiler(String uuid,
19: String aspectClassName, String aspectQualifiedName,
20: String containerClassName, String rawParameters,
21: ClassLoader loader) {
22: super (uuid, aspectClassName, aspectQualifiedName,
23: containerClassName, rawParameters, loader);
24: }
25:
26: protected void createAspectOf() {
27: m_cw.visitField(ACC_PUBLIC + ACC_STATIC,
28: FACTORY_SINGLE_ASPECT_FIELD_NAME,
29: m_aspectClassSignature, null, null);
30:
31: MethodVisitor cv = m_cw.visitMethod(ACC_PUBLIC + ACC_STATIC
32: + ACC_FINAL, FACTORY_ASPECTOF_METHOD_NAME, "()"
33: + m_aspectClassSignature, null, null);
34:
35: cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName,
36: FACTORY_SINGLE_ASPECT_FIELD_NAME,
37: m_aspectClassSignature);
38: Label ifNonNull = new Label();
39: cv.visitJumpInsn(IFNONNULL, ifNonNull);
40: if (m_hasAspectContainer) {
41: cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName,
42: FACTORY_CONTAINER_FIELD_NAME,
43: ASPECT_CONTAINER_CLASS_SIGNATURE);
44: cv.visitMethodInsn(INVOKEINTERFACE,
45: ASPECT_CONTAINER_CLASS_NAME,
46: ASPECT_CONTAINER_ASPECTOF_METHOD_NAME,
47: ASPECT_CONTAINER_ASPECTOF_PERJVM_METHOD_SIGNATURE);
48: cv.visitTypeInsn(CHECKCAST, m_aspectClassName);
49: } else {
50: cv.visitTypeInsn(NEW, m_aspectClassName);
51: cv.visitInsn(DUP);
52: cv.visitMethodInsn(INVOKESPECIAL, m_aspectClassName,
53: INIT_METHOD_NAME, NO_PARAM_RETURN_VOID_SIGNATURE);
54: }
55: cv.visitFieldInsn(PUTSTATIC, m_aspectFactoryClassName,
56: FACTORY_SINGLE_ASPECT_FIELD_NAME,
57: m_aspectClassSignature);
58: cv.visitLabel(ifNonNull);
59: cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName,
60: FACTORY_SINGLE_ASPECT_FIELD_NAME,
61: m_aspectClassSignature);
62: cv.visitInsn(ARETURN);
63: cv.visitMaxs(0, 0);
64: }
65:
66: protected void createHasAspect() {
67: MethodVisitor cv = m_cw.visitMethod(ACC_STATIC + ACC_PUBLIC
68: + ACC_FINAL, FACTORY_HASASPECT_METHOD_NAME,
69: NO_PARAM_RETURN_BOOLEAN_SIGNATURE, null, null);
70:
71: cv.visitFieldInsn(GETSTATIC, m_aspectFactoryClassName,
72: FACTORY_SINGLE_ASPECT_FIELD_NAME,
73: m_aspectClassSignature);
74: Label ifNonNull = new Label();
75: cv.visitJumpInsn(IFNONNULL, ifNonNull);
76: cv.visitInsn(ICONST_0);
77: cv.visitInsn(IRETURN);
78: cv.visitLabel(ifNonNull);
79: cv.visitInsn(ICONST_1);
80: cv.visitInsn(IRETURN);
81: cv.visitMaxs(0, 0);
82: }
83:
84: protected void createOtherArtifacts() {
85: ;
86: }
87: }
|