⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pricerbean.java

📁 EJB3.0请一定要上载质量高而且本站没有的源码
💻 JAVA
字号:
package examples.stateless;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Stateless;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptors;
import javax.interceptor.InvocationContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import examples.stateless.interceptors.AuditorInterceptor;
import examples.stateless.interceptors.LoggerInterceptor;
import examples.stateless.interfaces.PricerInjection;
import examples.stateless.interfaces.PricerLookup;
import examples.stateless.interfaces.TaxRate;

@Stateless
@Interceptors({LoggerInterceptor.class,AuditorInterceptor.class})
@Remote({PricerInjection.class,PricerLookup.class})
public class PricerBean implements PricerInjection, PricerLookup {
	private TaxRate taxRate;
	
	@EJB
	private TaxRate taxRate2;
	
	public double getTaxLookup(double cost, String state) {
		double tax = -1;
		tax = cost * taxRate.getTaxRate(state);
		return tax;
	}
	
	public double getTaxInjection(double cost, String state) {
		double tax = -1;
		tax = cost * taxRate2.getTaxRate(state);
		return tax;
	}
	
	@PostConstruct
	public void postConstruct() {
		try {
			InitialContext ic = new InitialContext();
			taxRate = (TaxRate)ic.lookup(TaxRate.class.getName());
		} 
		catch (NamingException e) {
			// some kind of appropriate handling here
		}
	}
	
	@PreDestroy
	public void preDestroy() {
		taxRate = null;
	}
	
	@AroundInvoke
	public Object logger(InvocationContext inv) throws Exception {
		System.out.println("Intercepted call via internal method to: "+inv.getMethod().getName());
		Object[] params = inv.getParameters();
		for (int i=0;i<params.length;i++) {
			System.out.println("\tparam: "+params[i]);
		}
		return inv.proceed();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -