KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > engine > helloworld > HelloworldImpl


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id$
20  * -------------------------------------------------------------------------
21  */

22
23 package org.objectweb.petals.engine.helloworld;
24
25 import java.util.logging.Level JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27
28 import javax.jbi.component.ComponentContext;
29 import javax.naming.NameNotFoundException JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31
32 import org.objectweb.petals.tools.jbicommon.util.StringHelper;
33
34 public class HelloworldImpl implements Helloworld {
35
36     public static final String JavaDoc HELLOWORLD_CONTEXT = "helloworldContext";
37
38     public static final String JavaDoc HELLOWORLD_JNDI_ENTRY = "helloworldEntry";
39
40     private final ComponentContext context;
41
42     private Logger JavaDoc logger; // NOPMD
43

44     public HelloworldImpl(ComponentContext context, Logger JavaDoc logger) {
45         super();
46         this.context = context;
47         this.logger = logger;
48     }
49
50     public void bindMessage(final String JavaDoc message) {
51         if (StringHelper.isNullOrEmpty(message)) {
52             logger.log(Level.INFO, "hello.printNothing");
53         } else {
54
55             String JavaDoc jndiName = HELLOWORLD_CONTEXT + "/" + HELLOWORLD_JNDI_ENTRY;
56
57             try {
58                 context.getNamingContext().unbind(jndiName);
59                 context.getNamingContext().bind(jndiName, message);
60             } catch (NameNotFoundException JavaDoc e1) {
61                 // Context doesn't exist, I can add it
62
try {
63                     context.getNamingContext().bind(jndiName, message);
64                 } catch (NamingException JavaDoc e) {
65                     logger.log(Level.WARNING, "hello.cantBind",
66                             new String JavaDoc[] { jndiName });
67                 }
68             } catch (NamingException JavaDoc e1) {
69                 logger.log(Level.WARNING, "hello.cantBind",
70                         new String JavaDoc[] { jndiName });
71             }
72         }
73
74     }
75
76     public void printMessage(final String JavaDoc message) {
77         if (StringHelper.isNullOrEmpty(message)) {
78             logger.log(Level.INFO, "hello.printNothing");
79         } else {
80             logger.log(Level.INFO, "hello.received", new String JavaDoc[] { message });
81         }
82     }
83
84     public String JavaDoc sayHello(final String JavaDoc message) {
85         String JavaDoc response = "You told me: " + message;
86         if (StringHelper.isNullOrEmpty(message)) {
87             logger.log(Level.INFO, "hello.printNothing");
88             response = "You told me nothing";
89         } else {
90             logger.log(Level.INFO, "hello.received", new String JavaDoc[] { message });
91             response = "You told me: " + message;
92         }
93         return response;
94     }
95
96 }
97
Popular Tags