@Test public void allocatorAbstractClasses() { final DomainObjectAllocator allocator = new DomainObjectAllocator(AbstractDO.class); boolean ok = false; try { allocator.allocateObject(AbstractDO.class, "xpto"); ok = true; } catch (final RuntimeException ex) { ok = false; } if (ok) { throw new AssertionError("Allocation of abstract class should fail."); } }
public <T extends AbstractDomainObject> T allocateObject(Class<T> objClass, Object oid) { if (objClass == null) { throw new RuntimeException("Cannot allocate object '" + oid + "'. Class not found"); } if (Modifier.isAbstract( objClass.getModifiers() )) { throw new RuntimeException("Cannot allocate object '" + oid + "'. Class is abstract"); } try { return getInstantiatorOf(objClass).newInstance(new OID(oid)); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException("Could not allocate object " + oid + " of class " + objClass.getName(), e); } }
DomainObjectAllocator { public <T extends AbstractDomainObject> T allocateObject(Class<T> objClass, Object oid) { if (objClass == null) { throw new RuntimeException("Cannot allocate object '" + oid + "'. Class not found"); } if (Modifier.isAbstract( objClass.getModifiers() )) { throw new RuntimeException("Cannot allocate object '" + oid + "'. Class is abstract"); } try { return getInstantiatorOf(objClass).newInstance(new OID(oid)); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException("Could not allocate object " + oid + " of class " + objClass.getName(), e); } } }
DomainObjectAllocator { public <T extends AbstractDomainObject> T allocateObject(Class<T> objClass, Object oid) { if (objClass == null) { throw new RuntimeException("Cannot allocate object '" + oid + "'. Class not found"); } if (Modifier.isAbstract( objClass.getModifiers() )) { throw new RuntimeException("Cannot allocate object '" + oid + "'. Class is abstract"); } try { return getInstantiatorOf(objClass).newInstance(new OID(oid)); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException("Could not allocate object " + oid + " of class " + objClass.getName(), e); } } DomainObjectAllocator(Class<?> baseType); }
DomainObjectAllocator { public <T extends AbstractDomainObject> T allocateObject(Class<T> objClass, Object oid) { if (objClass == null) { throw new RuntimeException("Cannot allocate object '" + oid + "'. Class not found"); } if (Modifier.isAbstract( objClass.getModifiers() )) { throw new RuntimeException("Cannot allocate object '" + oid + "'. Class is abstract"); } try { return getInstantiatorOf(objClass).newInstance(new OID(oid)); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException("Could not allocate object " + oid + " of class " + objClass.getName(), e); } } DomainObjectAllocator(Class<?> baseType); T allocateObject(Class<T> objClass, Object oid); }
DomainObjectAllocator { public <T extends AbstractDomainObject> T allocateObject(Class<T> objClass, Object oid) { if (objClass == null) { throw new RuntimeException("Cannot allocate object '" + oid + "'. Class not found"); } if (Modifier.isAbstract( objClass.getModifiers() )) { throw new RuntimeException("Cannot allocate object '" + oid + "'. Class is abstract"); } try { return getInstantiatorOf(objClass).newInstance(new OID(oid)); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new RuntimeException("Could not allocate object " + oid + " of class " + objClass.getName(), e); } } DomainObjectAllocator(Class<?> baseType); T allocateObject(Class<T> objClass, Object oid);  }