package com.sharetop.shareadsystem.admanager;import java.rmi.*;
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;
import com.sharetop.shareadsystem.usermanager.UserBean;
import com.sharetop.shareadsystem.SadsException;
import java.util.*;/**
* Sharetop shareAdSystem's ADManager EJB group.
* Sharetop Software Studio.Copyright(C)2002
* @author:yancheng([email protected])
* @version 1.0
* */
public class SadsSiteManagerBean implements SessionBean {
private SessionContext sessionContext;
private SadsSiteinfoHome siteHome;
private SadsAdtypeHome typeHome;
private ArrayList siteList=null;
private UserBean user; public void ejbCreate(UserBean user) {
this.user=user;
readEnvironmentEntity();
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
} //business method
/**
* 列出所有栏目
* */
public ArrayList listSite() throws SadsException {
if( !user.getUserRole().equals("sysadmin") ) throw new SadsException("No privilege.");
if( siteList==null ){
try{
siteList=new ArrayList();
Collection coll = siteHome.findAll();
Iterator iter = coll.iterator();
while(iter.hasNext()){
siteList.add(((SadsSiteinfo)iter.next()).getColumnInfo());
}
}
catch(Exception ex){
throw new SadsException("Error list all column");
}
}//end if
return siteList;
}
/**
* 新增栏目
* @param name 栏目名
* @param url 栏目URL
* */
public void addColumn(String name,String url) throws SadsException {
if( !user.getUserRole().equals("sysadmin") ) throw new SadsException("No privilege.");
String ctime = Long.toString(new Date().getTime());
try{
siteHome.create(ctime,name,url);
}
catch(Exception ex){
throw new SadsException("Error add column.");
}
}
/**
* 删除栏目
* @param id 栏目ID
* */
public void deleteColumn(String id) throws SadsException{
if( !user.getUserRole().equals("sysadmin") ) throw new SadsException("No privilege.");
try{
siteHome.findByPrimaryKey(id).remove();
}
catch(Exception ex){
throw new SadsException("Error delete column.");
}
}
/**
* 修改栏目信息
* @param name 栏目名
* @param url 栏目URL
* */
public void modifyColumn(String id,String name,String url) throws SadsException {
if( !user.getUserRole().equals("sysadmin") ) throw new SadsException("No privilege.");
try{
SadsSiteinfo siteInfo = siteHome.findByPrimaryKey(id);
siteInfo.setColumnInfo(name,url);
}
catch(Exception ex){
throw new SadsException("Error modify column.");
}
}
/**
* 获取广告代码
* @param id 广告类型ID
* */
public String getAdCode(String id) throws SadsException{
String res=null;
if( !user.getUserRole().equals("operator") ) throw new SadsException("No privilege.");
try{
SadsAdtype adtype = typeHome.findByPrimaryKey(id);
String[] adtypeInfo = adtype.getAdType();
res = adtypeInfo[1];
}
catch(Exception ex){
throw new SadsException("Error get Advertisement Code");
}
return res;
} //helper method
/**
* 读环境变量
* */
private void readEnvironmentEntity(){
try{
Context ictx=new InitialContext();
siteHome = (SadsSiteinfoHome)PortableRemoteObject.narrow(
ictx.lookup("java:comp/env/ejb/SiteInfoEJB"),
SadsSiteinfoHome.class);
typeHome = (SadsAdtypeHome)PortableRemoteObject.narrow(
ictx.lookup("java:comp/env/ejb/AdTypeEJB"),
SadsAdtypeHome.class);
}
catch(Exception ex){
throw new EJBException(ex);
}
}
}
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;
import com.sharetop.shareadsystem.usermanager.UserBean;
import com.sharetop.shareadsystem.SadsException;
import java.util.*;/**
* Sharetop shareAdSystem's ADManager EJB group.
* Sharetop Software Studio.Copyright(C)2002
* @author:yancheng([email protected])
* @version 1.0
* */
public class SadsSiteManagerBean implements SessionBean {
private SessionContext sessionContext;
private SadsSiteinfoHome siteHome;
private SadsAdtypeHome typeHome;
private ArrayList siteList=null;
private UserBean user; public void ejbCreate(UserBean user) {
this.user=user;
readEnvironmentEntity();
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
} //business method
/**
* 列出所有栏目
* */
public ArrayList listSite() throws SadsException {
if( !user.getUserRole().equals("sysadmin") ) throw new SadsException("No privilege.");
if( siteList==null ){
try{
siteList=new ArrayList();
Collection coll = siteHome.findAll();
Iterator iter = coll.iterator();
while(iter.hasNext()){
siteList.add(((SadsSiteinfo)iter.next()).getColumnInfo());
}
}
catch(Exception ex){
throw new SadsException("Error list all column");
}
}//end if
return siteList;
}
/**
* 新增栏目
* @param name 栏目名
* @param url 栏目URL
* */
public void addColumn(String name,String url) throws SadsException {
if( !user.getUserRole().equals("sysadmin") ) throw new SadsException("No privilege.");
String ctime = Long.toString(new Date().getTime());
try{
siteHome.create(ctime,name,url);
}
catch(Exception ex){
throw new SadsException("Error add column.");
}
}
/**
* 删除栏目
* @param id 栏目ID
* */
public void deleteColumn(String id) throws SadsException{
if( !user.getUserRole().equals("sysadmin") ) throw new SadsException("No privilege.");
try{
siteHome.findByPrimaryKey(id).remove();
}
catch(Exception ex){
throw new SadsException("Error delete column.");
}
}
/**
* 修改栏目信息
* @param name 栏目名
* @param url 栏目URL
* */
public void modifyColumn(String id,String name,String url) throws SadsException {
if( !user.getUserRole().equals("sysadmin") ) throw new SadsException("No privilege.");
try{
SadsSiteinfo siteInfo = siteHome.findByPrimaryKey(id);
siteInfo.setColumnInfo(name,url);
}
catch(Exception ex){
throw new SadsException("Error modify column.");
}
}
/**
* 获取广告代码
* @param id 广告类型ID
* */
public String getAdCode(String id) throws SadsException{
String res=null;
if( !user.getUserRole().equals("operator") ) throw new SadsException("No privilege.");
try{
SadsAdtype adtype = typeHome.findByPrimaryKey(id);
String[] adtypeInfo = adtype.getAdType();
res = adtypeInfo[1];
}
catch(Exception ex){
throw new SadsException("Error get Advertisement Code");
}
return res;
} //helper method
/**
* 读环境变量
* */
private void readEnvironmentEntity(){
try{
Context ictx=new InitialContext();
siteHome = (SadsSiteinfoHome)PortableRemoteObject.narrow(
ictx.lookup("java:comp/env/ejb/SiteInfoEJB"),
SadsSiteinfoHome.class);
typeHome = (SadsAdtypeHome)PortableRemoteObject.narrow(
ictx.lookup("java:comp/env/ejb/AdTypeEJB"),
SadsAdtypeHome.class);
}
catch(Exception ex){
throw new EJBException(ex);
}
}
}
Context sessionContext=new InitialContext();(1)UserEntityRemoteHome userHome=(UserEntityRemoteHome)PortableRemoteObject.narrow(sessionContext.lookup("java:comp/env/ejb/UserEntityBeanRemote"),UserEntityRemoteHome.class);(2)UserEntityRemoteHome userHome=(UserEntityRemoteHome)sessionContext.lookup("UserEntityRemoteHome");
UserEntityRemote user=userHome.findByPrimaryKey(userId);
这两种方法都不行报错:
java.rmi.RemoteException: EJB Exception: ; nested exception is:
javax.ejb.EJBException
- with nested exception:
[javax.naming.NameNotFoundException: Unable to resolve UserEntityRemoteHome. Resolved: '' Unresolved:'UserEntityRemoteHome' ; remaining name '']javax.naming.NameNotFoundException: Unable to resolve UserEntityRemoteHome. Resolved: '' Unresolved:'UserEntityRemoteHome' ; remaining name '' <<no stack trace available>>-- Failed: isUser(zack1024, 8224036)-- Return value from isUser(zack1024, 8224036): false.--------------- nested within: ------------------javax.ejb.EJBException
- with nested exception:
[javax.naming.NameNotFoundException: Unable to resolve UserEntityRemoteHome. Resolved: '' Unresolved:'UserEntityRemoteHome' ; remaining name ''] <<no stack trace available>>
<ejb-name>SadsSiteManagerEJB</ejb-name>
<home>com.sharetop.shareadsystem.admanager.SadsSiteManagerHome</home>
<remote>com.sharetop.shareadsystem.admanager.SadsSiteManager</remote>
<ejb-class>com.sharetop.shareadsystem.admanager.SadsSiteManagerBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref>
<description />
<ejb-ref-name>ejb/SiteInfoEJB</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.sharetop.shareadsystem.admanager.SadsSiteinfoHome</home>
<remote>com.sharetop.shareadsystem.admanager.SadsSiteinfo</remote>
<ejb-link>SadsSiteinfoEJB</ejb-link>
</ejb-ref>
<ejb-ref>
<description />
<ejb-ref-name>ejb/AdTypeEJB</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.sharetop.shareadsystem.admanager.SadsAdtypeHome</home>
<remote>com.sharetop.shareadsystem.admanager.SadsAdtype</remote>
<ejb-link>SadsAdtypeEJB</ejb-link>
</ejb-ref>
</session>
问题不在那,单独的entitybean,sessionbean我都会做了,现在我的问题是调用的问题
有什么差别
???
真的,那奇怪了,我就是用第二种方法连上的,而wrox的那本ejb编程指南上有个例子也完全是这种方式