HolidayCalendarTestClient1.java~17~
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:3k
源码类别:
Java编程
开发平台:
Java
- package meetings;
- import com.cwj.meetings.*;
- import javax.naming.*;
- import java.util.Properties;
- import javax.rmi.PortableRemoteObject;
- public class HolidayCalendarTestClient1 extends Object {
- // private HolidayCalendarHome holidayCalendarHome = null;
- // private HolidayCalendarLocalHome localHome=null;
- //Construct the EJB test client
- public HolidayCalendarTestClient1() {
- initialize();
- }
- public void initialize() {
- try {
- //get naming context
- Context context = getInitialContext();
- //look up jndi name
- // Object ref = context.lookup("HolidayCalendar");
- // Object ref = context.lookup("HolidayCalendarLocal");
- //look up jndi name and cast to Home interface
- // holidayCalendarHome = (HolidayCalendarHome) PortableRemoteObject.narrow(ref, HolidayCalendarHome.class);
- // holidayCalendarHome=(HolidayCalendarHome)context.lookup("HolidayCalendar");
- HolidayCalendarLocalHome lh=(HolidayCalendarLocalHome)context.lookup("HolidayCalendar");
- //
- System.out.println(lh);
- HolidayCalendarLocal hcal = lh.create();
- if(hcal.isCompanyHoliday(new java.util.Date())) {
- System.out.println("Today is a holiday :-)");
- }
- else {
- System.out.println("Today is a working day :-(");
- }
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- private Context getInitialContext() throws Exception {
- String url = "t3://127.0.0.1:7001";
- String user = null;
- String password = null;
- Properties properties = null;
- try {
- properties = new Properties();
- properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
- properties.put(Context.PROVIDER_URL, url);
- if (user != null) {
- properties.put(Context.SECURITY_PRINCIPAL, user);
- properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
- }
- return new InitialContext(properties);
- }
- catch(Exception e) {
- System.out.println("Unable to connect to WebLogic server at " + url);
- System.out.println("Please make sure that the server is running.");
- throw e;
- }
- }
- //----------------------------------------------------------------------------
- // Utility Methods
- //----------------------------------------------------------------------------
- // public HolidayCalendarHome getHome() {
- // return holidayCalendarHome;
- // }
- //Main method
- public static void main(String[] args) {
- HolidayCalendarTestClient1 client = new HolidayCalendarTestClient1();
- // Use the getHome() method of the client object to call Home interface
- // methods that will return a Remote interface reference. Then
- // use that Remote interface reference to access the EJB.
- }
- }