001: package hero.session;
002:
003: import javax.ejb.CreateException;
004: import javax.ejb.EJBException;
005: import javax.ejb.SessionBean;
006: import javax.ejb.SessionContext;
007: import javax.naming.Context;
008: import hero.interfaces.*;
009: import hero.util.HeroException;
010:
011: /**
012: * Encapsulates the retrival of DB data
013: *
014: * @author Andreas Schaefer
015: * @version $Revision: 1.5 $
016: *
017: * @ejb:bean name="InsertAuthRoleUser"
018: * display-name="Makes inserts in the AuthRole_User table"
019: * type="Stateless"
020: * jndi-name="ejb/hero/InsertAuthRoleUser"
021: * local-jndi-name="ejb/hero/InsertAuthRoleUser_L"
022: *
023: *
024: * @ejb:transaction-type type="Container"
025: *
026: * @jonas.bean
027: * ejb-name="InsertAuthRoleUser"
028: * jndi-name="ejb/hero/InsertAuthRoleUser"
029: * @ejb.permission unchecked="yes"
030: * @ejb.security-identity run-as="SuperAdmin"
031: *
032: * @ejb.resource-ref res-ref-name="jdbc/myDS"
033: * res-type="javax.sql.DataSource"
034: * res-auth="Application"
035: * @jonas.resource
036: * res-ref-name="jdbc/myDS"
037: * jndi-name="bonita"
038: *
039: * @jboss.container-configuration name="Standard Stateless SessionBean for Bonita"
040: */
041: public class InsertAuthRoleUserBean implements SessionBean {
042: private SessionContext mContext;
043:
044: /**
045: * Makes inserts in User table
046: *
047: *
048: * @throws RemoteException
049: *
050: * @ejb:interface-method view-type="remote"
051: * @ejb:transaction type="Required"
052: **/
053: public void initializeUser(String name, String password,
054: String email) {
055:
056: Context lContext;
057: BnUserLocalHome uhome = null;
058: BnUserLocal user;
059: BnUserValue uv;
060:
061: try {
062: uhome = hero.interfaces.BnUserUtil.getLocalHome();
063: try {
064: BnUserLocal us = uhome.findByName(name);
065: throw new HeroException("BnUser " + name
066: + " already exist in the system ");
067: } catch (javax.ejb.FinderException nn) {
068: user = uhome.create(new BnUserValue());
069: uv = user.getBnUserValue();
070: //uv.setId(id);
071: uv.setName(name);
072: uv.setPassword(password);
073: uv.setEmail(email);
074: uv.setCreationDate(null);
075: uv.setModificationDate(null);
076: uv.setJabber(null);
077: user.setBnUserValue(uv);
078: }
079: } catch (java.lang.Exception e) {
080: e.printStackTrace(System.out);
081: }
082:
083: }
084:
085: /**
086: * Makes inserts in User table
087: *
088: *
089: * @throws RemoteException
090: *
091: * @ejb:interface-method view-type="remote"
092: * @ejb:transaction type="Required"
093: **/
094: public void initializeAuthRole(String name, String rolegroup) {
095:
096: Context lContext;
097: BnAuthRoleLocalHome arhome = null;
098: BnAuthRoleLocal arole;
099: try {
100: arhome = hero.interfaces.BnAuthRoleUtil.getLocalHome();
101: try {
102: BnAuthRoleLocal us = arhome.findByName(name);
103: throw new HeroException("BnAuthRole " + name
104: + " already exist in the system ");
105: } catch (javax.ejb.FinderException nn) {
106: BnAuthRoleValue arv = new BnAuthRoleValue();
107: arv.setName(name);
108: arv.setBnRoleGroup(rolegroup);
109: arole = arhome.create(arv);
110: }
111: } catch (java.lang.Exception e) {
112: e.printStackTrace(System.out);
113: }
114:
115: }
116:
117: /**
118: * Makes inserts in AuthRole_User table
119: *
120: * @throws RemoteException
121: *
122: * @ejb:interface-method view-type="remote"
123: * @ejb:transaction type="Required"
124: **/
125: public void initialize(String User, String AuthRole) {
126:
127: Context lContext;
128: BnUserLocalHome uhome = null;
129: BnAuthRoleLocalHome arhome = null;
130: BnUserLocal user;
131: BnAuthRoleLocal authRole;
132: try {
133: uhome = hero.interfaces.BnUserUtil.getLocalHome();
134: arhome = hero.interfaces.BnAuthRoleUtil.getLocalHome();
135: user = uhome.findByName(User);
136: authRole = arhome.findByName(AuthRole);
137:
138: if (!authRole.getBnUsers().contains(user))
139: authRole.getBnUsers().add(user);
140: if (!user.getBnAuthRoles().contains(authRole))
141: user.getBnAuthRoles().add(authRole);
142:
143: } catch (java.lang.Exception e) {
144: e.printStackTrace(System.out);
145: }
146:
147: }
148:
149: /**
150: * Create the Session Bean
151: *
152: * @throws CreateException
153: *
154: * @ejb:create-method view-type="remote"
155: **/
156: public void ejbCreate() throws CreateException {
157: }
158:
159: // -------------------------------------------------------------------------
160: // Framework Callbacks
161: // -------------------------------------------------------------------------
162:
163: public void setSessionContext(SessionContext aContext)
164: throws EJBException {
165: mContext = aContext;
166: }
167:
168: public void ejbActivate() throws EJBException {
169: }
170:
171: public void ejbPassivate() throws EJBException {
172: }
173:
174: public void ejbRemove() throws EJBException {
175: }
176:
177: }
|