@Test public void shouldAllocateObject() { DomainObjectAllocator allocator = new DomainObjectAllocator(MyADO.class); AbstractDomainObject object = allocator.allocateObject(MyDO.class, "xpto"); assertEquals(object.getClass(), MyDO.class); assertEquals(object.getExternalId(), "xpto"); }
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);  }