I'm trying to constuct a service implimentation that receives references to a 
couple of other services that registers the objects into a super class. But I 
get a null pointer exception.

What am I doing wrong here?


public class AppModule {

    public static void bind(ServiceBinder binder) {
        // bind low-level services and utilities
        binder.bind(CommonsEmailNotificationSender.class); // implements 
NotificationSender to send email
        binder.bind(TextMarketerNotificationSender.class); // implements 
NotificationSender to send sms

 ...
        // bind facades
 ...
        binder.bind(NotificationSenderFacade.class, 
DefaultNotificationSenderFacade.class); // combines the NotificationSender 
instances above

    }



public interface NotificationSender {

    boolean sendNotification(String toUsername, String fromUsername, String 
replyto, String to, String messageText, boolean admin);

    boolean sendNotificationLater(String toUsername, String fromUsername, 
String replyto, String to, String messageText, boolean admin);



public interface NotificationSenderFacade {

    NotificationSender getNotificationSender(String classnme);

    boolean sendNotification(String toUsername, String fromUsername, 
List<NotificationRouting>routes, String messageText, boolean admin);

    boolean sendNotificationLater(String toUsername, String fromUsername, 
List<NotificationRouting>routes, String messageText, boolean admin);



public abstract class AbstractNotificationSenderFacade implements 
NotificationSenderFacade {

    /**
     * The log.
     */
    @Inject
    private Logger log;

    private Map<String, NotificationSender> notificationSenders
            = new HashMap<String, NotificationSender>();

    // put the notification senders into a map during subclass construction
    protected void registerNotificationSender(NotificationSender 
notificationSender) {
        String classname = notificationSender.getClass().getSimpleName();
        notificationSenders.put(classname, notificationSender);
        log.info("registered " + classname);
    }



@EagerLoad
public class DefaultNotificationSenderFacade extends 
AbstractNotificationSenderFacade {

    /**
     * The log.
     */
    @Inject
    private Logger log;

    /**
     * Create the facade for the given the notification senders.
     *
     * @param emailNotificationSender
     * @param smsNotificationSender
     */
    public DefaultNotificationSenderFacade(CommonsEmailNotificationSender 
emailNotificationSender,
            TextMarketerNotificationSender smsNotificationSender) {
        super();
        super.registerNotificationSender(emailNotificationSender);
        super.registerNotificationSender(smsNotificationSender);
        log.debug("registered notification senders");
    }

    @Override
    public boolean sendNotification(String toUsername, String fromUsername, 
List<NotificationRouting> routes, String messageText, boolean admin) {
       boolean success = true;
        for (NotificationRouting route : routes) {
            if (route.getTo().contains("@")) {
                boolean done = 
super.getNotificationSender("CommonsEmailNotificationSender")
                        .sendNotification(toUsername, fromUsername, 
route.getReplyto(), route.getTo(), messageText, admin);



AppModule.NotificationSenderFacade Loading class 
com.quivinco.webapps.tbs.utils.DefaultNotificationSenderFacade.
AppModule.NotificationSenderFacade Marking class 
com.quivinco.webapps.tbs.utils.DefaultNotificationSenderFacade to be (re-)loaded
AppModule.NotificationSenderFacade BEGIN Analyzing 
com.quivinco.webapps.tbs.utils.DefaultNotificationSenderFacade
AppModule.NotificationSenderFacade Marking class 
com.quivinco.webapps.tbs.utils.AbstractNotificationSenderFacade to be 
(re-)loaded
AppModule.NotificationSenderFacade BEGIN Analyzing 
com.quivinco.webapps.tbs.utils.AbstractNotificationSenderFacade
AppModule.NotificationSenderFacade   END Analyzing 
com.quivinco.webapps.tbs.utils.AbstractNotificationSenderFacade
AppModule.NotificationSenderFacade   END Analyzing 
com.quivinco.webapps.tbs.utils.DefaultNotificationSenderFacade
AppModule.CommonsEmailNotificationSender Creating non-proxied instance of 
service CommonsEmailNotificationSender
AppModule.CommonsEmailNotificationSender Invoking constructor 
com.quivinco.webapps.tbs.utils.CommonsEmailNotificationSender() (at 
CommonsEmailNotificationSender.java:23) via 
com.quivinco.webapps.tbs.services.AppModule.bind(ServiceBinder) (at 
AppModule.java:75) (for service 'CommonsEmailNotificationSender')
AppModule.TextMarketerNotificationSender Creating non-proxied instance of 
service TextMarketerNotificationSender
AppModule.TextMarketerNotificationSender Invoking constructor 
com.quivinco.webapps.tbs.utils.TextMarketerNotificationSender() (at 
TextMarketerNotificationSender.java:16) via 
com.quivinco.webapps.tbs.services.AppModule.bind(ServiceBinder) (at 
AppModule.java:75) (for service 'TextMarketerNotificationSender')
AppModule.NotificationSenderFacade Invoking constructor public 
com.quivinco.webapps.tbs.utils.DefaultNotificationSenderFacade(com.quivinco.webapps.tbs.utils.CommonsEmailNotificationSender,com.quivinco.webapps.tbs.utils.TextMarketerNotificationSender)
 (for service 'NotificationSenderFacade')
ioc.Registry Error invoking constructor public 
com.quivinco.webapps.tbs.utils.DefaultNotificationSenderFacade(com.quivinco.webapps.tbs.utils.CommonsEmailNotificationSender,com.quivinco.webapps.tbs.utils.TextMarketerNotificationSender):
 java.lang.NullPointerException
ioc.Registry Operations trace:
ioc.Registry [ 1] Realizing service NotificationSenderFacade
ioc.Registry [ 2] Instantiating service NotificationSenderFacade implementation 
via com.quivinco.webapps.tbs.services.AppModule.bind(ServiceBinder) (at 
AppModule.java:75)
ioc.Registry [ 3] Reloading class 
com.quivinco.webapps.tbs.utils.DefaultNotificationSenderFacade.
ioc.Registry [ 4] Invoking constructor public 
com.quivinco.webapps.tbs.utils.DefaultNotificationSenderFacade(com.quivinco.webapps.tbs.utils.CommonsEmailNotificationSender,com.quivinco.webapps.tbs.utils.TextMarketerNotificationSender)
 (for service 'NotificationSenderFacade')
AppModule.NotificationSenderFacade Construction of service 
NotificationSenderFacade failed: Error invoking constructor public 
com.quivinco.webapps.tbs.utils.DefaultNotificationSenderFacade(com.quivinco.webapps.tbs.utils.CommonsEmailNotificationSender,com.quivinco.webapps.tbs.utils.TextMarketerNotificationSender):
 java.lang.NullPointerException




---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com

Reply via email to