container/profiles/src/main/java/org/mobicents/slee/container/deployment/profile/ConcreteProfileMBeanGenerator.java
public void generateProfileMBean() throws Exception
	{
		if (SleeProfileClassCodeGenerator.checkCombination(component) == -1)
		{
			throw new DeploymentException("Profile Specification doesn't match any combination " + "from the JSLEE spec 1.0 section 10.5.2");
		}

		String profileMBeanConcreteClassName = profileMBeanConcreteInterface.getName() + "Impl";

		profileMBeanConcreteClass = pool.makeClass(profileMBeanConcreteClassName);

		// set interface & super class
		try {
			profileMBeanConcreteClass.setInterfaces(new CtClass[] {profileMBeanConcreteInterface});
			profileMBeanConcreteClass.setSuperclass(pool.get(AbstractProfileMBeanImpl.class.getName()));			
		}
		catch (NotFoundException e) {
			throw new SLEEException(e.getMessage(),e);
		}
		
		// implement cmp acessor & management methods gather in the mbean interface building
		for (CtMethod method : mBeanCmpAcessorMethods) {
			
			// copy method & remove abstract modifier			
			CtMethod newMethod = CtNewMethod.copy( method, profileMBeanConcreteClass, null );
			// generate body
			String body = null;				
			if (method.getName().startsWith("set")) {
				body = 	"{ " +
						"	beforeSetCmpField();" +
						"	try { " +
						"		(("+component.getProfileCmpConcreteClass().getName()+")getProfileObject().getProfileConcrete())." + method.getName()+"($1);" +
						"	} finally {" +
						"		afterSetCmpField();" +
						"	}" +
						"}"; 				
			}
			else {
				body = 	"{ " +
						"	boolean activatedTransaction = beforeGetCmpField();" +
						"	try { " +
						"		return ($r) (("+component.getProfileCmpConcreteClass().getName()+")getProfileObject().getProfileConcrete())." + method.getName()+"();" +
						"	} finally {" +
						"		afterGetCmpField(activatedTransaction);" +
						"	}" +
						"}";
			}
			if(logger.isTraceEnabled()) {
				logger.trace("Implemented profile mbean method named "+method.getName()+", with body:\n"+body);
			}
			newMethod.setBody(body);
			profileMBeanConcreteClass.addMethod(newMethod);
		}
		
		for (CtMethod method : mBeanManagementMethods) {
			
			// copy method & remove abstract modifier			
			CtMethod newMethod = CtNewMethod.copy( method, profileMBeanConcreteClass, null );
			
			// generate body
			boolean voidReturnType = newMethod.getReturnType().equals(CtClass.voidType);
				
			String body = "{ boolean activatedTransaction = beforeManagementMethodInvocation(); try { ";
			if (!voidReturnType) {
				body += "return ($r) ";
			}
			body += "(("+component.getProfileCmpConcreteClass().getName()+")getProfileObject().getProfileConcrete())." + method.getName()+"($$); } catch(Throwable t) { throwableOnManagementMethodInvocation(t); } finally { afterManagementMethodInvocation(activatedTransaction); }";
			if (!voidReturnType) {
				body += "throw new "+SLEEException.class.getName()+"(\"bad code generated\");";				 				
			}
			body += " }";
						
			if(logger.isTraceEnabled()) {
				logger.trace("Implemented profile mbean method named "+method.getName()+", with body:\n"+body);
			}
			newMethod.setBody(body);
			profileMBeanConcreteClass.addMethod(newMethod);
		}		
		
		try {
			profileMBeanConcreteClass.writeFile(this.component.getDeploymentDir().getAbsolutePath());
		}
		catch (Throwable e) {
			throw new SLEEException(e.getMessage(),e);
		}
		finally {
			profileMBeanConcreteClass.defrost();
		}

		try {
			component.setProfileMBeanConcreteImplClass(Thread.currentThread().getContextClassLoader().loadClass(profileMBeanConcreteClassName));
		}
		catch (Throwable e) {
			throw new SLEEException(e.getMessage(),e);
		}
	}
public void generateProfileMBean() throws Exception
	{
		if (SleeProfileClassCodeGenerator.checkCombination(component) == -1)
		{
			throw new DeploymentException("Profile Specification doesn't match any combination " + "from the JSLEE spec 1.0 section 10.5.2");
		}

		String profileMBeanConcreteClassName = profileMBeanConcreteInterface.getName() + "Impl";

		profileMBeanConcreteClass = pool.makeClass(profileMBeanConcreteClassName);

		// set interface & super class
		try {
			profileMBeanConcreteClass.setInterfaces(new CtClass[] {profileMBeanConcreteInterface});
			profileMBeanConcreteClass.setSuperclass(pool.get(AbstractProfileMBeanImpl.class.getName()));			
		}
		catch (NotFoundException e) {
			throw new SLEEException(e.getMessage(),e);
		}
		
		// implement cmp acessor & management methods gather in the mbean interface building
		for (CtMethod method : mBeanCmpAcessorMethods) {
			
			// copy method & remove abstract modifier			
			CtMethod newMethod = CtNewMethod.copy( method, profileMBeanConcreteClass, null );
			// generate body
			String body = null;				
			if (method.getName().startsWith("set")) {
				body = 	"{ " +
						"	beforeSetCmpField();" +
						"	try { " +
						"		(("+component.getProfileCmpConcreteClass().getName()+")getProfileObject().getProfileConcrete())." + method.getName()+"($1);" +
						"	} finally {" +
						"		afterSetCmpField();" +
						"	}" +
						"}"; 				
			}
			else {
				body = 	"{ " +
						"	boolean activatedTransaction = beforeGetCmpField();" +
						"	try { " +
						"		return ($r) (("+component.getProfileCmpConcreteClass().getName()+")getProfileObject().getProfileConcrete())." + method.getName()+"();" +
						"	} finally {" +
						"		afterGetCmpField(activatedTransaction);" +
						"	}" +
						"}";
			}
			if(logger.isTraceEnabled()) {
				logger.trace("Implemented profile mbean method named "+method.getName()+", with body:\n"+body);
			}
			newMethod.setBody(body);
			profileMBeanConcreteClass.addMethod(newMethod);
		}
		
		for (CtMethod method : mBeanManagementMethods) {
			
			// copy method & remove abstract modifier			
			CtMethod newMethod = CtNewMethod.copy( method, profileMBeanConcreteClass, null );
			
			// generate body
			boolean voidReturnType = newMethod.getReturnType().equals(CtClass.voidType);
				
			String body = "{ boolean activatedTransaction = beforeManagementMethodInvocation(); try { ";
			if (!voidReturnType) {
				body += "return ($r) ";
			}
			body += "(("+component.getProfileCmpConcreteClass().getName()+")getProfileObject().getProfileConcrete())." + method.getName()+"($$); } catch(Throwable t) { throwableOnManagementMethodInvocation(t); } finally { afterManagementMethodInvocation(activatedTransaction); }";
			if (!voidReturnType) {
				body += "throw new "+SLEEException.class.getName()+"(\"bad code generated\");";				 				
			}
			body += " }";
						
			if(logger.isTraceEnabled()) {
				logger.trace("Implemented profile mbean method named "+method.getName()+", with body:\n"+body);
			}
			newMethod.setBody(body);
			profileMBeanConcreteClass.addMethod(newMethod);
		}		
		
		try {
			profileMBeanConcreteClass.writeFile(this.component.getDeploymentDir().getAbsolutePath());
		}
		catch (Throwable e) {
			throw new SLEEException(e.getMessage(),e);
		}
		finally {
			profileMBeanConcreteClass.defrost();
		}

		try {
			component.setProfileMBeanConcreteImplClass(Thread.currentThread().getContextClassLoader().loadClass(profileMBeanConcreteClassName));
		}
		catch (Throwable e) {
			throw new SLEEException(e.getMessage(),e);
		}
	}
public void generateProfileMBean ( ) throws Exception { if ( SleeProfileClassCodeGenerator . checkCombination ( component ) == - 1 ) { throw new DeploymentException ( "Profile Specification doesn't match any combination " + "from the JSLEE spec 1.0 section 10.5.2" ) ; } String profileMBeanConcreteClassName = profileMBeanConcreteInterface . getName ( ) + "Impl" ; profileMBeanConcreteClass = pool . makeClass ( profileMBeanConcreteClassName ) ; // set interface & super class
 try { profileMBeanConcreteClass . setInterfaces ( new CtClass [ ] { profileMBeanConcreteInterface } ) ; profileMBeanConcreteClass . setSuperclass ( pool . get ( AbstractProfileMBeanImpl . class . getName ( ) ) ) ; } catch ( NotFoundException e ) { throw new SLEEException ( e . getMessage ( ) , e ) ; } // implement cmp acessor & management methods gather in the mbean interface building
 for ( CtMethod method : mBeanCmpAcessorMethods ) { // copy method & remove abstract modifier			
 CtMethod newMethod = CtNewMethod . copy ( method , profileMBeanConcreteClass , null ) ; // generate body
 String body = null ; if ( method . getName ( ) . startsWith ( "set" ) ) { body = "{ " + "	beforeSetCmpField();" + "	try { " + "		((" + component . getProfileCmpConcreteClass ( ) . getName ( ) + ")getProfileObject().getProfileConcrete())." + method . getName ( ) + "($1);" + "	} finally {" + "		afterSetCmpField();" + "	}" + "}" ; } else { body = "{ " + "	boolean activatedTransaction = beforeGetCmpField();" + "	try { " + "		return ($r) ((" + component . getProfileCmpConcreteClass ( ) . getName ( ) + ")getProfileObject().getProfileConcrete())." + method . getName ( ) + "();" + "	} finally {" + "		afterGetCmpField(activatedTransaction);" + "	}" + "}" ; } if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Implemented profile mbean method named " + method . getName ( ) + ", with body:\n" + body ) ; } newMethod . setBody ( body ) ; profileMBeanConcreteClass . addMethod ( newMethod ) ; } for ( CtMethod method : mBeanManagementMethods ) { // copy method & remove abstract modifier			
 CtMethod newMethod = CtNewMethod . copy ( method , profileMBeanConcreteClass , null ) ; // generate body
 boolean voidReturnType = newMethod . getReturnType ( ) . equals ( CtClass . voidType ) ; String body = "{ boolean activatedTransaction = beforeManagementMethodInvocation(); try { " ; if ( ! voidReturnType ) { body += "return ($r) " ; } body += "((" + component . getProfileCmpConcreteClass ( ) . getName ( ) + ")getProfileObject().getProfileConcrete())." + method . getName ( ) + "($$); } catch(Throwable t) { throwableOnManagementMethodInvocation(t); } finally { afterManagementMethodInvocation(activatedTransaction); }" ; if ( ! voidReturnType ) { body += "throw new " + SLEEException . class . getName ( ) + "(\"bad code generated\");" ; } body += " }" ; if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Implemented profile mbean method named " + method . getName ( ) + ", with body:\n" + body ) ; } newMethod . setBody ( body ) ; profileMBeanConcreteClass . addMethod ( newMethod ) ; } try { profileMBeanConcreteClass . writeFile ( this . component . getDeploymentDir ( ) . getAbsolutePath ( ) ) ; } catch ( Throwable e ) { throw new SLEEException ( e . getMessage ( ) , e ) ; } finally { profileMBeanConcreteClass . defrost ( ) ; } try { component . setProfileMBeanConcreteImplClass ( Thread . currentThread ( ) . getContextClassLoader ( ) . loadClass ( profileMBeanConcreteClassName ) ) ; } catch ( Throwable e ) { throw new SLEEException ( e . getMessage ( ) , e ) ; } }
This method generates concrete class of MBean impl
This method generates concrete class of MBean impl