📄 componentbean.java
字号:
package com.wiley.compBooks.roman.session.fazuul;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
/**
* Stateful Session Bean.
*/
public class ComponentBean implements SessionBean {
// Constants used for reading properties object
public static final String ENV_MATCHES = "MATCHES";
public static final String ENV_DESCRIPTION = "DESCRIPTION_";
// Conversational state
public String name;
public String description;
private transient SessionContext ctx;
public void ejbCreate(String name) {
this.name = name;
/*
* Get the description of our Bean by querying the SessionContext
* and retrieving the application-specific properties.
*/
Properties props = ctx.getEnvironment();
description = (String) props.get(ENV_DESCRIPTION + name);
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext ctx) {
this.ctx = ctx;
}
/**
* Attaches this component to another component. If attach is successful,
* the Bean will call remove() on the two EJB Objects, and generate a new,
* combined Component.
*
* @return newly formed Component if successful
* @exception ComponentException thrown if two Components can't fit together
*/
public Component attachTo(Component other) throws RemoteException, ComponentException {
/*
* Retrieve the application-specific environment properties from
* the current context.
*/
Properties props = ctx.getEnvironment();
/*
* Get the list of matching components from the properties
*/
String matchString = (String) props.get(ENV_MATCHES);
Enumeration matches = new StringTokenizer(matchString, ",");
/*
* Loop through each match listing. Match listings are of the form
* x+y=z, such as Snarf+Vrommell=Subbert. Check to see if any of
* the matches involve our components.
*/
while (matches.hasMoreElements()) {
String equationString = (String) matches.nextElement();
Enumeration equation = new StringTokenizer(equationString, "+=");
String nameA = (String) equation.nextElement();
String nameB = (String) equation.nextElement();
String result = (String) equation.nextElement();
/*
* If there's a match, make the new, combined component
*/
if ( ( nameA.equals(this.getName())
&& nameB.equals(other.getName()) ) ||
( nameB.equals(this.getName())
&& nameA.equals(other.getName()) ) ) {
/*
* Get my Home Object from Session Context.
*/
ComponentHome home = (ComponentHome) ctx.getEJBHome();
/*
* Create a new Component, and return it
*/
try {
return home.create(result);
}
catch (Exception e) {
throw new ComponentException(e.toString());
}
}
}
/*
* Two components don't fit together, so throw an exception
*/
throw new ComponentException("Those components do not fit together!");
}
/**
* Returns the short name of this component
*/
public String getName() throws RemoteException {
return name;
}
/**
* Returns the long description of this component
*/
public String getDescription() throws RemoteException {
return description;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -