That's what I was asking for as well. It is definitely the intent that
DefaultGuiceModule be used primarily for injected things that will almost
never need to be changed between implementations. I also have a preference
for keeping the bindings as close to the package that they're declared in as
well.

I'm not sure about not being able to re-bind though. If that's true, then
you're right and making it a separate module is indeed the only clean way to
make this work. If someone were to be using Guice by pulling in release jars
(say, from maven), they'd have no choice but to re-implement all of
HttpGuiceModule & DefaultGuiceModule by hand, even if they're only trying to
provide custom opensocial data handlers.

On Wed, Apr 9, 2008 at 1:03 AM, Ian Boston <[EMAIL PROTECTED]> wrote:

> Can we have one module that has just the services in it please.....
>
> as I understand it Guice 1.0 doesnt have re-bind capabilities, so if the
> services are in a core module, then an implementor, will have to replicate
> the implementation of the opensocial core module, rather than just creating
> a module to define the service bindings.
>
> (all said as a Guice beginner :) )
> Ian
>
>
>
> Ian
>
>
>
>
> On 8 Apr 2008, at 18:21, Kevin Brown wrote:
>
> > You should be providing a separate guice module for social stuff. It
> > doesn't
> > make sense to be creating all these social bindings for people who
> > aren't
> > using the social stuff at all yet (and it really doesn't make sense for
> > shindig.gadgets to be referencing stuff in shindig.social).
> >
> > The module loader already allows multiple modules to be converted to a
> > single injector; just add yours separated with a colon.
> >
> > On Tue, Apr 8, 2008 at 7:42 AM, <[EMAIL PROTECTED]> wrote:
> >
> >  Author: doll
> > > Date: Tue Apr  8 07:42:54 2008
> > > New Revision: 645947
> > >
> > > URL: http://svn.apache.org/viewvc?rev=645947&view=rev
> > > Log:
> > > The social data classes now use guice to get all of their
> > > dependencies.
> > >
> > > Modified:
> > >
> > >
> > >  
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
> > >
> > >
> > >  
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/GadgetDataServlet.java
> > >
> > >
> > >  
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/OpenSocialDataHandler.java
> > >   incubator/shindig/trunk/java/gadgets/src/main/webapp/WEB-INF/web.xml
> > >
> > > Modified:
> > >
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
> > > URL:
> > > http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/
> > > src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java?rev=645947&r1=645946&r2=645947&view=diff
> > >
> > >
> > > ==============================================================================
> > > ---
> > >
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
> > > (original)
> > > +++
> > >
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/DefaultGuiceModule.java
> > > Tue Apr  8 07:42:54 2008
> > > @@ -18,18 +18,31 @@
> > >  */
> > >  package org.apache.shindig.gadgets;
> > >
> > > -import org.apache.shindig.gadgets.oauth.OAuthFetcherFactory;
> > > -import org.apache.shindig.util.ResourceLoader;
> > > -
> > >  import com.google.inject.AbstractModule;
> > >  import com.google.inject.CreationException;
> > > +import com.google.inject.Inject;
> > > +import com.google.inject.Provider;
> > >  import com.google.inject.Scopes;
> > > +import com.google.inject.TypeLiteral;
> > >  import com.google.inject.name.Names;
> > >  import com.google.inject.spi.Message;
> > > +import org.apache.shindig.gadgets.oauth.OAuthFetcherFactory;
> > > +import org.apache.shindig.social.GadgetDataHandler;
> > > +import org.apache.shindig.social.opensocial.ActivitiesService;
> > > +import org.apache.shindig.social.opensocial.DataService;
> > > +import org.apache.shindig.social.opensocial.OpenSocialDataHandler;
> > > +import org.apache.shindig.social.opensocial.PeopleService;
> > > +import
> > > org.apache.shindig.social.samplecontainer.BasicActivitiesService;
> > > +import org.apache.shindig.social.samplecontainer.BasicDataService;
> > > +import org.apache.shindig.social.samplecontainer.BasicPeopleService;
> > > +import
> > > org.apache.shindig.social.samplecontainer.StateFileDataHandler;
> > > +import org.apache.shindig.util.ResourceLoader;
> > >
> > >  import java.io.IOException;
> > >  import java.io.InputStream;
> > > +import java.util.ArrayList;
> > >  import java.util.Arrays;
> > > +import java.util.List;
> > >  import java.util.Properties;
> > >  import java.util.concurrent.Executor;
> > >  import java.util.concurrent.Executors;
> > > @@ -64,6 +77,15 @@
> > >    bind(SyndicatorConfig.class).in(Scopes.SINGLETON);
> > >    bind(GadgetFeatureRegistry.class).in(Scopes.SINGLETON);
> > >    bind(GadgetServer.class).in(Scopes.SINGLETON);
> > > +
> > > +    // Social guice
> > > +    bind(PeopleService.class).to(BasicPeopleService.class);
> > > +    bind(DataService.class).to(BasicDataService.class);
> > > +    bind(ActivitiesService.class).to(BasicActivitiesService.class);
> > > +
> > > +    bind(new TypeLiteral<List<GadgetDataHandler>>() {})
> > > +        .toProvider(GadgetDataHandlersProvider.class);
> > > +
> > >  }
> > >
> > >  public DefaultGuiceModule(Properties properties) {
> > > @@ -84,5 +106,22 @@
> > >          new Message("Unable to load properties: " +
> > > DEFAULT_PROPERTIES)));
> > >    }
> > >    this.properties = properties;
> > > +  }
> > > +
> > > +  public static class GadgetDataHandlersProvider
> > > +      implements Provider<List<GadgetDataHandler>> {
> > > +    List<GadgetDataHandler> handlers;
> > > +
> > > +    @Inject
> > > +    public GadgetDataHandlersProvider(OpenSocialDataHandler
> > > +        openSocialDataHandler, StateFileDataHandler stateFileHandler)
> > > {
> > > +      handlers = new ArrayList<GadgetDataHandler>();
> > > +      handlers.add(openSocialDataHandler);
> > > +      handlers.add(stateFileHandler);
> > > +    }
> > > +
> > > +    public List<GadgetDataHandler> get() {
> > > +      return handlers;
> > > +    }
> > >  }
> > >  }
> > >
> > > Modified:
> > >
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/GadgetDataServlet.java
> > > URL:
> > > http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/
> > > src/main/java/org/apache/shindig/social/GadgetDataServlet.java?rev=645947&r1=645946&r2=645947&view=diff
> > >
> > >
> > > ==============================================================================
> > > ---
> > >
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/GadgetDataServlet.java
> > > (original)
> > > +++
> > >
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/GadgetDataServlet.java
> > > Tue Apr  8 07:42:54 2008
> > > @@ -17,30 +17,23 @@
> > >  */
> > >  package org.apache.shindig.social;
> > >
> > > +import com.google.inject.Inject;
> > >  import org.apache.shindig.gadgets.GadgetException;
> > >  import org.apache.shindig.gadgets.GadgetToken;
> > >  import org.apache.shindig.gadgets.GadgetTokenDecoder;
> > >  import org.apache.shindig.gadgets.http.InjectedServlet;
> > > -import org.apache.shindig.social.opensocial.OpenSocialDataHandler;
> > > -import
> > > org.apache.shindig.social.samplecontainer.StateFileDataHandler;
> > > -
> > > -import com.google.inject.Inject;
> > > -
> > >  import org.json.JSONArray;
> > >  import org.json.JSONException;
> > >  import org.json.JSONObject;
> > >
> > > +import javax.servlet.http.HttpServletRequest;
> > > +import javax.servlet.http.HttpServletResponse;
> > >  import java.io.IOException;
> > >  import java.io.PrintWriter;
> > >  import java.util.ArrayList;
> > >  import java.util.List;
> > >  import java.util.logging.Logger;
> > >
> > > -import javax.servlet.ServletConfig;
> > > -import javax.servlet.ServletException;
> > > -import javax.servlet.http.HttpServletRequest;
> > > -import javax.servlet.http.HttpServletResponse;
> > > -
> > >  /**
> > >  * Servlet for handling gadget requests for data. The request accepts
> > > one
> > > json
> > >  * parameter of the format:
> > > @@ -61,37 +54,17 @@
> > >  private static final Logger logger
> > >      = Logger.getLogger("org.apache.shindig.social");
> > >
> > > -  // TODO: get through injection
> > > -  private static final List<GadgetDataHandler> handlers
> > > -      = new ArrayList<GadgetDataHandler>();
> > > -
> > > -
> > > +  private List<GadgetDataHandler> handlers;
> > >  private GadgetTokenDecoder gadgetTokenDecoder;
> > >
> > >  @Inject
> > > -  public void setGadgetTokenDecoder(GadgetTokenDecoder
> > > gadgetTokenDecoder) {
> > > -   this.gadgetTokenDecoder = gadgetTokenDecoder;
> > > +  public void setGadgetDataHandlers(List<GadgetDataHandler> handlers)
> > > {
> > > +    this.handlers = handlers;
> > >  }
> > >
> > > -  @Override
> > > -  public void init(ServletConfig config) throws ServletException {
> > > -    super.init(config);
> > > -
> > > -    String handlerNames = config.getInitParameter("handlers");
> > > -    if (handlerNames == null) {
> > > -      handlers.add(new OpenSocialDataHandler());
> > > -      handlers.add(new StateFileDataHandler());
> > > -    } else {
> > > -      for (String handlerName : handlerNames.split(",")) {
> > > -        try {
> > > -          GadgetDataHandler handler
> > > -              = (GadgetDataHandler)
> > > (Class.forName(handlerName)).newInstance();
> > > -          handlers.add(handler);
> > > -        } catch (Exception ex) {
> > > -          throw new ServletException(ex);
> > > -        }
> > > -      }
> > > -    }
> > > +  @Inject
> > > +  public void setGadgetTokenDecoder(GadgetTokenDecoder
> > > gadgetTokenDecoder) {
> > > +    this.gadgetTokenDecoder = gadgetTokenDecoder;
> > >  }
> > >
> > >  @Override
> > >
> > > Modified:
> > >
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/OpenSocialDataHandler.java
> > > URL:
> > > http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/
> > > src/main/java/org/apache/shindig/social/opensocial/OpenSocialDataHandler.java?rev=645947&r1=645946&r2=645947&view=diff
> > >
> > >
> > > ==============================================================================
> > > ---
> > >
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/OpenSocialDataHandler.java
> > > (original)
> > > +++
> > >
> > > incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/social/opensocial/OpenSocialDataHandler.java
> > > Tue Apr  8 07:42:54 2008
> > > @@ -38,6 +38,8 @@
> > >  import java.util.logging.Level;
> > >  import java.util.logging.Logger;
> > >
> > > +import com.google.inject.Inject;
> > > +
> > >  /**
> > >  * Servlet for serving the data required for opensocial.
> > >  * This will expand to be more sophisticated as time goes on.
> > > @@ -46,11 +48,17 @@
> > >  private static final Logger logger
> > >      = Logger.getLogger("org.apache.shindig.social");
> > >
> > > -  // TODO: get through injection
> > > -  private static PeopleService peopleHandler = new
> > > BasicPeopleService();
> > > -  private static DataService dataHandler = new BasicDataService();
> > > -  private static ActivitiesService activitiesHandler
> > > -      = new BasicActivitiesService();
> > > +  private PeopleService peopleHandler;
> > > +  private DataService dataHandler;
> > > +  private ActivitiesService activitiesHandler;
> > > +
> > > +  @Inject
> > > +  public OpenSocialDataHandler(PeopleService peopleHandler,
> > > +      DataService dataHandler, ActivitiesService activitiesHandler) {
> > > +    this.peopleHandler = peopleHandler;
> > > +    this.dataHandler = dataHandler;
> > > +    this.activitiesHandler = activitiesHandler;
> > > +  }
> > >
> > >  public enum OpenSocialDataType {
> > >    FETCH_PEOPLE,
> > >
> > > Modified:
> > > incubator/shindig/trunk/java/gadgets/src/main/webapp/WEB-INF/web.xml
> > > URL:
> > > http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/
> > > src/main/webapp/WEB-INF/web.xml?rev=645947&r1=645946&r2=645947&view=diff
> > >
> > >
> > > ==============================================================================
> > > ---
> > > incubator/shindig/trunk/java/gadgets/src/main/webapp/WEB-INF/web.xml
> > > (original)
> > > +++
> > > incubator/shindig/trunk/java/gadgets/src/main/webapp/WEB-INF/web.xml
> > > Tue Apr  8 07:42:54 2008
> > > @@ -63,13 +63,6 @@
> > >    <servlet-class>
> > >      org.apache.shindig.social.GadgetDataServlet
> > >    </servlet-class>
> > > -<!--
> > > -    <init-param>
> > > -      Add your custom classes that handle opensocial requests here
> > > -      <param-name>handlers</param-name>
> > > -      <parame-value>com.muysite.OpenSocialDataHandler</param-value>
> > > -    </init-param>
> > > --->
> > >  </servlet>
> > >
> > >  <!-- javascript serving -->
> > >
> > >
> > >
> > >
> >
> > --
> > ~Kevin
> >
>
>


-- 
~Kevin

Reply via email to