Example usage for org.springframework.core ResolvableType forClassWithGenerics

List of usage examples for org.springframework.core ResolvableType forClassWithGenerics

Introduction

In this page you can find the example usage for org.springframework.core ResolvableType forClassWithGenerics.

Prototype

public static ResolvableType forClassWithGenerics(Class<?> clazz, ResolvableType... generics) 

Source Link

Document

Return a ResolvableType for the specified Class with pre-declared generics.

Usage

From source file:net.radai.confusion.spring.SpringConfigurationChangedEvent.java

@Override
public ResolvableType getResolvableType() {
    return ResolvableType.forClassWithGenerics(getClass(), getConfigurationType());
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testPrototypeFactoryBeanIgnoredByNonEagerTypeMatching() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Properties p = new Properties();
    p.setProperty("x1.(class)", DummyFactory.class.getName());
    // Reset static state
    DummyFactory.reset();//from ww w. j a  va 2  s  . c o  m
    p.setProperty("x1.(singleton)", "false");
    p.setProperty("x1.singleton", "false");
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
    assertEquals(0, beanNames.length);
    beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
    assertEquals(0, beanNames.length);

    assertFalse(lbf.containsSingleton("x1"));
    assertTrue(lbf.containsBean("x1"));
    assertTrue(lbf.containsBean("&x1"));
    assertFalse(lbf.isSingleton("x1"));
    assertFalse(lbf.isSingleton("&x1"));
    assertTrue(lbf.isPrototype("x1"));
    assertTrue(lbf.isPrototype("&x1"));
    assertTrue(lbf.isTypeMatch("x1", TestBean.class));
    assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
    assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
    assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
    assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
    assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
    assertEquals(TestBean.class, lbf.getType("x1"));
    assertEquals(DummyFactory.class, lbf.getType("&x1"));
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testSingletonFactoryBeanIgnoredByNonEagerTypeMatching() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Properties p = new Properties();
    p.setProperty("x1.(class)", DummyFactory.class.getName());
    // Reset static state
    DummyFactory.reset();//from w  ww.j  a v a 2s .  com
    p.setProperty("x1.(singleton)", "false");
    p.setProperty("x1.singleton", "true");
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
    assertEquals(0, beanNames.length);
    beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
    assertEquals(0, beanNames.length);

    assertFalse(lbf.containsSingleton("x1"));
    assertTrue(lbf.containsBean("x1"));
    assertTrue(lbf.containsBean("&x1"));
    assertFalse(lbf.isSingleton("x1"));
    assertFalse(lbf.isSingleton("&x1"));
    assertTrue(lbf.isPrototype("x1"));
    assertTrue(lbf.isPrototype("&x1"));
    assertTrue(lbf.isTypeMatch("x1", TestBean.class));
    assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
    assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
    assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
    assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
    assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
    assertEquals(TestBean.class, lbf.getType("x1"));
    assertEquals(DummyFactory.class, lbf.getType("&x1"));
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testNonInitializedFactoryBeanIgnoredByNonEagerTypeMatching() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Properties p = new Properties();
    p.setProperty("x1.(class)", DummyFactory.class.getName());
    // Reset static state
    DummyFactory.reset();/* w  w w  . ja  va  2  s.  c  om*/
    p.setProperty("x1.singleton", "false");
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);

    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
    assertEquals(0, beanNames.length);
    beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
    assertEquals(0, beanNames.length);

    assertFalse(lbf.containsSingleton("x1"));
    assertTrue(lbf.containsBean("x1"));
    assertTrue(lbf.containsBean("&x1"));
    assertFalse(lbf.isSingleton("x1"));
    assertTrue(lbf.isSingleton("&x1"));
    assertTrue(lbf.isPrototype("x1"));
    assertFalse(lbf.isPrototype("&x1"));
    assertTrue(lbf.isTypeMatch("x1", TestBean.class));
    assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
    assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
    assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
    assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
    assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
    assertEquals(TestBean.class, lbf.getType("x1"));
    assertEquals(DummyFactory.class, lbf.getType("&x1"));
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testGetBeanWithArgsNotCreatedForFactoryBeanChecking() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd1 = new RootBeanDefinition(ConstructorDependency.class);
    bd1.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    lbf.registerBeanDefinition("bd1", bd1);
    RootBeanDefinition bd2 = new RootBeanDefinition(ConstructorDependencyFactoryBean.class);
    bd2.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    lbf.registerBeanDefinition("bd2", bd2);

    ConstructorDependency bean = lbf.getBean(ConstructorDependency.class, 42);
    assertThat(bean.beanName, equalTo("bd1"));
    assertThat(bean.spouseAge, equalTo(42));

    assertEquals(1, lbf.getBeanNamesForType(ConstructorDependency.class).length);
    assertEquals(1, lbf.getBeanNamesForType(ConstructorDependencyFactoryBean.class).length);
    assertEquals(1, lbf/* w  w  w.j ava  2  s . c  om*/
            .getBeanNamesForType(ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)).length);
    assertEquals(0, lbf
            .getBeanNamesForType(ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)).length);
}

From source file:org.springframework.cloud.function.web.RequestProcessor.java

public Mono<ResponseEntity<?>> post(FunctionWrapper wrapper, String body, boolean stream) {
    Object function = wrapper.handler();
    Class<?> inputType = this.inspector.getInputType(function);
    Type itemType = getItemType(function);

    Object input = body == null && inputType.isAssignableFrom(String.class) ? "" : body;

    if (input != null) {
        if (this.shouldUseJsonConversion((String) input, wrapper.headers.getContentType())) {
            Type jsonType = body.startsWith("[") && Collection.class.isAssignableFrom(inputType)
                    || body.startsWith("{") ? inputType : Collection.class;
            if (body.startsWith("[")) {
                jsonType = ResolvableType.forClassWithGenerics((Class<?>) jsonType, (Class<?>) itemType)
                        .getType();/*from w w w  .  jav  a 2  s .  com*/
            }
            input = this.mapper.toObject((String) input, jsonType);
        } else {
            input = this.converter.convert(function, (String) input);
        }
    }

    return response(wrapper, input, stream);
}

From source file:org.springframework.cloud.iot.coap.method.ResolvableMethod.java

private static ResolvableType toResolvableType(Class<?> type, Class<?>... generics) {
    return (ObjectUtils.isEmpty(generics) ? ResolvableType.forClass(type)
            : ResolvableType.forClassWithGenerics(type, generics));
}

From source file:org.springframework.cloud.iot.coap.method.ResolvableMethod.java

private static ResolvableType toResolvableType(Class<?> type, ResolvableType generic,
        ResolvableType... generics) {/*from  w  w  w  . j  a  va2 s.  c  o  m*/
    ResolvableType[] genericTypes = new ResolvableType[generics.length + 1];
    genericTypes[0] = generic;
    System.arraycopy(generics, 0, genericTypes, 1, generics.length);
    return ResolvableType.forClassWithGenerics(type, genericTypes);
}

From source file:org.springframework.security.web.method.ResolvableMethod.java

private static ResolvableType toResolvableType(Class<?> type, Class<?>... generics) {
    return ObjectUtils.isEmpty(generics) ? ResolvableType.forClass(type)
            : ResolvableType.forClassWithGenerics(type, generics);
}