001: package hero.session;
002:
003: import hero.interfaces.BnUserLocal;
004: import hero.interfaces.BnUserLocalHome;
005: import hero.interfaces.BnUserUtil;
006: import hero.interfaces.UserRegistrationLocal;
007: import hero.interfaces.UserRegistrationLocalHome;
008: import hero.interfaces.UserRegistrationUtil;
009: import hero.util.HeroException;
010: import hero.user.UserBase;
011: import hero.user.UserBaseException;
012: import hero.user.UserBaseService;
013:
014: import java.rmi.RemoteException;
015: import java.util.ArrayList;
016: import java.util.Collection;
017: import java.util.Iterator;
018: import java.util.Map;
019:
020: import javax.ejb.CreateException;
021: import javax.ejb.FinderException;
022: import javax.ejb.SessionBean;
023: import javax.ejb.SessionContext;
024:
025: /**
026: * @ejb:bean name="UserService"
027: * display-name="UserService Bean"
028: * type="Stateless"
029: * transaction-type="Container"
030: * jndi-name="ejb/hero/UserService"
031: * local-jndi-name="ejb/hero/UserService_L"
032: *
033: * @ejb:ejb-ref ejb-name="UserService"
034: * ref-name="myhero/UserService"
035: * @ejb:transaction-type type="Container"
036: * @ejb.permission role-name="BONITAUSER,user,SuperAdmin"
037: *
038: * @jonas.bean
039: * ejb-name="UserService"
040: * jndi-name="ejb/hero/UserService"
041: *
042: * @jboss.container-configuration name="Standard Stateless SessionBean for Bonita"
043: **/
044:
045: public class UserServiceBean implements SessionBean {
046: SessionContext mContext;
047:
048: /**
049: * Create the User Session Bean. This method is the first one to invoke in order to
050: * creates a new user account.
051: *
052: * @throws CreateException
053: *
054: * @ejb:create-method view-type="both"
055: **/
056: public void ejbCreate() throws CreateException {
057: }
058:
059: /**
060: * @ejb.interface-method
061: * @ejb.transaction type="Supports"
062: * @param name
063: */
064: public BnUserLocal findUserLocal(String name) throws HeroException {
065: BnUserLocalHome uHome;
066: try {
067: uHome = BnUserUtil.getLocalHome();
068: } catch (javax.naming.NamingException ne) {
069: throw new HeroException(ne.getMessage());
070: }
071: try {
072: return (uHome.findByName(name));
073: } catch (FinderException f) {
074: return (registerUser(name));
075: }
076: }
077:
078: /**
079: * @ejb.interface-method
080: * @ejb.transaction type="Supports"
081: * @param name
082: */
083: public BnUserLocal findUser(String name) throws HeroException {
084: BnUserLocalHome uHome;
085: try {
086: uHome = BnUserUtil.getLocalHome();
087: } catch (javax.naming.NamingException ne) {
088: throw new HeroException(ne.getMessage());
089: }
090: try {
091: findUserInBase(name);
092: } catch (Exception ne) {
093: throw new HeroException(ne.getMessage());
094: }
095: try {
096: return (uHome.findByName(name));
097: } catch (Exception f) {
098: return (registerUser(name));
099: }
100: }
101:
102: /**
103: * @ejb.interface-method
104: * @ejb.transaction type="Supports"
105: * @param name
106: */
107: public Collection findUsers() throws HeroException {
108: BnUserLocalHome uHome;
109: try {
110: uHome = BnUserUtil.getLocalHome();
111: } catch (javax.naming.NamingException ne) {
112: throw new HeroException(ne.getMessage());
113: }
114: try {
115: return (findUsersInBase());
116: } catch (Exception f) {
117: throw new HeroException(f.getMessage());
118: }
119: }
120:
121: /**
122: * @ejb.interface-method
123: * @ejb.transaction type="Supports"
124: * @param name
125: */
126: public Map getUserInfos(String name) throws HeroException {
127: return (findUserInBase(name));
128: }
129:
130: private Map findUserInBase(String id) throws HeroException {
131: Collection ucol = UserBaseService.getInstance().getUserBases();
132: Iterator i = ucol.iterator();
133: Map uinfos = null;
134: while (i.hasNext()) {
135: UserBase ub = (UserBase) i.next();
136: try {
137: uinfos = ub.getUserInfos(id);
138: break;
139: } catch (UserBaseException u) {
140: throw new HeroException(u.getMessage());
141: }
142: }
143: return uinfos;
144: }
145:
146: private Collection findUsersInBase() throws HeroException {
147: Collection ucol = UserBaseService.getInstance().getUserBases();
148: Iterator i = ucol.iterator();
149: Collection uinfos = new ArrayList();
150: while (i.hasNext()) {
151: UserBase ub = (UserBase) i.next();
152: try {
153: uinfos = ub.getUsers();
154: break;
155: } catch (UserBaseException u) {
156: throw new HeroException(u.getMessage());
157: }
158: }
159: return uinfos;
160: }
161:
162: private BnUserLocal registerUser(String name) throws HeroException {
163: try {
164: UserRegistrationLocalHome urh = UserRegistrationUtil
165: .getLocalHome();
166: UserRegistrationLocal ur = urh.create();
167: BnUserLocal user = ur.userCreate(name);
168: ur.remove();
169: return (user);
170: } catch (Exception e) {
171: throw new HeroException(e.getMessage());
172: }
173:
174: }
175:
176: /**
177: * Internal Enterprise Java Beans method.
178: */
179: public void setSessionContext(javax.ejb.SessionContext context)
180: throws RemoteException {
181: this .mContext = context;
182: }
183:
184: /**
185: * Internal Enterprise Java Beans method.
186: */
187: public void unsetSessionContext() throws RemoteException {
188: }
189:
190: /**
191: * Internal Enterprise Java Beans method.
192: */
193: public void ejbRemove() throws java.rmi.RemoteException {
194: }
195:
196: /**
197: * Internal Enterprise Java Beans method.
198: */
199: public void ejbActivate() throws java.rmi.RemoteException {
200: }
201:
202: /**
203: * Internal Enterprise Java Beans method.
204: */
205: public void ejbPassivate() throws java.rmi.RemoteException {
206: }
207: }
|