Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

MethodDescription
<T> T get(final Class<T> type, final String path);

Creates an object of class type and maps it from a resource from under specified path

<T> T get(final Class<T> type, final Resource resource);Creates an object of class type and maps it from the resource
Object get(final String className, final String path) throws ClassNotFoundException;Creates an object of a class defined by specified className String and maps it from a resource from under specified path
<T> List<T> getList(final Class<T> type, final Iterator<String> paths);Creates a list of objects of class type and maps them accordingly from resources from under paths defined by paths interator.
<T> List<T> getList(final Class<T> type, final String[] paths);

Creates a list of objects of class type and maps them accordingly from resources from under paths defined by paths array.

ModelProvider can be injected to your models, so that you can read a model from an arbitrary resource or path, e.g.:

Code Block
import com.cognifide.app.util.Currency;

import com.cognifide.slice.api.provider.ModelProvider;
import com.cognifide.slice.mapper.annotation.JcrProperty;
import com.cognifide.slice.mapper.annotation.SliceResource;
import com.google.inject.Inject;

@SliceResource
public class OrderModel {

    private final static String CONFIGURATION_PATH = "/content/app/configuration/jcr:content/currency";

    private final ModelProvider modelProvider;

    @JcrProperty
    private int value;

    @Inject
    public OrderModel(ModelProvider modelProvider) {
        this.modelProvider = modelProvider;
    }

    public int getValue() {
        Currency currency = modelProvider.get(Currency.class, CONFIGURATION_PATH);
        return formatToCurrency(value, currency);
    }
    ...
}

 

ChildrenProvider

Link, LinkBuilder

...