container/common/src/main/java/org/mobicents/slee/container/deployment/ConcreteClassGeneratorUtils.java
public static void addInterceptedMethod(CtClass concreteClass,
			CtMethod method, String interceptorName, boolean callSuperMethod) {
		if (method == null) throw new InvalidParameterException("Intercepted method should not be null");
		if (interceptorName == null) throw new InvalidParameterException("Interceptor class name should not be null");

		String methodToAdd = "public ";
		//Add the return type
		boolean hasReturn = false;
		CtClass returnType = null;
		try {
			returnType = method.getReturnType();
			methodToAdd = methodToAdd.concat(returnType.getName() + " ");
			hasReturn = true;
		} catch (NotFoundException nfe) {
			//nfe.printStackTrace();
		    logger.trace("No return type -- assuming return type is void " );
			methodToAdd = methodToAdd + "void ";
		}
		//Add the method name
		methodToAdd = methodToAdd.concat(method.getName() + "(");
		//Add the parameters
		CtClass[] parameterTypes = null;
		;
		String parametersInit = "Object[] args=null;";
		String argsInit = "Class[] classes=null;";
		try {
			parameterTypes = method.getParameterTypes();
			parametersInit = parametersInit + "args=new Object["
					+ parameterTypes.length + "];";
			argsInit = argsInit + "classes=new Class[" + parameterTypes.length
					+ "];";
			for (int argNumber = 0; argNumber < parameterTypes.length; argNumber++) {
				methodToAdd = methodToAdd.concat(parameterTypes[argNumber]
						.getName()
						+ " arg_" + argNumber);
				//handle the primitive types
				if (!parameterTypes[argNumber].isPrimitive())
					parametersInit = parametersInit + " args[" + argNumber
							+ "]=arg_" + argNumber + ";";
				else
					parametersInit = parametersInit
							+ " args["
							+ argNumber
							+ "]="
							+ ClassUtils
									.getObjectFromPrimitiveType(
											parameterTypes[argNumber].getName(),
											"arg_" + argNumber) + ";";
				String typeClass = parameterTypes[argNumber].getName();
				//handle the primitive types
				if (!parameterTypes[argNumber].isPrimitive()) {
					if (parameterTypes[argNumber].isArray()) {
						String arrayClassRepresentation = toArray(parameterTypes[argNumber]);
						if (arrayClassRepresentation != null)
							argsInit = argsInit + "classes[" + argNumber + "]="
									+ SleeContainerUtils.class.getName() + ".getCurrentThreadClassLoader().loadClass(\""
									+ arrayClassRepresentation + "\");";
					} else
						argsInit = argsInit + "classes[" + argNumber
								+ "]="+SleeContainerUtils.class.getName() + ".getCurrentThreadClassLoader().loadClass(\"" + typeClass + "\");";
				} else
					argsInit = argsInit + "classes[" + argNumber + "]="
							+ ClassUtils.getClassFromPrimitiveType(typeClass) + ".TYPE;";
				if (argNumber + 1 < parameterTypes.length)
					methodToAdd = methodToAdd + ",";
			}
			
			methodToAdd += ") ";

			// Add method exceptions
			if (method.getExceptionTypes().length > 0)
			{
			    CtClass[] exceptions = method.getExceptionTypes();
				methodToAdd += " throws ";
				for (int i = 0; i < exceptions.length-1; i++) {
				    String exName = exceptions[i].getName();
				    methodToAdd += exName + ", ";
				}
				methodToAdd += exceptions[exceptions.length-1].getName();
			}

		} catch (NotFoundException nfe) {
			nfe.printStackTrace();
			throw new SLEEException("Failed creating concrete Profile MBean implementation class", nfe);
		}
		
		// Start adding method body
		methodToAdd +=  " { ";
		methodToAdd += "" + parametersInit;
		methodToAdd += "" + argsInit;
		methodToAdd += "Class clazz=this.getClass();";
		methodToAdd += "Object result=null;";
		methodToAdd += "try{";
		//call the super method
		if (callSuperMethod) {
		    if(method.getName().equals("profileStore")){
				methodToAdd = methodToAdd + "super." + method.getName() + "(";
				if (parameterTypes != null && parameterTypes.length > 0) {
					for (int argNumber = 0; argNumber < parameterTypes.length; argNumber++) {
						methodToAdd = methodToAdd + "arg_" + argNumber;
						if (argNumber + 1 < parameterTypes.length)
							methodToAdd = methodToAdd + ",";
					}
				}
				methodToAdd = methodToAdd + ");";
		    }
		}
		methodToAdd = methodToAdd
				+ "java.lang.reflect.Method method=clazz.getDeclaredMethod(\""
				+ method.getName() + "\",classes" + ");";
		methodToAdd = methodToAdd + "result=" + interceptorName
				+ ".invoke(this,method,args); ";
		methodToAdd = methodToAdd
				+ "}catch(RuntimeException t){t.printStackTrace(); throw (t); "
				+ " } catch (Exception ex1) { ex1.printStackTrace(); throw (ex1); }";
		//call the super method
		if (callSuperMethod) {
		    if(!method.getName().equals("profileStore")){				
				methodToAdd = methodToAdd + "super." + method.getName() + "(";
				if (parameterTypes != null && parameterTypes.length > 0) {
					for (int argNumber = 0; argNumber < parameterTypes.length; argNumber++) {
						methodToAdd = methodToAdd + "arg_" + argNumber;
						if (argNumber + 1 < parameterTypes.length)
							methodToAdd += ",";
					}
				}
				methodToAdd += ");";
		    }
		}
		//handle the primitive types
		if (hasReturn) {
			if (!returnType.getName().equalsIgnoreCase("void")) {
				if (!returnType.isPrimitive())
					methodToAdd = methodToAdd + "return ("
							+ returnType.getName() + ")result;";
				else
					methodToAdd = methodToAdd
							+ "return "
							+ ClassUtils
									.getPrimitiveTypeFromObject(returnType
											.getName(), "result") + ";";
			}

		}
		methodToAdd += "}";
		//Add the implementation code
		logger.trace("Method " + methodToAdd + " added");
		CtMethod methodTest;
		try {
			methodTest = CtNewMethod.make(methodToAdd, concreteClass);
			concreteClass.addMethod(methodTest);
		} catch (CannotCompileException cce) {
			throw new SLEEException("Cannot compile method " + method.getName(), cce);
		}
	}
public static void addInterceptedMethod(CtClass concreteClass,
			CtMethod method, String interceptorName, boolean callSuperMethod) {
		if (method == null) throw new InvalidParameterException("Intercepted method should not be null");
		if (interceptorName == null) throw new InvalidParameterException("Interceptor class name should not be null");

		String methodToAdd = "public ";
		//Add the return type
		boolean hasReturn = false;
		CtClass returnType = null;
		try {
			returnType = method.getReturnType();
			methodToAdd = methodToAdd.concat(returnType.getName() + " ");
			hasReturn = true;
		} catch (NotFoundException nfe) {
			//nfe.printStackTrace();
		    logger.trace("No return type -- assuming return type is void " );
			methodToAdd = methodToAdd + "void ";
		}
		//Add the method name
		methodToAdd = methodToAdd.concat(method.getName() + "(");
		//Add the parameters
		CtClass[] parameterTypes = null;
		;
		String parametersInit = "Object[] args=null;";
		String argsInit = "Class[] classes=null;";
		try {
			parameterTypes = method.getParameterTypes();
			parametersInit = parametersInit + "args=new Object["
					+ parameterTypes.length + "];";
			argsInit = argsInit + "classes=new Class[" + parameterTypes.length
					+ "];";
			for (int argNumber = 0; argNumber < parameterTypes.length; argNumber++) {
				methodToAdd = methodToAdd.concat(parameterTypes[argNumber]
						.getName()
						+ " arg_" + argNumber);
				//handle the primitive types
				if (!parameterTypes[argNumber].isPrimitive())
					parametersInit = parametersInit + " args[" + argNumber
							+ "]=arg_" + argNumber + ";";
				else
					parametersInit = parametersInit
							+ " args["
							+ argNumber
							+ "]="
							+ ClassUtils
									.getObjectFromPrimitiveType(
											parameterTypes[argNumber].getName(),
											"arg_" + argNumber) + ";";
				String typeClass = parameterTypes[argNumber].getName();
				//handle the primitive types
				if (!parameterTypes[argNumber].isPrimitive()) {
					if (parameterTypes[argNumber].isArray()) {
						String arrayClassRepresentation = toArray(parameterTypes[argNumber]);
						if (arrayClassRepresentation != null)
							argsInit = argsInit + "classes[" + argNumber + "]="
									+ SleeContainerUtils.class.getName() + ".getCurrentThreadClassLoader().loadClass(\""
									+ arrayClassRepresentation + "\");";
					} else
						argsInit = argsInit + "classes[" + argNumber
								+ "]="+SleeContainerUtils.class.getName() + ".getCurrentThreadClassLoader().loadClass(\"" + typeClass + "\");";
				} else
					argsInit = argsInit + "classes[" + argNumber + "]="
							+ ClassUtils.getClassFromPrimitiveType(typeClass) + ".TYPE;";
				if (argNumber + 1 < parameterTypes.length)
					methodToAdd = methodToAdd + ",";
			}
			
			methodToAdd += ") ";

			// Add method exceptions
			if (method.getExceptionTypes().length > 0)
			{
			    CtClass[] exceptions = method.getExceptionTypes();
				methodToAdd += " throws ";
				for (int i = 0; i < exceptions.length-1; i++) {
				    String exName = exceptions[i].getName();
				    methodToAdd += exName + ", ";
				}
				methodToAdd += exceptions[exceptions.length-1].getName();
			}

		} catch (NotFoundException nfe) {
			nfe.printStackTrace();
			throw new SLEEException("Failed creating concrete Profile MBean implementation class", nfe);
		}
		
		// Start adding method body
		methodToAdd +=  " { ";
		methodToAdd += "" + parametersInit;
		methodToAdd += "" + argsInit;
		methodToAdd += "Class clazz=this.getClass();";
		methodToAdd += "Object result=null;";
		methodToAdd += "try{";
		//call the super method
		if (callSuperMethod) {
		    if(method.getName().equals("profileStore")){
				methodToAdd = methodToAdd + "super." + method.getName() + "(";
				if (parameterTypes != null && parameterTypes.length > 0) {
					for (int argNumber = 0; argNumber < parameterTypes.length; argNumber++) {
						methodToAdd = methodToAdd + "arg_" + argNumber;
						if (argNumber + 1 < parameterTypes.length)
							methodToAdd = methodToAdd + ",";
					}
				}
				methodToAdd = methodToAdd + ");";
		    }
		}
		methodToAdd = methodToAdd
				+ "java.lang.reflect.Method method=clazz.getDeclaredMethod(\""
				+ method.getName() + "\",classes" + ");";
		methodToAdd = methodToAdd + "result=" + interceptorName
				+ ".invoke(this,method,args); ";
		methodToAdd = methodToAdd
				+ "}catch(RuntimeException t){t.printStackTrace(); throw (t); "
				+ " } catch (Exception ex1) { ex1.printStackTrace(); throw (ex1); }";
		//call the super method
		if (callSuperMethod) {
		    if(!method.getName().equals("profileStore")){				
				methodToAdd = methodToAdd + "super." + method.getName() + "(";
				if (parameterTypes != null && parameterTypes.length > 0) {
					for (int argNumber = 0; argNumber < parameterTypes.length; argNumber++) {
						methodToAdd = methodToAdd + "arg_" + argNumber;
						if (argNumber + 1 < parameterTypes.length)
							methodToAdd += ",";
					}
				}
				methodToAdd += ");";
		    }
		}
		//handle the primitive types
		if (hasReturn) {
			if (!returnType.getName().equalsIgnoreCase("void")) {
				if (!returnType.isPrimitive())
					methodToAdd = methodToAdd + "return ("
							+ returnType.getName() + ")result;";
				else
					methodToAdd = methodToAdd
							+ "return "
							+ ClassUtils
									.getPrimitiveTypeFromObject(returnType
											.getName(), "result") + ";";
			}

		}
		methodToAdd += "}";
		//Add the implementation code
		logger.trace("Method " + methodToAdd + " added");
		CtMethod methodTest;
		try {
			methodTest = CtNewMethod.make(methodToAdd, concreteClass);
			concreteClass.addMethod(methodTest);
		} catch (CannotCompileException cce) {
			throw new SLEEException("Cannot compile method " + method.getName(), cce);
		}
	}
Add a concrete method invoking the interceptor <B>interceptorName </B>
with the same parameters,name,return type as the method <B>method </B>

@param concreteClass
the concrete where to add the interceptor method
@param method
method from which is generating the new proxy method
@param interceptorName
the interceptor name implementing the interface
InvocationHandler. This name must be the name of an existing
field of the concrete class
@param callSuperMethod
if true the concrete implementation of the method will call
super()