Interface ResourceFactory
- All Known Implementing Classes:
BndResourceFactory, CoreResourceFactory, EclipseResourceFactory, GitResourceFactory, JavaResourceFactory, MvnRepoResourceFactory
public interface ResourceFactory
Defines both an interface for factories that create
Resources and
factory methods for invoking an appropriate factory.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Map<ClassLoader, List<ResourceFactory>> The factories as found by theServiceLoader. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Resource>
Tcreate(ResourceType<T> type, Object... args) Short forcreate(type, null, args).static <T extends Resource>
Tcreate(ResourceType<T> type, Project project, Object... args) Returns a new resource with the given type, passing the given arguments to the constructor of the resource.newResource(ResourceType<T> type, Project project, Object... args) Returns a new resource of the given type if the factory instance can create it.
-
Field Details
-
FACTORIES
The factories as found by theServiceLoader.
-
-
Method Details
-
create
Returns a new resource with the given type, passing the given arguments to the constructor of the resource. The implementation uses
ServiceLoaderto find aResourceFactorythat creates the resource, i.e. that does not returnOptional.empty()when<T>newResource(org.jdrupes.builder.api.ResourceType<T>,org.jdrupes.builder.api.Project,java.lang.Object...)is called.The implementation uses
ServiceLoader.load(Class, ClassLoader)with the class loader of theProjectif provided, or the class loader of the current thread otherwise.- Type Parameters:
T- the generic resource type- Parameters:
type- the resource typeproject- the projectargs- the additional arguments- Returns:
- the resource
-
create
Short forcreate(type, null, args).- Type Parameters:
T- the generic resource type- Parameters:
type- the resource typeargs- the additional arguments- Returns:
- the resource
-
newResource
Returns a new resource of the given type if the factory instance can create it.- Type Parameters:
T- the generic resource type- Parameters:
type- the resource typeproject- the projectargs- the additional arguments- Returns:
- the result.
Optional.empty()if the resource cannot be created by the factory instance.
-