Package org.springframework.context

Examples of org.springframework.context.MessageSource


  protected abstract String getFormComponentLabel();
  protected abstract JComponent getFormComponentControl();
  protected abstract void applyChanges();
 
  protected String getMessage(String key){
    MessageSource messageSource = (MessageSource)ApplicationServicesLocator.services().getService(MessageSource.class);
    return messageSource.getMessage(key, new Object[]{}, Locale.getDefault());
  }
View Full Code Here


    public void testRegisteredServiceIsReturned() {
        ValueChangeDetector vcd = new DefaultValueChangeDetector();
        getApplicationServices().setValueChangeDetector(vcd);
        assertSame("Expected same object back", vcd, getApplicationServices().getService(ValueChangeDetector.class));

        MessageSource msrc = new StaticMessageSource();
        getApplicationServices().setMessageSource(msrc);
        assertSame("Expected same object back", msrc, getApplicationServices().getService(MessageSource.class));
    }
View Full Code Here

        }
    }

    public void testSetRegistryEntries() {
        ValueChangeDetector vcd = new DefaultValueChangeDetector();
        MessageSource msrc = new StaticMessageSource();

        HashMap entries = new HashMap();
        entries.put("org.springframework.binding.value.ValueChangeDetector", vcd);
        entries.put("org.springframework.context.MessageSource", msrc);
View Full Code Here

        .equals("This is a default msg if not found in theme cat."));
  }

  public void testThemeSourceNesting() throws NoSuchMessageException {
    String overriddenMsg = getThemeMessage("theme.example2", null, null, Locale.UK);
    MessageSource ms = ((ThemeSource) root).getTheme(AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME).getMessageSource();
    String originalMsg = ms.getMessage("theme.example2", null, Locale.UK);
    assertTrue("correct overridden msg", "test-message2".equals(overriddenMsg));
    assertTrue("correct original msg", "message2".equals(originalMsg));
  }
View Full Code Here

  public void testThemeSourceNestingWithParentDefault() throws NoSuchMessageException {
    StaticWebApplicationContext leaf = new StaticWebApplicationContext();
    leaf.setParent(getApplicationContext());
    leaf.refresh();
    assertNotNull("theme still found", leaf.getTheme("theme"));
    MessageSource ms = leaf.getTheme("theme").getMessageSource();
    String msg = ms.getMessage("theme.example2", null, null, Locale.UK);
    assertEquals("correct overridden msg", "test-message2", msg);
  }
View Full Code Here

  }

  public void testMessageSourceAware() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
        "/org/springframework/context/support/test/context*.xml");
    MessageSource messageSource = (MessageSource) ctx.getBean("messageSource");
    Service service1 = (Service) ctx.getBean("service");
    assertEquals(ctx, service1.getMessageSource());
    Service service2 = (Service) ctx.getBean("service2");
    assertEquals(ctx, service2.getMessageSource());
    AutowiredService autowiredService1 = (AutowiredService) ctx.getBean("autowiredService");
View Full Code Here

    assertEquals(13, beanCount);
    context.refresh();

    FooServiceImpl fooService = (FooServiceImpl) context.getBean("fooService");
    StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
    MessageSource ms = (MessageSource) context.getBean("messageSource");
    assertTrue(fooService.isInitCalled());
    assertEquals("bar", fooService.foo(123));
    assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory);
    assertEquals(2, fooService.listableBeanFactory.size());
    assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0));
View Full Code Here

    sac.registerSingleton("singletonFactoryToBeProxied", DummyFactory.class);
    sac.registerSingleton("autowiredIndexedTestBean", IndexedTestBean.class);

    sac.refresh();

    MessageSource messageSource = (MessageSource) sac.getBean("messageSource");
    ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
    assertFalse(Proxy.isProxyClass(messageSource.getClass()));
    assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass()));
    assertTrue(Proxy.isProxyClass(singletonToBeProxied.getSpouse().getClass()));

    // test whether autowiring succeeded with auto proxy creation
    assertEquals(sac.getBean("autowiredIndexedTestBean"), singletonToBeProxied.getNestedIndexedBean());
View Full Code Here

    sac.registerSingleton("singletonNoInterceptor", TestBean.class);
    sac.registerSingleton("singletonToBeProxied", TestBean.class);
    sac.registerPrototype("prototypeToBeProxied", TestBean.class);
    sac.refresh();

    MessageSource messageSource = (MessageSource) sac.getBean("messageSource");
    ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor");
    ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
    ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied");
    assertFalse(AopUtils.isCglibProxy(messageSource));
    assertTrue(AopUtils.isCglibProxy(singletonNoInterceptor));
View Full Code Here

  /**
   * Resolves messages.
   */
  private static class MessageSourcePropertyAccessor implements PropertyAccessor {
    public Object getProperty(Map context, Object target, Object name) throws OgnlException {
      MessageSource messageSource = (MessageSource) target;
      ExternalContext externalContext;
      Object root = Ognl.getRoot(context);
      if (root instanceof RequestContext) {
        externalContext = ((RequestContext) root).getExternalContext();
      } else {
        externalContext = ExternalContextHolder.getExternalContext();
      }
      if (externalContext != null) {
        return messageSource.getMessage(name.toString(), null, null, externalContext.getLocale());
      } else {
        return messageSource.getMessage(name.toString(), null, null, null);
      }
    }
View Full Code Here

TOP

Related Classes of org.springframework.context.MessageSource

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.