Skip to contentPackage: Loadable
Loadable
Coverage
1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * blueMarine III: Semantic DAM
5: * http://tidalwave.it/projects/bluemarine3
6: *
7: * Copyright (C) 2024 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/bluemarine3-src
22: * git clone https://github.com/tidalwave-it/bluemarine3-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.dam.model.role;
27:
28: import jakarta.annotation.Nonnull;
29: import java.util.Optional;
30: import java.util.Set;
31: import java.io.IOException;
32: import it.tidalwave.dam.model.Entity;
33: import it.tidalwave.dam.model.MimeType;
34: import it.tidalwave.dam.model.io.FileEntity;
35: import it.tidalwave.util.As;
36:
37: /***************************************************************************************************************************************************************
38: *
39: * This role is capable to load an {@link Entity} from a {@link FileEntity}. It also provides the {@link MimeType} to {@link FileEntity} instances, provided
40: * that it is properly annotated, that is also associated to {@link FileEntity}.
41: *
42: * @stereotype Role
43: * @see Entity
44: * @see FileEntity
45: * @see it.tidalwave.dam.model.spi.role.LoadableSupport
46: * @author Fabrizio Giudici
47: *
48: **************************************************************************************************************************************************************/
49: public interface Loadable<T extends Entity>
50: {
51: public static final As.Type<Loadable<Entity>> _Loadable_ = As.type(Loadable.class);
52:
53: /***********************************************************************************************************************************************************
54: * {@return the set of supported file extensions}.
55: **********************************************************************************************************************************************************/
56: @Nonnull
57: public Set<String> getSupportedExtensions();
58:
59: /***********************************************************************************************************************************************************
60: * {@return the set of supported MIME types}.
61: **********************************************************************************************************************************************************/
62: @Nonnull
63: public Set<MimeType> getSupportedMimeTypes();
64:
65: /***********************************************************************************************************************************************************
66: * {@return a new instance loaded from the given file}.
67: * @param file the file
68: **********************************************************************************************************************************************************/
69: public T load (@Nonnull FileEntity file)
70: throws IOException;
71:
72: /***********************************************************************************************************************************************************
73: * {@return {@true} if this {@code Loadable} supports the given file}. By default the file extensions is checked, but subclasses might override this method
74: * and provide more sophisticated approaches, for instance inspecting contents.
75: * @param file the file
76: **********************************************************************************************************************************************************/
77: public default boolean probe (@Nonnull final FileEntity file)
78: {
79: return getSupportedExtensions().contains(file.getLcExtension());
80: }
81:
82: /***********************************************************************************************************************************************************
83: * {@return the MIME type of the given file}.
84: * @param file the file
85: **********************************************************************************************************************************************************/
86: @Nonnull
87: public Optional<MimeType> getMimeType (@Nonnull final FileEntity file);
88: }