1 4 package com.tc.aspectwerkz; 5 6 import com.tc.aspectwerkz.perx.PerObjectAspect; 7 8 16 public class DeploymentModel { 17 18 public static final DeploymentModel PER_JVM = new DeploymentModel("perJVM"); 19 public static final DeploymentModel PER_CLASS = new DeploymentModel("perClass"); 20 public static final DeploymentModel PER_INSTANCE = new DeploymentModel("perInstance"); 21 22 public static final DeploymentModel PER_TARGET = new DeploymentModel("perTarget"); 23 public static final DeploymentModel PER_THIS = new DeploymentModel("perThis"); 24 public static final DeploymentModel PER_CFLOW = new DeploymentModel("perCflow"); 25 public static final DeploymentModel PER_CFLOWBELOW = new DeploymentModel("perCflowbelow"); 26 27 private static final String THIS_POINTCUT = "this(" + PerObjectAspect.ADVICE_ARGUMENT_NAME + ")"; 28 private static final String TARGET_POINTCUT = "target(" + PerObjectAspect.ADVICE_ARGUMENT_NAME + ")"; 29 30 protected final String m_name; 31 32 private DeploymentModel(String name) { 33 m_name = name; 34 } 35 36 public String toString() { 37 return m_name; 38 } 39 40 public boolean equals(Object o) { 41 if (this == o) { 42 return true; 43 } 44 if (!(o instanceof DeploymentModel)) { 45 return false; 46 } 47 final DeploymentModel adviceType = (DeploymentModel) o; 48 if ((m_name != null) ? (!m_name.equals(adviceType.m_name)) : (adviceType.m_name != null)) { 49 return false; 50 } 51 return true; 52 } 53 54 public int hashCode() { 55 return ((m_name != null) ? m_name.hashCode() : 0); 56 } 57 58 public static DeploymentModel getDeploymentModelFor(final String deploymentModelAsString) { 59 if (deploymentModelAsString == null || deploymentModelAsString.equals("")) { 60 return PER_JVM; } 62 if (deploymentModelAsString.equalsIgnoreCase(PER_JVM.toString())) { 63 return PER_JVM; 64 } else if (deploymentModelAsString.equalsIgnoreCase(PER_CLASS.toString())) { 65 return PER_CLASS; 66 } else if (deploymentModelAsString.equalsIgnoreCase(PER_INSTANCE.toString())) { 67 return PER_INSTANCE; 68 } else if (deploymentModelAsString.equalsIgnoreCase(PER_CFLOW.toString())) { 69 return PER_CFLOW; 70 } else if (deploymentModelAsString.equalsIgnoreCase(PER_CFLOWBELOW.toString())) { 71 return PER_CFLOWBELOW; 72 } else if (deploymentModelAsString.equalsIgnoreCase(PER_THIS.toString())) { 73 return PER_THIS; 74 } else if (deploymentModelAsString.equalsIgnoreCase(PER_TARGET.toString())) { 75 return PER_TARGET; 76 } else if (deploymentModelAsString.toLowerCase().startsWith(PER_THIS.m_name.toLowerCase())) { 78 return new PointcutControlledDeploymentModel(PER_THIS, 79 getDeploymentExpression(deploymentModelAsString, THIS_POINTCUT) 80 ); 81 } else if (deploymentModelAsString.toLowerCase().startsWith(PER_TARGET.m_name.toLowerCase())) { 82 return new PointcutControlledDeploymentModel(PER_TARGET, 83 getDeploymentExpression(deploymentModelAsString, TARGET_POINTCUT) 84 ); 85 } else { 86 System.out.println( 87 "AW::WARNING - no such deployment model [" + deploymentModelAsString + "] using default (perJVM)" 88 ); 89 return PER_JVM; } 91 } 92 93 97 private static String getDeploymentExpression(String deploymentModelAsString, 98 final String pointcut) { 99 int startIndex = deploymentModelAsString.indexOf('('); 100 int endIndex = deploymentModelAsString.lastIndexOf(')'); 101 102 if (startIndex == -1 || endIndex == -1 || startIndex >= endIndex) { 103 System.out.println( 104 "AW::ERROR - wrong deployment model definition [" + deploymentModelAsString + "]"); 105 106 return ""; 107 } 108 109 return deploymentModelAsString.substring(startIndex + 1, endIndex).trim() 110 + " && " 111 + pointcut; 112 } 113 114 117 public static final class PointcutControlledDeploymentModel extends DeploymentModel { 118 119 private String m_expression; 120 121 private PointcutControlledDeploymentModel(DeploymentModel deploymentModel, String expression) { 122 super(deploymentModel.m_name); 123 m_expression = expression; 124 } 125 126 public String getDeploymentExpression() { 127 return m_expression; 128 } 129 130 public String toString() { 131 return m_name; 133 } 134 135 public boolean equals(Object o) { 136 return super.equals(o); 137 } 138 139 public int hashCode() { 140 return super.hashCode(); 141 } 142 } 143 } | Popular Tags |