1 package com.instantbank.lettertemplate.control.util;
2
3 import java.rmi.RemoteException;
4 import javax.rmi.PortableRemoteObject;
5 import javax.naming.InitialContext;
6 import javax.naming.NamingException;
7 import javax.ejb.CreateException;
8 import javax.ejb.SessionContext;
9
10 import com.instantbank.common.utilcomponents.JNDINames;
11 import com.instantbank.component.lettertemplate.ejb.LetterTemplateHome;
12 import com.instantbank.component.job.ejb.JobHome;
13 import com.instantbank.lettertemplate.control.ejb.LetterTemplateControllerHome;
14
15
21 public final class EJBUtil {
22
23
29 public static LetterTemplateControllerHome getLetterTemplateControllerHome() throws Exception {
30 try {
31 InitialContext initial = new InitialContext();
32 Object objref = initial.lookup(JNDINames.LETTERTEMPLATE_SCC_EJBHOME);
33 return (LetterTemplateControllerHome)
34 PortableRemoteObject.narrow(objref, LetterTemplateControllerHome.class);
35 }
36 catch(NamingException ne) {
37 throw new Exception(ne.getMessage());
38 }
39 }
40
41
42
48 public static LetterTemplateHome getLetterTemplateHome() throws Exception {
49 try {
50 InitialContext initial = new InitialContext();
51 Object objref = initial.lookup(JNDINames.LETTERTEMPLATE_EJBHOME);
52 return (LetterTemplateHome)
53 PortableRemoteObject.narrow(objref, LetterTemplateHome.class);
54 }
55 catch(NamingException ne) {
56 throw new Exception(ne.getMessage());
57 }
58 }
59
60
61
67 public static JobHome getJobHome() throws Exception {
68 try {
69 InitialContext initial = new InitialContext();
70 Object objref = initial.lookup(JNDINames.JOB_EJBHOME);
71 return (JobHome)
72 PortableRemoteObject.narrow(objref, JobHome.class);
73 }
74 catch(NamingException ne) {
75 throw new Exception(ne.getMessage());
76 }
77 }
78
79
80
87 public static String getUserId(SessionContext context)
88 throws Exception {
89 String userId = context.getCallerPrincipal().getName();
90 return userId;
91 }
92
93
94
102 public static boolean isUserInRole(SessionContext context, String rol)
103 throws Exception {
104 return (context.isCallerInRole(rol));
105 }
106
107 }
108