Package com.inspiresoftware.lib.dto.geda.adapter

Examples of com.inspiresoftware.lib.dto.geda.adapter.BeanFactory


        item3.setName("3");
        entity.getCollection().add(item1);
        entity.getCollection().add(item2);
        entity.getCollection().add(item3);

        final BeanFactory factory = new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                if ("TestEntity7CollectionSubClass".equals(entityBeanKey)) {
                    return TestEntity7CollectionSubClass.class;
                }
View Full Code Here


        item3.setName("3");
        entity.getCollection().add(item1);
        entity.getCollection().add(item2);
        entity.getCollection().add(item3);

        final BeanFactory factory = new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                return null;
            }
View Full Code Here

    final TestDto4ComplexClass dto = new TestDto4ComplexClass();
    final TestEntity4Class entity = new TestEntity4Class();
    entity.setWrapper(new TestEntity4SubClass());
    entity.getWrapper().setName("Name");

        final BeanFactory factory = new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                return null;
            }
View Full Code Here

  @Test
  public void testWrappedNullEntityProperty() throws GeDAException {
    final TestDto4ComplexClass dto = new TestDto4ComplexClass();
    final TestEntity4Class entity = new TestEntity4Class();

        final BeanFactory factory = new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                return null;
            }
View Full Code Here

  public void testDeepWrappedNullProperty() throws GeDAException {
    final TestDto5Class dto = new TestDto5Class();
    final TestEntity5Class entity = new TestEntity5Class();
    entity.setWrapper(new TestEntity4Class());
    entity.getWrapper().setWrapper(null);
    final BeanFactory beanFactory = new TestBeanFactory();
   
    final Assembler assembler =
      DTOAssembler.newCustomAssembler(TestDto5Class.class, TestEntity5Class.class, synthesizer);
   
    assembler.assembleDto(dto, entity, null, null);
View Full Code Here

  @Test
  public void testDeepWrappedDoubleNullProperty() throws GeDAException {
    final TestDto5Class dto = new TestDto5Class();
    final TestEntity5Class entity = new TestEntity5Class();
    entity.setWrapper(null);
    final BeanFactory beanFactory = new TestBeanFactory();
   
    final Assembler assembler =
      DTOAssembler.newCustomAssembler(TestDto5Class.class, TestEntity5Class.class, synthesizer);

    assembler.assembleDto(dto, entity, null, null);
View Full Code Here

    dto.setMyColl(coll);
    final Map<String, TestDto18aClass<String>> map = new HashMap<String, TestDto18aClass<String>>();
    map.put("m1", item);
    dto.setMyMap(map);
   
    assembler.assembleEntity(dto, entity, null, new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                return null;
            }

            public Object get(final String entityBeanKey) {
        return new TestEntity18aClass<String>();
      }
     
    });
   
    assertEquals("prop", entity.getMyProp());
   
    assertNotNull(entity.getMyColl());
    assertNotSame(dto.getMyColl(), entity.getMyColl());
    assertEquals(1, entity.getMyColl().size());
    assertEquals("item", entity.getMyColl().iterator().next().getMyProp());
   
    assertNotNull(entity.getMyMap());
    assertNotSame(dto.getMyMap(), entity.getMyMap());
    assertEquals(1, entity.getMyMap().size());
    assertEquals("item", entity.getMyMap().iterator().next().getMyProp());
   
    entity.setMyProp("e1");
    entity.getMyColl().iterator().next().setMyProp("ci1");
    entity.getMyMap().iterator().next().setMyProp("mi1");
   
    assembler.assembleDto(dto, entity, null, new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                return null;
            }
View Full Code Here

        final Assembler assembler = DTOAssembler.newCustomAssembler(dto.getClass(), entity.getClass(), synthesizer);

        final Map<String, Object> adapters = new HashMap<String, Object>();
        adapters.put("CatalogCodeMatcher", new CatalogCodeMatcher());

        assembler.assembleDto(dto, entity, adapters, new BeanFactory() {
            public Class getClazz(final String entityBeanKey) {
                if ("DtoCatalogCode".equals(entityBeanKey)) {
                    return TestDtoCatalogCodeClass.class;
                } else if ("DtoCode".equals(entityBeanKey)) {
                    return TestDtoCodeClass.class;
                } else if ("DtoCatalog".equals(entityBeanKey)) {
                    return TestDtoCatalogClass.class;
                }
                fail("Unknown DTO key: " + entityBeanKey);
                return null;
            }

            public Object get(final String entityBeanKey) {
                if ("DtoCatalogCode".equals(entityBeanKey)) {
                    return new TestDtoCatalogCodeClass();
                } else if ("DtoCode".equals(entityBeanKey)) {
                    return new TestDtoCodeClass();
                } else if ("DtoCatalog".equals(entityBeanKey)) {
                    return new TestDtoCatalogClass();
                }
                fail("Unknown DTO key: " + entityBeanKey);
                return null;
            }
        });

        assertEquals("ID-ABC", dto.getId());

        final TestDtoCodeClass dtoType = dto.getType();
        assertNotNull(dtoType);
        assertEquals("ID-123", dtoType.getId());
        assertEquals("CODE-AG1", dtoType.getCode());

        final Collection<TestDtoCodeClass> dtoCodes = dto.getCodes();
        assertNotNull(dtoCodes);
        assertFalse(dtoCodes.isEmpty());
        // The collection is actually an ArrayList, so we will cheat a little
        final List<TestDtoCodeClass> dtoCodesAsList = (List) dtoCodes;
        assertEquals(2, dtoCodesAsList.size());

        final TestDtoCodeClass dtoCode1 = dtoCodesAsList.get(0);
        assertNotNull(dtoCode1);
        assertEquals("ID-123", dtoCode1.getId());
        assertEquals("CODE-AG1", dtoCode1.getCode());

        final TestDtoCodeClass dtoCode2 = dtoCodesAsList.get(1);
        assertNotNull(dtoCode2);
        assertEquals("ID-235", dtoCode2.getId());
        assertEquals("CODE-DT1", dtoCode2.getCode());

        final TestEntityCatalog<TestEntityCatalogCode> entityCopy = new TestEntityCatalogClass<TestEntityCatalogCode>();

        assembler.assembleEntity(dto, entityCopy, adapters, new BeanFactory() {
            public Class getClazz(final String entityBeanKey) {
                if ("CatalogCode".equals(entityBeanKey)) {
                    return TestEntityCatalogCodeClass.class;
                } else if ("Catalog".equals(entityBeanKey)) {
                    return TestEntityCatalogClass.class;
View Full Code Here

    public <T> T assembleDto(final String dtoFilter,
                             final T dto,
                             final Object entity,
                             final Registry registry,
                             final String context) {
        final BeanFactory beanFactory = Registries.beanFactory(registry);
        final Class dtoClassFilter;
        if (dtoFilter == null) {
            dtoClassFilter = dto.getClass();
        } else {
            dtoClassFilter = beanFactory.getClazz(dtoFilter);
            if (dtoClassFilter == null) {
                throw new IllegalArgumentException("DTO factory has no class specified for key: " + dtoFilter);
            }
        }
        try {
View Full Code Here

                                 final Collection<T> dtos,
                                 final Collection entities,
                                 final Registry registry,
                                 final String context) {
        if (entities != null && !entities.isEmpty()) {
            final BeanFactory beanFactory = Registries.beanFactory(registry);
            final Class dtoClassFilter;
            if (dtoFilter == null) {
                dtoClassFilter = beanFactory.getClazz(keyDto);
                if (dtoClassFilter == null) {
                    throw new IllegalArgumentException("DTO factory has no class specified for key: " + keyDto);
                }
            } else {
                dtoClassFilter = beanFactory.getClazz(dtoFilter);
                if (dtoClassFilter == null) {
                    throw new IllegalArgumentException("DTO factory has no class specified for key: " + dtoFilter);
                }
            }
            final Class entityClass = entities.iterator().next().getClass();

            final Assembler asm = DTOAssembler.newCustomAssembler(dtoClassFilter, entityClass, classLoader.get(), registry, osgiJavassisstSynthesizer);

            for (final Object entity : entities) {
                final Object dto = beanFactory.get(keyDto);
                if (dto == null) {
                    throw new IllegalArgumentException("DTO factory has no class specified for key: " + keyDto);
                }
                try {
                    if (this.onDtoAssembly != null) {
View Full Code Here

TOP

Related Classes of com.inspiresoftware.lib.dto.geda.adapter.BeanFactory

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.