This section describes key classes which are essential while using Slice. They constitute a base for a day-to-day development.
ModelProvider
The com.cognifide.slice.api.provider.ModelProvider
interface is a basic interface of Slice. It allows you to fetch an injectable object(s) mapped from specified resource or path. It's very similar to Guice com.google.inject.Injector
because it is used for fetching objects of different classes. However it's more Sling-related because it always takes resource (or path) as a parameter, so that an object of the specified class can be mapped. You should use ModelProvider
whenever there is a need for injecting a model mapped from a given resource (path).
ModelProvider
allows you to fetch either a single object of a specified class or a list of objects of a specified class. During execution of methods of this interface, the execution context is modified, meaning that the specified path is put on the top of the execution stack. This allows other objects to inject the specified resource (or path) and use it as a current resource. Read more about execution stack here.
Below table describes methods of the interface.
Method | Description |
---|---|
<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. |
ChildrenProvider
Link, LinkBuilder
...