KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > appclients > timeclient > TimeClient


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: TimeClient.java,v 1.2 2004/07/06 13:04:06 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas.jtests.appclients.timeclient;
26
27 import javax.naming.InitialContext JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29 import javax.xml.namespace.QName JavaDoc;
30 import javax.xml.rpc.Call JavaDoc;
31 import javax.xml.rpc.Service JavaDoc;
32
33 /**
34  * @author Guillaume Sauthier
35  */

36 public class TimeClient {
37
38     /**
39      * Service Ref Name
40      */

41     private static final String JavaDoc SERVICE_REF_NAME = "java:comp/env/service/time";
42
43     /**
44      * InitialContext
45      */

46     private InitialContext JavaDoc ic;
47
48     /**
49      *
50      */

51     public TimeClient() throws Exception JavaDoc {
52         init();
53     }
54
55     /**
56      *
57      */

58     private void init() throws NamingException JavaDoc {
59         ic = new InitialContext JavaDoc();
60     }
61
62     public boolean hasBindedService() throws NamingException JavaDoc {
63         Object JavaDoc o = lookupService();
64         if (o != null) {
65             if (o instanceof Service JavaDoc) {
66                 return true;
67             }
68         }
69         return false;
70     }
71     
72     /*
73     public boolean isServiceWellConfigured() throws NamingException {
74         Service s = (Service) lookupService();
75         if (s instanceof XXX) {
76             return true;
77         }
78         return false;
79     }
80     */

81
82     private Object JavaDoc lookupService() throws NamingException JavaDoc {
83         return ic.lookup(SERVICE_REF_NAME);
84     }
85
86     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
87         TimeClient tc = new TimeClient();
88
89         if (!tc.hasBindedService()) {
90             throw new Exception JavaDoc("TimeClient should have a Service instance binded to '" + SERVICE_REF_NAME + "'");
91         }
92         
93         tc.handlersInvoked();
94     }
95
96     /**
97      * @return
98      */

99     private boolean handlersInvoked() throws Exception JavaDoc {
100         Service JavaDoc s = (Service JavaDoc) lookupService();
101         Call JavaDoc call = s.createCall(new QName JavaDoc("TimePort"), new QName JavaDoc("jonas:Time", "getDate"));
102         call.invoke(new Object JavaDoc[] {});
103         StaticPassValue spv = StaticPassValue.getInstance();
104         String JavaDoc init = spv.getInit();
105         String JavaDoc req = spv.getRequest();
106         String JavaDoc resp = spv.getResponse();
107         if (init == null) {
108             throw new Exception JavaDoc("Handler.init not invoked");
109         }
110         if (req == null) {
111             throw new Exception JavaDoc("Handler.handleRequest not invoked");
112         }
113         if (resp == null) {
114             throw new Exception JavaDoc("Handler.handlerResponse not invoked");
115         }
116         return true;
117     }
118 }
Popular Tags