Package org.apache.isis.core.metamodel.facets.object.viewmodel

Examples of org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet


            final DomainObjectContainer container) throws IOException, InvalidFormatException {

        final List<T> viewModels = Lists.newArrayList();
       
        final ObjectSpecification objectSpec = specificationLoader.loadSpecification(cls);
        final ViewModelFacet viewModelFacet = objectSpec.getFacet(ViewModelFacet.class);

        if(viewModelFacet == null) {
            throw new IllegalArgumentException("Class '" + objectSpec.getCssClass() + "' is not a view model");
        }
       
        final ByteArrayInputStream bais = new ByteArrayInputStream(bs);
        final Workbook wb = org.apache.poi.ss.usermodel.WorkbookFactory.create(bais);
        final CellMarshaller cellMarshaller = newCellMarshaller(wb);

        final Sheet sheet = wb.getSheetAt(0);
       
        boolean header = true;
        final Map<Integer, Property> propertyByColumn = Maps.newHashMap();

        for(final Row row: sheet) {
            if(header) {
                for(final Cell cell: row) {
                    int columnIndex = cell.getColumnIndex();
                    final String propertyName = cellMarshaller.getStringCellValue(cell);
                    final OneToOneAssociation property = getAssociation(objectSpec, propertyName);
                    if(property != null) {
                        final Class<?> propertyType = property.getSpecification().getCorrespondingClass();
                        propertyByColumn.put(columnIndex, new Property(propertyName, property, propertyType));
                    }
                }
                header = false;
            } else {
                // detail

                // copy the row into the template object
                final T template = container.newTransientInstance(cls);
                final ObjectAdapter templateAdapter = adapterManager.adapterFor(template);
               
                for(final Cell cell: row) {
                    int columnIndex = cell.getColumnIndex();
                    final Property property = propertyByColumn.get(columnIndex);
                    if(property != null) {
                        final OneToOneAssociation otoa = property.getOneToOneAssociation();
                        final Object value = cellMarshaller.getCellValue(cell, otoa);
                        if(value != null) {
                            final ObjectAdapter valueAdapter = adapterManager.adapterFor(value);
                            otoa.set(templateAdapter, valueAdapter);
                        }
                    } else {
                        // not expected; just ignore.
                    }
                }
               
                final String memento = viewModelFacet.memento(template);
                final T viewModel = container.newViewModelInstance(cls, memento);
                viewModels.add(viewModel);
            }
        }
       
View Full Code Here


    public ObjectAdapter createViewModelInstance(ObjectSpecification objectSpec, String memento) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("creating view model instance of " + objectSpec);
        }
        final Object pojo = objectSpec.createObject();
        ViewModelFacet facet = objectSpec.getFacet(ViewModelFacet.class);
        facet.initialize(pojo, memento);
        final ObjectAdapter adapter = getAdapterManager().adapterFor(pojo);
        return objectSpec.initialize(adapter);
    }
View Full Code Here

TOP

Related Classes of org.apache.isis.core.metamodel.facets.object.viewmodel.ViewModelFacet

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.