Permalink
Browse files

added AddAppointment, ViewAppointment + new style of working with tho…

…se interfaces

after discussing we thought it is bad how the LoginUser calls remotely his local UserMgt class
Through that we thought it would be nice, if the client will use the UserMgt class but with the interface
of ILoginUser - for the client the change was:
from:
    ILoginUser loginUser = (ILoginUser) ctx.lookup("LoginUser/remote");
to:
    ILoginUser loginUser = (ILoginUser) ctx.lookup("UserMgt/remote");

for the serverside
    we tried to let UserMgt implement ILoginUser cause else the ctx-proxy couldn't cast it
        this didn't work either
    so we tried to let @Remote include multiple interfaces which isn't supported
    so now the IUserMgt class will extend from our ILoginUser interface

maybe this idea needs discussion - but in our oppinion this looks a lot cleaner

PS: the implementation of AddAppointment and ViewAppointment don't work - the "new" operator
must be changed to that code we have in LoginUser class
  • Loading branch information...
1 parent 48bedf0 commit ab8211b52ad3d05711ec403f8f667bd81b0e97bb carl committed Jun 12, 2011
View
29 project/src/bean/AddAppointment.java
@@ -0,0 +1,29 @@
+package bean;
+
+import java.util.Collection;
+import java.util.Date;
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+import bean.CalendarMgt;
+
+@Stateful
+@Remote(IAddAppointment.class)
+
+public class AddAppointment implements IAddAppointment {
+
+ @Override
+ public Boolean addAppointment(Date start, Date end, String title,
+ String notes, Boolean isPrivate, AppointmentType type,
+ Collection<String> userEmails) {
+ // TODO Auto-generated method stub
+ CalendarMgt cMgt = new CalendarMgt();
+ return cMgt.addAppointment(start, end, title, notes, isPrivate, type, userEmails);
+ }
+
+ @Override
+ public void remove() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
View
4 project/src/bean/CalendarMgt.java
@@ -3,6 +3,8 @@
import bean.Calendar;
import bean.Appointment;
import bean.AppointmentType;
+import bean.IAddAppointment;
+import bean.IViewAppointment;
import javax.ejb.Remote;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@@ -18,7 +20,7 @@
@Stateful
@Remote(ICalendarMgt.class)
-public class CalendarMgt implements ICalendarMgt
+public class CalendarMgt implements ICalendarMgt, IViewAppointment, IAddAppointment
{
@PersistenceContext
private EntityManager manager;
View
8 project/src/bean/IAddAppointment.java
@@ -0,0 +1,8 @@
+package bean;
+
+import java.util.Collection;
+import java.util.Date;
+
+public interface IAddAppointment {
+ public Boolean addAppointment(Date start, Date end, String title, String notes, Boolean isPrivate, AppointmentType type, Collection<String> userEmails);
+}
View
4 project/src/bean/ICalendarMgt.java
@@ -1,12 +1,14 @@
package bean;
import bean.Appointment;
+import bean.IAddAppointment;
+import bean.IViewAppointment;
import bean.AppointmentType;
import javax.ejb.Remove;
import java.util.Date;
import java.util.Collection;
-public interface ICalendarMgt
+public interface ICalendarMgt extends IAddAppointment, IViewAppointment
{
public Boolean addAppointment(Date start, Date end, String title, String notes, Boolean isPrivate, AppointmentType type, Collection<String> userEmails);
public Collection<Appointment> viewAppointments(String email);
View
3 project/src/bean/IUserMgt.java
@@ -1,9 +1,10 @@
package bean;
import bean.Calendar;
+import bean.ILoginUser;
import javax.ejb.Remove;
-public interface IUserMgt
+public interface IUserMgt extends ILoginUser
{
public void login(String name, String email);
public Calendar getUserCalendar(String email);
View
7 project/src/bean/IViewAppointment.java
@@ -0,0 +1,7 @@
+package bean;
+
+import java.util.Collection;
+
+public interface IViewAppointment {
+ public Collection<Appointment> viewAppointments(String email);
+}
View
19 project/src/bean/ViewAppointment.java
@@ -0,0 +1,19 @@
+package bean;
+
+import java.util.Collection;
+
+public class ViewAppointment implements IViewAppointment {
+
+ @Override
+ public Collection<Appointment> viewAppointments(String email) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void remove() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
View
15 project/src/client/Client.java
@@ -1,9 +1,9 @@
package client;
-import bean.IUserMgt;
import bean.ILoginUser;
-import bean.ICalendarMgt;
+import bean.IViewAppointment;
+import bean.IAddAppointment;
import bean.Appointment;
import bean.AppointmentType;
@@ -21,17 +21,16 @@
public static void main(String[] args) throws Exception
{
InitialContext ctx = new InitialContext();
- IUserMgt uMgt = (IUserMgt) ctx.lookup("UserMgt/remote");
- ILoginUser loginUser = (ILoginUser) ctx.lookup("LoginUser/remote");
- ICalendarMgt cMgt = (ICalendarMgt) ctx.lookup("CalendarMgt/remote");
+ ILoginUser loginUser = (ILoginUser) ctx.lookup("UserMgt/remote");
+ IAddAppointment addApp = (IAddAppointment) ctx.lookup("CalendarMgt/remote");
+ IViewAppointment viewApp = (IViewAppointment) ctx.lookup("CalendarMgt/remote");
System.out.println("starting login");
loginUser.login("Alice", "alice@a.com");
- assert(uMgt.getUserCalendar("email") != null);
System.out.println("starting addAppointment");
HashSet <String> userEmails = new HashSet <String>();
userEmails.add("alice@a.com");
- cMgt.addAppointment(
+ addApp.addAppointment(
new Date(2011,6,19), // start
new Date(2011,6,20), // end
"title",
@@ -41,7 +40,7 @@ public static void main(String[] args) throws Exception
userEmails);
System.out.println("starting viewAppointments:");
- viewAppointments(cMgt.viewAppointments("alice@a.com"));
+ viewAppointments(viewApp.viewAppointments("alice@a.com"));
}
public static void viewAppointments(Collection<Appointment> appointments)

0 comments on commit ab8211b

Please sign in to comment.