Coverage Report - org.apache.shindig.social.core.config.SocialApiGuiceModule
 
Classes in this File Line Coverage Branch Coverage Complexity
SocialApiGuiceModule
100%
11/11
N/A
0
SocialApiGuiceModule$1
100%
1/1
N/A
0
SocialApiGuiceModule$HandlerDispatcherProvider
0%
0/6
N/A
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements. See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership. The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License. You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied. See the License for the
 16  
  * specific language governing permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.apache.shindig.social.core.config;
 20  
 
 21  
 import org.apache.shindig.auth.AnonymousAuthenticationHandler;
 22  
 import org.apache.shindig.auth.AuthenticationHandler;
 23  
 import org.apache.shindig.common.servlet.ParameterFetcher;
 24  
 import org.apache.shindig.social.core.oauth.AuthenticationHandlerProvider;
 25  
 import org.apache.shindig.social.core.util.BeanJsonConverter;
 26  
 import org.apache.shindig.social.core.util.BeanXStreamAtomConverter;
 27  
 import org.apache.shindig.social.core.util.BeanXStreamConverter;
 28  
 import org.apache.shindig.social.opensocial.service.BeanConverter;
 29  
 import org.apache.shindig.social.opensocial.service.DataServiceServletFetcher;
 30  
 import org.apache.shindig.social.opensocial.service.StandardHandlerDispatcher;
 31  
 import org.apache.shindig.social.opensocial.service.HandlerDispatcher;
 32  
 import org.apache.shindig.social.sample.service.SampleContainerHandler;
 33  
 
 34  
 import com.google.inject.AbstractModule;
 35  
 import com.google.inject.Inject;
 36  
 import com.google.inject.Provider;
 37  
 import com.google.inject.TypeLiteral;
 38  
 import com.google.inject.name.Names;
 39  
 
 40  
 import java.util.List;
 41  
 
 42  
 /**
 43  
  * Provides social api component injection. Implementor may want to replace this module if they need
 44  
  * to replace some of the internals of the Social API, like for instance the JSON to Bean to JSON
 45  
  * converter Beans, however in general this should not be required, as most default implementations
 46  
  * have been specified with the Guice @ImplementedBy annotation.
 47  
  */
 48  2
 public class SocialApiGuiceModule extends AbstractModule {
 49  
 
 50  
   /** {@inheritDoc} */
 51  
   @Override
 52  
   protected void configure() {
 53  2
     bind(HandlerDispatcher.class).toProvider(HandlerDispatcherProvider.class);
 54  
 
 55  2
     bind(ParameterFetcher.class).annotatedWith(Names.named("DataServiceServlet"))
 56  
         .to(DataServiceServletFetcher.class);
 57  
 
 58  2
     bind(String.class).annotatedWith(Names.named("shindig.canonical.json.db"))
 59  
         .toInstance("sampledata/canonicaldb.json");
 60  
 
 61  2
     bind(Boolean.class)
 62  
         .annotatedWith(Names.named(AnonymousAuthenticationHandler.ALLOW_UNAUTHENTICATED))
 63  
         .toInstance(Boolean.TRUE);
 64  
 
 65  2
     bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.xml")).to(
 66  
         BeanXStreamConverter.class);
 67  2
     bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.json")).to(
 68  
         BeanJsonConverter.class);
 69  2
     bind(BeanConverter.class).annotatedWith(Names.named("shindig.bean.converter.atom")).to(
 70  
         BeanXStreamAtomConverter.class);
 71  
 
 72  2
     bind(new TypeLiteral<List<AuthenticationHandler>>(){}).toProvider(
 73  
         AuthenticationHandlerProvider.class);
 74  2
   }
 75  
 
 76  
   /**
 77  
    * Provider for the HandlerDispatcher.  Adds the sample container handler
 78  
    * at "samplecontainer".
 79  
    */
 80  0
   static class HandlerDispatcherProvider implements Provider<HandlerDispatcher> {
 81  
     private final HandlerDispatcher dispatcher;
 82  
 
 83  
     @Inject
 84  
     public HandlerDispatcherProvider(StandardHandlerDispatcher dispatcher,
 85  0
         Provider<SampleContainerHandler> sampleHandler) {
 86  0
       dispatcher.addHandler("samplecontainer", sampleHandler);
 87  0
       this.dispatcher = dispatcher;
 88  0
     }
 89  
 
 90  
     public HandlerDispatcher get() {
 91  0
       return dispatcher;
 92  
     }
 93  
   }
 94  
 }