Package br.com.caelum.vraptor.ioc

Examples of br.com.caelum.vraptor.ioc.Container


    assertNotNull("can provide ServletContext", context);
  }

  @Test
  public void shouldProvideTheContainer() {
    Container itself = this.container.instanceFor(Container.class);
    assertNotNull("can provide the container", itself);
  }
View Full Code Here


  @Test
  public void shouldRemovePreviouslyRegisteredComponentIfRegisteringAgain() {
  provider.register(Base.class, MyFirstImplementation.class);
  provider.register(Base.class,MySecondImplementation.class);
  Container container = provider.provideRequestContainer(webRequest);
  Base instance = container.instanceFor(Base.class);
  assertThat(instance.getClass(), is(typeCompatibleWith(MySecondImplementation.class)));
  }
View Full Code Here

  @Test
  public void shouldRemovePreviouslyRegisteredComponentIfRegisteringAgainInAnotherScope() {
  provider.register(Base.class, MyFirstImplementation.class);
  provider.register(Base.class,AppImplementation.class);
  Container container = provider.provideRequestContainer(webRequest);
  Base instance = container.instanceFor(Base.class);
  assertThat(instance.getClass(), is(typeCompatibleWith(AppImplementation.class)));
  }
View Full Code Here

            OgnlContext ctx = (OgnlContext) context;
            String fieldName = ctx.getCurrentEvaluation().getPrevious().getNode().toString();
            Object origin = ctx.getCurrentEvaluation().getPrevious().getSource();
            Method setter = ReflectionBasedNullHandler.findMethod(origin.getClass(),
                    "set" + Info.capitalize(fieldName), origin.getClass(), null);
            Container container = (Container) context.get(Container.class);
            EmptyElementsRemoval removal = container.instanceFor(EmptyElementsRemoval.class);
            removal.add(array, setter, origin);
            try {
                setter.invoke(origin, array);
            } catch (IllegalArgumentException e) {
                // TODO better
View Full Code Here

    @SuppressWarnings("unchecked")
    public Object convertValue(Map context, Object target, Member member, String propertyName, Object value,
            Class toType) {
        Type genericType = genericTypeToConvert(target, member);
        Class type = rawTypeOf(genericType);
        Container container = (Container) context.get(Container.class);
        Converter<?> converter = converters.to(type, container);
        if (converter == null) {
            // TODO better, validation error?
            throw new IllegalArgumentException("Cannot instantiate a converter for type " + type.getName());
        }
View Full Code Here

            return null;
        }

        try {

            Container container = (Container) context.get(Container.class);
            if (target instanceof List) {
                return list.instantiate(container, target, property, ctx.getCurrentEvaluation().getPrevious());
            }

            String propertyCapitalized = Info.capitalize((String) property);
View Full Code Here

        if (!type.equals(String.class)) {
          // suckable ognl doesnt support dependency injection or
          // anything alike... just that suckable context... therefore
          // procedural
          // programming and ognl live together forever!
          Container container = (Container) context.get(Container.class);
          Converter<?> converter = container.instanceFor(Converters.class).to(type, container);
          ResourceBundle bundle = (ResourceBundle) context.get(ResourceBundle.class);
          Object result = converter.convert((String) value, type, bundle);
          super.setProperty(context, target, key, result);
          return;
        }
View Full Code Here

    private static final Logger logger = LoggerFactory.getLogger(PicoProvider.class);
  private final Container container;

    private final class AppScopedContainer implements Container {
    public <T> T instanceFor(Class<T> type) {
      Container container = containersByThread.get();
      if (container == null) {
        return picoContainer.getComponent(type);
      }
      return container.instanceFor(type);
    }
View Full Code Here

    jsonSerializers.add(new MessageGsonConverter());

    GsonSerializerBuilder gsonBuilder =  new GsonBuilderWrapper(new MockInstanceImpl<>(jsonSerializers), new MockInstanceImpl<>(jsonDeserializers), new Serializee());
    GsonJSONSerialization jsonSerialization = new GsonJSONSerialization(response, extractor, gsonBuilder, environment);

    Container container = mock(Container.class);
    when(container.instanceFor(JSONSerialization.class)).thenReturn(jsonSerialization);
    when(container.instanceFor(XMLSerialization.class)).thenReturn(xmlSerialization);

    ResourceBundle bundle = new SingletonResourceBundle("message.cat", "Just another {0} in {1}");
    serialization = new I18nMessageSerialization(container , bundle);
  }
View Full Code Here

TOP

Related Classes of br.com.caelum.vraptor.ioc.Container

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.