PlannerClient.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:1k
源码类别:
Java编程
开发平台:
Java
- package com.borland.training.meetings.clients;
- import com.borland.training.meetings.sessions.*;
- import javax.naming.*;
- import java.util.Calendar;
- import java.util.Date;
- public class PlannerClient {
- public static void main(String[] args) {
- try {
- //get naming context
- Context ctx = new InitialContext();
- System.out.println("Looking for PlannerHome");
- //look up jndi name
- java.lang.Object ref = ctx.lookup("meetings/Planner");
- //cast to Home interface
- PlannerHome plannerHome = (PlannerHome)
- javax.rmi.PortableRemoteObject.narrow(ref, PlannerHome.class);
- System.out.println("Initializing meeting data");
- java.util.Collection attendeeIds = new java.util.Vector(2);
- attendeeIds.add(new Long(1));
- attendeeIds.add(new Long(2));
- Calendar cal = Calendar.getInstance();
- cal.set(2002, Calendar.DECEMBER, 21, 0, 0, 0);
- Date startTime = cal.getTime();
- System.out.println("Start time: " + startTime);
- System.out.println("Looking for periods of availability");
- Planner planner = plannerHome.create(attendeeIds, startTime);
- for(int i=0; i < 5; i++) {
- TimePeriod tp = planner.nextAvailableTimePeriod();
- if(tp == null) {
- break;
- }
- System.out.println(tp.getStartTime() + ", " + tp.getFinishTime());
- }
- System.out.println("Done");
- planner.remove();
- }
- catch(Exception e) {
- System.err.println("Exception caught");
- e.printStackTrace();
- }
- }
- }