?? machinebean.java
字號:
package com.wiley.compBooks.roman.session.fazuul;
import javax.ejb.*;
import java.util.*;
import javax.naming.*;
/**
* Stateless Session Bean. Simple factory for generating random Components.
*/
public class MachineBean implements SessionBean {
// Constants used for properties file reading
public static final String COMPONENT_LIST = "COMPONENT_LIST";
private transient SessionContext ctx;
//
// EJB-required methods
//
public void ejbCreate() {
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext ctx) {
this.ctx = ctx;
}
//
// Business methods
//
/**
* Makes a new, random component
*/
public Component makeComponent() throws MachineException {
/*
* Get properties from Session Context, and retrieve app-specific
* property that lists the available components for creation.
*/
Properties props = ctx.getEnvironment();
String componentString = (String) props.get(COMPONENT_LIST);
StringTokenizer components = new StringTokenizer(componentString, ",");
/*
* Find a random component name
*/
int componentNumber = Math.abs(
new Random().nextInt() % components.countTokens());
String componentName = null;
for (int i=0; i <= componentNumber; i++) {
componentName = (String) components.nextToken();
}
try {
/*
* Get a reference to the ComponentHome Object via JNDI. We
* need the Component's Home Object to create Components.
*
* We rely on app-specific properties to define
* the Initial Context params which JNDI needs.
*/
Context ctx = new InitialContext(props);
ComponentHome home = (ComponentHome) ctx.lookup("ComponentHome");
/*
* Use the factory to create the new, merged component, and
* return it.
*/
return home.create(componentName);
}
catch (Exception e) {
throw new MachineException(e);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -