KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > wssample > beans > wsclient > GoogleClientBeanSLR


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  * Initial developer(s): Guillaume Sauthier______________.
22  * Contributor(s): ______________________________________.
23  *
24  * --------------------------------------------------------------------------
25  * $Id: GoogleClientBeanSLR.java,v 1.1 2004/12/20 11:07:51 sauthieg Exp $
26  * --------------------------------------------------------------------------
27  */

28 package org.objectweb.wssample.beans.wsclient;
29
30 import java.rmi.RemoteException JavaDoc;
31
32 import javax.ejb.CreateException JavaDoc;
33 import javax.ejb.SessionBean JavaDoc;
34 import javax.ejb.SessionContext JavaDoc;
35 import javax.naming.Context JavaDoc;
36 import javax.naming.InitialContext JavaDoc;
37 import javax.naming.NamingException JavaDoc;
38
39 import org.objectweb.jonas.common.Log;
40 import org.objectweb.util.monolog.api.Logger;
41 import org.objectweb.util.monolog.api.BasicLevel;
42
43 import org.objectweb.wssample.genbean.google.GoogleSearchResult;
44 import org.objectweb.wssample.genbean.google.GoogleSearchService;
45 import org.objectweb.wssample.genbean.google.GoogleSearchPort;
46
47 import javax.xml.rpc.ServiceException JavaDoc;
48
49 /**
50  * GoogleClientBean implementation. This bean use Google WebServices API
51  * to execute a given Query.
52  *
53  * @author Guillaume Sauthier
54  */

55 public class GoogleClientBeanSLR implements SessionBean JavaDoc {
56
57     /**
58      * logger
59      */

60     private static Logger logger = null;
61
62     /**
63      * Session Context
64      */

65     private SessionContext JavaDoc ejbContext;
66
67     // ------------------------------------------------------------------
68
// SessionBean implementation
69
// ------------------------------------------------------------------
70

71     /**
72      * Set the SessionContext
73      * @param ctx the SessionContext
74      */

75     public void setSessionContext(SessionContext JavaDoc ctx) {
76         if (logger == null) {
77             logger = Log.getLogger("org.objectweb.jonas_tests");
78         }
79         logger.log(BasicLevel.DEBUG, "");
80         ejbContext = ctx;
81     }
82
83     /**
84      * ejbRemove
85      */

86     public void ejbRemove() {
87         logger.log(BasicLevel.DEBUG, "");
88     }
89
90     /**
91      * ejbCreate
92      * @throws CreateException CreateException
93      */

94     public void ejbCreate() throws CreateException JavaDoc {
95         logger.log(BasicLevel.DEBUG, "");
96     }
97
98     /**
99      * ejbPassivate
100      */

101     public void ejbPassivate() {
102         logger.log(BasicLevel.DEBUG, "");
103     }
104
105     /**
106      * ejbActivate
107      */

108     public void ejbActivate() {
109         logger.log(BasicLevel.DEBUG, "");
110     }
111
112     // ------------------------------------------------------------------
113
// GoogleClientBean implementation
114
// ------------------------------------------------------------------
115

116     /**
117      * Execute a Query via Google WS api.
118      *
119      * @param query Query String
120      * @return query results
121      */

122     public GoogleSearchResult executeQuery(java.lang.String JavaDoc query) {
123
124         logger.log(BasicLevel.INFO, "Executing Google Query '" + query + "'");
125
126         try {
127
128             // Get the InitialContext where retrieve Service
129
Context JavaDoc ctx = new InitialContext JavaDoc();
130
131             // Lookup the service
132
GoogleSearchService google =
133                 (GoogleSearchService) ctx.lookup("java:comp/env/service/google");
134
135             // get Google Port
136
GoogleSearchPort search = google.getGoogleSearchPort();
137
138             // get Google Key
139
String JavaDoc key = (String JavaDoc) ctx.lookup("java:comp/env/googleKey");
140
141             // Execute the query
142
return search.doGoogleSearch(key,
143                                          query,
144                                          0, // first index
145
10, // maxresult
146
false, //filter
147
null, //restrict
148
false, // safesearch
149
null, //lr
150
null, //ie
151
null //oe
152
);
153         } catch (NamingException JavaDoc ne) {
154             return null;
155         } catch (RemoteException JavaDoc re) {
156             return null;
157         } catch (ServiceException JavaDoc se) {
158             return null;
159         }
160     }
161 }
162
163
Popular Tags