@Test(expected = IllegalArgumentException.class) public void shouldDenyMostInterfaces() throws Exception { handler.instantiate(TheInterface.class); }
public <T> T instantiate(Class<T> baseType) { if (baseType.isArray()) { return baseType.cast(Array.newInstance(baseType.getComponentType(), 0)); } Class<?> typeToInstantiate = baseType; if (baseType.isInterface() || Modifier.isAbstract(baseType.getModifiers())) { if (!CONCRETE_TYPES.containsKey(baseType)) { throw new IllegalArgumentException("Vraptor does not support this interface or abstract type: " + typeToInstantiate.getName()); } typeToInstantiate = CONCRETE_TYPES.get(baseType); } Object instance = new Mirror().on(typeToInstantiate).invoke().constructor().withoutArgs(); if(Collection.class.isAssignableFrom(typeToInstantiate)) { removal.add((Collection)instance); } return baseType.cast(instance); }
GenericNullHandler implements NullHandler { public <T> T instantiate(Class<T> baseType) { if (baseType.isArray()) { return baseType.cast(Array.newInstance(baseType.getComponentType(), 0)); } Class<?> typeToInstantiate = baseType; if (baseType.isInterface() || Modifier.isAbstract(baseType.getModifiers())) { if (!CONCRETE_TYPES.containsKey(baseType)) { throw new IllegalArgumentException("Vraptor does not support this interface or abstract type: " + typeToInstantiate.getName()); } typeToInstantiate = CONCRETE_TYPES.get(baseType); } Object instance = new Mirror().on(typeToInstantiate).invoke().constructor().withoutArgs(); if(Collection.class.isAssignableFrom(typeToInstantiate)) { removal.add((Collection)instance); } return baseType.cast(instance); } }
GenericNullHandler implements NullHandler { public <T> T instantiate(Class<T> baseType) { if (baseType.isArray()) { return baseType.cast(Array.newInstance(baseType.getComponentType(), 0)); } Class<?> typeToInstantiate = baseType; if (baseType.isInterface() || Modifier.isAbstract(baseType.getModifiers())) { if (!CONCRETE_TYPES.containsKey(baseType)) { throw new IllegalArgumentException("Vraptor does not support this interface or abstract type: " + typeToInstantiate.getName()); } typeToInstantiate = CONCRETE_TYPES.get(baseType); } Object instance = new Mirror().on(typeToInstantiate).invoke().constructor().withoutArgs(); if(Collection.class.isAssignableFrom(typeToInstantiate)) { removal.add((Collection)instance); } return baseType.cast(instance); } GenericNullHandler(EmptyElementsRemoval removal); }
GenericNullHandler implements NullHandler { public <T> T instantiate(Class<T> baseType) { if (baseType.isArray()) { return baseType.cast(Array.newInstance(baseType.getComponentType(), 0)); } Class<?> typeToInstantiate = baseType; if (baseType.isInterface() || Modifier.isAbstract(baseType.getModifiers())) { if (!CONCRETE_TYPES.containsKey(baseType)) { throw new IllegalArgumentException("Vraptor does not support this interface or abstract type: " + typeToInstantiate.getName()); } typeToInstantiate = CONCRETE_TYPES.get(baseType); } Object instance = new Mirror().on(typeToInstantiate).invoke().constructor().withoutArgs(); if(Collection.class.isAssignableFrom(typeToInstantiate)) { removal.add((Collection)instance); } return baseType.cast(instance); } GenericNullHandler(EmptyElementsRemoval removal); T instantiate(Class<T> baseType); }
GenericNullHandler implements NullHandler { public <T> T instantiate(Class<T> baseType) { if (baseType.isArray()) { return baseType.cast(Array.newInstance(baseType.getComponentType(), 0)); } Class<?> typeToInstantiate = baseType; if (baseType.isInterface() || Modifier.isAbstract(baseType.getModifiers())) { if (!CONCRETE_TYPES.containsKey(baseType)) { throw new IllegalArgumentException("Vraptor does not support this interface or abstract type: " + typeToInstantiate.getName()); } typeToInstantiate = CONCRETE_TYPES.get(baseType); } Object instance = new Mirror().on(typeToInstantiate).invoke().constructor().withoutArgs(); if(Collection.class.isAssignableFrom(typeToInstantiate)) { removal.add((Collection)instance); } return baseType.cast(instance); } GenericNullHandler(EmptyElementsRemoval removal); T instantiate(Class<T> baseType);  }