KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > session > InsertAuthRoleUserBean


1 package hero.session;
2
3 import javax.ejb.CreateException JavaDoc;
4 import javax.ejb.EJBException JavaDoc;
5 import javax.ejb.SessionBean JavaDoc;
6 import javax.ejb.SessionContext JavaDoc;
7 import javax.naming.Context JavaDoc;
8 import hero.interfaces.*;
9 import hero.util.HeroException;
10
11
12 /**
13  * Encapsulates the retrival of DB data
14  *
15  * @author Andreas Schaefer
16  * @version $Revision: 1.4 $
17  *
18  * @ejb:bean name="InsertAuthRoleUser"
19  * display-name="Makes inserts in the AuthRole_User table"
20  * type="Stateless"
21  * jndi-name="ejb/hero/InsertAuthRoleUser"
22  * local-jndi-name="ejb/hero/InsertAuthRoleUser_L"
23  *
24  *
25  * @ejb:transaction-type type="Container"
26  *
27  * @jonas.bean
28  * ejb-name="InsertAuthRoleUser"
29  * jndi-name="ejb/hero/InsertAuthRoleUser"
30  * @ejb.permission unchecked="yes"
31  * @ejb.security-identity run-as="SuperAdmin"
32  *
33  * @ejb.resource-ref res-ref-name="jdbc/myDS"
34  * res-type="javax.sql.DataSource"
35  * res-auth="Application"
36  * @jonas.resource
37  * res-ref-name="jdbc/myDS"
38  * jndi-name="bonita"
39 */

40 public class InsertAuthRoleUserBean implements SessionBean JavaDoc
41 {
42    private SessionContext JavaDoc mContext;
43
44  /**
45     * Makes inserts in User table
46     *
47     *
48     * @throws RemoteException
49     *
50     * @ejb:interface-method view-type="remote"
51     * @ejb:transaction type="Required"
52     **/

53    public void initializeUser(String JavaDoc name,String JavaDoc password,String JavaDoc email) {
54        
55     Context JavaDoc lContext;
56     BnUserLocalHome uhome = null;
57     BnUserLocal user;
58     BnUserValue uv;
59
60     try {
61         uhome = hero.interfaces.BnUserUtil.getLocalHome();
62         try {
63             BnUserLocal us = uhome.findByName(name);
64             throw new HeroException("BnUser " + name + " already exist in the system ");
65         } catch (javax.ejb.FinderException JavaDoc nn) {
66             user = uhome.create(new BnUserValue());
67             uv=user.getBnUserValue();
68             //uv.setId(id);
69
uv.setName(name);
70             uv.setPassword(password);
71             uv.setEmail(email);
72             uv.setCreationDate(null);
73             uv.setModificationDate(null);
74             uv.setJabber(null);
75             user.setBnUserValue(uv);
76         }
77     } catch (java.lang.Exception JavaDoc e) {
78         e.printStackTrace(System.out);
79     }
80
81    }
82
83  /**
84     * Makes inserts in User table
85     *
86     *
87     * @throws RemoteException
88     *
89     * @ejb:interface-method view-type="remote"
90     * @ejb:transaction type="Required"
91     **/

92    public void initializeAuthRole(String JavaDoc name,String JavaDoc rolegroup) {
93        
94     Context JavaDoc lContext;
95     BnAuthRoleLocalHome arhome = null;
96     BnAuthRoleLocal arole;
97     try {
98         arhome = hero.interfaces.BnAuthRoleUtil.getLocalHome();
99         try {
100             BnAuthRoleLocal us = arhome.findByName(name);
101             throw new HeroException("BnAuthRole " + name + " already exist in the system ");
102         } catch (javax.ejb.FinderException JavaDoc nn) {
103             BnAuthRoleValue arv = new BnAuthRoleValue();
104             arv.setName(name);
105             arv.setBnRoleGroup(rolegroup);
106             arole = arhome.create(arv);
107         }
108     } catch (java.lang.Exception JavaDoc e) {
109         e.printStackTrace(System.out);
110     }
111
112    }
113
114    /**
115     * Makes inserts in AuthRole_User table
116     *
117     * @throws RemoteException
118     *
119     * @ejb:interface-method view-type="remote"
120     * @ejb:transaction type="Required"
121     **/

122    public void initialize(String JavaDoc User,String JavaDoc AuthRole) {
123        
124     Context JavaDoc lContext;
125     BnUserLocalHome uhome = null;
126     BnAuthRoleLocalHome arhome = null;
127     BnUserLocal user;
128     BnAuthRoleLocal authRole;
129     try {
130         uhome = hero.interfaces.BnUserUtil.getLocalHome();
131         arhome = hero.interfaces.BnAuthRoleUtil.getLocalHome();
132         user=uhome.findByName(User);
133         authRole=arhome.findByName(AuthRole);
134         
135         if (!authRole.getBnUsers().contains(user))
136             authRole.getBnUsers().add(user);
137         if (!user.getBnAuthRoles().contains(authRole))
138             user.getBnAuthRoles().add(authRole);
139     
140     } catch (java.lang.Exception JavaDoc e) {
141         e.printStackTrace(System.out);
142     }
143
144    }
145
146    /**
147     * Create the Session Bean
148     *
149     * @throws CreateException
150     *
151     * @ejb:create-method view-type="remote"
152     **/

153    public void ejbCreate() throws CreateException JavaDoc {}
154
155
156    // -------------------------------------------------------------------------
157
// Framework Callbacks
158
// -------------------------------------------------------------------------
159

160    public void setSessionContext( SessionContext JavaDoc aContext ) throws EJBException JavaDoc
161    {
162       mContext = aContext;
163    }
164    
165    public void ejbActivate()
166       throws EJBException JavaDoc
167    {
168    }
169    
170    public void ejbPassivate()
171       throws EJBException JavaDoc
172    {
173    }
174
175    public void ejbRemove()
176       throws EJBException JavaDoc
177    {
178    }
179
180 }
181
Popular Tags