1 22 23 package org.objectweb.petals.engine.helloworld; 24 25 import java.util.logging.Level ; 26 import java.util.logging.Logger ; 27 28 import javax.jbi.component.ComponentContext; 29 import javax.naming.NameNotFoundException ; 30 import javax.naming.NamingException ; 31 32 import org.objectweb.petals.tools.jbicommon.util.StringHelper; 33 34 public class HelloworldImpl implements Helloworld { 35 36 public static final String HELLOWORLD_CONTEXT = "helloworldContext"; 37 38 public static final String HELLOWORLD_JNDI_ENTRY = "helloworldEntry"; 39 40 private final ComponentContext context; 41 42 private Logger logger; 44 public HelloworldImpl(ComponentContext context, Logger logger) { 45 super(); 46 this.context = context; 47 this.logger = logger; 48 } 49 50 public void bindMessage(final String message) { 51 if (StringHelper.isNullOrEmpty(message)) { 52 logger.log(Level.INFO, "hello.printNothing"); 53 } else { 54 55 String jndiName = HELLOWORLD_CONTEXT + "/" + HELLOWORLD_JNDI_ENTRY; 56 57 try { 58 context.getNamingContext().unbind(jndiName); 59 context.getNamingContext().bind(jndiName, message); 60 } catch (NameNotFoundException e1) { 61 try { 63 context.getNamingContext().bind(jndiName, message); 64 } catch (NamingException e) { 65 logger.log(Level.WARNING, "hello.cantBind", 66 new String [] { jndiName }); 67 } 68 } catch (NamingException e1) { 69 logger.log(Level.WARNING, "hello.cantBind", 70 new String [] { jndiName }); 71 } 72 } 73 74 } 75 76 public void printMessage(final String message) { 77 if (StringHelper.isNullOrEmpty(message)) { 78 logger.log(Level.INFO, "hello.printNothing"); 79 } else { 80 logger.log(Level.INFO, "hello.received", new String [] { message }); 81 } 82 } 83 84 public String sayHello(final String message) { 85 String 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 [] { message }); 91 response = "You told me: " + message; 92 } 93 return response; 94 } 95 96 } 97 | Popular Tags |