Package org.apache.isis.applib.services.bookmark

Examples of org.apache.isis.applib.services.bookmark.BookmarkService


    @Override
    public void initialize(Object viewModelPojo, String mementoStr) {

        final MementoService mementoService = servicesInjector.lookupService(MementoService.class);
        final BookmarkService bookmarkService = servicesInjector.lookupService(BookmarkService.class);

        final MementoService.Memento memento = mementoService.parse(mementoStr);

        final Set<String> mementoKeys = memento.keySet();

        // manually recreate the adapter in order to be able to query state via the metamodel
        ObjectAdapter viewModelAdapter = adapterManager.getAdapterFor(viewModelPojo);
        if(viewModelAdapter == null) {
            final ObjectSpecification objectSpecification = specificationLoader.loadSpecification(viewModelPojo.getClass());
            final ObjectSpecId objectSpecId = objectSpecification.getSpecId();
            viewModelAdapter = adapterManager.mapRecreatedPojo(new RootOidDefault(objectSpecId, mementoStr, Oid.State.VIEWMODEL), viewModelPojo);
        }

        final ObjectSpecification spec = viewModelAdapter.getSpecification();
        final List<OneToOneAssociation> properties = spec.getProperties(Contributed.EXCLUDED);
        for (OneToOneAssociation property : properties) {
            final String propertyId = property.getId();

            Object propertyValue = null;

            if(mementoKeys.contains(propertyId)) {
                final Class<?> propertyType = property.getSpecification().getCorrespondingClass();
                propertyValue = memento.get(propertyId, propertyType);
            } else if(mementoKeys.contains(propertyId + ".bookmark")) {
                final Bookmark propertyValueBookmark = memento.get(propertyId + ".bookmark", Bookmark.class);
                propertyValue = bookmarkService.lookup(propertyValueBookmark);
            }

            if(propertyValue != null) {
                property.set(viewModelAdapter, adapterManager.adapterFor(propertyValue));
            }
View Full Code Here


   
    @Override
    public String memento(Object viewModelPojo) {

        final MementoService mementoService = servicesInjector.lookupService(MementoService.class);
        final BookmarkService bookmarkService = servicesInjector.lookupService(BookmarkService.class);

        final MementoService.Memento memento = mementoService.create();

        // this is horrible, but there's a catch-22 here...
        // we need an adapter in order to query the state of the object via the metamodel, on the other hand
        // we can't create an adapter without the identifier, which is what we're trying to derive
        // so... we create a temporary transient adapter, use it to wrap this adapter and interrogate this pojo,
        // then throw away that adapter (remove from the adapter map)
        boolean createdTemporaryAdapter = false;
        ObjectAdapter viewModelAdapter = adapterManager.getAdapterFor(viewModelPojo);
        if(viewModelAdapter == null) {
            final ObjectSpecification objectSpecification = specificationLoader.loadSpecification(viewModelPojo.getClass());
            final ObjectSpecId objectSpecId = objectSpecification.getSpecId();
            viewModelAdapter = adapterManager.mapRecreatedPojo(RootOidDefault.create(objectSpecId, UUID.randomUUID().toString()), viewModelPojo);

            createdTemporaryAdapter = true;
        }

        try {
            final ObjectSpecification spec = viewModelAdapter.getSpecification();
            final List<OneToOneAssociation> properties = spec.getProperties(Contributed.EXCLUDED);
            for (OneToOneAssociation property : properties) {
                // ignore read-only
                if(!property.containsDoOpFacet(PropertySetterFacet.class)) {
                    continue;
                }
                // ignore those explicitly annotated as @NotPersisted
                if(property.isNotPersisted()) {
                    continue;
                }

                // otherwise, include
                final ObjectAdapter propertyValueAdapter = property.get(adapterManager.adapterFor(viewModelPojo));
                if(propertyValueAdapter != null) {
                    final Object propertyValue = propertyValueAdapter.getObject();
                    if(mementoService.canSet(propertyValue)) {
                        memento.set(property.getId(), propertyValue);
                    } else {
                        final Bookmark propertyValueBookmark = bookmarkService.bookmarkFor(propertyValue);
                        memento.set(property.getId() + ".bookmark", propertyValueBookmark);
                    }
                }
            }
            return memento.asString();
View Full Code Here

TOP

Related Classes of org.apache.isis.applib.services.bookmark.BookmarkService

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.